diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-04-18 05:28:56 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-04-18 19:17:17 -0700 |
commit | eebad48efeeee858be83d754a6b1326133e51d36 (patch) | |
tree | 4611e2b89a9fcbe7aecf2a0709c7056cef9ba183 /bfd/elf-bfd.h | |
parent | 2304772225e51cb939d3766cde47d7651d15176e (diff) | |
download | gdb-eebad48efeeee858be83d754a6b1326133e51d36.zip gdb-eebad48efeeee858be83d754a6b1326133e51d36.tar.gz gdb-eebad48efeeee858be83d754a6b1326133e51d36.tar.bz2 |
elf: Strip unreferenced weak undefined symbols
Linker will resolve an undefined symbol only if it is referenced by
relocation. Unreferenced weak undefined symbols serve no purpose.
Weak undefined symbols appear in the dynamic symbol table only when they
are referenced by dynamic relocation. Mark symbols with relocation and
strip undefined weak symbols if they don't have relocation and aren't
in the dynamic symbol table.
bfd/
PR ld/31652
* elf-bfd.h (elf_link_hash_entry): Add has_reloc.
* elf-vxworks.c (elf_vxworks_emit_relocs): Set has_reloc.
* elflink.c (_bfd_elf_link_output_relocs): Likewise.
(elf_link_output_extsym): Strip undefined weak symbols if they
don't have relocation and aren't in the dynamic symbol table.
ld/
PR ld/31652
* testsuite/ld-elf/elf.exp: Run undefweak tests.
* testsuite/ld-elf/undefweak-1.rd: New file.
* testsuite/ld-elf/undefweak-1a.s: Likewise.
* testsuite/ld-elf/undefweak-1b.s: Likewise.
* testsuite/ld-x86-64/weakundef-1.nd: Likewise.
* testsuite/ld-x86-64/weakundef-1a.s: Likewise.
* testsuite/ld-x86-64/weakundef-1b.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run undefweak tests.
Diffstat (limited to 'bfd/elf-bfd.h')
-rw-r--r-- | bfd/elf-bfd.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index ef5dcb5..92a0287 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -232,6 +232,8 @@ struct elf_link_hash_entry a strong defined symbol alias. U.ALIAS points to a list of aliases, the definition having is_weakalias clear. */ unsigned int is_weakalias : 1; + /* Symbol has a relocation. */ + unsigned int has_reloc : 1; /* String table index in .dynstr if this is a dynamic symbol. */ unsigned long dynstr_index; |