diff options
author | Alan Modra <amodra@gmail.com> | 2015-02-18 17:02:39 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2015-02-19 13:36:34 +1030 |
commit | d983c8c5503d680c6d4955ceb610a9beebc64460 (patch) | |
tree | 328f5687e73b6db52f604b3596c0b1cc03fd515a /bfd/elflink.c | |
parent | 8545136955641adbf35e121fbbfc8cd5fd06e4a7 (diff) | |
download | gdb-d983c8c5503d680c6d4955ceb610a9beebc64460.zip gdb-d983c8c5503d680c6d4955ceb610a9beebc64460.tar.gz gdb-d983c8c5503d680c6d4955ceb610a9beebc64460.tar.bz2 |
Strip undefined symbols from .symtab
bfd/
PR ld/4317
* elflink.c (elf_link_input_bfd): Drop undefined local syms.
(elf_link_output_extsym): Drop local and global undefined syms.
Tidy. Expand comment.
ld/testsuite/
PR ld/4317
* ld-aarch64/gc-tls-relocs.d, * ld-cris/locref2.d,
* ld-elf/ehdr_start-weak.d, * ld-elf/group1.d,
* ld-i386/compressed1.d, * ld-ia64/error1.d, * ld-ia64/error2.d,
* ld-ia64/error3.d, * ld-mips-elf/pic-and-nonpic-1.nd,
* ld-mmix/undef-3.d, * ld-powerpc/tlsexe.r, * ld-powerpc/tlsexetoc.r,
* ld-powerpc/tlsso.r, * ld-powerpc/tlstocso.r,
* ld-x86-64/compressed1.d, * ld-x86-64/pie1.d: Update.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r-- | bfd/elflink.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c index 038e43d..0cd85f1 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8902,8 +8902,9 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) a regular file, or that we have been told to strip. However, if h->indx is set to -2, the symbol is used by a reloc and we must output it. */ + strip = FALSE; if (h->indx == -2) - strip = FALSE; + ; else if ((h->def_dynamic || h->ref_dynamic || h->root.type == bfd_link_hash_new) @@ -8929,12 +8930,11 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) && h->root.u.undef.abfd != NULL && (h->root.u.undef.abfd->flags & BFD_PLUGIN) != 0) strip = TRUE; - else - strip = FALSE; /* If we're stripping it, and it's not a dynamic symbol, there's - nothing else to do unless it is a forced local symbol or a - STT_GNU_IFUNC symbol. */ + nothing else to do. However, if it is a forced local symbol or + an ifunc symbol we need to give the backend finish_dynamic_symbol + function a chance to make it dynamic. */ if (strip && h->dynindx == -1 && h->type != STT_GNU_IFUNC @@ -9205,9 +9205,18 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) } } - /* If we're stripping it, then it was just a dynamic symbol, and - there's nothing else to do. */ - if (strip || (input_sec->flags & SEC_EXCLUDE) != 0) + /* If the symbol is undefined, and we didn't output it to .dynsym, + strip it from .symtab too. Obviously we can't do this for + relocatable output or when needed for --emit-relocs. */ + else if (input_sec == bfd_und_section_ptr + && h->indx != -2 + && !flinfo->info->relocatable) + return TRUE; + /* Also strip others that we couldn't earlier due to dynamic symbol + processing. */ + if (strip) + return TRUE; + if ((input_sec->flags & SEC_EXCLUDE) != 0) return TRUE; /* Output a FILE symbol so that following locals are not associated @@ -9455,8 +9464,9 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) *ppsection = isec; - /* Don't output the first, undefined, symbol. */ - if (ppsection == flinfo->sections) + /* Don't output the first, undefined, symbol. In fact, don't + output any undefined local symbol. */ + if (isec == bfd_und_section_ptr) continue; if (ELF_ST_TYPE (isym->st_info) == STT_SECTION) |