aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@imgtec.com>2016-07-12 01:30:48 +0100
committerMaciej W. Rozycki <macro@imgtec.com>2016-07-14 20:08:59 +0100
commit96e9ba5fbba2e1e8fcafd8576d0a98738a0fbc49 (patch)
tree91f9cf9e54974d3b879edba4fbaf7bb82fdb3b06 /ld
parent0c117286270e8166022900f4e5fef89719ccd2dc (diff)
downloadgdb-96e9ba5fbba2e1e8fcafd8576d0a98738a0fbc49.zip
gdb-96e9ba5fbba2e1e8fcafd8576d0a98738a0fbc49.tar.gz
gdb-96e9ba5fbba2e1e8fcafd8576d0a98738a0fbc49.tar.bz2
MIPS/GAS: Keep the ISA bit in the addend of branch relocations
Correct a problem with the ISA bit being stripped from the addend of compressed branch relocations, affecting RELA targets. It has been there since microMIPS support has been added, with: commit df58fc944dbc6d5efd8d3826241b64b6af22f447 Author: Richard Sandiford <rdsandiford@googlemail.com> Date: Sun Jul 24 14:20:15 2011 +0000 <https://sourceware.org/ml/binutils/2011-07/msg00198.html>, ("MIPS: microMIPS ASE support") and R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1 and R_MICROMIPS_PC16_S1 relocations originally affected, and the R_MIPS16_PC16_S1 relocation recently added with commit c9775dde3277 ("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support") actually triggering a linker error, due to its heightened processing strictness level: $ cat test.s .text .set mips16 foo: b bar .set bar, 0x1235 .align 4, 0 $ as -EB -n32 -o test.o test.s $ objdump -dr test.o test.o: file format elf32-ntradbigmips Disassembly of section .text: 00000000 <foo>: 0: f000 1000 b 4 <foo+0x4> 0: R_MIPS16_PC16_S1 *ABS*+0x1230 ... $ ld -melf32btsmipn32 -Ttext 0 -e 0 -o test test.o test.o: In function `foo': (.text+0x0): Branch to a non-instruction-aligned address $ This is because the ISA bit of the branch target does not match the ISA bit of the referring branch, hardwired to 1 of course. Retain the ISA bit then, so that the linker knows this is really MIPS16 code referred: $ objdump -dr fixed.o fixed.o: file format elf32-ntradbigmips Disassembly of section .text: 00000000 <foo>: 0: f000 1000 b 4 <foo+0x4> 0: R_MIPS16_PC16_S1 *ABS*+0x1231 ... $ ld -melf32btsmipn32 -Ttext 0 -e 0 -o fixed fixed.o $ Add a set of MIPS16 tests to cover the relevant cases, excluding linker tests though which would overflow the in-place addend on REL targets and use them as dump patterns for RELA targets only. gas/ * config/tc-mips.c (md_apply_fix) <BFD_RELOC_MIPS16_16_PCREL_S1> <BFD_RELOC_MICROMIPS_7_PCREL_S1, BFD_RELOC_MICROMIPS_10_PCREL_S1> <BFD_RELOC_MICROMIPS_16_PCREL_S1>: Keep the ISA bit in the addend calculated. * testsuite/gas/mips/mips16-branch-absolute.s: Set the ISA bit in `bar', export `foo'. * testsuite/gas/mips/mips16-branch-absolute.d: Adjust accordingly. * testsuite/gas/mips/mips16-branch-absolute-n32.d: Likewise. * testsuite/gas/mips/mips16-branch-absolute-n64.d: Likewise. * testsuite/gas/mips/mips16-branch-absolute-addend-n32.d: Likewise. * testsuite/gas/mips/mips16-branch-absolute-addend-n64.d: Likewise. ld/ * testsuite/ld-mips-elf/mips16-branch-absolute.d: New test. * testsuite/ld-mips-elf/mips16-branch-absolute-n32.d: New test. * testsuite/ld-mips-elf/mips16-branch-absolute-n64.d: New test. * testsuite/ld-mips-elf/mips16-branch-absolute-addend.d: New test. * testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d: New test. * testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d: New test. * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests, except from `mips16-branch-absolute' and `mips16-branch-absolute-addend', referred indirectly only.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog15
-rw-r--r--ld/testsuite/ld-mips-elf/mips-elf.exp10
-rw-r--r--ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d6
-rw-r--r--ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d6
-rw-r--r--ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend.d17
-rw-r--r--ld/testsuite/ld-mips-elf/mips16-branch-absolute-n32.d6
-rw-r--r--ld/testsuite/ld-mips-elf/mips16-branch-absolute-n64.d6
-rw-r--r--ld/testsuite/ld-mips-elf/mips16-branch-absolute.d17
8 files changed, 83 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 640b36f..1f8a499 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,20 @@
2016-07-14 Maciej W. Rozycki <macro@imgtec.com>
+ * testsuite/ld-mips-elf/mips16-branch-absolute.d: New test.
+ * testsuite/ld-mips-elf/mips16-branch-absolute-n32.d: New test.
+ * testsuite/ld-mips-elf/mips16-branch-absolute-n64.d: New test.
+ * testsuite/ld-mips-elf/mips16-branch-absolute-addend.d: New
+ test.
+ * testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d: New
+ test.
+ * testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d: New
+ test.
+ * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests, except
+ from `mips16-branch-absolute' and
+ `mips16-branch-absolute-addend', referred indirectly only.
+
+2016-07-14 Maciej W. Rozycki <macro@imgtec.com>
+
* testsuite/ld-mips-elf/branch-absolute.d: New test.
* testsuite/ld-mips-elf/branch-absolute-n32.d: New test.
* testsuite/ld-mips-elf/branch-absolute-n64.d: New test.
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index 21867f1..cca6695 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -157,6 +157,16 @@ run_dump_test "mips16-branch-2" [list [list ld $abi_ldflags(o32)]]
run_dump_test "mips16-branch-3" [list [list ld $abi_ldflags(o32)]]
run_dump_test "mips16-branch-addend-2" [list [list ld $abi_ldflags(o32)]]
run_dump_test "mips16-branch-addend-3" [list [list ld $abi_ldflags(o32)]]
+if $has_newabi {
+ run_dump_test "mips16-branch-absolute-n32" \
+ [list [list ld $abi_ldflags(n32)]]
+ run_dump_test "mips16-branch-absolute-addend-n32" \
+ [list [list ld $abi_ldflags(n32)]]
+ run_dump_test "mips16-branch-absolute-n64" \
+ [list [list ld $abi_ldflags(n64)]]
+ run_dump_test "mips16-branch-absolute-addend-n64" \
+ [list [list ld $abi_ldflags(n64)]]
+}
run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]]
if $has_newabi {
diff --git a/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d
new file mode 100644
index 0000000..69c37c1
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression with addend (n32)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: mips16-branch-absolute-addend.d
diff --git a/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d
new file mode 100644
index 0000000..d6047b9
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression with addend (n64)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: mips16-branch-absolute-addend.d
diff --git a/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend.d b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend.d
new file mode 100644
index 0000000..2427b9a
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend.d
@@ -0,0 +1,17 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression with addend
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
+#as: -EB -32
+#ld: -EB -Ttext 0x12340000 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+ \.\.\.
+[0-9a-f]+ <[^>]*> f445 1014 b 0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 6012 bteqz 0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 6110 btnez 0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 220e beqz v0,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 2a0c bnez v0,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 6500 nop
+ \.\.\.
diff --git a/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n32.d b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n32.d
new file mode 100644
index 0000000..7bff198
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n32.d
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression (n32)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: mips16-branch-absolute.d
diff --git a/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n64.d b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n64.d
new file mode 100644
index 0000000..6edb58d
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n64.d
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression (n64)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: mips16-branch-absolute.d
diff --git a/ld/testsuite/ld-mips-elf/mips16-branch-absolute.d b/ld/testsuite/ld-mips-elf/mips16-branch-absolute.d
new file mode 100644
index 0000000..eac08fa
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/mips16-branch-absolute.d
@@ -0,0 +1,17 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute.s
+#as: -EB -32
+#ld: -EB -Ttext 0 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+ \.\.\.
+[0-9a-f]+ <[^>]*> f100 1018 b 0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 6016 bteqz 0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 6114 btnez 0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 2212 beqz v0,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 2a10 bnez v0,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 6500 nop
+ \.\.\.