]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf: Renumber local dynamic symbols only if needed
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 28 Nov 2025 08:07:57 +0000 (16:07 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 30 Nov 2025 04:32:08 +0000 (12:32 +0800)
Only hppa, ia64 and sparc ELF targets use local dynamic symbols.  But
elf_link_renumber_local_hash_table_dynsyms is always called to renumber
local dynamic symbols even if there is none.  Add has_local_dynsyms to
elf_link_hash_table and set it to true only if there are local dynamic
symbols.  Renumber local dynamic symbols only if there are local dynamic
symbols.

* elf-bfd.h (elf_link_hash_table): Add has_local_dynsyms.
* elflink.c (_bfd_elf_link_renumber_dynsyms): Renumber local
dynamic symbols only if there are local dynamic symbols.
(_bfd_elf_adjust_dynamic_symbol): Set has_local_dynsyms if
there are local dynamic symbols.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elf-bfd.h
bfd/elflink.c

index 5f08d1a4dfb49368e512232bfb4f5a92c73afccc..1a0d476c37dff1b291f3a3fd4afd3bc91fa4df7c 100644 (file)
@@ -637,6 +637,9 @@ struct elf_link_hash_table
   /* Whether dynamic relocations are present.  */
   bool dynamic_relocs;
 
+  /* TRUE if there are local dynamic symbols.  */
+  bool has_local_dynsyms;
+
   /* True if this target has relocatable executables, so needs dynamic
      section symbols.  */
   bool is_relocatable_executable;
index adc21d7d821a82cfc8b5dc7912266957b9ea4eb2..529f81159e337f0072aa4674d80d3c2ad97b5880 100644 (file)
@@ -1064,9 +1064,10 @@ _bfd_elf_link_renumber_dynsyms (bfd *output_bfd,
   if (do_sec)
     *section_sym_count = dynsymcount;
 
-  elf_link_hash_traverse (elf_hash_table (info),
-                         elf_link_renumber_local_hash_table_dynsyms,
-                         &dynsymcount);
+  if (elf_hash_table (info)->has_local_dynsyms)
+    elf_link_hash_traverse (elf_hash_table (info),
+                           elf_link_renumber_local_hash_table_dynsyms,
+                           &dynsymcount);
 
   if (elf_hash_table (info)->dynlocal)
     {
@@ -3269,6 +3270,10 @@ _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data)
   if (! is_elf_hash_table (eif->info->hash))
     return false;
 
+  htab = elf_hash_table (eif->info);
+  if (h->forced_local && h->dynindx != -1)
+    htab->has_local_dynsyms = true;
+
   /* Ignore indirect symbols.  These are added by the versioning code.  */
   if (h->root.type == bfd_link_hash_indirect)
     return true;
@@ -3277,7 +3282,6 @@ _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data)
   if (! _bfd_elf_fix_symbol_flags (h, eif))
     return false;
 
-  htab = elf_hash_table (eif->info);
   bed = get_elf_backend_data (htab->dynobj);
 
   if (h->root.type == bfd_link_hash_undefweak)