From cefdd1cd64f3b67aba1b219547b8f895c22d48ed Mon Sep 17 00:00:00 2001 From: Igor Kudrin Date: Mon, 28 Aug 2017 08:03:00 -0700 Subject: Fix bad offset calculation for R_AARCH64_TLSDESC_* relocs. If a custom linker script with an unexpected relative layout of .got and .got.plt sections was used, gold might produce a wrong offset when applying R_AARCH64_TLSDESC_* relocations. This patch fixes the issue by calculating "got_tlsdesc_offset" in a more direct way. gold/ * aarch64.cc (Target_aarch64::Relocate::relocate_tls): Make got_tlsdesc_offset signed and fix its calculation. * testsuite/Makefile.am (aarch64_tlsdesc): New test. * testsuite/Makefile.in: Regenerate. * testsuite/aarch64_tlsdesc.s: New test source file. * testsuite/aarch64_tlsdesc.sh: New test script. * testsuite/aarch64_tlsdesc.t: New test linker script. --- gold/aarch64.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gold/aarch64.cc') diff --git a/gold/aarch64.cc b/gold/aarch64.cc index 58c744967a5..2194a21de2a 100644 --- a/gold/aarch64.cc +++ b/gold/aarch64.cc @@ -7563,15 +7563,15 @@ Target_aarch64::Relocate::relocate_tls( tls_got_offset_type = (tlsopt == tls::TLSOPT_TO_IE ? GOT_TYPE_TLS_OFFSET : GOT_TYPE_TLS_DESC); - unsigned int got_tlsdesc_offset = 0; + int got_tlsdesc_offset = 0; if (r_type != elfcpp::R_AARCH64_TLSDESC_CALL && tlsopt == tls::TLSOPT_NONE) { // We created GOT entries in the .got.tlsdesc portion of the // .got.plt section, but the offset stored in the symbol is the // offset within .got.tlsdesc. - got_tlsdesc_offset = (target->got_->data_size() - + target->got_plt_section()->data_size()); + got_tlsdesc_offset = (target->got_tlsdesc_->address() + - target->got_->address()); } typename elfcpp::Elf_types::Elf_Addr got_entry_address; if (gsym != NULL) -- cgit v1.2.1