diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-04-04 18:46:40 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-04-05 05:02:38 -0700 |
commit | c0419c024bf922128131671e40de0aed736e38ed (patch) | |
tree | d3d57c0080c27f60f9505c90f80c30e0c2e8bb3b /bfd/elf-bfd.h | |
parent | eac88f3298491fdf2caa0d7dd97a3dde954b8b74 (diff) | |
download | gdb-c0419c024bf922128131671e40de0aed736e38ed.zip gdb-c0419c024bf922128131671e40de0aed736e38ed.tar.gz gdb-c0419c024bf922128131671e40de0aed736e38ed.tar.bz2 |
elf: Always honor the first definition in shared object and archive
GCC doesn't put builtin function symbol references, which are defined in
the shared C library, in the IR symbol table. When linker rescans shared
objects and archives for newly added symbol references generated from the
IR inputs, it skips definitions of the builtin functions in shared
objects and archives.
Add first_hash to elf_link_hash_table to track unreferenced definitions
defined first in shared objects and archives. Always use them to resolve
any references.
bfd/
PR ld/31482
PR ld/31489
* elf-bfd.h (elf_link_hash_table): Add first_hash.
* elflink.c (elf_link_add_to_first_hash): New function.
(elf_link_add_object_symbols): Initialize first_hash for an IR
input. Always use the first definition in shared object. Add
the first unreferenced dynamic definition to first_hash.
(_bfd_elf_archive_symbol_lookup): Add the first unreferenced
definition to first_hash..
(elf_link_add_archive_symbols): Use the symbol definition in
archive if symbol is defined first in this archive.
(_bfd_elf_link_hash_table_free): Also free first_hash.
ld/
PR ld/31482
PR ld/31489
* testsuite/ld-plugin/lto.exp: Add PR ld/31482 and PR ld/31489
tests.
* testsuite/ld-elf/pr31482a-no-lto.c: New file.
* testsuite/ld-elf/pr31482b-no-lto.c: Likewise.
* testsuite/ld-elf/pr31482c-no-lto.c: Likewise.
* testsuite/ld-elf/pr31482d-no-lto.c: Likewise.
* testsuite/ld-plugin/pass1.out: Likewise.
* testsuite/ld-plugin/pr31482a.c: Likewise.
* testsuite/ld-plugin/pr31482b.c: Likewise.
* testsuite/ld-plugin/pr31482c.c: Likewise.
Diffstat (limited to 'bfd/elf-bfd.h')
-rw-r--r-- | bfd/elf-bfd.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index f31244f..cf043d6 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -737,6 +737,10 @@ struct elf_link_hash_table /* Small local sym cache. */ struct sym_cache sym_cache; + /* Hash table of symbols which are first defined in archives or shared + objects when there are any IR inputs. */ + struct bfd_link_hash_table *first_hash; + /* Short-cuts to get to dynamic linker sections. */ asection *sgot; asection *sgotplt; |