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