]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Correct _bfd_elf_section_for_symbol
authorAlan Modra <amodra@gmail.com>
Tue, 21 Oct 2025 09:21:09 +0000 (19:51 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 21 Oct 2025 11:33:00 +0000 (22:03 +1030)
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.

bfd/elf-bfd.h
bfd/elf-eh-frame.c
bfd/elflink.c

index 5d19529d9724c359323b951bb188490be8ab3756..a2b3eb0fa9f4148e4b9e13fd5c9732646f71d8b1 100644 (file)
@@ -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
index 4eda3c991bb495b40bdcae679295a85824a16c53..62cba84f45885a133d8a86c44125f2ce31445a9f 100644 (file)
@@ -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;
index 3f3ea2cce514e60bb54161cf50f3bd4f640e141f..c7a5a52f1dd673f0f3303996c4bcc072fecf080a 100644 (file)
@@ -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.  */