]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
copy_private_symbol_data
authorAlan Modra <amodra@gmail.com>
Mon, 22 Apr 2024 00:00:23 +0000 (09:30 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 23 Apr 2024 01:49:35 +0000 (11:19 +0930)
bfd_copy_private_symbol_data is a bfd function that appeared in
commit 89665c8562da a long time ago, but seemingly wasn't used
anywhere until Jan added it to gas/symbols.c in commit 6a2b6326c21e.

The function is used to modify ELF symbol st_shndx for symbols defined
in odd sections like .symtab, so that they get the corresponding
section st_shndx in an output file.  This patch fixes some bitrot in
the function.  After commit c03551323c04 which introduced
output_elf_obj_tdata, elf_strtab_sec and elf_shstrtab_sec will
segfault if used on an input bfd.

PR 14493
* elf.c (_bfd_elf_copy_private_symbol_data): Don't use
elf_strtab_sec and elf_shstrtab_sec.

bfd/elf.c

index 52a6a2f56c3837fe8955249850dca8318841e63d..41ec649ebabfd0dd669eb3cb63310fc2c2268020 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8785,9 +8785,9 @@ _bfd_elf_copy_private_symbol_data (bfd *ibfd,
        shndx = MAP_ONESYMTAB;
       else if (shndx == elf_dynsymtab (ibfd))
        shndx = MAP_DYNSYMTAB;
-      else if (shndx == elf_strtab_sec (ibfd))
+      else if (shndx == elf_elfsections (ibfd)[elf_onesymtab (ibfd)]->sh_link)
        shndx = MAP_STRTAB;
-      else if (shndx == elf_shstrtab_sec (ibfd))
+      else if (shndx == elf_elfheader (ibfd)->e_shstrndx)
        shndx = MAP_SHSTRTAB;
       else if (find_section_in_list (shndx, elf_symtab_shndx_list (ibfd)))
        shndx = MAP_SYM_SHNDX;