From d983c8c5503d680c6d4955ceb610a9beebc64460 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 18 Feb 2015 17:02:39 +1030 Subject: 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. --- bfd/ChangeLog | 7 +++++++ bfd/elflink.c | 30 ++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 44fc2bb..71f258f 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2015-02-19 Alan Modra + + 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. + 2015-02-17 Alan Modra PR ld/17975 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) -- cgit v1.1