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 /bfd/elfxx-aarch64.c | |
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 'bfd/elfxx-aarch64.c')
-rw-r--r-- | bfd/elfxx-aarch64.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 33af6c2..1f69280 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -395,10 +395,12 @@ _bfd_aarch64_elf_put_addend (bfd *abfd, } bfd_vma -_bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type, +_bfd_aarch64_elf_resolve_relocation (bfd *input_bfd, + bfd_reloc_code_real_type r_type, bfd_vma place, bfd_vma value, bfd_vma addend, bfd_boolean weak_undef_p) { + bfd_boolean tls_reloc = TRUE; switch (r_type) { case BFD_RELOC_AARCH64_NONE: @@ -446,6 +448,8 @@ _bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type, case BFD_RELOC_AARCH64_MOVW_G2_NC: case BFD_RELOC_AARCH64_MOVW_G2_S: case BFD_RELOC_AARCH64_MOVW_G3: + tls_reloc = FALSE; + /* fall-through. */ case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: @@ -466,6 +470,15 @@ _bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type, case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12: case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12: case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12: + /* Weak Symbols and TLS relocations are implementation defined. For this + case we choose to emit 0. */ + if (weak_undef_p && tls_reloc) + { + _bfd_error_handler (_("%pB: warning: Weak TLS is implementation " + "defined and may not work as expected"), + input_bfd); + value = place; + } value = value + addend; break; |