[binutils-gdb] Correct _bfd_elf_section_for_symbol

Alan Modra amodra@sourceware.org
Tue Oct 21 11:33:29 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7d169f96d5f372c76ee560355af3dcac4355418f

commit 7d169f96d5f372c76ee560355af3dcac4355418f
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Oct 21 19:51:09 2025 +1030

    Correct _bfd_elf_section_for_symbol
    
    This function was added in commit 2f0c68f23bb3 as part of the compact
    EH support.  By the comments it looks like to code was copied from
    bfd_elf_reloc_symbol_deleted_p without sufficient editing, and would
    only work for local syms due to the discarded_section test left in
    place for global syms.  Fix that, and remove the discard param.
    
            * elf-bfd.h (_bfd_elf_section_for_symbol): Update prototype.
            * elf-eh-frame.c (_bfd_elf_parse_eh_frame_entry): Adjust.
            * elflink.c (_bfd_elf_section_for_symbol): Remove "discard".
            Don't test for discarded_section.

Diff:
---
 bfd/elf-bfd.h      |  2 +-
 bfd/elf-eh-frame.c |  2 +-
 bfd/elflink.c      | 24 +++++-------------------
 3 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 5d19529d972..a2b3eb0fa9f 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2612,7 +2612,7 @@ extern bool _bfd_elf_create_dynamic_sections
 extern bool _bfd_elf_create_got_section
   (bfd *, struct bfd_link_info *);
 extern asection *_bfd_elf_section_for_symbol
-  (struct elf_reloc_cookie *, unsigned long, bool);
+  (struct elf_reloc_cookie *, unsigned long);
 extern struct elf_link_hash_entry *_bfd_elf_define_linkage_sym
   (bfd *, struct bfd_link_info *, asection *, const char *);
 extern void _bfd_elf_init_1_index_section
diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
index 4eda3c991bb..62cba84f458 100644
--- a/bfd/elf-eh-frame.c
+++ b/bfd/elf-eh-frame.c
@@ -555,7 +555,7 @@ _bfd_elf_parse_eh_frame_entry (struct bfd_link_info *info,
   if (r_symndx == STN_UNDEF)
     return false;
 
-  text_sec = _bfd_elf_section_for_symbol (cookie, r_symndx, false);
+  text_sec = _bfd_elf_section_for_symbol (cookie, r_symndx);
 
   if (text_sec == NULL)
     return false;
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 3f3ea2cce51..c7a5a52f1dd 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -142,8 +142,7 @@ get_ext_sym_hash_from_cookie (struct elf_reloc_cookie *cookie, unsigned long r_s
 
 asection *
 _bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie,
-			     unsigned long r_symndx,
-			     bool discard)
+			     unsigned long r_symndx)
 {
   struct elf_link_hash_entry *h;
 
@@ -151,28 +150,15 @@ _bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie,
   
   if (h != NULL)
     {
-      if ((h->root.type == bfd_link_hash_defined
-	   || h->root.type == bfd_link_hash_defweak)
-	   && discarded_section (h->root.u.def.section))
+      if (h->root.type == bfd_link_hash_defined
+	  || h->root.type == bfd_link_hash_defweak)
 	return h->root.u.def.section;
       else
 	return NULL;
     }
 
-  /* It's not a relocation against a global symbol,
-     but it could be a relocation against a local
-     symbol for a discarded section.  */
-  asection *isec;
-  Elf_Internal_Sym *isym;
-
-  /* Need to: get the symbol; get the section.  */
-  isym = &cookie->locsyms[r_symndx];
-  isec = bfd_section_from_elf_index (cookie->abfd, isym->st_shndx);
-  if (isec != NULL
-      && discard ? discarded_section (isec) : 1)
-    return isec;
-
-  return NULL;
+  Elf_Internal_Sym *isym = &cookie->locsyms[r_symndx];
+  return bfd_section_from_elf_index (cookie->abfd, isym->st_shndx);
 }
 
 /* Define a symbol in a dynamic linkage section.  */


More information about the Binutils-cvs mailing list