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/elfnn-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/elfnn-aarch64.c')
-rw-r--r-- | bfd/elfnn-aarch64.c | 83 |
1 files changed, 63 insertions, 20 deletions
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 4e6cbc9..fd44505 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -3004,7 +3004,8 @@ aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, + offset); r_type = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type); - value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE); + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, r_type, place, + value, 0, FALSE); return _bfd_aarch64_elf_put_addend (input_bfd, input_section->contents + offset, r_type, howto, value) == bfd_reloc_ok; @@ -5585,7 +5586,8 @@ bad_ifunc_reloc: /* FALLTHROUGH */ case BFD_RELOC_AARCH64_CALL26: case BFD_RELOC_AARCH64_JUMP26: - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, signed_addend, weak_undef_p); return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, @@ -5662,7 +5664,8 @@ bad_ifunc_reloc: addend = (globals->root.sgot->output_section->vma + globals->root.sgot->output_offset); - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, addend, weak_undef_p); return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value); case BFD_RELOC_AARCH64_ADD_LO12: @@ -5840,7 +5843,8 @@ bad_ifunc_reloc: signed_addend = 0; } } - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, signed_addend, weak_undef_p); *unresolved_reloc_p = FALSE; break; @@ -5900,7 +5904,8 @@ bad_ifunc_reloc: case BFD_RELOC_AARCH64_MOVW_G2_S: case BFD_RELOC_AARCH64_MOVW_G3: case BFD_RELOC_AARCH64_TSTBR14: - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, signed_addend, weak_undef_p); break; @@ -5945,7 +5950,8 @@ bad_ifunc_reloc: if (aarch64_relocation_aginst_gp_p (bfd_r_type)) addend = (globals->root.sgot->output_section->vma + globals->root.sgot->output_offset); - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, addend, weak_undef_p); } else @@ -5992,7 +5998,8 @@ bad_ifunc_reloc: if (aarch64_relocation_aginst_gp_p (bfd_r_type)) addend = base_got->output_section->vma + base_got->output_offset; - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, addend, weak_undef_p); } @@ -6029,7 +6036,8 @@ bad_ifunc_reloc: + globals->root.sgot->output_section->vma + globals->root.sgot->output_offset); - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, 0, weak_undef_p); *unresolved_reloc_p = FALSE; break; @@ -6042,7 +6050,8 @@ bad_ifunc_reloc: return bfd_reloc_notsupported; value = symbol_got_offset (input_bfd, h, r_symndx); - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, 0, weak_undef_p); *unresolved_reloc_p = FALSE; break; @@ -6063,10 +6072,26 @@ bad_ifunc_reloc: case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, - signed_addend - dtpoff_base (info), - weak_undef_p); - break; + { + if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) + { + int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB: TLS relocation %s against undefined symbol `%s'"), + input_bfd, elfNN_aarch64_howto_table[howto_index].name, + h->root.root.string); + bfd_set_error (bfd_error_bad_value); + return bfd_reloc_notsupported; + } + + bfd_vma def_value + = weak_undef_p ? 0 : signed_addend - dtpoff_base (info); + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, + def_value, weak_undef_p); + break; + } case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: @@ -6084,11 +6109,27 @@ bad_ifunc_reloc: case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, - signed_addend - tpoff_base (info), - weak_undef_p); - *unresolved_reloc_p = FALSE; - break; + { + if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) + { + int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB: TLS relocation %s against undefined symbol `%s'"), + input_bfd, elfNN_aarch64_howto_table[howto_index].name, + h->root.root.string); + bfd_set_error (bfd_error_bad_value); + return bfd_reloc_notsupported; + } + + bfd_vma def_value + = weak_undef_p ? 0 : signed_addend - tpoff_base (info); + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, + def_value, weak_undef_p); + *unresolved_reloc_p = FALSE; + break; + } case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: @@ -6103,7 +6144,8 @@ bad_ifunc_reloc: + globals->root.sgotplt->output_offset + globals->sgotplt_jump_table_size); - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, 0, weak_undef_p); *unresolved_reloc_p = FALSE; break; @@ -6121,7 +6163,8 @@ bad_ifunc_reloc: value -= (globals->root.sgot->output_section->vma + globals->root.sgot->output_offset); - value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, + place, value, 0, weak_undef_p); *unresolved_reloc_p = FALSE; break; |