]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Don't read and cache local syms for gc-sections
authorAlan Modra <amodra@gmail.com>
Thu, 30 Oct 2025 05:56:50 +0000 (16:26 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 30 Oct 2025 05:56:50 +0000 (16:26 +1030)
commit8b99ca44515b2b56f1492786e23522e4abbe8a96
tree4b870d37557c35acb87928551bf130b5be492bbb
parent57ccec66689305cdb59afa179b3f9a6464c84820
Don't read and cache local syms for gc-sections

Most places just need the local sym section, so reading and sometimes
caching the symbols is excessive.  A symbol shndx can be stored in 4
bytes, an elf symbol internal form requires 32 bytes.  When caching
the local symbols we went slightly crazy trying to avoid memory usage,
resulting in the symbols being freed then immediately read again for
the testcase in the PR33530.

To avoid this problem, this patch caches the local symbol section
indices in the bfd rather than in the reloc cookie.  They are not
initialised until there is a need for them, so unlike elf_sym_hashes
for global syms you cannot rely on them being present.

One place that does need local syms is adjust_eh_frame_local_symbols,
but that is called once via bfd_discard_info so there is no problem
simply reading them.  The other place that needs local syms is
ppc64_elf_gc_mark_hook for the old ELFv1 ABI when handling .opd.
bfd_sym_from_r_symndx should be sufficient for function pointer
references to static functions, which is how this code is triggered.

PR 33530
* elf-bfd.h (struct elf_reloc_cookie): Delete "locsyms",
"sym_hashes", "bad_symtab".  Make "locsymcount" and
"extsymoff" unsigned int.
(struct elf_obj_tdata): Add loc_shndx.
(elf_loc_shndx): Define.
(_bfd_get_local_sym_section): Declare.
* elf-eh-frame.c (find_merged_cie): Use
_bfd_get_local_sym_section for local syms.
(adjust_eh_frame_local_symbols): Read local syms if any match
.eh_frame section.  Return them if changed.
(_bfd_elf_discard_section_eh_frame): Adjust.
* elf64-ppc.c (ppc64_elf_gc_mark_hook): Use
_bfd_get_local_sym_section.  Use bfd_sym_from_r_symndx when
reading opd local symbol.
* elflink.c (_bfd_get_local_sym_section): New function.
(_bfd_elf_section_for_symbol): Use it.
(elf_link_add_object_symbols): Remove unnecessary cast on
bfd_zalloc return.
(init_reloc_cookie): Remove "info" and "keep_memory" params.
Adjust all callers.  Don't stash elf_sym_hashes and
elf_bad_symtab to cookie.  Don't read local syms to cookie.
(fini_reloc_cookie): Do nothing.
(_bfd_elf_gc_mark_hook): Use _bfd_get_local_sym_section.
(elf_gc_mark_debug_section): Likewise.
(bfd_elf_reloc_symbol_deleted_p): Likewise.  Update cookie use.
bfd/elf-bfd.h
bfd/elf-eh-frame.c
bfd/elf64-ppc.c
bfd/elflink.c