[PATCH] elf: Store __ehdr_start hash in elf_link_hash_table

H.J. Lu hjl.tools@gmail.com
Mon Feb 3 04:09:42 GMT 2025


Store __ehdr_start hash in elf_link_hash_table so that we just need to
lookup it up 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): Store __ehdr_start hash in
	hehdr_start.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 bfd/elf-bfd.h | 3 +++
 bfd/elf.c     | 6 +++---
 ld/ldelf.c    | 1 +
 3 files changed, 7 insertions(+), 3 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..624b32d6dcd 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1797,6 +1797,7 @@ ldelf_before_allocation (char **audit, char **depaudit,
 	      /* It will be converted to section-relative later.  */
 	      ehdr_start->u.def.section = bfd_abs_section_ptr;
 	      ehdr_start->u.def.value = 0;
+	      htab->hehdr_start = h;
 	    }
 	}
 
-- 
2.48.1



More information about the Binutils mailing list