1 | /* Run-time dynamic linker data structures for loaded ELF shared objects. |
2 | Copyright (C) 1995-2021 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 | #ifndef _LDSODEFS_H |
20 | #define _LDSODEFS_H 1 |
21 | |
22 | #include <features.h> |
23 | |
24 | #include <stdbool.h> |
25 | #define __need_size_t |
26 | #define __need_NULL |
27 | #include <stddef.h> |
28 | #include <string.h> |
29 | #include <stdint.h> |
30 | |
31 | #include <elf.h> |
32 | #include <dlfcn.h> |
33 | #include <fpu_control.h> |
34 | #include <sys/mman.h> |
35 | #include <link.h> |
36 | #include <dl-lookupcfg.h> |
37 | #include <dl-sysdep.h> |
38 | #include <libc-lock.h> |
39 | #include <hp-timing.h> |
40 | #include <tls.h> |
41 | #include <list_t.h> |
42 | |
43 | __BEGIN_DECLS |
44 | |
45 | #define VERSYMIDX(sym) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (sym)) |
46 | #define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \ |
47 | + DT_EXTRANUM + DT_VALTAGIDX (tag)) |
48 | #define ADDRIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \ |
49 | + DT_EXTRANUM + DT_VALNUM + DT_ADDRTAGIDX (tag)) |
50 | |
51 | /* Type of GNU hash which the machine uses. */ |
52 | #ifndef ELF_MACHINE_GNU_HASH_ADDRIDX |
53 | # define ELF_MACHINE_GNU_HASH_ADDRIDX ADDRIDX (DT_GNU_HASH) |
54 | #endif |
55 | |
56 | /* Calculate the index of a symbol in GNU hash. */ |
57 | #ifndef ELF_MACHINE_HASH_SYMIDX |
58 | # define ELF_MACHINE_HASH_SYMIDX(map, hasharr) \ |
59 | ((hasharr) - (map)->l_gnu_chain_zero) |
60 | #endif |
61 | |
62 | /* Setup MIPS xhash. Defined only for MIPS. */ |
63 | #ifndef ELF_MACHINE_XHASH_SETUP |
64 | # define ELF_MACHINE_XHASH_SETUP(hash32, symbias, map) \ |
65 | ((void) (hash32), (void) (symbias), (void) (map)) |
66 | #endif |
67 | |
68 | /* We use this macro to refer to ELF types independent of the native wordsize. |
69 | `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */ |
70 | #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type) |
71 | |
72 | /* All references to the value of l_info[DT_PLTGOT], |
73 | l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA], |
74 | l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)] |
75 | have to be accessed via the D_PTR macro. The macro is needed since for |
76 | most architectures the entry is already relocated - but for some not |
77 | and we need to relocate at access time. */ |
78 | #ifdef DL_RO_DYN_SECTION |
79 | # define D_PTR(map, i) ((map)->i->d_un.d_ptr + (map)->l_addr) |
80 | #else |
81 | # define D_PTR(map, i) (map)->i->d_un.d_ptr |
82 | #endif |
83 | |
84 | /* Result of the lookup functions and how to retrieve the base address. */ |
85 | typedef struct link_map *lookup_t; |
86 | #define LOOKUP_VALUE(map) map |
87 | #define LOOKUP_VALUE_ADDRESS(map, set) ((set) || (map) ? (map)->l_addr : 0) |
88 | |
89 | /* Calculate the address of symbol REF using the base address from map MAP, |
90 | if non-NULL. Don't check for NULL map if MAP_SET is TRUE. */ |
91 | #define SYMBOL_ADDRESS(map, ref, map_set) \ |
92 | ((ref) == NULL ? 0 \ |
93 | : (__glibc_unlikely ((ref)->st_shndx == SHN_ABS) ? 0 \ |
94 | : LOOKUP_VALUE_ADDRESS (map, map_set)) + (ref)->st_value) |
95 | |
96 | /* Type of a constructor function, in DT_INIT, DT_INIT_ARRAY, |
97 | DT_PREINIT_ARRAY. */ |
98 | typedef void (*dl_init_t) (int, char **, char **); |
99 | |
100 | /* On some architectures a pointer to a function is not just a pointer |
101 | to the actual code of the function but rather an architecture |
102 | specific descriptor. */ |
103 | #ifndef ELF_FUNCTION_PTR_IS_SPECIAL |
104 | # define DL_SYMBOL_ADDRESS(map, ref) \ |
105 | (void *) SYMBOL_ADDRESS (map, ref, false) |
106 | # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr)) |
107 | # define DL_CALL_DT_INIT(map, start, argc, argv, env) \ |
108 | ((dl_init_t) (start)) (argc, argv, env) |
109 | # define DL_CALL_DT_FINI(map, start) ((fini_t) (start)) () |
110 | #endif |
111 | |
112 | /* On some architectures dladdr can't use st_size of all symbols this way. */ |
113 | #define DL_ADDR_SYM_MATCH(L, SYM, MATCHSYM, ADDR) \ |
114 | ((ADDR) >= (L)->l_addr + (SYM)->st_value \ |
115 | && ((((SYM)->st_shndx == SHN_UNDEF || (SYM)->st_size == 0) \ |
116 | && (ADDR) == (L)->l_addr + (SYM)->st_value) \ |
117 | || (ADDR) < (L)->l_addr + (SYM)->st_value + (SYM)->st_size) \ |
118 | && ((MATCHSYM) == NULL || (MATCHSYM)->st_value < (SYM)->st_value)) |
119 | |
120 | /* According to the ELF gABI no STV_HIDDEN or STV_INTERNAL symbols are |
121 | expected to be present in dynamic symbol tables as they should have |
122 | been either removed or converted to STB_LOCAL binding by the static |
123 | linker. However some GNU binutils versions produce such symbols in |
124 | some cases. To prevent such symbols present in a buggy binary from |
125 | preempting global symbols we filter them out with this predicate. */ |
126 | static __always_inline bool |
127 | dl_symbol_visibility_binds_local_p (const ElfW(Sym) *sym) |
128 | { |
129 | return (ELFW(ST_VISIBILITY) (sym->st_other) == STV_HIDDEN |
130 | || ELFW(ST_VISIBILITY) (sym->st_other) == STV_INTERNAL); |
131 | } |
132 | |
133 | /* Unmap a loaded object, called by _dl_close (). */ |
134 | #ifndef DL_UNMAP_IS_SPECIAL |
135 | # define DL_UNMAP(map) _dl_unmap_segments (map) |
136 | #endif |
137 | |
138 | /* Reloc type classes as returned by elf_machine_type_class(). |
139 | ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by |
140 | some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be |
141 | satisfied by any symbol in the executable. Some architectures do |
142 | not support copy relocations. In this case we define the macro to |
143 | zero so that the code for handling them gets automatically optimized |
144 | out. ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA means address of protected |
145 | data defined in the shared library may be external, i.e., due to copy |
146 | relocation. */ |
147 | #define ELF_RTYPE_CLASS_PLT 1 |
148 | #ifndef DL_NO_COPY_RELOCS |
149 | # define ELF_RTYPE_CLASS_COPY 2 |
150 | #else |
151 | # define ELF_RTYPE_CLASS_COPY 0 |
152 | #endif |
153 | /* If DL_EXTERN_PROTECTED_DATA is defined, address of protected data |
154 | defined in the shared library may be external, i.e., due to copy |
155 | relocation. */ |
156 | #ifdef DL_EXTERN_PROTECTED_DATA |
157 | # define ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA 4 |
158 | #else |
159 | # define ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA 0 |
160 | #endif |
161 | |
162 | /* ELF uses the PF_x macros to specify the segment permissions, mmap |
163 | uses PROT_xxx. In most cases the three macros have the values 1, 2, |
164 | and 3 but not in a matching order. The following macros allows |
165 | converting from the PF_x values to PROT_xxx values. */ |
166 | #define PF_TO_PROT \ |
167 | ((PROT_READ << (PF_R * 4)) \ |
168 | | (PROT_WRITE << (PF_W * 4)) \ |
169 | | (PROT_EXEC << (PF_X * 4)) \ |
170 | | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4)) \ |
171 | | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4)) \ |
172 | | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4) \ |
173 | | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4))) |
174 | |
175 | /* The filename itself, or the main program name, if available. */ |
176 | #define DSO_FILENAME(name) ((name)[0] ? (name) \ |
177 | : (rtld_progname ?: "<main program>")) |
178 | |
179 | #define RTLD_PROGNAME (rtld_progname ?: "<program name unknown>") |
180 | |
181 | /* For the version handling we need an array with only names and their |
182 | hash values. */ |
183 | struct r_found_version |
184 | { |
185 | const char *name; |
186 | ElfW(Word) hash; |
187 | |
188 | int hidden; |
189 | const char *filename; |
190 | }; |
191 | |
192 | /* We want to cache information about the searches for shared objects. */ |
193 | |
194 | enum r_dir_status { unknown, nonexisting, existing }; |
195 | |
196 | struct r_search_path_elem |
197 | { |
198 | /* This link is only used in the `all_dirs' member of `r_search_path'. */ |
199 | struct r_search_path_elem *next; |
200 | |
201 | /* Strings saying where the definition came from. */ |
202 | const char *what; |
203 | const char *where; |
204 | |
205 | /* Basename for this search path element. The string must end with |
206 | a slash character. */ |
207 | const char *dirname; |
208 | size_t dirnamelen; |
209 | |
210 | enum r_dir_status status[0]; |
211 | }; |
212 | |
213 | struct r_strlenpair |
214 | { |
215 | const char *str; |
216 | size_t len; |
217 | }; |
218 | |
219 | |
220 | /* A data structure for a simple single linked list of strings. */ |
221 | struct libname_list |
222 | { |
223 | const char *name; /* Name requested (before search). */ |
224 | struct libname_list *next; /* Link to next name for this object. */ |
225 | int dont_free; /* Flag whether this element should be freed |
226 | if the object is not entirely unloaded. */ |
227 | }; |
228 | |
229 | |
230 | /* Bit masks for the objects which valid callers can come from to |
231 | functions with restricted interface. */ |
232 | enum allowmask |
233 | { |
234 | allow_libc = 1, |
235 | allow_libdl = 2, |
236 | allow_libpthread = 4, |
237 | allow_ldso = 8 |
238 | }; |
239 | |
240 | |
241 | struct audit_ifaces |
242 | { |
243 | void (*activity) (uintptr_t *, unsigned int); |
244 | char *(*objsearch) (const char *, uintptr_t *, unsigned int); |
245 | unsigned int (*objopen) (struct link_map *, Lmid_t, uintptr_t *); |
246 | void (*preinit) (uintptr_t *); |
247 | union |
248 | { |
249 | uintptr_t (*symbind32) (Elf32_Sym *, unsigned int, uintptr_t *, |
250 | uintptr_t *, unsigned int *, const char *); |
251 | uintptr_t (*symbind64) (Elf64_Sym *, unsigned int, uintptr_t *, |
252 | uintptr_t *, unsigned int *, const char *); |
253 | }; |
254 | union |
255 | { |
256 | #ifdef ARCH_PLTENTER_MEMBERS |
257 | ARCH_PLTENTER_MEMBERS; |
258 | #endif |
259 | }; |
260 | union |
261 | { |
262 | #ifdef ARCH_PLTEXIT_MEMBERS |
263 | ARCH_PLTEXIT_MEMBERS; |
264 | #endif |
265 | }; |
266 | unsigned int (*objclose) (uintptr_t *); |
267 | |
268 | struct audit_ifaces *next; |
269 | }; |
270 | |
271 | |
272 | /* Test whether given NAME matches any of the names of the given object. */ |
273 | extern int _dl_name_match_p (const char *__name, const struct link_map *__map) |
274 | attribute_hidden; |
275 | |
276 | /* Compute next higher prime number. */ |
277 | extern unsigned long int _dl_higher_prime_number (unsigned long int n) |
278 | attribute_hidden; |
279 | |
280 | /* A stripped down strtoul-like implementation. */ |
281 | uint64_t _dl_strtoul (const char *, char **) attribute_hidden; |
282 | |
283 | /* Function used as argument for `_dl_receive_error' function. The |
284 | arguments are the error code, error string, and the objname the |
285 | error occurred in. */ |
286 | typedef void (*receiver_fct) (int, const char *, const char *); |
287 | |
288 | /* Internal functions of the run-time dynamic linker. |
289 | These can be accessed if you link again the dynamic linker |
290 | as a shared library, as in `-lld' or `/lib/ld.so' explicitly; |
291 | but are not normally of interest to user programs. |
292 | |
293 | The `-ldl' library functions in <dlfcn.h> provide a simple |
294 | user interface to run-time dynamic linking. */ |
295 | |
296 | |
297 | #ifndef SHARED |
298 | # define EXTERN extern |
299 | # define GL(name) _##name |
300 | #else |
301 | # define EXTERN |
302 | # if IS_IN (rtld) |
303 | # define GL(name) _rtld_local._##name |
304 | # else |
305 | # define GL(name) _rtld_global._##name |
306 | # endif |
307 | struct rtld_global |
308 | { |
309 | #endif |
310 | /* Don't change the order of the following elements. 'dl_loaded' |
311 | must remain the first element. Forever. */ |
312 | |
313 | /* Non-shared code has no support for multiple namespaces. */ |
314 | #ifdef SHARED |
315 | # define DL_NNS 16 |
316 | #else |
317 | # define DL_NNS 1 |
318 | #endif |
319 | EXTERN struct link_namespaces |
320 | { |
321 | /* A pointer to the map for the main map. */ |
322 | struct link_map *_ns_loaded; |
323 | /* Number of object in the _dl_loaded list. */ |
324 | unsigned int _ns_nloaded; |
325 | /* Direct pointer to the searchlist of the main object. */ |
326 | struct r_scope_elem *_ns_main_searchlist; |
327 | /* This is zero at program start to signal that the global scope map is |
328 | allocated by rtld. Later it keeps the size of the map. It might be |
329 | reset if in _dl_close if the last global object is removed. */ |
330 | unsigned int _ns_global_scope_alloc; |
331 | |
332 | /* During dlopen, this is the number of objects that still need to |
333 | be added to the global scope map. It has to be taken into |
334 | account when resizing the map, for future map additions after |
335 | recursive dlopen calls from ELF constructors. */ |
336 | unsigned int _ns_global_scope_pending_adds; |
337 | |
338 | /* Once libc.so has been loaded into the namespace, this points to |
339 | its link map. */ |
340 | struct link_map *libc_map; |
341 | |
342 | /* Search table for unique objects. */ |
343 | struct unique_sym_table |
344 | { |
345 | __rtld_lock_define_recursive (, lock) |
346 | struct unique_sym |
347 | { |
348 | uint32_t hashval; |
349 | const char *name; |
350 | const ElfW(Sym) *sym; |
351 | const struct link_map *map; |
352 | } *entries; |
353 | size_t size; |
354 | size_t n_elements; |
355 | void (*free) (void *); |
356 | } _ns_unique_sym_table; |
357 | /* Keep track of changes to each namespace' list. */ |
358 | struct r_debug _ns_debug; |
359 | } _dl_ns[DL_NNS]; |
360 | /* One higher than index of last used namespace. */ |
361 | EXTERN size_t _dl_nns; |
362 | |
363 | /* During the program run we must not modify the global data of |
364 | loaded shared object simultanously in two threads. Therefore we |
365 | protect `_dl_open' and `_dl_close' in dl-close.c. |
366 | |
367 | This must be a recursive lock since the initializer function of |
368 | the loaded object might as well require a call to this function. |
369 | At this time it is not anymore a problem to modify the tables. */ |
370 | __rtld_lock_define_recursive (EXTERN, _dl_load_lock) |
371 | /* This lock is used to keep __dl_iterate_phdr from inspecting the |
372 | list of loaded objects while an object is added to or removed |
373 | from that list. */ |
374 | __rtld_lock_define_recursive (EXTERN, _dl_load_write_lock) |
375 | |
376 | /* Incremented whenever something may have been added to dl_loaded. */ |
377 | EXTERN unsigned long long _dl_load_adds; |
378 | |
379 | /* The object to be initialized first. */ |
380 | EXTERN struct link_map *_dl_initfirst; |
381 | |
382 | /* Map of shared object to be profiled. */ |
383 | EXTERN struct link_map *_dl_profile_map; |
384 | |
385 | /* Counters for the number of relocations performed. */ |
386 | EXTERN unsigned long int _dl_num_relocations; |
387 | EXTERN unsigned long int _dl_num_cache_relocations; |
388 | |
389 | /* List of search directories. */ |
390 | EXTERN struct r_search_path_elem *_dl_all_dirs; |
391 | |
392 | /* Structure describing the dynamic linker itself. */ |
393 | EXTERN struct link_map _dl_rtld_map; |
394 | #ifdef SHARED |
395 | /* Used to store the audit information for the link map of the |
396 | dynamic loader. */ |
397 | struct auditstate _dl_rtld_auditstate[DL_NNS]; |
398 | #endif |
399 | |
400 | #if !PTHREAD_IN_LIBC && defined SHARED \ |
401 | && defined __rtld_lock_default_lock_recursive |
402 | EXTERN void (*_dl_rtld_lock_recursive) (void *); |
403 | EXTERN void (*_dl_rtld_unlock_recursive) (void *); |
404 | #endif |
405 | |
406 | /* Get architecture specific definitions. */ |
407 | #define PROCINFO_DECL |
408 | #ifndef PROCINFO_CLASS |
409 | # define PROCINFO_CLASS EXTERN |
410 | #endif |
411 | #include <dl-procruntime.c> |
412 | |
413 | #if !PTHREAD_IN_LIBC |
414 | /* If loading a shared object requires that we make the stack executable |
415 | when it was not, we do it by calling this function. |
416 | It returns an errno code or zero on success. */ |
417 | EXTERN int (*_dl_make_stack_executable_hook) (void **); |
418 | #endif |
419 | |
420 | /* Prevailing state of the stack, PF_X indicating it's executable. */ |
421 | EXTERN ElfW(Word) _dl_stack_flags; |
422 | |
423 | /* Flag signalling whether there are gaps in the module ID allocation. */ |
424 | EXTERN bool _dl_tls_dtv_gaps; |
425 | /* Highest dtv index currently needed. */ |
426 | EXTERN size_t _dl_tls_max_dtv_idx; |
427 | /* Information about the dtv slots. */ |
428 | EXTERN struct dtv_slotinfo_list |
429 | { |
430 | size_t len; |
431 | struct dtv_slotinfo_list *next; |
432 | struct dtv_slotinfo |
433 | { |
434 | size_t gen; |
435 | struct link_map *map; |
436 | } slotinfo[]; |
437 | } *_dl_tls_dtv_slotinfo_list; |
438 | /* Number of modules in the static TLS block. */ |
439 | EXTERN size_t _dl_tls_static_nelem; |
440 | /* Size actually allocated in the static TLS block. */ |
441 | EXTERN size_t _dl_tls_static_used; |
442 | /* Remaining amount of static TLS that may be used for optimizing |
443 | dynamic TLS access (e.g. with TLSDESC). */ |
444 | EXTERN size_t _dl_tls_static_optional; |
445 | |
446 | /* Number of additional entries in the slotinfo array of each slotinfo |
447 | list element. A large number makes it almost certain take we never |
448 | have to iterate beyond the first element in the slotinfo list. */ |
449 | #define TLS_SLOTINFO_SURPLUS (62) |
450 | |
451 | /* Number of additional slots in the dtv allocated. */ |
452 | #define DTV_SURPLUS (14) |
453 | |
454 | /* Initial dtv of the main thread, not allocated with normal malloc. */ |
455 | EXTERN void *_dl_initial_dtv; |
456 | /* Generation counter for the dtv. */ |
457 | EXTERN size_t _dl_tls_generation; |
458 | |
459 | #if !THREAD_GSCOPE_IN_TCB |
460 | EXTERN void (*_dl_init_static_tls) (struct link_map *); |
461 | #endif |
462 | |
463 | /* Scopes to free after next THREAD_GSCOPE_WAIT (). */ |
464 | EXTERN struct dl_scope_free_list |
465 | { |
466 | size_t count; |
467 | void *list[50]; |
468 | } *_dl_scope_free_list; |
469 | #if THREAD_GSCOPE_IN_TCB |
470 | /* List of active thread stacks, with memory managed by glibc. */ |
471 | EXTERN list_t _dl_stack_used; |
472 | |
473 | /* List of thread stacks that were allocated by the application. */ |
474 | EXTERN list_t _dl_stack_user; |
475 | |
476 | /* List of queued thread stacks. */ |
477 | EXTERN list_t _dl_stack_cache; |
478 | |
479 | /* Total size of all stacks in the cache (sum over stackblock_size). */ |
480 | EXTERN size_t _dl_stack_cache_actsize; |
481 | |
482 | /* We need to record what list operations we are going to do so |
483 | that, in case of an asynchronous interruption due to a fork() |
484 | call, we can correct for the work. */ |
485 | EXTERN uintptr_t _dl_in_flight_stack; |
486 | |
487 | /* Mutex protecting the stack lists. */ |
488 | EXTERN int _dl_stack_cache_lock; |
489 | #else |
490 | EXTERN int _dl_thread_gscope_count; |
491 | #endif |
492 | #ifdef SHARED |
493 | }; |
494 | # define __rtld_global_attribute__ |
495 | # if IS_IN (rtld) |
496 | # ifdef HAVE_SDATA_SECTION |
497 | # define __rtld_local_attribute__ \ |
498 | __attribute__ ((visibility ("hidden"), section (".sdata"))) |
499 | # undef __rtld_global_attribute__ |
500 | # define __rtld_global_attribute__ __attribute__ ((section (".sdata"))) |
501 | # else |
502 | # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden"))) |
503 | # endif |
504 | extern struct rtld_global _rtld_local __rtld_local_attribute__; |
505 | # undef __rtld_local_attribute__ |
506 | # endif |
507 | extern struct rtld_global _rtld_global __rtld_global_attribute__; |
508 | # undef __rtld_global_attribute__ |
509 | #endif |
510 | |
511 | #ifndef SHARED |
512 | # define GLRO(name) _##name |
513 | #else |
514 | # if IS_IN (rtld) |
515 | # define GLRO(name) _rtld_local_ro._##name |
516 | # else |
517 | # define GLRO(name) _rtld_global_ro._##name |
518 | # endif |
519 | struct rtld_global_ro |
520 | { |
521 | #endif |
522 | |
523 | /* If nonzero the appropriate debug information is printed. */ |
524 | EXTERN int _dl_debug_mask; |
525 | #define DL_DEBUG_LIBS (1 << 0) |
526 | #define DL_DEBUG_IMPCALLS (1 << 1) |
527 | #define DL_DEBUG_BINDINGS (1 << 2) |
528 | #define DL_DEBUG_SYMBOLS (1 << 3) |
529 | #define DL_DEBUG_VERSIONS (1 << 4) |
530 | #define DL_DEBUG_RELOC (1 << 5) |
531 | #define DL_DEBUG_FILES (1 << 6) |
532 | #define DL_DEBUG_STATISTICS (1 << 7) |
533 | #define DL_DEBUG_UNUSED (1 << 8) |
534 | #define DL_DEBUG_SCOPES (1 << 9) |
535 | /* These two are used only internally. */ |
536 | #define DL_DEBUG_HELP (1 << 10) |
537 | #define DL_DEBUG_PRELINK (1 << 11) |
538 | |
539 | /* OS version. */ |
540 | EXTERN unsigned int _dl_osversion; |
541 | /* Platform name. */ |
542 | EXTERN const char *_dl_platform; |
543 | EXTERN size_t _dl_platformlen; |
544 | |
545 | /* Cached value of `getpagesize ()'. */ |
546 | EXTERN size_t _dl_pagesize; |
547 | |
548 | /* Cached value of `sysconf (_SC_MINSIGSTKSZ)'. */ |
549 | EXTERN size_t _dl_minsigstacksize; |
550 | |
551 | /* Do we read from ld.so.cache? */ |
552 | EXTERN int _dl_inhibit_cache; |
553 | |
554 | /* Copy of the content of `_dl_main_searchlist' at startup time. */ |
555 | EXTERN struct r_scope_elem _dl_initial_searchlist; |
556 | |
557 | /* CLK_TCK as reported by the kernel. */ |
558 | EXTERN int _dl_clktck; |
559 | |
560 | /* If nonzero print warnings messages. */ |
561 | EXTERN int _dl_verbose; |
562 | |
563 | /* File descriptor to write debug messages to. */ |
564 | EXTERN int _dl_debug_fd; |
565 | |
566 | /* Do we do lazy relocations? */ |
567 | EXTERN int _dl_lazy; |
568 | |
569 | /* Nonzero if runtime lookups should not update the .got/.plt. */ |
570 | EXTERN int _dl_bind_not; |
571 | |
572 | /* Nonzero if references should be treated as weak during runtime |
573 | linking. */ |
574 | EXTERN int _dl_dynamic_weak; |
575 | |
576 | /* Default floating-point control word. */ |
577 | EXTERN fpu_control_t _dl_fpu_control; |
578 | |
579 | /* Expected cache ID. */ |
580 | EXTERN int _dl_correct_cache_id; |
581 | |
582 | /* Mask for hardware capabilities that are available. */ |
583 | EXTERN uint64_t _dl_hwcap; |
584 | |
585 | #if !HAVE_TUNABLES |
586 | /* Mask for important hardware capabilities we honour. */ |
587 | EXTERN uint64_t _dl_hwcap_mask; |
588 | #endif |
589 | |
590 | #ifdef HAVE_AUX_VECTOR |
591 | /* Pointer to the auxv list supplied to the program at startup. */ |
592 | EXTERN ElfW(auxv_t) *_dl_auxv; |
593 | #endif |
594 | |
595 | /* Get architecture specific definitions. */ |
596 | #include <dl-procinfo.c> |
597 | |
598 | /* Names of shared object for which the RPATH should be ignored. */ |
599 | EXTERN const char *_dl_inhibit_rpath; |
600 | |
601 | /* Location of the binary. */ |
602 | EXTERN const char *_dl_origin_path; |
603 | |
604 | /* -1 if the dynamic linker should honor library load bias, |
605 | 0 if not, -2 use the default (honor biases for normal |
606 | binaries, don't honor for PIEs). */ |
607 | EXTERN ElfW(Addr) _dl_use_load_bias; |
608 | |
609 | /* Size of the static TLS block. */ |
610 | EXTERN size_t _dl_tls_static_size; |
611 | |
612 | /* Alignment requirement of the static TLS block. */ |
613 | EXTERN size_t _dl_tls_static_align; |
614 | |
615 | /* Size of surplus space in the static TLS area for dynamically |
616 | loaded modules with IE-model TLS or for TLSDESC optimization. |
617 | See comments in elf/dl-tls.c where it is initialized. */ |
618 | EXTERN size_t _dl_tls_static_surplus; |
619 | |
620 | /* Name of the shared object to be profiled (if any). */ |
621 | EXTERN const char *_dl_profile; |
622 | /* Filename of the output file. */ |
623 | EXTERN const char *_dl_profile_output; |
624 | /* Name of the object we want to trace the prelinking. */ |
625 | EXTERN const char *_dl_trace_prelink; |
626 | /* Map of shared object to be prelink traced. */ |
627 | EXTERN struct link_map *_dl_trace_prelink_map; |
628 | |
629 | /* All search directories defined at startup. This is assigned a |
630 | non-NULL pointer by the ld.so startup code (after initialization |
631 | to NULL), so this can also serve as an indicator whether a copy |
632 | of ld.so is initialized and active. See the rtld_active function |
633 | below. */ |
634 | EXTERN struct r_search_path_elem *_dl_init_all_dirs; |
635 | |
636 | #ifdef NEED_DL_SYSINFO |
637 | /* Syscall handling improvements. This is very specific to x86. */ |
638 | EXTERN uintptr_t _dl_sysinfo; |
639 | #endif |
640 | |
641 | #ifdef NEED_DL_SYSINFO_DSO |
642 | /* The vsyscall page is a virtual DSO pre-mapped by the kernel. |
643 | This points to its ELF header. */ |
644 | EXTERN const ElfW(Ehdr) *_dl_sysinfo_dso; |
645 | |
646 | /* At startup time we set up the normal DSO data structure for it, |
647 | and this points to it. */ |
648 | EXTERN struct link_map *_dl_sysinfo_map; |
649 | |
650 | # define PROCINFO_DECL |
651 | # ifndef PROCINFO_CLASS |
652 | # define PROCINFO_CLASS EXTERN |
653 | # endif |
654 | # include <dl-vdso-setup.c> |
655 | #endif |
656 | |
657 | /* Mask for more hardware capabilities that are available on some |
658 | platforms. */ |
659 | EXTERN uint64_t _dl_hwcap2; |
660 | |
661 | #ifdef SHARED |
662 | /* We add a function table to _rtld_global which is then used to |
663 | call the function instead of going through the PLT. The result |
664 | is that we can avoid exporting the functions and we do not jump |
665 | PLT relocations in libc.so. */ |
666 | void (*_dl_debug_printf) (const char *, ...) |
667 | __attribute__ ((__format__ (__printf__, 1, 2))); |
668 | void (*_dl_mcount) (ElfW(Addr) frompc, ElfW(Addr) selfpc); |
669 | lookup_t (*_dl_lookup_symbol_x) (const char *, struct link_map *, |
670 | const ElfW(Sym) **, struct r_scope_elem *[], |
671 | const struct r_found_version *, int, int, |
672 | struct link_map *); |
673 | void *(*_dl_open) (const char *file, int mode, const void *caller_dlopen, |
674 | Lmid_t nsid, int argc, char *argv[], char *env[]); |
675 | void (*_dl_close) (void *map); |
676 | /* libdl in a secondary namespace (after dlopen) must use |
677 | _dl_catch_error from the main namespace, so it has to be |
678 | exported in some way. */ |
679 | int (*_dl_catch_error) (const char **objname, const char **errstring, |
680 | bool *mallocedp, void (*operate) (void *), |
681 | void *args); |
682 | /* libdl in a secondary namespace must use free from the base |
683 | namespace. */ |
684 | void (*_dl_error_free) (void *); |
685 | void *(*_dl_tls_get_addr_soft) (struct link_map *); |
686 | #ifdef HAVE_DL_DISCOVER_OSVERSION |
687 | int (*_dl_discover_osversion) (void); |
688 | #endif |
689 | |
690 | /* Dynamic linker operations used after static dlopen. */ |
691 | const struct dlfcn_hook *_dl_dlfcn_hook; |
692 | |
693 | /* List of auditing interfaces. */ |
694 | struct audit_ifaces *_dl_audit; |
695 | unsigned int _dl_naudit; |
696 | }; |
697 | # define __rtld_global_attribute__ |
698 | # if IS_IN (rtld) |
699 | # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden"))) |
700 | extern struct rtld_global_ro _rtld_local_ro |
701 | attribute_relro __rtld_local_attribute__; |
702 | extern struct rtld_global_ro _rtld_global_ro |
703 | attribute_relro __rtld_global_attribute__; |
704 | # undef __rtld_local_attribute__ |
705 | # else |
706 | /* We cheat a bit here. We declare the variable as as const even |
707 | though it is at startup. */ |
708 | extern const struct rtld_global_ro _rtld_global_ro |
709 | attribute_relro __rtld_global_attribute__; |
710 | # endif |
711 | # undef __rtld_global_attribute__ |
712 | #endif |
713 | #undef EXTERN |
714 | |
715 | #ifndef SHARED |
716 | /* dl-support.c defines these and initializes them early on. */ |
717 | extern const ElfW(Phdr) *_dl_phdr; |
718 | extern size_t _dl_phnum; |
719 | #endif |
720 | |
721 | #if PTHREAD_IN_LIBC |
722 | /* This function changes the permissions of all stacks (not just those |
723 | of the main stack). */ |
724 | int _dl_make_stacks_executable (void **stack_endp) attribute_hidden; |
725 | #else |
726 | /* This is the initial value of GL(dl_make_stack_executable_hook). |
727 | A threads library can change it. The ld.so implementation changes |
728 | the permissions of the main stack only. */ |
729 | extern int _dl_make_stack_executable (void **stack_endp); |
730 | rtld_hidden_proto (_dl_make_stack_executable) |
731 | #endif |
732 | |
733 | /* Variable pointing to the end of the stack (or close to it). This value |
734 | must be constant over the runtime of the application. Some programs |
735 | might use the variable which results in copy relocations on some |
736 | platforms. But this does not matter, ld.so can always use the local |
737 | copy. */ |
738 | extern void *__libc_stack_end |
739 | #ifndef LIBC_STACK_END_NOT_RELRO |
740 | attribute_relro |
741 | #endif |
742 | ; |
743 | rtld_hidden_proto (__libc_stack_end) |
744 | |
745 | /* Parameters passed to the dynamic linker. */ |
746 | extern int _dl_argc attribute_hidden attribute_relro; |
747 | extern char **_dl_argv |
748 | #ifndef DL_ARGV_NOT_RELRO |
749 | attribute_relro |
750 | #endif |
751 | ; |
752 | rtld_hidden_proto (_dl_argv) |
753 | #if IS_IN (rtld) |
754 | extern unsigned int _dl_skip_args attribute_hidden |
755 | # ifndef DL_ARGV_NOT_RELRO |
756 | attribute_relro |
757 | # endif |
758 | ; |
759 | extern unsigned int _dl_skip_args_internal attribute_hidden |
760 | # ifndef DL_ARGV_NOT_RELRO |
761 | attribute_relro |
762 | # endif |
763 | ; |
764 | #endif |
765 | #define rtld_progname _dl_argv[0] |
766 | |
767 | /* Flag set at startup and cleared when the last initializer has run. */ |
768 | extern int _dl_starting_up; |
769 | weak_extern (_dl_starting_up) |
770 | rtld_hidden_proto (_dl_starting_up) |
771 | |
772 | /* Random data provided by the kernel. */ |
773 | extern void *_dl_random attribute_hidden attribute_relro; |
774 | |
775 | /* Write message on the debug file descriptor. The parameters are |
776 | interpreted as for a `printf' call. All the lines start with a |
777 | tag showing the PID. */ |
778 | extern void _dl_debug_printf (const char *fmt, ...) |
779 | __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden; |
780 | |
781 | /* Write message on the debug file descriptor. The parameters are |
782 | interpreted as for a `printf' call. All the lines buf the first |
783 | start with a tag showing the PID. */ |
784 | extern void _dl_debug_printf_c (const char *fmt, ...) |
785 | __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden; |
786 | |
787 | |
788 | /* Write a message on the specified descriptor FD. The parameters are |
789 | interpreted as for a `printf' call. */ |
790 | #if IS_IN (rtld) || !defined (SHARED) |
791 | extern void _dl_dprintf (int fd, const char *fmt, ...) |
792 | __attribute__ ((__format__ (__printf__, 2, 3))) |
793 | attribute_hidden; |
794 | #else |
795 | __attribute__ ((always_inline, __format__ (__printf__, 2, 3))) |
796 | static inline void |
797 | _dl_dprintf (int fd, const char *fmt, ...) |
798 | { |
799 | /* Use local declaration to avoid includign <stdio.h>. */ |
800 | extern int __dprintf(int fd, const char *format, ...) attribute_hidden; |
801 | __dprintf (fd, fmt, __builtin_va_arg_pack ()); |
802 | } |
803 | #endif |
804 | |
805 | /* Write LENGTH bytes at BUFFER to FD, like write. Returns the number |
806 | of bytes written on success, or a negative error constant on |
807 | failure. */ |
808 | ssize_t _dl_write (int fd, const void *buffer, size_t length) |
809 | attribute_hidden; |
810 | |
811 | /* Write a message on the specified descriptor standard output. The |
812 | parameters are interpreted as for a `printf' call. */ |
813 | void _dl_printf (const char *fmt, ...) |
814 | attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2))); |
815 | |
816 | /* Write a message on the specified descriptor standard error. The |
817 | parameters are interpreted as for a `printf' call. */ |
818 | void _dl_error_printf (const char *fmt, ...) |
819 | attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2))); |
820 | |
821 | /* Write a message on the specified descriptor standard error and exit |
822 | the program. The parameters are interpreted as for a `printf' call. */ |
823 | void _dl_fatal_printf (const char *fmt, ...) |
824 | __attribute__ ((__format__ (__printf__, 1, 2), __noreturn__)); |
825 | rtld_hidden_proto (_dl_fatal_printf) |
826 | |
827 | /* An exception raised by the _dl_signal_error function family and |
828 | caught by _dl_catch_error function family. Exceptions themselves |
829 | are copied as part of the raise operation, but the strings are |
830 | not. */ |
831 | struct dl_exception |
832 | { |
833 | const char *objname; |
834 | const char *errstring; |
835 | |
836 | /* This buffer typically stores both objname and errstring |
837 | above. */ |
838 | char *message_buffer; |
839 | }; |
840 | |
841 | /* Creates a new exception. This calls malloc; if allocation fails, |
842 | dummy values are inserted. OBJECT is the name of the problematical |
843 | shared object, or null if its a general problem. ERRSTRING is a |
844 | string describing the specific problem. */ |
845 | void _dl_exception_create (struct dl_exception *, const char *object, |
846 | const char *errstring) |
847 | __attribute__ ((nonnull (1, 3))); |
848 | rtld_hidden_proto (_dl_exception_create) |
849 | |
850 | /* Used internally to implement dlerror message freeing. See |
851 | include/dlfcn.h and dlfcn/dlerror.c. */ |
852 | void _dl_error_free (void *ptr) attribute_hidden; |
853 | |
854 | /* Like _dl_exception_create, but create errstring from a format |
855 | string FMT. Currently, only "%s" and "%%" are supported as format |
856 | directives. */ |
857 | void _dl_exception_create_format (struct dl_exception *, const char *objname, |
858 | const char *fmt, ...) |
859 | __attribute__ ((nonnull (1, 3), format (printf, 3, 4))); |
860 | rtld_hidden_proto (_dl_exception_create_format) |
861 | |
862 | /* Deallocate the exception, freeing allocated buffers (if |
863 | possible). */ |
864 | void _dl_exception_free (struct dl_exception *) |
865 | __attribute__ ((nonnull (1))); |
866 | rtld_hidden_proto (_dl_exception_free) |
867 | |
868 | /* This function is called by all the internal dynamic linker |
869 | functions when they encounter an error. ERRCODE is either an |
870 | `errno' code or zero; it specifies the return value of |
871 | _dl_catch_error. OCCASION is included in the error message if the |
872 | process is terminated immediately. */ |
873 | void _dl_signal_exception (int errcode, struct dl_exception *, |
874 | const char *occasion) |
875 | __attribute__ ((__noreturn__)); |
876 | libc_hidden_proto (_dl_signal_exception) |
877 | |
878 | /* Like _dl_signal_exception, but creates the exception first. */ |
879 | extern void _dl_signal_error (int errcode, const char *object, |
880 | const char *occasion, const char *errstring) |
881 | __attribute__ ((__noreturn__)); |
882 | libc_hidden_proto (_dl_signal_error) |
883 | |
884 | /* Like _dl_signal_exception, but may return when called in the |
885 | context of _dl_receive_error. This is only used during ld.so |
886 | bootstrap. In static and profiled builds, this is equivalent to |
887 | _dl_signal_exception. */ |
888 | #if IS_IN (rtld) |
889 | extern void _dl_signal_cexception (int errcode, struct dl_exception *, |
890 | const char *occasion) attribute_hidden; |
891 | #else |
892 | __attribute__ ((always_inline)) |
893 | static inline void |
894 | _dl_signal_cexception (int errcode, struct dl_exception *exception, |
895 | const char *occasion) |
896 | { |
897 | _dl_signal_exception (errcode, exception, occasion); |
898 | } |
899 | #endif |
900 | |
901 | /* See _dl_signal_cexception above. */ |
902 | #if IS_IN (rtld) |
903 | extern void _dl_signal_cerror (int errcode, const char *object, |
904 | const char *occasion, const char *errstring) |
905 | attribute_hidden; |
906 | #else |
907 | __attribute__ ((always_inline)) |
908 | static inline void |
909 | _dl_signal_cerror (int errcode, const char *object, |
910 | const char *occasion, const char *errstring) |
911 | { |
912 | _dl_signal_error (errcode, object, occasion, errstring); |
913 | } |
914 | #endif |
915 | |
916 | /* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike |
917 | `_dl_catch_error' the operation is resumed after the OPERATE |
918 | function returns. |
919 | ARGS is passed as argument to OPERATE. */ |
920 | extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *), |
921 | void *args) attribute_hidden; |
922 | |
923 | /* Call OPERATE, catching errors from `_dl_signal_error' and related |
924 | functions. If there is no error, *ERRSTRING is set to null. If |
925 | there is an error, *ERRSTRING is set to a string constructed from |
926 | the strings passed to _dl_signal_error, and the error code passed |
927 | is the return value and *OBJNAME is set to the object name which |
928 | experienced the problems. ERRSTRING if nonzero points to a |
929 | malloc'ed string which the caller has to free after use. ARGS is |
930 | passed as argument to OPERATE. MALLOCEDP is set to true only if |
931 | the returned string is allocated using the libc's malloc. */ |
932 | extern int _dl_catch_error (const char **objname, const char **errstring, |
933 | bool *mallocedp, void (*operate) (void *), |
934 | void *args); |
935 | libc_hidden_proto (_dl_catch_error) |
936 | |
937 | /* Used for initializing GLRO (_dl_catch_error). */ |
938 | extern __typeof__ (_dl_catch_error) _rtld_catch_error attribute_hidden; |
939 | |
940 | /* Call OPERATE (ARGS). If no error occurs, set *EXCEPTION to zero. |
941 | Otherwise, store a copy of the raised exception in *EXCEPTION, |
942 | which has to be freed by _dl_exception_free. As a special case, if |
943 | EXCEPTION is null, call OPERATE (ARGS) with exception handling |
944 | disabled (so that exceptions are fatal). */ |
945 | int _dl_catch_exception (struct dl_exception *exception, |
946 | void (*operate) (void *), void *args); |
947 | libc_hidden_proto (_dl_catch_exception) |
948 | |
949 | /* Open the shared object NAME and map in its segments. |
950 | LOADER's DT_RPATH is used in searching for NAME. |
951 | If the object is already opened, returns its existing map. */ |
952 | extern struct link_map *_dl_map_object (struct link_map *loader, |
953 | const char *name, |
954 | int type, int trace_mode, int mode, |
955 | Lmid_t nsid) attribute_hidden; |
956 | |
957 | /* Call _dl_map_object on the dependencies of MAP, and set up |
958 | MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously |
959 | loaded objects that will be inserted into MAP->l_searchlist after MAP |
960 | but before its dependencies. */ |
961 | extern void _dl_map_object_deps (struct link_map *map, |
962 | struct link_map **preloads, |
963 | unsigned int npreloads, int trace_mode, |
964 | int open_mode) |
965 | attribute_hidden; |
966 | |
967 | /* Cache the locations of MAP's hash table. */ |
968 | extern void _dl_setup_hash (struct link_map *map) attribute_hidden; |
969 | |
970 | |
971 | /* Collect the directories in the search path for LOADER's dependencies. |
972 | The data structure is defined in <dlfcn.h>. If COUNTING is true, |
973 | SI->dls_cnt and SI->dls_size are set; if false, those must be as set |
974 | by a previous call with COUNTING set, and SI must point to SI->dls_size |
975 | bytes to be used in filling in the result. */ |
976 | extern void _dl_rtld_di_serinfo (struct link_map *loader, |
977 | Dl_serinfo *si, bool counting); |
978 | |
979 | /* Process PT_GNU_PROPERTY program header PH in module L after |
980 | PT_LOAD segments are mapped from file FD. */ |
981 | void _dl_process_pt_gnu_property (struct link_map *l, int fd, |
982 | const ElfW(Phdr) *ph); |
983 | |
984 | |
985 | /* Search loaded objects' symbol tables for a definition of the symbol |
986 | referred to by UNDEF. *SYM is the symbol table entry containing the |
987 | reference; it is replaced with the defining symbol, and the base load |
988 | address of the defining object is returned. SYMBOL_SCOPE is a |
989 | null-terminated list of object scopes to search; each object's |
990 | l_searchlist (i.e. the segment of the dependency tree starting at that |
991 | object) is searched in turn. REFERENCE_NAME should name the object |
992 | containing the reference; it is used in error messages. |
993 | TYPE_CLASS describes the type of symbol we are looking for. */ |
994 | enum |
995 | { |
996 | /* If necessary add dependency between user and provider object. */ |
997 | DL_LOOKUP_ADD_DEPENDENCY = 1, |
998 | /* Return most recent version instead of default version for |
999 | unversioned lookup. */ |
1000 | DL_LOOKUP_RETURN_NEWEST = 2, |
1001 | /* Set if dl_lookup* called with GSCOPE lock held. */ |
1002 | DL_LOOKUP_GSCOPE_LOCK = 4, |
1003 | /* Set if dl_lookup is called for non-lazy relocation processing |
1004 | from _dl_relocate_object in elf/dl-reloc.c. */ |
1005 | DL_LOOKUP_FOR_RELOCATE = 8, |
1006 | }; |
1007 | |
1008 | /* Lookup versioned symbol. */ |
1009 | extern lookup_t _dl_lookup_symbol_x (const char *undef, |
1010 | struct link_map *undef_map, |
1011 | const ElfW(Sym) **sym, |
1012 | struct r_scope_elem *symbol_scope[], |
1013 | const struct r_found_version *version, |
1014 | int type_class, int flags, |
1015 | struct link_map *skip_map) |
1016 | attribute_hidden; |
1017 | |
1018 | |
1019 | /* Restricted version of _dl_lookup_symbol_x. Searches MAP (and only |
1020 | MAP) for the symbol UNDEF_NAME, with GNU hash NEW_HASH (computed |
1021 | with dl_new_hash), symbol version VERSION, and symbol version hash |
1022 | VERSION_HASH (computed with _dl_elf_hash). Returns a pointer to |
1023 | the symbol table entry in MAP on success, or NULL on failure. MAP |
1024 | must have symbol versioning information, or otherwise the result is |
1025 | undefined. */ |
1026 | const ElfW(Sym) *_dl_lookup_direct (struct link_map *map, |
1027 | const char *undef_name, |
1028 | uint32_t new_hash, |
1029 | const char *version, |
1030 | uint32_t version_hash) attribute_hidden; |
1031 | |
1032 | /* Add the new link_map NEW to the end of the namespace list. */ |
1033 | extern void _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid) |
1034 | attribute_hidden; |
1035 | |
1036 | /* Allocate a `struct link_map' for a new object being loaded. */ |
1037 | extern struct link_map *_dl_new_object (char *realname, const char *libname, |
1038 | int type, struct link_map *loader, |
1039 | int mode, Lmid_t nsid) |
1040 | attribute_hidden; |
1041 | |
1042 | /* Relocate the given object (if it hasn't already been). |
1043 | SCOPE is passed to _dl_lookup_symbol in symbol lookups. |
1044 | If RTLD_LAZY is set in RELOC-MODE, don't relocate its PLT. */ |
1045 | extern void _dl_relocate_object (struct link_map *map, |
1046 | struct r_scope_elem *scope[], |
1047 | int reloc_mode, int consider_profiling) |
1048 | attribute_hidden; |
1049 | |
1050 | /* Protect PT_GNU_RELRO area. */ |
1051 | extern void _dl_protect_relro (struct link_map *map) attribute_hidden; |
1052 | |
1053 | /* Call _dl_signal_error with a message about an unhandled reloc type. |
1054 | TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value. |
1055 | PLT is nonzero if this was a PLT reloc; it just affects the message. */ |
1056 | extern void _dl_reloc_bad_type (struct link_map *map, |
1057 | unsigned int type, int plt) |
1058 | attribute_hidden __attribute__ ((__noreturn__)); |
1059 | |
1060 | /* Resolve conflicts if prelinking. */ |
1061 | extern void _dl_resolve_conflicts (struct link_map *l, |
1062 | ElfW(Rela) *conflict, |
1063 | ElfW(Rela) *conflictend) |
1064 | attribute_hidden; |
1065 | |
1066 | /* Check the version dependencies of all objects available through |
1067 | MAP. If VERBOSE print some more diagnostics. */ |
1068 | extern int _dl_check_all_versions (struct link_map *map, int verbose, |
1069 | int trace_mode) attribute_hidden; |
1070 | |
1071 | /* Check the version dependencies for MAP. If VERBOSE print some more |
1072 | diagnostics. */ |
1073 | extern int _dl_check_map_versions (struct link_map *map, int verbose, |
1074 | int trace_mode) attribute_hidden; |
1075 | |
1076 | /* Initialize the object in SCOPE by calling the constructors with |
1077 | ARGC, ARGV, and ENV as the parameters. */ |
1078 | extern void _dl_init (struct link_map *main_map, int argc, char **argv, |
1079 | char **env) attribute_hidden; |
1080 | |
1081 | /* Call the finalizer functions of all shared objects whose |
1082 | initializer functions have completed. */ |
1083 | extern void _dl_fini (void) attribute_hidden; |
1084 | |
1085 | /* Sort array MAPS according to dependencies of the contained objects. */ |
1086 | extern void _dl_sort_maps (struct link_map **maps, unsigned int nmaps, |
1087 | char *used, bool for_fini) attribute_hidden; |
1088 | |
1089 | /* The dynamic linker calls this function before and having changing |
1090 | any shared object mappings. The `r_state' member of `struct r_debug' |
1091 | says what change is taking place. This function's address is |
1092 | the value of the `r_brk' member. */ |
1093 | extern void _dl_debug_state (void); |
1094 | rtld_hidden_proto (_dl_debug_state) |
1095 | |
1096 | /* Initialize `struct r_debug' if it has not already been done. The |
1097 | argument is the run-time load address of the dynamic linker, to be put |
1098 | in the `r_ldbase' member. Returns the address of the structure. */ |
1099 | extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns) |
1100 | attribute_hidden; |
1101 | |
1102 | /* Initialize the basic data structure for the search paths. SOURCE |
1103 | is either "LD_LIBRARY_PATH" or "--library-path". |
1104 | GLIBC_HWCAPS_PREPEND adds additional glibc-hwcaps subdirectories to |
1105 | search. GLIBC_HWCAPS_MASK is used to filter the built-in |
1106 | subdirectories if not NULL. */ |
1107 | extern void _dl_init_paths (const char *library_path, const char *source, |
1108 | const char *glibc_hwcaps_prepend, |
1109 | const char *glibc_hwcaps_mask) |
1110 | attribute_hidden; |
1111 | |
1112 | /* Gather the information needed to install the profiling tables and start |
1113 | the timers. */ |
1114 | extern void _dl_start_profile (void) attribute_hidden; |
1115 | |
1116 | /* The actual functions used to keep book on the calls. */ |
1117 | extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc); |
1118 | rtld_hidden_proto (_dl_mcount) |
1119 | |
1120 | /* This function is simply a wrapper around the _dl_mcount function |
1121 | which does not require a FROMPC parameter since this is the |
1122 | calling function. */ |
1123 | extern void _dl_mcount_wrapper (void *selfpc); |
1124 | |
1125 | /* Show the members of the auxiliary array passed up from the kernel. */ |
1126 | extern void _dl_show_auxv (void) attribute_hidden; |
1127 | |
1128 | /* Return all environment variables starting with `LD_', one after the |
1129 | other. */ |
1130 | extern char *_dl_next_ld_env_entry (char ***position) attribute_hidden; |
1131 | |
1132 | /* Return an array with the names of the important hardware |
1133 | capabilities. PREPEND is a colon-separated list of glibc-hwcaps |
1134 | directories to search first. MASK is a colon-separated list used |
1135 | to filter the built-in glibc-hwcaps subdirectories. The length of |
1136 | the array is written to *SZ, and the maximum of all strings length |
1137 | is written to *MAX_CAPSTRLEN. */ |
1138 | const struct r_strlenpair *_dl_important_hwcaps (const char *prepend, |
1139 | const char *mask, |
1140 | size_t *sz, |
1141 | size_t *max_capstrlen) |
1142 | attribute_hidden; |
1143 | |
1144 | /* Look up NAME in ld.so.cache and return the file name stored there, |
1145 | or null if none is found. Caller must free returned string. */ |
1146 | extern char *_dl_load_cache_lookup (const char *name) attribute_hidden; |
1147 | |
1148 | /* If the system does not support MAP_COPY we cannot leave the file open |
1149 | all the time since this would create problems when the file is replaced. |
1150 | Therefore we provide this function to close the file and open it again |
1151 | once needed. */ |
1152 | extern void _dl_unload_cache (void) attribute_hidden; |
1153 | |
1154 | /* System-dependent function to read a file's whole contents in the |
1155 | most convenient manner available. *SIZEP gets the size of the |
1156 | file. On error MAP_FAILED is returned. */ |
1157 | extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep, |
1158 | int prot) attribute_hidden; |
1159 | |
1160 | /* System-specific function to do initial startup for the dynamic linker. |
1161 | After this, file access calls and getenv must work. This is responsible |
1162 | for setting __libc_enable_secure if we need to be secure (e.g. setuid), |
1163 | and for setting _dl_argc and _dl_argv, and then calling _dl_main. */ |
1164 | extern ElfW(Addr) _dl_sysdep_start (void **start_argptr, |
1165 | void (*dl_main) (const ElfW(Phdr) *phdr, |
1166 | ElfW(Word) phnum, |
1167 | ElfW(Addr) *user_entry, |
1168 | ElfW(auxv_t) *auxv)) |
1169 | attribute_hidden; |
1170 | |
1171 | extern void _dl_sysdep_start_cleanup (void) attribute_hidden; |
1172 | |
1173 | |
1174 | /* Determine next available module ID and set the L l_tls_modid. */ |
1175 | extern void _dl_assign_tls_modid (struct link_map *l) attribute_hidden; |
1176 | |
1177 | /* Count the modules with TLS segments. */ |
1178 | extern size_t _dl_count_modids (void) attribute_hidden; |
1179 | |
1180 | /* Calculate offset of the TLS blocks in the static TLS block. */ |
1181 | extern void _dl_determine_tlsoffset (void) attribute_hidden; |
1182 | |
1183 | /* Calculate the size of the static TLS surplus, when the given |
1184 | number of audit modules are loaded. */ |
1185 | void _dl_tls_static_surplus_init (size_t naudit) attribute_hidden; |
1186 | |
1187 | /* This function is called very early from dl_main to set up TLS and |
1188 | other thread-related data structures. */ |
1189 | void __tls_pre_init_tp (void) attribute_hidden; |
1190 | |
1191 | /* This function is called after processor-specific initialization of |
1192 | the TCB and thread pointer via TLS_INIT_TP, to complete very early |
1193 | initialization of the thread library. */ |
1194 | void __tls_init_tp (void) attribute_hidden; |
1195 | |
1196 | #ifndef SHARED |
1197 | /* Set up the TCB for statically linked applications. This is called |
1198 | early during startup because we always use TLS (for errno and the |
1199 | stack protector, among other things). */ |
1200 | void __libc_setup_tls (void); |
1201 | |
1202 | # if ENABLE_STATIC_PIE |
1203 | /* Relocate static executable with PIE. */ |
1204 | extern void _dl_relocate_static_pie (void) attribute_hidden; |
1205 | |
1206 | /* Get a pointer to _dl_main_map. */ |
1207 | extern struct link_map * _dl_get_dl_main_map (void) |
1208 | __attribute__ ((visibility ("hidden" ))); |
1209 | # else |
1210 | # define _dl_relocate_static_pie() |
1211 | # endif |
1212 | #endif |
1213 | |
1214 | /* Initialization of libpthread for statically linked applications. |
1215 | If libpthread is not linked in, this is an empty function. */ |
1216 | void __pthread_initialize_minimal (void) weak_function; |
1217 | |
1218 | /* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */ |
1219 | extern void *_dl_allocate_tls (void *mem); |
1220 | rtld_hidden_proto (_dl_allocate_tls) |
1221 | |
1222 | /* Get size and alignment requirements of the static TLS block. */ |
1223 | extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp); |
1224 | |
1225 | extern void _dl_allocate_static_tls (struct link_map *map) attribute_hidden; |
1226 | |
1227 | /* These are internal entry points to the two halves of _dl_allocate_tls, |
1228 | only used within rtld.c itself at startup time. */ |
1229 | extern void *_dl_allocate_tls_storage (void) attribute_hidden; |
1230 | extern void *_dl_allocate_tls_init (void *); |
1231 | rtld_hidden_proto (_dl_allocate_tls_init) |
1232 | |
1233 | /* Deallocate memory allocated with _dl_allocate_tls. */ |
1234 | extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb); |
1235 | rtld_hidden_proto (_dl_deallocate_tls) |
1236 | |
1237 | extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden; |
1238 | |
1239 | /* Find origin of the executable. */ |
1240 | extern const char *_dl_get_origin (void) attribute_hidden; |
1241 | |
1242 | /* Count DSTs. */ |
1243 | extern size_t _dl_dst_count (const char *name) attribute_hidden; |
1244 | |
1245 | /* Substitute DST values. */ |
1246 | extern char *_dl_dst_substitute (struct link_map *l, const char *name, |
1247 | char *result) attribute_hidden; |
1248 | |
1249 | /* Open the shared object NAME, relocate it, and run its initializer if it |
1250 | hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If |
1251 | the object is already opened, returns its existing map. */ |
1252 | extern void *_dl_open (const char *name, int mode, const void *caller, |
1253 | Lmid_t nsid, int argc, char *argv[], char *env[]) |
1254 | attribute_hidden; |
1255 | |
1256 | /* Free or queue for freeing scope OLD. If other threads might be |
1257 | in the middle of _dl_fixup, _dl_profile_fixup or dl*sym using the |
1258 | old scope, OLD can't be freed until no thread is using it. */ |
1259 | extern int _dl_scope_free (void *) attribute_hidden; |
1260 | |
1261 | |
1262 | /* Add module to slot information data. If DO_ADD is false, only the |
1263 | required memory is allocated. Must be called with GL |
1264 | (dl_load_lock) acquired. If the function has already been called |
1265 | for the link map L with !do_add, then this function will not raise |
1266 | an exception, otherwise it is possible that it encounters a memory |
1267 | allocation failure. */ |
1268 | extern void _dl_add_to_slotinfo (struct link_map *l, bool do_add) |
1269 | attribute_hidden; |
1270 | |
1271 | /* Update slot information data for at least the generation of the |
1272 | module with the given index. */ |
1273 | extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid) |
1274 | attribute_hidden; |
1275 | |
1276 | /* Look up the module's TLS block as for __tls_get_addr, |
1277 | but never touch anything. Return null if it's not allocated yet. */ |
1278 | extern void *_dl_tls_get_addr_soft (struct link_map *l) attribute_hidden; |
1279 | |
1280 | extern int _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr) |
1281 | attribute_hidden; |
1282 | |
1283 | /* Show show of an object. */ |
1284 | extern void _dl_show_scope (struct link_map *new, int from) |
1285 | attribute_hidden; |
1286 | |
1287 | extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr); |
1288 | rtld_hidden_proto (_dl_find_dso_for_object) |
1289 | |
1290 | /* Initialization which is normally done by the dynamic linker. */ |
1291 | extern void _dl_non_dynamic_init (void) |
1292 | attribute_hidden; |
1293 | |
1294 | /* Used by static binaries to check the auxiliary vector. */ |
1295 | extern void _dl_aux_init (ElfW(auxv_t) *av) |
1296 | attribute_hidden; |
1297 | |
1298 | /* Initialize the static TLS space for the link map in all existing |
1299 | threads. */ |
1300 | #if THREAD_GSCOPE_IN_TCB |
1301 | void _dl_init_static_tls (struct link_map *map) attribute_hidden; |
1302 | #endif |
1303 | static inline void |
1304 | dl_init_static_tls (struct link_map *map) |
1305 | { |
1306 | #if THREAD_GSCOPE_IN_TCB |
1307 | /* The stack list is available to ld.so, so the initialization can |
1308 | be handled within ld.so directly. */ |
1309 | _dl_init_static_tls (map); |
1310 | #else |
1311 | GL (dl_init_static_tls) (map); |
1312 | #endif |
1313 | } |
1314 | |
1315 | #ifndef SHARED |
1316 | /* Called before relocating ld.so during static dlopen. This can be |
1317 | used to partly initialize the dormant ld.so copy in the static |
1318 | dlopen namespace. */ |
1319 | void __rtld_static_init (struct link_map *map) attribute_hidden; |
1320 | #endif |
1321 | |
1322 | /* Return true if the ld.so copy in this namespace is actually active |
1323 | and working. If false, the dl_open/dlfcn hooks have to be used to |
1324 | call into the outer dynamic linker (which happens after static |
1325 | dlopen). */ |
1326 | #ifdef SHARED |
1327 | static inline bool |
1328 | rtld_active (void) |
1329 | { |
1330 | /* The default-initialized variable does not have a non-zero |
1331 | dl_init_all_dirs member, so this allows us to recognize an |
1332 | initialized and active ld.so copy. */ |
1333 | return GLRO(dl_init_all_dirs) != NULL; |
1334 | } |
1335 | |
1336 | static inline struct auditstate * |
1337 | link_map_audit_state (struct link_map *l, size_t index) |
1338 | { |
1339 | if (l == &GL (dl_rtld_map)) |
1340 | /* The auditstate array is stored separately. */ |
1341 | return &GL (dl_rtld_auditstate) [index]; |
1342 | else |
1343 | { |
1344 | /* The auditstate array follows the link map in memory. */ |
1345 | struct auditstate *base = (struct auditstate *) (l + 1); |
1346 | return &base[index]; |
1347 | } |
1348 | } |
1349 | #endif /* SHARED */ |
1350 | |
1351 | #if PTHREAD_IN_LIBC && defined SHARED |
1352 | /* Recursive locking implementation for use within the dynamic loader. |
1353 | Used to define the __rtld_lock_lock_recursive and |
1354 | __rtld_lock_unlock_recursive via <libc-lock.h>. Initialized to a |
1355 | no-op dummy implementation early. Similar |
1356 | to GL (dl_rtld_lock_recursive) and GL (dl_rtld_unlock_recursive) |
1357 | in !PTHREAD_IN_LIBC builds. */ |
1358 | extern int (*___rtld_mutex_lock) (pthread_mutex_t *) attribute_hidden; |
1359 | extern int (*___rtld_mutex_unlock) (pthread_mutex_t *lock) attribute_hidden; |
1360 | |
1361 | /* Called after libc has been loaded, but before RELRO is activated. |
1362 | Used to initialize the function pointers to the actual |
1363 | implementations. */ |
1364 | void __rtld_mutex_init (void) attribute_hidden; |
1365 | #else /* !PTHREAD_IN_LIBC */ |
1366 | static inline void |
1367 | __rtld_mutex_init (void) |
1368 | { |
1369 | /* The initialization happens later (!PTHREAD_IN_LIBC) or is not |
1370 | needed at all (!SHARED). */ |
1371 | } |
1372 | #endif /* !PTHREAD_IN_LIBC */ |
1373 | |
1374 | #if THREAD_GSCOPE_IN_TCB |
1375 | void __thread_gscope_wait (void) attribute_hidden; |
1376 | # define THREAD_GSCOPE_WAIT() __thread_gscope_wait () |
1377 | #endif |
1378 | |
1379 | __END_DECLS |
1380 | |
1381 | #endif /* ldsodefs.h */ |
1382 | |