[binutils-gdb] elf: Store __ehdr_start hash in elf_link_hash_table

H.J. Lu hjl@sourceware.org
Tue Feb 4 05:03:14 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bc61d5916a04605079723f6674bd33d2a923af2e

commit bc61d5916a04605079723f6674bd33d2a923af2e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 3 11:30:50 2025 +0800

    elf: Store __ehdr_start hash in elf_link_hash_table
    
    Since
    
    commit 97da0e2677c4a38df2406576428ec27d1da26e7c
    Author: Alan Modra <amodra@gmail.com>
    Date:   Wed Jan 12 23:42:23 2022 +1030
    
        tweak __ehdr_start visibility and flags for check_relocs
    
    creates __ehdr_start hash in lang_symbol_tweaks, store __ehdr_start hash
    in elf_link_hash_table so that we just need to lookup it up only once.
    
    bfd/
    
            * elf-bfd.h (elf_link_hash_table): Add hehdr_start.
            * elf.c (assign_file_positions_for_load_sections): Use
            hehdr_start.
    
    ld/
    
            * ldelf.c (ldelf_before_allocation): Use hehdr_start for
            __ehdr_start hash.
            * ldlang.c (lang_symbol_tweaks): Store hehdr_start hash in
            hehdr_start.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 bfd/elf-bfd.h | 3 +++
 bfd/elf.c     | 6 +++---
 ld/ldelf.c    | 3 +--
 ld/ldlang.c   | 1 +
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index c89327fdc9c..785a37dd7fd 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -699,6 +699,9 @@ struct elf_link_hash_table
   /* The _DYNAMIC symbol.  */
   struct elf_link_hash_entry *hdynamic;
 
+  /* The __ehdr_start symbol.  */
+  struct elf_link_hash_entry *hehdr_start;
+
   /* A pointer to information used to merge SEC_MERGE sections.  */
   void *merge_info;
 
diff --git a/bfd/elf.c b/bfd/elf.c
index 0fa580d8d78..0e40d6d1d30 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6419,9 +6419,9 @@ assign_file_positions_for_load_sections (bfd *abfd,
 	 program headers, so provide a symbol __ehdr_start pointing there.
 	 A program can use this to examine itself robustly.  */
 
-      struct elf_link_hash_entry *hash
-	= elf_link_hash_lookup (elf_hash_table (link_info), "__ehdr_start",
-				false, false, true);
+      struct elf_link_hash_table *htab = elf_hash_table (link_info);
+      struct elf_link_hash_entry *hash = htab->hehdr_start;
+
       /* If the symbol was referenced and not defined, define it.  */
       if (hash != NULL
 	  && (hash->root.type == bfd_link_hash_new
diff --git a/ld/ldelf.c b/ld/ldelf.c
index dbc3d77d47b..141ee598a28 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1772,8 +1772,7 @@ ldelf_before_allocation (char **audit, char **depaudit,
       if (!bfd_link_relocatable (&link_info))
 	{
 	  struct elf_link_hash_table *htab = elf_hash_table (&link_info);
-	  struct elf_link_hash_entry *h
-	    = elf_link_hash_lookup (htab, "__ehdr_start", false, false, true);
+	  struct elf_link_hash_entry *h = htab->hehdr_start;
 
 	  /* Only adjust the export class if the symbol was referenced
 	     and not defined, otherwise leave it alone.  */
diff --git a/ld/ldlang.c b/ld/ldlang.c
index cd94e201837..4a4acaa5493 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -7176,6 +7176,7 @@ lang_symbol_tweaks (void)
 	  h->def_regular = 1;
 	  h->root.linker_def = 1;
 	  h->root.rel_from_abs = 1;
+	  elf_hash_table (&link_info)->hehdr_start = h;
 	}
     }
 }


More information about the Binutils-cvs mailing list