summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2018-07-03 12:18:10 +0930
committerAlan Modra <amodra@gmail.com>2018-07-13 01:16:25 +0930
commitae0e76dcfcb7a8d2d8b5cbd7fcb976b5825534fb (patch)
tree3be3fdf89a15455f0ee5850ab9b46ae768d4a083
parent08196b220b115083b2f21bbf0fa0522b712b5b04 (diff)
downloadbinutils-gdb-ae0e76dcfcb7a8d2d8b5cbd7fcb976b5825534fb.tar.gz
Hide dynamic symbols in discarded sections
This is a followup to git commit 97196564c7 "Strip global symbol defined in discarded section". If a symbol defined in a discarded section was dynamic, that patch left .dynsym with holes (ie. all zero entries). For example, the following from libstdc++.so: Symbol table '.dynsym' contains 6090 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000000a74e0 0 SECTION LOCAL DEFAULT 10 2: 0000000000264180 0 SECTION LOCAL DEFAULT 17 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_addUserCommitAction 4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_memcpyRtWn 5: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND readelf: Warning: local symbol 5 found at index >= .dynsym's sh_info value of 3 6: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND readelf: Warning: local symbol 6 found at index >= .dynsym's sh_info value of 3 [snip] This patch removes the symbols from .dynsym too. PR 17550 * elflink.c (_bfd_elf_fix_symbol_flags): Hide dynamic symbols in discarded sections. (cherry picked from commit af0bfb9c4283ce80fe37ad6360d12cae8ec38696)
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/elflink.c8
2 files changed, 12 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 0f298d7dbe4..263098471c8 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-03 Alan Modra <amodra@gmail.com>
+
+ PR 17550
+ * elflink.c (_bfd_elf_fix_symbol_flags): Hide dynamic symbols
+ in discarded sections.
+
2018-07-11 Max Filippov <jcmvbkbc@gmail.com>
* elf32-xtensa.c (elf_xtensa_allocate_dynrelocs): Don't allocate
diff --git a/bfd/elflink.c b/bfd/elflink.c
index eb3b6198323..b24fb95848d 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -2853,10 +2853,14 @@ _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h,
&& (h->root.u.def.section->owner->flags & (DYNAMIC | BFD_PLUGIN)) == 0)
h->def_regular = 1;
+ /* Symbols defined in discarded sections shouldn't be dynamic. */
+ if (h->root.type == bfd_link_hash_undefined && h->indx == -3)
+ (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
+
/* If a weak undefined symbol has non-default visibility, we also
hide it from the dynamic linker. */
- if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
- && h->root.type == bfd_link_hash_undefweak)
+ else if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak)
(*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
/* A hidden versioned symbol in executable should be forced local if