* [PATCH] MIPS: Use R_MICROMIPS_JALR rather than R_MIPS_JALR in microMIPS code
@ 2016-11-23 12:40 Maciej W. Rozycki
2016-11-23 17:49 ` Joseph Myers
0 siblings, 1 reply; 3+ messages in thread
From: Maciej W. Rozycki @ 2016-11-23 12:40 UTC (permalink / raw)
To: libc-alpha; +Cc: Joseph S. Myers
In a microMIPS compilation of `.init' code use the R_MICROMIPS_JALR
relocation intended for PIC call relaxation in microMIPS code rather
than the corresponding R_MIPS_JALR relocation meant for regular MIPS
code only.
* sysdeps/mips/mips32/crti.S (JALR_RELOC): New macro.
(_init): Use it in place of hardcoded R_MIPS_JALR.
* sysdeps/mips/mips64/n32/crti.S (JALR_RELOC): New macro.
(_init): Use it in place of hardcoded R_MIPS_JALR.
* sysdeps/mips/mips64/n64/crti.S (JALR_RELOC): New macro.
(_init): Use it in place of hardcoded R_MIPS_JALR.
---
No regressions with the `mips-mti-linux-gnu' target in o32 regular MIPS
and microMIPS multilib testing and neither in n32 and n64 regular MIPS
multilib testing.
OK to apply?
Maciej
glibc-umips-jalr.diff
Index: glibc/sysdeps/mips/mips32/crti.S
===================================================================
--- glibc.orig/sysdeps/mips/mips32/crti.S 2016-11-17 15:28:32.000000000 +0000
+++ glibc/sysdeps/mips/mips32/crti.S 2016-11-17 15:36:52.838901381 +0000
@@ -40,6 +40,12 @@
#include <libc-symbols.h>
+#ifdef __mips_micromips
+# define JALR_RELOC R_MICROMIPS_JALR
+#else
+# define JALR_RELOC R_MIPS_JALR
+#endif
+
#ifndef PREINIT_FUNCTION
# define PREINIT_FUNCTION __gmon_start__
#endif
@@ -71,13 +77,13 @@
lw $2,%got(PREINIT_FUNCTION)($28)
beq $2,$0,.Lno_weak_fn
lw $25,%call16(PREINIT_FUNCTION)($28)
- .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION
+ .reloc 1f,JALR_RELOC,PREINIT_FUNCTION
1: jalr $25
.Lno_weak_fn:
.insn
#else
lw $25,%got(PREINIT_FUNCTION)($28)
- .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION
+ .reloc 1f,JALR_RELOC,PREINIT_FUNCTION
1: jalr $25
#endif
Index: glibc/sysdeps/mips/mips64/n32/crti.S
===================================================================
--- glibc.orig/sysdeps/mips/mips64/n32/crti.S 2016-11-17 15:30:48.000000000 +0000
+++ glibc/sysdeps/mips/mips64/n32/crti.S 2016-11-17 15:37:17.195020438 +0000
@@ -40,6 +40,12 @@
#include <libc-symbols.h>
+#ifdef __mips_micromips
+# define JALR_RELOC R_MICROMIPS_JALR
+#else
+# define JALR_RELOC R_MIPS_JALR
+#endif
+
#ifndef PREINIT_FUNCTION
# define PREINIT_FUNCTION __gmon_start__
#endif
@@ -71,13 +77,13 @@
lw $2,%got_disp(PREINIT_FUNCTION)($28)
beq $2,$0,.Lno_weak_fn
lw $25,%call16(PREINIT_FUNCTION)($28)
- .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION
+ .reloc 1f,JALR_RELOC,PREINIT_FUNCTION
1: jalr $25
.Lno_weak_fn:
.insn
#else
lw $25,%got_disp(PREINIT_FUNCTION)($28)
- .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION
+ .reloc 1f,JALR_RELOC,PREINIT_FUNCTION
1: jalr $25
#endif
Index: glibc/sysdeps/mips/mips64/n64/crti.S
===================================================================
--- glibc.orig/sysdeps/mips/mips64/n64/crti.S 2016-11-17 15:30:56.000000000 +0000
+++ glibc/sysdeps/mips/mips64/n64/crti.S 2016-11-17 15:38:09.690102763 +0000
@@ -40,6 +40,12 @@
#include <libc-symbols.h>
+#ifdef __mips_micromips
+# define JALR_RELOC R_MICROMIPS_JALR
+#else
+# define JALR_RELOC R_MIPS_JALR
+#endif
+
#ifndef PREINIT_FUNCTION
# define PREINIT_FUNCTION __gmon_start__
#endif
@@ -71,13 +77,13 @@
ld $2,%got_disp(PREINIT_FUNCTION)($28)
beq $2,$0,.Lno_weak_fn
ld $25,%call16(PREINIT_FUNCTION)($28)
- .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION
+ .reloc 1f,JALR_RELOC,PREINIT_FUNCTION
1: jalr $25
.Lno_weak_fn:
.insn
#else
ld $25,%got_disp(PREINIT_FUNCTION)($28)
- .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION
+ .reloc 1f,JALR_RELOC,PREINIT_FUNCTION
1: jalr $25
#endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MIPS: Use R_MICROMIPS_JALR rather than R_MIPS_JALR in microMIPS code
2016-11-23 12:40 [PATCH] MIPS: Use R_MICROMIPS_JALR rather than R_MIPS_JALR in microMIPS code Maciej W. Rozycki
@ 2016-11-23 17:49 ` Joseph Myers
2016-11-23 18:28 ` Maciej W. Rozycki
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2016-11-23 17:49 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: libc-alpha
On Wed, 23 Nov 2016, Maciej W. Rozycki wrote:
> In a microMIPS compilation of `.init' code use the R_MICROMIPS_JALR
> relocation intended for PIC call relaxation in microMIPS code rather
> than the corresponding R_MIPS_JALR relocation meant for regular MIPS
> code only.
>
> * sysdeps/mips/mips32/crti.S (JALR_RELOC): New macro.
> (_init): Use it in place of hardcoded R_MIPS_JALR.
> * sysdeps/mips/mips64/n32/crti.S (JALR_RELOC): New macro.
> (_init): Use it in place of hardcoded R_MIPS_JALR.
> * sysdeps/mips/mips64/n64/crti.S (JALR_RELOC): New macro.
> (_init): Use it in place of hardcoded R_MIPS_JALR.
> ---
> No regressions with the `mips-mti-linux-gnu' target in o32 regular MIPS
> and microMIPS multilib testing and neither in n32 and n64 regular MIPS
> multilib testing.
>
> OK to apply?
OK.
It would probably make sense to add at least one mips16 and one microMIPS
configuration to build-many-glibcs.py so build failures for such
configurations are more readily detected (though I suppose a wrong
relocation like this might not result in a build failure?).
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MIPS: Use R_MICROMIPS_JALR rather than R_MIPS_JALR in microMIPS code
2016-11-23 17:49 ` Joseph Myers
@ 2016-11-23 18:28 ` Maciej W. Rozycki
0 siblings, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2016-11-23 18:28 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
On Wed, 23 Nov 2016, Joseph Myers wrote:
> > OK to apply?
>
> OK.
Applied, thanks.
> It would probably make sense to add at least one mips16 and one microMIPS
> configuration to build-many-glibcs.py so build failures for such
> configurations are more readily detected (though I suppose a wrong
> relocation like this might not result in a build failure?).
In the R_MIPS_JALR case BFD linker code checks the opcode of the
instruction at the relocation location so that JALR and JR (for tail
calls) are substituted with BAL and J respectively, and the microMIPS
encodings are different, so no match happens and an invalid relocation is
silently ignored. So no build failure will ever happen indeed.
The R_MICROMIPS_JALR case is more complicated and currently not handled
by the BFD linker at all, with the relocation always silently ignored,
though I plan to get to it sometime. Most transformations are limited by
the assymetry of the 16-bit instruction set, however some can still be
made, e.g. JR16 can be changed into B16, and all can still be made in the
`-minsn32' mode (which is however hardly ever used). This is probably the
reason why it hasn't been implemented with the original microMIPS effort.
I have no idea what GOLD does with these relocations, although I suppose
any handling will have been semantically copied from the BFD linker.
Maciej
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-23 18:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23 12:40 [PATCH] MIPS: Use R_MICROMIPS_JALR rather than R_MIPS_JALR in microMIPS code Maciej W. Rozycki
2016-11-23 17:49 ` Joseph Myers
2016-11-23 18:28 ` Maciej W. Rozycki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).