elf: Renumber local dynamic symbols only if needed

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>
This commit is contained in:
H.J. Lu
2025-11-28 16:07:57 +08:00
parent 09e5148c02
commit 54fbc12d64
2 changed files with 11 additions and 4 deletions

View 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;

View 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)