public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: copy_private_symbol_data
Date: Tue, 23 Apr 2024 21:11:02 +0930	[thread overview]
Message-ID: <ZieeTmDWE0MvP1jC@squeak.grove.modra.org> (raw)

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.

diff --git a/bfd/elf.c b/bfd/elf.c
index 52a6a2f56c3..41ec649ebab 100644
--- 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;

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2024-04-23 11:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZieeTmDWE0MvP1jC@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).