diff options
author | Tamar Christina <tamar.christina@arm.com> | 2019-08-22 11:35:35 +0100 |
---|---|---|
committer | Tamar Christina <tamar.christina@arm.com> | 2019-08-22 11:43:15 +0100 |
commit | 652afeef247770b22c44ca292d1f4c65be40a696 (patch) | |
tree | 67dbfe62d2b3c87351b844f745f4363b1b0bb512 /ld/testsuite | |
parent | b20d385926d84f7daa8cd7c54f748f3d6a81bfc6 (diff) | |
download | gdb-652afeef247770b22c44ca292d1f4c65be40a696.zip gdb-652afeef247770b22c44ca292d1f4c65be40a696.tar.gz gdb-652afeef247770b22c44ca292d1f4c65be40a696.tar.bz2 |
AArch64: Fix LD crash on weak and undefined TLS symbols. (PR/24602).
This patch fixes a few linker crashes due to TLS code reaching an assert when it
shouldn't.
The first scenario is with weak TLS symbols that remain weak during linking. In
this case the mid-end would not have seen a TLS symbol and so wouldn't have
allocated the TLS section. We currently assert here and the linker crashes with
a not very useful message.
This patch changes this to return the value 0 for the TLS symbol in question
emulating what lld and gold and other BFD targets do. However because weak TLS
is implementation defined and we don't define any behavior for it I also emit a
warning to the user to inform them of such.
Secondly when a strong TLS reference is undefined. The linker crashes even after
it correctly reported that there is an undefined reference. This changes it so
that it gracefully exits and reports a useful error.
bfd/ChangeLog:
PR ld/24601
* elfnn-aarch64.c (aarch64_relocate): Handle weak TLS and undefined TLS.
Also Pass input_bfd to _bfd_aarch64_elf_resolve_relocation.
* elfxx-aarch64.c (_bfd_aarch64_elf_resolve_relocation): Use it.
* elfxx-aarch64.h (_bfd_aarch64_elf_resolve_relocation): Emit warning
for weak TLS.
ld/ChangeLog:
PR ld/24601
* testsuite/ld-aarch64/aarch64-elf.exp (undef-tls, weak-tls): New.
* testsuite/ld-aarch64/undef-tls.d: New test.
* testsuite/ld-aarch64/undef-tls.s: New test.
* testsuite/ld-aarch64/weak-tls.d: New test.
* testsuite/ld-aarch64/weak-tls.s: New test.
Diffstat (limited to 'ld/testsuite')
-rw-r--r-- | ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/undef-tls.d | 17 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/undef-tls.s | 13 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/weak-tls.d | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/weak-tls.s | 16 |
5 files changed, 56 insertions, 0 deletions
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index ab8d152..631fde0 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -424,3 +424,5 @@ run_dump_test "bti-pac-plt-1" run_dump_test "bti-pac-plt-2" run_dump_test "bti-warn" +run_dump_test "weak-tls" +run_dump_test "undef-tls" diff --git a/ld/testsuite/ld-aarch64/undef-tls.d b/ld/testsuite/ld-aarch64/undef-tls.d new file mode 100644 index 0000000..8b43ca4 --- /dev/null +++ b/ld/testsuite/ld-aarch64/undef-tls.d @@ -0,0 +1,17 @@ +#source: undef-tls.s +#ld: -e0 --emit-relocs +#objdump: -dr +#... +#error:.*: in function `get':.* +#error:.*: undefined reference to `tls'.* +#error:.*: TLS relocation R_AARCH64_TLSLE_ADD_TPREL_HI12 against undefined symbol `tls'.* +#error:.*: dangerous relocation: unsupported relocation.* +#error:.*: undefined reference to `tls'.* +#error:.*: TLS relocation R_AARCH64_TLSLE_ADD_TPREL_LO12_NC against undefined symbol `tls'.* +#error:.*: dangerous relocation: unsupported relocation.* +#error:.*: undefined reference to `dtl'.* +#error:.*: TLS relocation R_AARCH64_TLSLD_ADD_DTPREL_HI12 against undefined symbol `dtl'.* +#error:.*: dangerous relocation: unsupported relocation.* +#error:.*: undefined reference to `dtl'.* +#error:.*: TLS relocation R_AARCH64_TLSLD_ADD_DTPREL_LO12 against undefined symbol `dtl'.* +#error:.*: dangerous relocation: unsupported relocation.* diff --git a/ld/testsuite/ld-aarch64/undef-tls.s b/ld/testsuite/ld-aarch64/undef-tls.s new file mode 100644 index 0000000..6d57afb --- /dev/null +++ b/ld/testsuite/ld-aarch64/undef-tls.s @@ -0,0 +1,13 @@ + .global get + .type get, %function +get: +.LFB0: + mrs x0, tpidr_el0 + add x0, x0, #:tprel_hi12:tls, lsl #12 + add x0, x0, #:tprel_lo12_nc:tls + add x0, x0, #:dtprel_hi12:dtl + add x0, x0, #:dtprel_lo12:dtl + ret +.LFE0: + .size get, .-get + diff --git a/ld/testsuite/ld-aarch64/weak-tls.d b/ld/testsuite/ld-aarch64/weak-tls.d new file mode 100644 index 0000000..a826940 --- /dev/null +++ b/ld/testsuite/ld-aarch64/weak-tls.d @@ -0,0 +1,8 @@ +#source: weak-tls.s +#ld: -e0 --emit-relocs +#objdump: -dr +#... +#error:.*: warning: Weak TLS is implementation defined and may not work as expected.* +#error:.*: warning: Weak TLS is implementation defined and may not work as expected.* +#error:.*: in function `get':.* +#error:.*: relocation truncated to fit: R_AARCH64_TLSLD_ADD_DTPREL_LO12 against undefined symbol `dtl'.* diff --git a/ld/testsuite/ld-aarch64/weak-tls.s b/ld/testsuite/ld-aarch64/weak-tls.s new file mode 100644 index 0000000..3520a85 --- /dev/null +++ b/ld/testsuite/ld-aarch64/weak-tls.s @@ -0,0 +1,16 @@ + .global get + .type get, %function + .global dtl + .weak dtl +get: +.LFB0: + mrs x0, tpidr_el0 + add x0, x0, #:tprel_hi12:tls, lsl #12 + add x0, x0, #:tprel_lo12_nc:tls + add x0, x0, #:dtprel_hi12:dtl + add x0, x0, #:dtprel_lo12:dtl + ret +.LFE0: + .size get, .-get + .weak tls + |