elf: Make glibc.rtld.enable_secure ignore alias environment variables
[glibc.git] / elf / setup-vdso.h
blob888e1e4897958c5e1968245660b04d704f949302
1 /* Set up the data structures for the system-supplied DSO.
2 Copyright (C) 2012-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 static inline void __attribute__ ((always_inline))
20 setup_vdso (struct link_map *main_map __attribute__ ((unused)),
21 struct link_map ***first_preload __attribute__ ((unused)))
23 #ifdef NEED_DL_SYSINFO_DSO
24 if (GLRO(dl_sysinfo_dso) == NULL)
25 return;
27 /* Do an abridged version of the work _dl_map_object_from_fd would do
28 to map in the object. It's already mapped and prelinked (and
29 better be, since it's read-only and so we couldn't relocate it).
30 We just want our data structures to describe it as if we had just
31 mapped and relocated it normally. */
32 struct link_map *l = _dl_new_object ((char *) "", "", lt_library, NULL,
33 __RTLD_VDSO, LM_ID_BASE);
34 if (__glibc_likely (l != NULL))
36 l->l_phdr = ((const void *) GLRO(dl_sysinfo_dso)
37 + GLRO(dl_sysinfo_dso)->e_phoff);
38 l->l_phnum = GLRO(dl_sysinfo_dso)->e_phnum;
39 for (unsigned int i = 0; i < l->l_phnum; ++i)
41 const ElfW(Phdr) *const ph = &l->l_phdr[i];
42 if (ph->p_type == PT_DYNAMIC)
44 l->l_ld = (void *) ph->p_vaddr;
45 l->l_ldnum = ph->p_memsz / sizeof (ElfW(Dyn));
46 l->l_ld_readonly = (ph->p_flags & PF_W) == 0;
48 else if (ph->p_type == PT_LOAD)
50 if (! l->l_addr)
51 l->l_addr = ph->p_vaddr;
52 if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
53 l->l_map_end = ph->p_vaddr + ph->p_memsz;
55 else
56 /* There must be no TLS segment. */
57 assert (ph->p_type != PT_TLS);
59 l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso);
60 l->l_addr = l->l_map_start - l->l_addr;
61 l->l_map_end += l->l_addr;
62 l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
63 elf_get_dynamic_info (l, false, false);
64 _dl_setup_hash (l);
65 l->l_relocated = 1;
67 /* The vDSO is always used. */
68 l->l_used = 1;
70 /* Initialize l_local_scope to contain just this map. This allows
71 the use of dl_lookup_symbol_x to resolve symbols within the vdso.
72 So we create a single entry list pointing to l_real as its only
73 element */
74 l->l_local_scope[0]->r_nlist = 1;
75 l->l_local_scope[0]->r_list = &l->l_real;
77 /* Now that we have the info handy, use the DSO image's soname
78 so this object can be looked up by name. */
79 if (l->l_info[DT_SONAME] != NULL)
81 char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
82 + l->l_info[DT_SONAME]->d_un.d_val);
83 l->l_libname->name = dsoname;
84 l->l_name = dsoname;
87 /* Add the vDSO to the object list. */
88 _dl_add_to_namespace_list (l, LM_ID_BASE);
90 # if IS_IN (rtld)
91 /* Rearrange the list so this DSO appears after rtld_map. */
92 assert (l->l_next == NULL);
93 assert (l->l_prev == main_map);
94 GL(dl_rtld_map).l_next = l;
95 l->l_prev = &GL(dl_rtld_map);
96 *first_preload = &l->l_next;
97 # else
98 GL(dl_nns) = 1;
99 # endif
101 /* We have a prelinked DSO preloaded by the system. */
102 GLRO(dl_sysinfo_map) = l;
103 # ifdef NEED_DL_SYSINFO
104 if (GLRO(dl_sysinfo) == DL_SYSINFO_DEFAULT)
105 GLRO(dl_sysinfo) = GLRO(dl_sysinfo_dso)->e_entry + l->l_addr;
106 # endif
108 #endif