diff mbox

MIPS: Use R_MICROMIPS_JALR rather than R_MIPS_JALR in microMIPS code

Message ID alpine.DEB.2.20.17.1611231217350.10580@tp.orcam.me.uk
State Accepted
Headers show

Commit Message

Maciej W. Rozycki Nov. 23, 2016, 12:39 p.m. UTC
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

Comments

Joseph Myers Nov. 23, 2016, 5:49 p.m. UTC | #1
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?).
Maciej W. Rozycki Nov. 23, 2016, 6:28 p.m. UTC | #2
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
diff mbox

Patch

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