diff options
author | Maciej W. Rozycki <macro@imgtec.com> | 2016-07-12 01:31:29 +0100 |
---|---|---|
committer | Maciej W. Rozycki <macro@imgtec.com> | 2016-07-14 20:11:03 +0100 |
commit | b416ba9b5079a54585d4d508f0a514b98f701221 (patch) | |
tree | 1de23b3a6ecefd76a5e5bd84cbdbc631f23ffba2 /ld | |
parent | 96e9ba5fbba2e1e8fcafd8576d0a98738a0fbc49 (diff) | |
download | gdb-b416ba9b5079a54585d4d508f0a514b98f701221.zip gdb-b416ba9b5079a54585d4d508f0a514b98f701221.tar.gz gdb-b416ba9b5079a54585d4d508f0a514b98f701221.tar.bz2 |
MIPS/GAS: Don't convert PC-relative REL relocs against absolute symbols
Don't convert PC-relative REL relocations against absolute symbols to
section-relative references and retain the original symbol reference
instead. Offsets into the absolute section may overflow the limited
range of their in-place addend field, causing an assembly error, e.g.:
$ cat test.s
.text
.globl foo
.ent foo
foo:
b bar
.end foo
.set bar, 0x12345678
$ as -EB -32 -o test.o test.s
test.s: Assembler messages:
test.s:3: Error: relocation overflow
$
With the original reference retained the source can now be assembled and
linked successfully:
$ as -EB -32 -o test.o test.s
$ objdump -dr test.o
test.o: file format elf32-tradbigmips
Disassembly of section .text:
00000000 <foo>:
0: 1000ffff b 0 <foo>
0: R_MIPS_PC16 bar
4: 00000000 nop
...
$ ld -melf32btsmip -Ttext 0x12340000 -e foo -o test test.o
$ objdump -dr test
test: file format elf32-tradbigmips
Disassembly of section .text:
12340000 <foo>:
12340000: 1000159d b 12345678 <bar>
12340004: 00000000 nop
...
$
For simplicity always retain the original symbol reference, even if it
would indeed fit.
Making TC_FORCE_RELOCATION_ABS separate from TC_FORCE_RELOCATION causes
R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1 and R_MICROMIPS_PC16_S1 branch
relocations against absolute symbols to be converted on RELA targets to
section-relative references. This is an intended effect of this change.
Absolute symbols carry no ISA annotation in their `st_other' field and
their value is not going to change with linker relaxation, so it is safe
to discard the original reference and keep the calculated final symbol
value only in the relocation's addend.
Similarly R6 R_MIPS_PCHI16 and R_MIPS_PCLO16 relocations referring
absolute symbols can be safely converted even on REL targets, as there
the in-place addend of these relocations covers the entire 32-bit
address space so it can hold the calculated final symbol value, and
likewise the value referred won't be affected by any linker relaxation.
Add a set of suitable test cases and enable REL linker tests which now
work and were previously used as dump patterns for RELA tests only.
gas/
* config/tc-mips.h (TC_FORCE_RELOCATION_ABS): New macro.
(mips_force_relocation_abs): New prototype.
* config/tc-mips.c (mips_force_relocation_abs): New function.
* testsuite/gas/mips/branch-absolute.d: Adjust dump patterns.
* testsuite/gas/mips/mips16-branch-absolute.d: Likewise.
* testsuite/gas/mips/micromips-branch-absolute-n32.d: Likewise.
* testsuite/gas/mips/micromips-branch-absolute-n64.d: Likewise.
* testsuite/gas/mips/micromips-branch-absolute-addend-n32.d:
Likewise.
* testsuite/gas/mips/micromips-branch-absolute-addend-n64.d:
Likewise.
* testsuite/gas/mips/branch-absolute-addend.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-addend.d: New test.
* testsuite/gas/mips/micromips-branch-absolute-addend.d: New
test.
* testsuite/gas/mips/mips.exp: Run the new tests.
ld/
* testsuite/ld-mips-elf/mips-elf.exp: Run
`branch-absolute-addend', `mips16-branch-absolute',
`mips16-branch-absolute-addend' and
`micromips-branch-absolute-addend'.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-mips-elf/mips-elf.exp | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 1f8a499..250d076 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,12 @@ 2016-07-14 Maciej W. Rozycki <macro@imgtec.com> + * testsuite/ld-mips-elf/mips-elf.exp: Run + `branch-absolute-addend', `mips16-branch-absolute', + `mips16-branch-absolute-addend' and + `micromips-branch-absolute-addend'. + +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. diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp index cca6695..5c417c7 100644 --- a/ld/testsuite/ld-mips-elf/mips-elf.exp +++ b/ld/testsuite/ld-mips-elf/mips-elf.exp @@ -144,6 +144,7 @@ run_dump_test "mips16-1" run_dump_test "branch-misc-1" run_dump_test "branch-misc-2" run_dump_test "branch-absolute" [list [list ld $abi_ldflags(o32)]] +run_dump_test "branch-absolute-addend" [list [list ld $abi_ldflags(o32)]] if $has_newabi { run_dump_test "branch-absolute-n32" [list [list ld $abi_ldflags(n32)]] run_dump_test "branch-absolute-addend-n32" \ @@ -157,6 +158,9 @@ 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)]] +run_dump_test "mips16-branch-absolute" [list [list ld $abi_ldflags(o32)]] +run_dump_test "mips16-branch-absolute-addend" \ + [list [list ld $abi_ldflags(o32)]] if $has_newabi { run_dump_test "mips16-branch-absolute-n32" \ [list [list ld $abi_ldflags(n32)]] @@ -169,6 +173,8 @@ if $has_newabi { } run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]] +run_dump_test "micromips-branch-absolute-addend" \ + [list [list ld $abi_ldflags(o32)]] if $has_newabi { run_dump_test "micromips-branch-absolute-n32" \ [list [list ld $abi_ldflags(n32)]] |