de97469
commit c90363403b57b3b7919061851cb3e6d9c85e784a
de97469
Author: Florian Weimer <fweimer@redhat.com>
de97469
Date:   Tue Jan 18 13:53:11 2022 +0100
de97469
de97469
    elf: Move _dl_setup_hash to its own file
de97469
    
de97469
    And compile it with the early CFLAGS.  _dl_setup_hash is called
de97469
    very early for the ld.so link map, so it should be compiled
de97469
    differently.
de97469
    
de97469
    Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
de97469
    Tested-by: Stefan Liebler <stli@linux.ibm.com>
de97469
de97469
diff --git a/elf/Makefile b/elf/Makefile
de97469
index 778e393395fc5248..948296dc2437e9a1 100644
de97469
--- a/elf/Makefile
de97469
+++ b/elf/Makefile
de97469
@@ -69,6 +69,7 @@ dl-routines = \
de97469
   dl-reloc \
de97469
   dl-runtime \
de97469
   dl-scope \
de97469
+  dl-setup_hash \
de97469
   dl-sort-maps \
de97469
   dl-thread_gscope_wait \
de97469
   dl-tls \
de97469
@@ -154,6 +155,7 @@ CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
de97469
 
de97469
 # Add the requested compiler flags to the early startup code.
de97469
 CFLAGS-dl-printf.os += $(rtld-early-cflags)
de97469
+CFLAGS-dl-setup_hash.os += $(rtld-early-cflags)
de97469
 CFLAGS-dl-sysdep.os += $(rtld-early-cflags)
de97469
 CFLAGS-dl-tunables.os += $(rtld-early-cflags)
de97469
 CFLAGS-dl-write.os += $(rtld-early-cflags)
de97469
diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
de97469
index eea217eb2833164c..3391a990c8d288e5 100644
de97469
--- a/elf/dl-lookup.c
de97469
+++ b/elf/dl-lookup.c
de97469
@@ -948,51 +948,6 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map,
de97469
 }
de97469
 
de97469
 
de97469
-/* Cache the location of MAP's hash table.  */
de97469
-
de97469
-void
de97469
-_dl_setup_hash (struct link_map *map)
de97469
-{
de97469
-  Elf_Symndx *hash;
de97469
-
de97469
-  if (__glibc_likely (map->l_info[ELF_MACHINE_GNU_HASH_ADDRIDX] != NULL))
de97469
-    {
de97469
-      Elf32_Word *hash32
de97469
-	= (void *) D_PTR (map, l_info[ELF_MACHINE_GNU_HASH_ADDRIDX]);
de97469
-      map->l_nbuckets = *hash32++;
de97469
-      Elf32_Word symbias = *hash32++;
de97469
-      Elf32_Word bitmask_nwords = *hash32++;
de97469
-      /* Must be a power of two.  */
de97469
-      assert ((bitmask_nwords & (bitmask_nwords - 1)) == 0);
de97469
-      map->l_gnu_bitmask_idxbits = bitmask_nwords - 1;
de97469
-      map->l_gnu_shift = *hash32++;
de97469
-
de97469
-      map->l_gnu_bitmask = (ElfW(Addr) *) hash32;
de97469
-      hash32 += __ELF_NATIVE_CLASS / 32 * bitmask_nwords;
de97469
-
de97469
-      map->l_gnu_buckets = hash32;
de97469
-      hash32 += map->l_nbuckets;
de97469
-      map->l_gnu_chain_zero = hash32 - symbias;
de97469
-
de97469
-      /* Initialize MIPS xhash translation table.  */
de97469
-      ELF_MACHINE_XHASH_SETUP (hash32, symbias, map);
de97469
-
de97469
-      return;
de97469
-    }
de97469
-
de97469
-  if (!map->l_info[DT_HASH])
de97469
-    return;
de97469
-  hash = (void *) D_PTR (map, l_info[DT_HASH]);
de97469
-
de97469
-  map->l_nbuckets = *hash++;
de97469
-  /* Skip nchain.  */
de97469
-  hash++;
de97469
-  map->l_buckets = hash;
de97469
-  hash += map->l_nbuckets;
de97469
-  map->l_chain = hash;
de97469
-}
de97469
-
de97469
-
de97469
 static void
