]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
_bfd_elf_get_link_hash_entry tidy
authorAlan Modra <amodra@gmail.com>
Thu, 30 Oct 2025 05:56:44 +0000 (16:26 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 30 Oct 2025 05:56:44 +0000 (16:26 +1030)
Replace the "Elf_Internal_Shdr *symtab_hdr" parameter with
"unsigned int ext_sym_start", making it a duplicate of the existing
get_link_hash_entry function.

Also remove unnecessary checks from get_ext_sym_hash_from_cookie and
find_merged_cie.  The sym_hashes and symbol index checks in
get_ext_sym_hash_from_cookie are duplicates of those done in
_bfd_elf_get_link_hash_entry, and there is no need to check for a
global symbol before calling _bfd_elf_get_link_hash_entry.  When
bad_symtab, local symbols will have a NULL sym_hashes entry.  Removing
these unnecessary checks gets rid of some cookie->locsyms references.

PR 33530
* elf-bfd.h (_bfd_elf_get_link_hash_entry): Update declaration.
* elflink.c (_bfd_elf_get_link_hash_entry): Rename from
get_link_hash_entry, adjusting all calls and deleting original
function.
(get_ext_sym_hash_from_cookie): Make "symndx" unsigned int.
Remove unnecessary check on sym_hashes, symbol index and
symbol binding.
* elf-eh-frame.c (find_merged_cie): Remove similar unnecessary
checks.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Adjust.
* elfxx-x86.c (_bfd_x86_elf_check_relocs): Adjust.
(_bfd_x86_elf_link_relax_section): Adjust.

bfd/elf-bfd.h
bfd/elf-eh-frame.c
bfd/elf64-x86-64.c
bfd/elflink.c
bfd/elfxx-x86.c

index 05d4baac23c430ec5c1974cf365fb9a7d7e0cd49..dfadb3e933e3c1eac99067f63031b15a7d940a4a 100644 (file)
@@ -3169,7 +3169,7 @@ extern void _bfd_elf_link_munmap_section_contents
   (asection *);
 
 extern struct elf_link_hash_entry * _bfd_elf_get_link_hash_entry
-  (struct elf_link_hash_entry **, unsigned int, Elf_Internal_Shdr *);
+  (struct elf_link_hash_entry **, unsigned int, unsigned int);
 
 /* Large common section.  */
 extern asection _bfd_elf_large_com_section;
index 5ba8c9c12623fa94af2a7f86c524a8b604429863..87cf45a0db039d4c684c4a20bcf1c88fdf091676 100644 (file)
@@ -1238,6 +1238,7 @@ find_merged_cie (bfd *abfd, struct bfd_link_info *info, asection *sec,
 
   if (cie->per_encoding != DW_EH_PE_omit)
     {
+      struct elf_link_hash_entry *h;
       bool per_binds_local;
 
       /* Work out the address of personality routine, or at least
@@ -1254,14 +1255,13 @@ find_merged_cie (bfd *abfd, struct bfd_link_info *info, asection *sec,
       else
 #endif
        r_symndx = ELF32_R_SYM (rel->r_info);
-      if (r_symndx >= cookie->locsymcount
-         || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL)
-       {
-         struct elf_link_hash_entry *h;
 
-         r_symndx -= cookie->extsymoff;
-         h = cookie->sym_hashes[r_symndx];
+      h = NULL;
+      if (r_symndx >= cookie->extsymoff)
+       h = elf_sym_hashes (cookie->abfd)[r_symndx - cookie->extsymoff];
 
+      if (h != NULL)
+       {
          while (h->root.type == bfd_link_hash_indirect
                 || h->root.type == bfd_link_hash_warning)
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
index 59b431498971108f9c198efa27a0b524237f74de..f2a172662a524e4bdf6600927bec2610aaf649a5 100644 (file)
@@ -2615,7 +2615,8 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
       else
        {
          isym = NULL;
-         h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx, symtab_hdr);
+         h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx,
+                                           symtab_hdr->sh_info);
        }
 
       /* Check invalid x32 relocations.  */
index 860184bdcba3ecbd70a6e39c2f14a510d5ad9320..5f8ba26453df479ba9bd162561fb2af8c1a019ea 100644 (file)
@@ -93,10 +93,10 @@ _bfd_elf_link_keep_memory (struct bfd_link_info *info)
   return true;
 }
 
-static struct elf_link_hash_entry *
-get_link_hash_entry (struct elf_link_hash_entry **  sym_hashes,
-                    unsigned int                   symndx,
-                    unsigned int                   ext_sym_start)
+struct elf_link_hash_entry *
+_bfd_elf_get_link_hash_entry (struct elf_link_hash_entry **sym_hashes,
+                             unsigned int symndx,
+                             unsigned int ext_sym_start)
 {
   if (sym_hashes == NULL
       /* Guard against corrupt input.  See PR 32636 for an example.  */
@@ -105,7 +105,7 @@ get_link_hash_entry (struct elf_link_hash_entry **  sym_hashes,
 
   struct elf_link_hash_entry *h = sym_hashes[symndx - ext_sym_start];
 
-  /* The hash might be empty.  See PR 32641 for an example of this.  */
+  /* The hash might be empty when bad_symtab.  Also see PR32641.  */
   if (h == NULL)
     return NULL;
 
@@ -116,28 +116,15 @@ get_link_hash_entry (struct elf_link_hash_entry **  sym_hashes,
   return h;
 }
 
-struct elf_link_hash_entry *
-_bfd_elf_get_link_hash_entry (struct elf_link_hash_entry **  sym_hashes,
-                             unsigned int                   symndx,
-                             Elf_Internal_Shdr *            symtab_hdr)
-{
-  if (symtab_hdr == NULL)
-    return NULL;
-
-  return get_link_hash_entry (sym_hashes, symndx, symtab_hdr->sh_info);
-}
-
 static struct elf_link_hash_entry *
-get_ext_sym_hash_from_cookie (struct elf_reloc_cookie *cookie, unsigned long r_symndx)
+get_ext_sym_hash_from_cookie (struct elf_reloc_cookie *cookie,
+                             unsigned int symndx)
 {
-  if (cookie == NULL || cookie->sym_hashes == NULL)
+  if (cookie == NULL)
     return NULL;
   
-  if (r_symndx >= cookie->locsymcount
-      || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL)
-    return get_link_hash_entry (cookie->sym_hashes, r_symndx, cookie->extsymoff);
-
-  return NULL;
+  return _bfd_elf_get_link_hash_entry (cookie->sym_hashes, symndx,
+                                      cookie->extsymoff);
 }
 
 asection *
@@ -9121,7 +9108,8 @@ set_symbol_value (bfd *bfd_with_globals,
 
   /* It is a global symbol: set its link type
      to "defined" and give it a value.  */
-  h = get_link_hash_entry (elf_sym_hashes (bfd_with_globals), symidx, extsymoff);
+  h = _bfd_elf_get_link_hash_entry (elf_sym_hashes (bfd_with_globals), symidx,
+                                   extsymoff);
   if (h == NULL)
     return false;
   h->root.type = bfd_link_hash_defined;
@@ -11602,7 +11590,8 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
            {
              struct elf_link_hash_entry *h;
 
-             h = get_link_hash_entry (sym_hashes, symndx, extsymoff);
+             h = _bfd_elf_get_link_hash_entry (sym_hashes, symndx,
+                                               extsymoff);
              if (h == NULL)
                {
                  _bfd_error_handler
@@ -11747,7 +11736,8 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
                  || (elf_bad_symtab (input_bfd)
                      && flinfo->sections[r_symndx] == NULL))
                {
-                 h = get_link_hash_entry (sym_hashes, r_symndx, extsymoff);
+                 h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx,
+                                                   extsymoff);
 
                  /* Badly formatted input files can contain relocs that
                     reference non-existant symbols.  Check here so that
@@ -11988,8 +11978,8 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
                         reloc to point to the global hash table entry
                         for this symbol.  The symbol index is then
                         set at the end of bfd_elf_final_link.  */
-                     rh = get_link_hash_entry (elf_sym_hashes (input_bfd),
-                                               r_symndx, extsymoff);
+                     rh = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx,
+                                                        extsymoff);
                      if (rh == NULL)
                        {
                          /* FIXME: Generate an error ?  */
index b224a546901661872246c3711a432d5d1a321fe3..cffec0f5aaba5817bcc332a7a531b3b33f3f529d 100644 (file)
@@ -966,7 +966,8 @@ _bfd_x86_elf_check_relocs (bfd *abfd,
          goto error_return;
        }
 
-      h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx, symtab_hdr);
+      h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx,
+                                       symtab_hdr->sh_info);
 
       if (X86_NEED_DYNAMIC_RELOC_TYPE_P (is_x86_64, r_type)
          && NEED_DYNAMIC_RELOCATION_P (is_x86_64, info, true, h, sec,
@@ -1194,7 +1195,8 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
       else
        {
          /* Get H and SEC for GENERATE_DYNAMIC_RELOCATION_P below.  */
-         h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx, symtab_hdr);
+         h = _bfd_elf_get_link_hash_entry (sym_hashes, r_symndx,
+                                           symtab_hdr->sh_info);
          if (h == NULL)
            {
              /* FIXMEL: Issue an error message ?  */