]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: traverse loc_hash_table only if used
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 29 Nov 2025 00:47:46 +0000 (08:47 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 2 Dec 2025 01:02:39 +0000 (09:02 +0800)
Traverse x86 loc_hash_table only if it is used.

* elf32-i386.c (elf_i386_output_arch_local_syms): Traverse
loc_hash_table only if has_loc_hash_table is set.
* elf64-x86-64.c (elf_x86_64_output_arch_local_syms): Likewise.
* elfxx-x86.c (_bfd_elf_x86_get_local_sym_hash): Set
has_loc_hash_table.
(_bfd_x86_elf_late_size_sections): Traverse loc_hash_table only
if has_loc_hash_table is set.
* elfxx-x86.h (elf_x86_link_hash_table): Move plt0_pad_byte and
add has_loc_hash_table.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index abb361be993986d0f4121840fcf94d34ed7bfa7a..755c2176fd250f46b469ec0d9394a9d349091889 100644 (file)
@@ -4271,10 +4271,12 @@ elf_i386_output_arch_local_syms
   if (htab == NULL)
     return false;
 
-  /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols.  */
-  htab_traverse (htab->loc_hash_table,
-                elf_i386_finish_local_dynamic_symbol,
-                info);
+  /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols if
+     needed.  */
+  if (htab->has_loc_hash_table)
+    htab_traverse (htab->loc_hash_table,
+                  elf_i386_finish_local_dynamic_symbol,
+                  info);
 
   return true;
 }
index 337394fc4786c3cd22b274bf52fe52b94cf4f95c..1bffced9a30ea0e5a458da75969225af5f62193c 100644 (file)
@@ -5777,10 +5777,12 @@ elf_x86_64_output_arch_local_syms
   if (htab == NULL)
     return false;
 
-  /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols.  */
-  htab_traverse (htab->loc_hash_table,
-                elf_x86_64_finish_local_dynamic_symbol,
-                info);
+  /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols if
+     needed.  */
+  if (htab->has_loc_hash_table)
+    htab_traverse (htab->loc_hash_table,
+                  elf_x86_64_finish_local_dynamic_symbol,
+                  info);
 
   return true;
 }
index 24894193c86d9f584694654dea280c6550b1bf94..e5a24c4ac1d5b7df0829dd97502a9de54cbb16ff 100644 (file)
@@ -613,6 +613,7 @@ _bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table *htab,
       ret->elf.dynindx = -1;
       ret->plt_got.offset = (bfd_vma) -1;
       *slot = ret;
+      htab->has_loc_hash_table = 1;
     }
   return &ret->elf;
 }
@@ -2425,9 +2426,11 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
   elf_link_hash_traverse (&htab->elf, elf_x86_allocate_dynrelocs,
                          info);
 
-  /* Allocate .plt and .got entries, and space for local symbols.  */
-  htab_traverse (htab->loc_hash_table, elf_x86_allocate_local_dynreloc,
-                info);
+  /* Allocate .plt and .got entries, and space for local symbols if
+     needed.  */
+  if (htab->has_loc_hash_table)
+    htab_traverse (htab->loc_hash_table, elf_x86_allocate_local_dynreloc,
+                  info);
 
   /* For every jump slot reserved in the sgotplt, reloc_count is
      incremented.  However, when we reserve space for TLS descriptors,
index 7e196cd0475e99b91f82f3622e3ef645e5e5d961..99ef934156348ab82bc80fb75291b281649c6bf2 100644 (file)
@@ -673,9 +673,8 @@ struct elf_x86_link_hash_table
   /* TRUE if inputs call ___tls_get_addr.  This is only used for i386.  */
   unsigned int has_tls_get_addr_call : 1;
 
-   /* Value used to fill the unused bytes of the first PLT entry.  This
-      is only used for i386.  */
-  bfd_byte plt0_pad_byte;
+  /* TRUE if loc_hash_table is used.  */
+  unsigned int has_loc_hash_table : 1;
 
   /* TRUE if GOT is referenced.  */
   unsigned int got_referenced : 1;
@@ -688,6 +687,10 @@ struct elf_x86_link_hash_table
      function address.  */
   unsigned int pcrel_plt : 1;
 
+   /* Value used to fill the unused bytes of the first PLT entry.  This
+      is only used for i386.  */
+  bfd_byte plt0_pad_byte;
+
   bfd_vma (*r_info) (bfd_vma, bfd_vma);
   bfd_vma (*r_sym) (bfd_vma);
   bool (*is_reloc_section) (const char *);