de97469
 _dl_debug_bindings (const char *undef_name, struct link_map *undef_map,
de97469
 		    const ElfW(Sym) **ref, struct sym_val *value,
de97469
diff --git a/elf/dl-setup_hash.c b/elf/dl-setup_hash.c
de97469
new file mode 100644
de97469
index 0000000000000000..6dd57c5c94e541c2
de97469
--- /dev/null
de97469
+++ b/elf/dl-setup_hash.c
de97469
@@ -0,0 +1,63 @@
de97469
+/* Cache the location of a link map hash table.
de97469
+   Copyright (C) 1995-2022 Free Software Foundation, Inc.
de97469
+   This file is part of the GNU C Library.
de97469
+
de97469
+   The GNU C Library is free software; you can redistribute it and/or
de97469
+   modify it under the terms of the GNU Lesser General Public
de97469
+   License as published by the Free Software Foundation; either
de97469
+   version 2.1 of the License, or (at your option) any later version.
de97469
+
de97469
+   The GNU C Library is distributed in the hope that it will be useful,
de97469
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
de97469
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
de97469
+   Lesser General Public License for more details.
de97469
+
de97469
+   You should have received a copy of the GNU Lesser General Public
de97469
+   License along with the GNU C Library; if not, see
de97469
+   <https://www.gnu.org/licenses/>.  */
de97469
+
de97469
+#include <assert.h>
de97469
+#include <link.h>
de97469
+#include <ldsodefs.h>
de97469
+
de97469
+void
de97469
+_dl_setup_hash (struct link_map *map)
de97469
+{
de97469
+  Elf_Symndx *hash;
de97469
+
de97469
+  if (__glibc_likely (map->l_info[ELF_MACHINE_GNU_HASH_ADDRIDX] != NULL))
de97469
+    {
de97469
+      Elf32_Word *hash32
de97469
+        = (void *) D_PTR (map, l_info[ELF_MACHINE_GNU_HASH_ADDRIDX]);
de97469
+      map->l_nbuckets = *hash32++;
de97469
+      Elf32_Word symbias = *hash32++;
de97469
+      Elf32_Word bitmask_nwords = *hash32++;
de97469
+      /* Must be a power of two.  */
de97469
+      assert ((bitmask_nwords & (bitmask_nwords - 1)) == 0);
de97469
+      map->l_gnu_bitmask_idxbits = bitmask_nwords - 1;
de97469
+      map->l_gnu_shift = *hash32++;
de97469
+
de97469
+      map->l_gnu_bitmask = (ElfW(Addr) *) hash32;
de97469
+      hash32 += __ELF_NATIVE_CLASS / 32 * bitmask_nwords;
de97469
+
de97469
+      map->l_gnu_buckets = hash32;
de97469
+      hash32 += map->l_nbuckets;
de97469
+      map->l_gnu_chain_zero = hash32 - symbias;
de97469
+
de97469
+      /* Initialize MIPS xhash translation table.  */
de97469
+      ELF_MACHINE_XHASH_SETUP (hash32, symbias, map);
de97469
+
de97469
+      return;
de97469
+    }
de97469
+
de97469
+  if (!map->l_info[DT_HASH])
de97469
+    return;
de97469
+  hash = (void *) D_PTR (map, l_info[DT_HASH]);
de97469
+
de97469
+  map->l_nbuckets = *hash++;
de97469
+  /* Skip nchain.  */
de97469
+  hash++;
de97469
+  map->l_buckets = hash;
de97469
+  hash += map->l_nbuckets;
de97469
+  map->l_chain = hash;
de97469
+}