aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-02-05 08:38:16 -0800
committerH.J. Lu <hjl.tools@gmail.com>2018-02-05 08:38:16 -0800
commitcd04836359da82ae1dc67e5a05565536f4427b51 (patch)
treefc72f6593a58e26174caadbfe9515204901fb318 /bfd/elf64-x86-64.c
parentUse visitors for make_gdb_type (diff)
downloadbinutils-gdb-cd04836359da82ae1dc67e5a05565536f4427b51.tar.gz
binutils-gdb-cd04836359da82ae1dc67e5a05565536f4427b51.tar.bz2
binutils-gdb-cd04836359da82ae1dc67e5a05565536f4427b51.zip
x86: Remove the unused _GLOBAL_OFFSET_TABLE_
Since _GLOBAL_OFFSET_TABLE_ may be referenced implicitly on x86, checking ref_regular_nonweak leaves the unused _GLOBAL_OFFSET_TABLE_ in output. This patch checks explicit GOT references instead. ld-i386/discarded1.s and ld-x86-64/discarded1.s are updated to avoid linker optimization which removes GOT references. bfd/ PR ld/22782 * elf32-i386.c (elf_i386_check_relocs): Set got_referenced if _GLOBAL_OFFSET_TABLE_ is referenced or GOT is needed to resolve undefined weak symbol to 0. * elf64-x86-64.c (elf_x86_64_check_relocs): Set got_referenced if _GLOBAL_OFFSET_TABLE_ is referenced. * elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Check got_referenced instead of ref_regular_nonweak. Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol table. * elfxx-x86.h (elf_x86_link_hash_table): Add got_referenced. ld/ PR ld/22782 * testsuite/ld-i386/discarded1.s: Replace mov with div. * testsuite/ld-x86-64/discarded1.s: Likewise. * testsuite/ld-i386/i386.exp: Run pr22782. * testsuite/ld-i386/load1-nacl.d: Updated for removing _GLOBAL_OFFSET_TABLE_ from output. * testsuite/ld-i386/load1.d: Likewise. * testsuite/ld-x86-64/load1a-nacl.d: Likewise. * testsuite/ld-x86-64/load1a.d: Likewise. * testsuite/ld-x86-64/load1b-nacl.d: Likewise. * testsuite/ld-x86-64/load1b.d: Likewise. * testsuite/ld-i386/pr22782.d: New file. * testsuite/ld-i386/pr22782.s: Likewise. * testsuite/ld-x86-64/pr22782.s: Likewise. * testsuite/ld-x86-64/pr22782a.d: Likewise. * testsuite/ld-x86-64/pr22782b.d: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run pr22782a and pr22782b.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r--bfd/elf64-x86-64.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index ba4f47bff46..aad9b852961 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1927,6 +1927,10 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
rel, rel_end, h, r_symndx, FALSE))
goto error_return;
+ /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */
+ if (h == htab->elf.hgot)
+ htab->got_referenced = TRUE;
+
eh = (struct elf_x86_link_hash_entry *) h;
switch (r_type)
{