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 --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index c89327f..785a37d 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -699,6 +699,9 @@
   /* 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 0fa580d..0e40d6d 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6419,9 +6419,9 @@
 	 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 dbc3d77..141ee59 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1772,8 +1772,7 @@
       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 cd94e20..4a4acaa 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -7176,6 +7176,7 @@
 	  h->def_regular = 1;
 	  h->root.linker_def = 1;
 	  h->root.rel_from_abs = 1;
+	  elf_hash_table (&link_info)->hehdr_start = h;
 	}
     }
 }