1/* Partial initialization of ld.so loaded via static dlopen.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <assert.h>
20
21/* Very special case: This object is built into the static libc, but
22 must know the layout of _rtld_global_ro. */
23#define SHARED
24#include <ldsodefs.h>
25
26#include <rtld_static_init.h>
27
28static const struct dlfcn_hook _dlfcn_hook =
29 {
30 .dlopen = __dlopen,
31 .dlclose = __dlclose,
32 .dlsym = __dlsym,
33 .dlvsym = __dlvsym,
34 .dlerror = __dlerror,
35 .dladdr = __dladdr,
36 .dladdr1 = __dladdr1,
37 .dlinfo = __dlinfo,
38 .dlmopen = __dlmopen,
39 .libc_dlopen_mode = __libc_dlopen_mode,
40 .libc_dlsym = __libc_dlsym,
41 .libc_dlvsym = __libc_dlvsym,
42 .libc_dlclose = __libc_dlclose,
43 };
44
45void
46__rtld_static_init (struct link_map *map)
47{
48 const ElfW(Sym) *sym
49 = _dl_lookup_direct (map, undef_name: "_rtld_global_ro",
50 new_hash: 0x9f28436a, /* dl_new_hash output. */
51 version: "GLIBC_PRIVATE",
52 version_hash: 0x0963cf85); /* _dl_elf_hash output. */
53 assert (sym != NULL);
54 struct rtld_global_ro *dl = DL_SYMBOL_ADDRESS (map, sym);
55
56 /* Perform partial initialization here. Note that this runs before
57 ld.so is relocated, so only members initialized without
58 relocations can be written here. */
59#ifdef HAVE_AUX_VECTOR
60 extern __typeof (dl->_dl_auxv) _dl_auxv attribute_hidden;
61 dl->_dl_auxv = _dl_auxv;
62 extern __typeof (dl->_dl_clktck) _dl_clktck attribute_hidden;
63 dl->_dl_clktck = _dl_clktck;
64#endif
65 dl->_dl_dlfcn_hook = &_dlfcn_hook;
66 extern __typeof (dl->_dl_hwcap) _dl_hwcap attribute_hidden;
67 dl->_dl_hwcap = _dl_hwcap;
68 extern __typeof (dl->_dl_hwcap2) _dl_hwcap2 attribute_hidden;
69 dl->_dl_hwcap2 = _dl_hwcap2;
70 extern __typeof (dl->_dl_minsigstacksize) _dl_minsigstacksize
71 attribute_hidden;
72 dl->_dl_minsigstacksize = _dl_minsigstacksize;
73 extern __typeof (dl->_dl_pagesize) _dl_pagesize attribute_hidden;
74 dl->_dl_pagesize = _dl_pagesize;
75 extern __typeof (dl->_dl_tls_static_align) _dl_tls_static_align
76 attribute_hidden;
77 dl->_dl_tls_static_align = _dl_tls_static_align;
78 extern __typeof (dl->_dl_tls_static_size) _dl_tls_static_size
79 attribute_hidden;
80 dl->_dl_tls_static_size = _dl_tls_static_size;
81 dl->_dl_find_object = _dl_find_object;
82
83 __rtld_static_init_arch (map, dl);
84}
85

source code of glibc/elf/rtld_static_init.c