This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[committed] MIPS/BFD: Also handle `jalr $0, $25' with R_MIPS_JALR
- From: "Maciej W. Rozycki" <macro at imgtec dot com>
- To: <binutils at sourceware dot org>
- Date: Tue, 28 Feb 2017 00:24:51 +0000
- Subject: [committed] MIPS/BFD: Also handle `jalr $0, $25' with R_MIPS_JALR
- Authentication-results: sourceware.org; auth=none
Interpret the `jalr $0, $25' instruction encoding with an R_MIPS_JALR
relocation attached as an alias to `jr $25' and convert the jump to an
equivalent branch where possible, consequently covering the MIPSr6
architecture for the purpose of this optimization too.
bfd/
* elfxx-mips.c (mips_elf_perform_relocation): Also handle the
`jalr $0, $25' instruction encoding.
gas/
* testsuite/gas/mips/jalr4.s: Add `jalr $0, $25' instructions.
* testsuite/gas/mips/jalr4.d: Adjust accordingly. Remove MIPSr6
encoding patterns.
* testsuite/gas/mips/jalr4-n64.d: Likewise.
* testsuite/gas/mips/mipsr6@jalr4.d: New test.
* testsuite/gas/mips/mipsr6@jalr4-n32.d: New test.
* testsuite/gas/mips/mipsr6@jalr4-n64.d: New test.
ld/
* testsuite/ld-mips-elf/jalr4.dd: Adjust for `jalr $0, $25'
instructions.
* testsuite/ld-mips-elf/jalr4-r6.dd: New test.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
---
binutils-mips-bfd-jalr-zero-to-b.diff
Index: binutils/bfd/elfxx-mips.c
===================================================================
--- binutils.orig/bfd/elfxx-mips.c 2017-02-27 17:22:11.416575448 +0000
+++ binutils/bfd/elfxx-mips.c 2017-02-27 17:22:15.359774808 +0000
@@ -6465,13 +6465,13 @@ mips_elf_perform_relocation (struct bfd_
&& !cross_mode_jump_p
&& ((JAL_TO_BAL_P (input_bfd)
&& r_type == R_MIPS_26
- && (x >> 26) == 0x3) /* jal addr */
+ && (x >> 26) == 0x3) /* jal addr */
|| (JALR_TO_BAL_P (input_bfd)
&& r_type == R_MIPS_JALR
- && x == 0x0320f809) /* jalr t9 */
+ && x == 0x0320f809) /* jalr t9 */
|| (JR_TO_B_P (input_bfd)
&& r_type == R_MIPS_JALR
- && x == 0x03200008))) /* jr t9 */
+ && (x & ~1) == 0x03200008))) /* jr t9 / jalr zero, t9 */
{
bfd_vma addr;
bfd_vma dest;
@@ -6488,7 +6488,7 @@ mips_elf_perform_relocation (struct bfd_
off = dest - addr;
if (off <= 0x1ffff && off >= -0x20000)
{
- if (x == 0x03200008) /* jr t9 */
+ if ((x & ~1) == 0x03200008) /* jr t9 / jalr zero, t9 */
x = 0x10000000 | (((bfd_vma) off >> 2) & 0xffff); /* b addr */
else
x = 0x04110000 | (((bfd_vma) off >> 2) & 0xffff); /* bal addr */
Index: binutils/gas/testsuite/gas/mips/jalr4-n64.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/jalr4-n64.d 2017-02-27 20:30:53.587161360 +0000
+++ binutils/gas/testsuite/gas/mips/jalr4-n64.d 2017-02-27 20:30:59.743067596 +0000
@@ -11,7 +11,12 @@
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 0320000[89] jr t9
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200008 jr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar0
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
@@ -21,7 +26,12 @@
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 0320000[89] jr t9
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200008 jr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar1
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
@@ -31,7 +41,12 @@
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 0320000[89] jr t9
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200008 jr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar2
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
Index: binutils/gas/testsuite/gas/mips/jalr4.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/jalr4.d 2017-02-27 20:30:53.531344445 +0000
+++ binutils/gas/testsuite/gas/mips/jalr4.d 2017-02-27 20:30:59.750094710 +0000
@@ -9,19 +9,28 @@
[0-9a-f]+ <[^>]*> 0320f809 jalr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar0
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 0320000[89] jr t9
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200008 jr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar0
[0-9a-f]+ <[^>]*> 00000000 nop
[0-9a-f]+ <[^>]*> 0320f809 jalr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar1
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 0320000[89] jr t9
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200008 jr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar1
[0-9a-f]+ <[^>]*> 00000000 nop
[0-9a-f]+ <[^>]*> 0320f809 jalr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar2
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 0320000[89] jr t9
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200008 jr t9
[ ]*[0-9a-f]+: R_MIPS_JALR bar2
[0-9a-f]+ <[^>]*> 00000000 nop
\.\.\.
Index: binutils/gas/testsuite/gas/mips/jalr4.s
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/jalr4.s 2017-02-27 20:30:53.513063200 +0000
+++ binutils/gas/testsuite/gas/mips/jalr4.s 2017-02-27 20:30:59.758183231 +0000
@@ -8,14 +8,20 @@
.reloc 1f, R_MIPS_JALR, bar0
1: jalr $25
.reloc 1f, R_MIPS_JALR, bar0
+1: jalr $0, $25
+ .reloc 1f, R_MIPS_JALR, bar0
1: jr $25
.reloc 1f, R_MIPS_JALR, bar1
1: jalr $25
.reloc 1f, R_MIPS_JALR, bar1
+1: jalr $0, $25
+ .reloc 1f, R_MIPS_JALR, bar1
1: jr $25
.reloc 1f, R_MIPS_JALR, bar2
1: jalr $25
.reloc 1f, R_MIPS_JALR, bar2
+1: jalr $0, $25
+ .reloc 1f, R_MIPS_JALR, bar2
1: jr $25
.end foo
Index: binutils/gas/testsuite/gas/mips/mipsr6@jalr4-n32.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mipsr6@jalr4-n32.d 2017-02-27 20:30:59.778267890 +0000
@@ -0,0 +1,5 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JALR reloc unaligned/cross-mode (n32)
+#as: -n32
+#source: jalr4.s
+#dump: mipsr6@jalr4.d
Index: binutils/gas/testsuite/gas/mips/mipsr6@jalr4-n64.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mipsr6@jalr4-n64.d 2017-02-27 20:30:59.818910046 +0000
@@ -0,0 +1,57 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JALR reloc unaligned/cross-mode (n64)
+#as: -64
+#source: jalr4.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 nop
+ \.\.\.
+ \.\.\.
+ \.\.\.
+ \.\.\.
Index: binutils/gas/testsuite/gas/mips/mipsr6@jalr4.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mipsr6@jalr4.d 2017-02-27 20:30:59.838119529 +0000
@@ -0,0 +1,39 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS JALR reloc unaligned/cross-mode (o32)
+#as: -32
+#source: jalr4.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar0
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar1
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[ ]*[0-9a-f]+: R_MIPS_JALR bar2
+[0-9a-f]+ <[^>]*> 00000000 nop
+ \.\.\.
+ \.\.\.
+ \.\.\.
+ \.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/jalr4-r6.dd
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/jalr4-r6.dd 2017-02-27 20:30:59.869396929 +0000
@@ -0,0 +1,25 @@
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 04110017 bal 0+000060 <bar0>
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 10000015 b 0+000060 <bar0>
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 10000013 b 0+000060 <bar0>
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 0320f809 jalr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jr t9
+[0-9a-f]+ <[^>]*> 00000000 nop
+ \.\.\.
+ \.\.\.
+ \.\.\.
+ \.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/jalr4.dd
===================================================================
--- binutils.orig/ld/testsuite/ld-mips-elf/jalr4.dd 2017-02-27 20:30:53.427681948 +0000
+++ binutils/ld/testsuite/ld-mips-elf/jalr4.dd 2017-02-27 20:30:59.875535105 +0000
@@ -1,16 +1,22 @@
.*: +file format .*mips.*
Disassembly of section \.text:
-[0-9a-f]+ <[^>]*> 0411000f bal 0+000040 <bar0>
+[0-9a-f]+ <[^>]*> 04110017 bal 0+000060 <bar0>
[0-9a-f]+ <[^>]*> 00000000 nop
-[0-9a-f]+ <[^>]*> 1000000d b 0+000040 <bar0>
+[0-9a-f]+ <[^>]*> 10000015 b 0+000060 <bar0>
+[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 10000013 b 0+000060 <bar0>
[0-9a-f]+ <[^>]*> 00000000 nop
[0-9a-f]+ <[^>]*> 0320f809 jalr t9
[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[0-9a-f]+ <[^>]*> 00000000 nop
[0-9a-f]+ <[^>]*> 03200008 jr t9
[0-9a-f]+ <[^>]*> 00000000 nop
[0-9a-f]+ <[^>]*> 0320f809 jalr t9
[0-9a-f]+ <[^>]*> 00000000 nop
+[0-9a-f]+ <[^>]*> 03200009 jalr zero,t9
+[0-9a-f]+ <[^>]*> 00000000 nop
[0-9a-f]+ <[^>]*> 03200008 jr t9
[0-9a-f]+ <[^>]*> 00000000 nop
\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- binutils.orig/ld/testsuite/ld-mips-elf/mips-elf.exp 2017-02-27 20:30:53.489714268 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips-elf.exp 2017-02-27 20:30:59.889727282 +0000
@@ -1006,6 +1006,17 @@ foreach { abi } $abis {
"$abi_asflags($abi)" \
[list ../../../gas/testsuite/gas/mips/jalr4.s] \
[list "objdump {-d --prefix-addresses --show-raw-insn} jalr4.dd"] \
+ "jalr4-${abi}"] \
+ [list \
+ "MIPSr6 JALR reloc unaligned/cross-mode link test ($abi)" \
+ "$abi_ldflags($abi) -T jalr3.ld" "" \
+ [string map \
+ [list -32 "-mips32r6 -32" \
+ -n32 "-mips64r6 -n32" \
+ -64 "-mips64r6 -64"] \
+ [regsub -- -march=from-abi $abi_asflags($abi) ""]] \
+ {../../../gas/testsuite/gas/mips/jalr4.s} \
+ {{objdump {-d --prefix-addresses --show-raw-insn} jalr4-r6.dd}} \
"jalr4-${abi}"]]
}