Created attachment 7795 [details]
Hi while developing gold for aarch64, we found a case (attached) that overflows relocation R_AARCH64_TLSLE_ADD_TPREL_HI12, because the offset from TP (thread pointer) is too large (bigger than 2^24). Instead of generating an error, the bfd aarch64 linker silently truncates the higher bits of offset, leading to a run time error.
To reproduce, just compile -
gcc -O0 case.c
The exit value is 7, but the correct value should be 0.
The relocations to compute tp-offset of "i" is at 400600 and 400604, which is apparently not "10".
4005fc: d53bd040 mrs x0, tpidr_el0
400600: 91400000 add x0, x0, #0x0, lsl #12
400604: 91004000 add x0, x0, #0x10
400608: b9400000 ldr w0, [x0]
40060c: 910043ff add sp, sp, #0x10
400610: d65f03c0 ret
This was observed on trunk as well as 2.24.
The master branch has been updated by Jiong Wang <firstname.lastname@example.org>:
Author: Jiong Wang <email@example.com>
Date: Tue Jan 13 11:18:10 2015 +0000
[AArch64] Enable overflow check for R_AARCH64_TLSLE_ADD_TPREL_HI12
* elfnn-aarch64.c (elfNN_aarch64_howto_table): Mark
R_AARCH64_TLSLE_ADD_TPREL_HI12 as complain_overflow_unsigned.
* elfxx-aarch64.c (_bfd_aarch64_elf_resolve_relocation): Correct the bit
* ld-aarch64/pr17415.s: Source file for new test.
* ld-aarch64/pr17415.d: Expect file for new test.
* ld-aarch64/aarch64-elf.exp: Run the new test.