]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
elf: Always honor the first definition in shared object and archive
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 5 Apr 2024 01:46:40 +0000 (18:46 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 5 Apr 2024 12:02:38 +0000 (05:02 -0700)
commitc0419c024bf922128131671e40de0aed736e38ed
treed3d57c0080c27f60f9505c90f80c30e0c2e8bb3b
parenteac88f3298491fdf2caa0d7dd97a3dde954b8b74
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.
12 files changed:
bfd/elf-bfd.h
bfd/elflink.c
ld/testsuite/ld-elf/pr31482a-no-lto.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr31482b-no-lto.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr31482c-no-lto.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr31482d-no-lto.c [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pass1.out [new file with mode: 0644]
ld/testsuite/ld-plugin/pr31482a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr31482b.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr31482c.c [new file with mode: 0644]