elf: Make glibc.rtld.enable_secure ignore alias environment variables
[glibc.git] / elf / dl-setup_hash.c
blobe4d660cdd5ff5876071b2935ef746de658e9fa5a
1 /* Cache the location of a link map hash table.
2 Copyright (C) 1995-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <assert.h>
20 #include <link.h>
21 #include <ldsodefs.h>
23 void
24 _dl_setup_hash (struct link_map *map)
26 Elf_Symndx *hash;
28 if (__glibc_likely (map->l_info[ELF_MACHINE_GNU_HASH_ADDRIDX] != NULL))
30 Elf32_Word *hash32
31 = (void *) D_PTR (map, l_info[ELF_MACHINE_GNU_HASH_ADDRIDX]);
32 map->l_nbuckets = *hash32++;
33 Elf32_Word symbias = *hash32++;
34 Elf32_Word bitmask_nwords = *hash32++;
35 /* Must be a power of two. */
36 assert ((bitmask_nwords & (bitmask_nwords - 1)) == 0);
37 map->l_gnu_bitmask_idxbits = bitmask_nwords - 1;
38 map->l_gnu_shift = *hash32++;
40 map->l_gnu_bitmask = (ElfW(Addr) *) hash32;
41 hash32 += __ELF_NATIVE_CLASS / 32 * bitmask_nwords;
43 map->l_gnu_buckets = hash32;
44 hash32 += map->l_nbuckets;
45 map->l_gnu_chain_zero = hash32 - symbias;
47 /* Initialize MIPS xhash translation table. */
48 ELF_MACHINE_XHASH_SETUP (hash32, symbias, map);
50 return;
53 if (!map->l_info[DT_HASH])
54 return;
55 hash = (void *) D_PTR (map, l_info[DT_HASH]);
57 map->l_nbuckets = *hash++;
58 /* Skip nchain. */
59 hash++;
60 map->l_buckets = hash;
61 hash += map->l_nbuckets;
62 map->l_chain = hash;