diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2016-05-06 09:46:34 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2016-05-06 09:46:50 -0700 |
commit | 97196564c7e981bab7b968e19b171c5dfcb28c3c (patch) | |
tree | 4a4394c52a91f1baf906d5541da3d8653bf82991 /bfd | |
parent | 030e823caf4243a3337c2134a4a2f38490d3cf3d (diff) | |
download | gdb-97196564c7e981bab7b968e19b171c5dfcb28c3c.zip gdb-97196564c7e981bab7b968e19b171c5dfcb28c3c.tar.gz gdb-97196564c7e981bab7b968e19b171c5dfcb28c3c.tar.bz2 |
Strip global symbol defined in discarded section
When a global symbol is defined in COMDAT group, we shouldn't leave an
undefined symbol in symbol table when the symbol section is discarded
unless there is a reference to the symbol outside of COMDAT group.
bfd/
PR ld/17550
* elf-bfd.h (elf_link_hash_entry): Update comments for indx,
documenting that indx == -3 if symbol is defined in a discarded
section.
* elflink.c (elf_link_add_object_symbols): Set indx to -3 if
symbol is defined in a discarded section.
(elf_link_output_extsym): Strip a global symbol defined in a
discarded section.
ld/
PR ld/17550
* testsuite/ld-elf/pr17550-1.s: New file.
* testsuite/ld-elf/pr17550-2.s: Likewise.
* testsuite/ld-elf/pr17550-3.s: Likewise.
* testsuite/ld-elf/pr17550-4.s: Likewise.
* testsuite/ld-elf/pr17550a.d: Likewise.
* testsuite/ld-elf/pr17550b.d: Likewise.
* testsuite/ld-elf/pr17550c.d: Likewise.
* testsuite/ld-elf/pr17550d.d: Likewise.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 11 | ||||
-rw-r--r-- | bfd/elf-bfd.h | 3 | ||||
-rw-r--r-- | bfd/elflink.c | 12 |
3 files changed, 25 insertions, 1 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c6a51c4..dfd9c1b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,16 @@ 2016-05-06 H.J. Lu <hongjiu.lu@intel.com> + PR ld/17550 + * elf-bfd.h (elf_link_hash_entry): Update comments for indx, + documenting that indx == -3 if symbol is defined in a discarded + section. + * elflink.c (elf_link_add_object_symbols): Set indx to -3 if + symbol is defined in a discarded section. + (elf_link_output_extsym): Strip a global symbol defined in a + discarded section. + +2016-05-06 H.J. Lu <hongjiu.lu@intel.com> + * elf32-i386.c (elf_backend_add_symbol_hook): Defined for Intel MCU. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 9067dd9..863fc39 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -124,7 +124,8 @@ struct elf_link_hash_entry struct bfd_link_hash_entry root; /* Symbol index in output file. This is initialized to -1. It is - set to -2 if the symbol is used by a reloc. */ + set to -2 if the symbol is used by a reloc. It is set to -3 if + this symbol is defined in a discarded section. */ long indx; /* Symbol index as a dynamic symbol. Initialized to -1, and remains diff --git a/bfd/elflink.c b/bfd/elflink.c index b6ff6b6..6ccd5fc 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -4082,6 +4082,7 @@ error_free_dyn: bfd_boolean old_weak; bfd_boolean override; bfd_boolean common; + bfd_boolean discarded; unsigned int old_alignment; bfd *old_bfd; bfd_boolean matched; @@ -4092,6 +4093,7 @@ error_free_dyn: sec = NULL; value = isym->st_value; common = bed->common_definition (isym); + discarded = FALSE; bind = ELF_ST_BIND (isym->st_info); switch (bind) @@ -4142,6 +4144,7 @@ error_free_dyn: /* Symbols from discarded section are undefined. We keep its visibility. */ sec = bfd_und_section_ptr; + discarded = TRUE; isym->st_shndx = SHN_UNDEF; } else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) @@ -4385,6 +4388,11 @@ error_free_dyn: || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; + /* Setting the index to -3 tells elf_link_output_extsym that + this symbol is defined in a discarded section. */ + if (discarded) + h->indx = -3; + *sym_hash = h; new_weak = (flags & BSF_WEAK) != 0; @@ -9201,6 +9209,10 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) return FALSE; } } + + /* Strip a global symbol defined in a discarded section. */ + if (h->indx == -3) + return TRUE; } /* We should also warn if a forced local symbol is referenced from |