]> sourceware.org Git - glibc.git/blob - sysdeps/generic/ldsodefs.h
02bd579ef89cf869f62fb126dbb88709cd4b7232
[glibc.git] / sysdeps / generic / ldsodefs.h
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 \f
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 !PTHREAD_IN_LIBC
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 PTHREAD_IN_LIBC
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 #endif
490 #if !THREAD_GSCOPE_IN_TCB
491 EXTERN int _dl_thread_gscope_count;
492 #endif
493 #ifdef SHARED
494 };
495 # define __rtld_global_attribute__
496 # if IS_IN (rtld)
497 # ifdef HAVE_SDATA_SECTION
498 # define __rtld_local_attribute__ \
499 __attribute__ ((visibility ("hidden"), section (".sdata")))
500 # undef __rtld_global_attribute__
501 # define __rtld_global_attribute__ __attribute__ ((section (".sdata")))
502 # else
503 # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
504 # endif
505 extern struct rtld_global _rtld_local __rtld_local_attribute__;
506 # undef __rtld_local_attribute__
507 # endif
508 extern struct rtld_global _rtld_global __rtld_global_attribute__;
509 # undef __rtld_global_attribute__
510 #endif
511
512 #ifndef SHARED
513 # define GLRO(name) _##name
514 #else
515 # if IS_IN (rtld)
516 # define GLRO(name) _rtld_local_ro._##name
517 # else
518 # define GLRO(name) _rtld_global_ro._##name
519 # endif
520 struct rtld_global_ro
521 {
522 #endif
523
524 /* If nonzero the appropriate debug information is printed. */
525 EXTERN int _dl_debug_mask;
526 #define DL_DEBUG_LIBS (1 << 0)
527 #define DL_DEBUG_IMPCALLS (1 << 1)
528 #define DL_DEBUG_BINDINGS (1 << 2)
529 #define DL_DEBUG_SYMBOLS (1 << 3)
530 #define DL_DEBUG_VERSIONS (1 << 4)
531 #define DL_DEBUG_RELOC (1 << 5)
532 #define DL_DEBUG_FILES (1 << 6)
533 #define DL_DEBUG_STATISTICS (1 << 7)
534 #define DL_DEBUG_UNUSED (1 << 8)
535 #define DL_DEBUG_SCOPES (1 << 9)
536 /* These two are used only internally. */
537 #define DL_DEBUG_HELP (1 << 10)
538 #define DL_DEBUG_PRELINK (1 << 11)
539
540 /* OS version. */
541 EXTERN unsigned int _dl_osversion;
542 /* Platform name. */
543 EXTERN const char *_dl_platform;
544 EXTERN size_t _dl_platformlen;
545
546 /* Cached value of `getpagesize ()'. */
547 EXTERN size_t _dl_pagesize;
548
549 /* Cached value of `sysconf (_SC_MINSIGSTKSZ)'. */
550 EXTERN size_t _dl_minsigstacksize;
551
552 /* Do we read from ld.so.cache? */
553 EXTERN int _dl_inhibit_cache;
554
555 /* Copy of the content of `_dl_main_searchlist' at startup time. */
556 EXTERN struct r_scope_elem _dl_initial_searchlist;
557
558 /* CLK_TCK as reported by the kernel. */
559 EXTERN int _dl_clktck;
560
561 /* If nonzero print warnings messages. */
562 EXTERN int _dl_verbose;
563
564 /* File descriptor to write debug messages to. */
565 EXTERN int _dl_debug_fd;
566
567 /* Do we do lazy relocations? */
568 EXTERN int _dl_lazy;
569
570 /* Nonzero if runtime lookups should not update the .got/.plt. */
571 EXTERN int _dl_bind_not;
572
573 /* Nonzero if references should be treated as weak during runtime
574 linking. */
575 EXTERN int _dl_dynamic_weak;
576
577 /* Default floating-point control word. */
578 EXTERN fpu_control_t _dl_fpu_control;
579
580 /* Expected cache ID. */
581 EXTERN int _dl_correct_cache_id;
582
583 /* Mask for hardware capabilities that are available. */
584 EXTERN uint64_t _dl_hwcap;
585
586 #if !HAVE_TUNABLES
587 /* Mask for important hardware capabilities we honour. */
588 EXTERN uint64_t _dl_hwcap_mask;
589 #endif
590
591 #ifdef HAVE_AUX_VECTOR
592 /* Pointer to the auxv list supplied to the program at startup. */
593 EXTERN ElfW(auxv_t) *_dl_auxv;
594 #endif
595
596 /* Get architecture specific definitions. */
597 #include <dl-procinfo.c>
598
599 /* Names of shared object for which the RPATH should be ignored. */
600 EXTERN const char *_dl_inhibit_rpath;
601
602 /* Location of the binary. */
603 EXTERN const char *_dl_origin_path;
604
605 /* -1 if the dynamic linker should honor library load bias,
606 0 if not, -2 use the default (honor biases for normal
607 binaries, don't honor for PIEs). */
608 EXTERN ElfW(Addr) _dl_use_load_bias;
609
610 /* Size of the static TLS block. */
611 EXTERN size_t _dl_tls_static_size;
612
613 /* Alignment requirement of the static TLS block. */
614 EXTERN size_t _dl_tls_static_align;
615
616 /* Size of surplus space in the static TLS area for dynamically
617 loaded modules with IE-model TLS or for TLSDESC optimization.
618 See comments in elf/dl-tls.c where it is initialized. */
619 EXTERN size_t _dl_tls_static_surplus;
620
621 /* Name of the shared object to be profiled (if any). */
622 EXTERN const char *_dl_profile;
623 /* Filename of the output file. */
624 EXTERN const char *_dl_profile_output;
625 /* Name of the object we want to trace the prelinking. */
626 EXTERN const char *_dl_trace_prelink;
627 /* Map of shared object to be prelink traced. */
628 EXTERN struct link_map *_dl_trace_prelink_map;
629
630 /* All search directories defined at startup. This is assigned a
631 non-NULL pointer by the ld.so startup code (after initialization
632 to NULL), so this can also serve as an indicator whether a copy
633 of ld.so is initialized and active. See the rtld_active function
634 below. */
635 EXTERN struct r_search_path_elem *_dl_init_all_dirs;
636
637 #ifdef NEED_DL_SYSINFO
638 /* Syscall handling improvements. This is very specific to x86. */
639 EXTERN uintptr_t _dl_sysinfo;
640 #endif
641
642 #ifdef NEED_DL_SYSINFO_DSO
643 /* The vsyscall page is a virtual DSO pre-mapped by the kernel.
644 This points to its ELF header. */
645 EXTERN const ElfW(Ehdr) *_dl_sysinfo_dso;
646
647 /* At startup time we set up the normal DSO data structure for it,
648 and this points to it. */
649 EXTERN struct link_map *_dl_sysinfo_map;
650
651 # define PROCINFO_DECL
652 # ifndef PROCINFO_CLASS
653 # define PROCINFO_CLASS EXTERN
654 # endif
655 # include <dl-vdso-setup.c>
656 #endif
657
658 /* Mask for more hardware capabilities that are available on some
659 platforms. */
660 EXTERN uint64_t _dl_hwcap2;
661
662 #ifdef SHARED
663 /* We add a function table to _rtld_global which is then used to
664 call the function instead of going through the PLT. The result
665 is that we can avoid exporting the functions and we do not jump
666 PLT relocations in libc.so. */
667 void (*_dl_debug_printf) (const char *, ...)
668 __attribute__ ((__format__ (__printf__, 1, 2)));
669 void (*_dl_mcount) (ElfW(Addr) frompc, ElfW(Addr) selfpc);
670 lookup_t (*_dl_lookup_symbol_x) (const char *, struct link_map *,
671 const ElfW(Sym) **, struct r_scope_elem *[],
672 const struct r_found_version *, int, int,
673 struct link_map *);
674 void *(*_dl_open) (const char *file, int mode, const void *caller_dlopen,
675 Lmid_t nsid, int argc, char *argv[], char *env[]);
676 void (*_dl_close) (void *map);
677 /* libdl in a secondary namespace (after dlopen) must use
678 _dl_catch_error from the main namespace, so it has to be
679 exported in some way. */
680 int (*_dl_catch_error) (const char **objname, const char **errstring,
681 bool *mallocedp, void (*operate) (void *),
682 void *args);
683 /* libdl in a secondary namespace must use free from the base
684 namespace. */
685 void (*_dl_error_free) (void *);
686 void *(*_dl_tls_get_addr_soft) (struct link_map *);
687 #ifdef HAVE_DL_DISCOVER_OSVERSION
688 int (*_dl_discover_osversion) (void);
689 #endif
690
691 /* Dynamic linker operations used after static dlopen. */
692 const struct dlfcn_hook *_dl_dlfcn_hook;
693
694 /* List of auditing interfaces. */
695 struct audit_ifaces *_dl_audit;
696 unsigned int _dl_naudit;
697 };
698 # define __rtld_global_attribute__
699 # if IS_IN (rtld)
700 # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
701 extern struct rtld_global_ro _rtld_local_ro
702 attribute_relro __rtld_local_attribute__;
703 extern struct rtld_global_ro _rtld_global_ro
704 attribute_relro __rtld_global_attribute__;
705 # undef __rtld_local_attribute__
706 # else
707 /* We cheat a bit here. We declare the variable as as const even
708 though it is at startup. */
709 extern const struct rtld_global_ro _rtld_global_ro
710 attribute_relro __rtld_global_attribute__;
711 # endif
712 # undef __rtld_global_attribute__
713 #endif
714 #undef EXTERN
715
716 #ifndef SHARED
717 /* dl-support.c defines these and initializes them early on. */
718 extern const ElfW(Phdr) *_dl_phdr;
719 extern size_t _dl_phnum;
720 #endif
721
722 #if PTHREAD_IN_LIBC
723 /* This function changes the permissions of all stacks (not just those
724 of the main stack). */
725 int _dl_make_stacks_executable (void **stack_endp) attribute_hidden;
726 #else
727 /* This is the initial value of GL(dl_make_stack_executable_hook).
728 A threads library can change it. The ld.so implementation changes
729 the permissions of the main stack only. */
730 extern int _dl_make_stack_executable (void **stack_endp);
731 rtld_hidden_proto (_dl_make_stack_executable)
732 #endif
733
734 /* Variable pointing to the end of the stack (or close to it). This value
735 must be constant over the runtime of the application. Some programs
736 might use the variable which results in copy relocations on some
737 platforms. But this does not matter, ld.so can always use the local
738 copy. */
739 extern void *__libc_stack_end
740 #ifndef LIBC_STACK_END_NOT_RELRO
741 attribute_relro
742 #endif
743 ;
744 rtld_hidden_proto (__libc_stack_end)
745
746 /* Parameters passed to the dynamic linker. */
747 extern int _dl_argc attribute_hidden attribute_relro;
748 extern char **_dl_argv
749 #ifndef DL_ARGV_NOT_RELRO
750 attribute_relro
751 #endif
752 ;
753 rtld_hidden_proto (_dl_argv)
754 #if IS_IN (rtld)
755 extern unsigned int _dl_skip_args attribute_hidden
756 # ifndef DL_ARGV_NOT_RELRO
757 attribute_relro
758 # endif
759 ;
760 extern unsigned int _dl_skip_args_internal attribute_hidden
761 # ifndef DL_ARGV_NOT_RELRO
762 attribute_relro
763 # endif
764 ;
765 #endif
766 #define rtld_progname _dl_argv[0]
767
768 /* Flag set at startup and cleared when the last initializer has run. */
769 extern int _dl_starting_up;
770 weak_extern (_dl_starting_up)
771 rtld_hidden_proto (_dl_starting_up)
772
773 /* Random data provided by the kernel. */
774 extern void *_dl_random attribute_hidden attribute_relro;
775
776 /* Write message on the debug file descriptor. The parameters are
777 interpreted as for a `printf' call. All the lines start with a
778 tag showing the PID. */
779 extern void _dl_debug_printf (const char *fmt, ...)
780 __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
781
782 /* Write message on the debug file descriptor. The parameters are
783 interpreted as for a `printf' call. All the lines buf the first
784 start with a tag showing the PID. */
785 extern void _dl_debug_printf_c (const char *fmt, ...)
786 __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
787
788
789 /* Write a message on the specified descriptor FD. The parameters are
790 interpreted as for a `printf' call. */
791 #if IS_IN (rtld) || !defined (SHARED)
792 extern void _dl_dprintf (int fd, const char *fmt, ...)
793 __attribute__ ((__format__ (__printf__, 2, 3)))
794 attribute_hidden;
795 #else
796 __attribute__ ((always_inline, __format__ (__printf__, 2, 3)))
797 static inline void
798 _dl_dprintf (int fd, const char *fmt, ...)
799 {
800 /* Use local declaration to avoid includign <stdio.h>. */
801 extern int __dprintf(int fd, const char *format, ...) attribute_hidden;
802 __dprintf (fd, fmt, __builtin_va_arg_pack ());
803 }
804 #endif
805
806 /* Write LENGTH bytes at BUFFER to FD, like write. Returns the number
807 of bytes written on success, or a negative error constant on
808 failure. */
809 ssize_t _dl_write (int fd, const void *buffer, size_t length)
810 attribute_hidden;
811
812 /* Write a message on the specified descriptor standard output. The
813 parameters are interpreted as for a `printf' call. */
814 void _dl_printf (const char *fmt, ...)
815 attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2)));
816
817 /* Write a message on the specified descriptor standard error. The
818 parameters are interpreted as for a `printf' call. */
819 void _dl_error_printf (const char *fmt, ...)
820 attribute_hidden __attribute__ ((__format__ (__printf__, 1, 2)));
821
822 /* Write a message on the specified descriptor standard error and exit
823 the program. The parameters are interpreted as for a `printf' call. */
824 void _dl_fatal_printf (const char *fmt, ...)
825 __attribute__ ((__format__ (__printf__, 1, 2), __noreturn__));
826 rtld_hidden_proto (_dl_fatal_printf)
827
828 /* An exception raised by the _dl_signal_error function family and
829 caught by _dl_catch_error function family. Exceptions themselves
830 are copied as part of the raise operation, but the strings are
831 not. */
832 struct dl_exception
833 {
834 const char *objname;
835 const char *errstring;
836
837 /* This buffer typically stores both objname and errstring
838 above. */
839 char *message_buffer;
840 };
841
842 /* Creates a new exception. This calls malloc; if allocation fails,
843 dummy values are inserted. OBJECT is the name of the problematical
844 shared object, or null if its a general problem. ERRSTRING is a
845 string describing the specific problem. */
846 void _dl_exception_create (struct dl_exception *, const char *object,
847 const char *errstring)
848 __attribute__ ((nonnull (1, 3)));
849 rtld_hidden_proto (_dl_exception_create)
850
851 /* Used internally to implement dlerror message freeing. See
852 include/dlfcn.h and dlfcn/dlerror.c. */
853 void _dl_error_free (void *ptr) attribute_hidden;
854
855 /* Like _dl_exception_create, but create errstring from a format
856 string FMT. Currently, only "%s" and "%%" are supported as format
857 directives. */
858 void _dl_exception_create_format (struct dl_exception *, const char *objname,
859 const char *fmt, ...)
860 __attribute__ ((nonnull (1, 3), format (printf, 3, 4)));
861 rtld_hidden_proto (_dl_exception_create_format)
862
863 /* Deallocate the exception, freeing allocated buffers (if
864 possible). */
865 void _dl_exception_free (struct dl_exception *)
866 __attribute__ ((nonnull (1)));
867 rtld_hidden_proto (_dl_exception_free)
868
869 /* This function is called by all the internal dynamic linker
870 functions when they encounter an error. ERRCODE is either an
871 `errno' code or zero; it specifies the return value of
872 _dl_catch_error. OCCASION is included in the error message if the
873 process is terminated immediately. */
874 void _dl_signal_exception (int errcode, struct dl_exception *,
875 const char *occasion)
876 __attribute__ ((__noreturn__));
877 libc_hidden_proto (_dl_signal_exception)
878
879 /* Like _dl_signal_exception, but creates the exception first. */
880 extern void _dl_signal_error (int errcode, const char *object,
881 const char *occasion, const char *errstring)
882 __attribute__ ((__noreturn__));
883 libc_hidden_proto (_dl_signal_error)
884
885 /* Like _dl_signal_exception, but may return when called in the
886 context of _dl_receive_error. This is only used during ld.so
887 bootstrap. In static and profiled builds, this is equivalent to
888 _dl_signal_exception. */
889 #if IS_IN (rtld)
890 extern void _dl_signal_cexception (int errcode, struct dl_exception *,
891 const char *occasion) attribute_hidden;
892 #else
893 __attribute__ ((always_inline))
894 static inline void
895 _dl_signal_cexception (int errcode, struct dl_exception *exception,
896 const char *occasion)
897 {
898 _dl_signal_exception (errcode, exception, occasion);
899 }
900 #endif
901
902 /* See _dl_signal_cexception above. */
903 #if IS_IN (rtld)
904 extern void _dl_signal_cerror (int errcode, const char *object,
905 const char *occasion, const char *errstring)
906 attribute_hidden;
907 #else
908 __attribute__ ((always_inline))
909 static inline void
910 _dl_signal_cerror (int errcode, const char *object,
911 const char *occasion, const char *errstring)
912 {
913 _dl_signal_error (errcode, object, occasion, errstring);
914 }
915 #endif
916
917 /* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike
918 `_dl_catch_error' the operation is resumed after the OPERATE
919 function returns.
920 ARGS is passed as argument to OPERATE. */
921 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
922 void *args) attribute_hidden;
923
924 /* Call OPERATE, catching errors from `_dl_signal_error' and related
925 functions. If there is no error, *ERRSTRING is set to null. If
926 there is an error, *ERRSTRING is set to a string constructed from
927 the strings passed to _dl_signal_error, and the error code passed
928 is the return value and *OBJNAME is set to the object name which
929 experienced the problems. ERRSTRING if nonzero points to a
930 malloc'ed string which the caller has to free after use. ARGS is
931 passed as argument to OPERATE. MALLOCEDP is set to true only if
932 the returned string is allocated using the libc's malloc. */
933 extern int _dl_catch_error (const char **objname, const char **errstring,
934 bool *mallocedp, void (*operate) (void *),
935 void *args);
936 libc_hidden_proto (_dl_catch_error)
937
938 /* Used for initializing GLRO (_dl_catch_error). */
939 extern __typeof__ (_dl_catch_error) _rtld_catch_error attribute_hidden;
940
941 /* Call OPERATE (ARGS). If no error occurs, set *EXCEPTION to zero.
942 Otherwise, store a copy of the raised exception in *EXCEPTION,
943 which has to be freed by _dl_exception_free. As a special case, if
944 EXCEPTION is null, call OPERATE (ARGS) with exception handling
945 disabled (so that exceptions are fatal). */
946 int _dl_catch_exception (struct dl_exception *exception,
947 void (*operate) (void *), void *args);
948 libc_hidden_proto (_dl_catch_exception)
949
950 /* Open the shared object NAME and map in its segments.
951 LOADER's DT_RPATH is used in searching for NAME.
952 If the object is already opened, returns its existing map. */
953 extern struct link_map *_dl_map_object (struct link_map *loader,
954 const char *name,
955 int type, int trace_mode, int mode,
956 Lmid_t nsid) attribute_hidden;
957
958 /* Call _dl_map_object on the dependencies of MAP, and set up
959 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
960 loaded objects that will be inserted into MAP->l_searchlist after MAP
961 but before its dependencies. */
962 extern void _dl_map_object_deps (struct link_map *map,
963 struct link_map **preloads,
964 unsigned int npreloads, int trace_mode,
965 int open_mode)
966 attribute_hidden;
967
968 /* Cache the locations of MAP's hash table. */
969 extern void _dl_setup_hash (struct link_map *map) attribute_hidden;
970
971
972 /* Collect the directories in the search path for LOADER's dependencies.
973 The data structure is defined in <dlfcn.h>. If COUNTING is true,
974 SI->dls_cnt and SI->dls_size are set; if false, those must be as set
975 by a previous call with COUNTING set, and SI must point to SI->dls_size
976 bytes to be used in filling in the result. */
977 extern void _dl_rtld_di_serinfo (struct link_map *loader,
978 Dl_serinfo *si, bool counting);
979
980 /* Process PT_GNU_PROPERTY program header PH in module L after
981 PT_LOAD segments are mapped from file FD. */
982 void _dl_process_pt_gnu_property (struct link_map *l, int fd,
983 const ElfW(Phdr) *ph);
984
985
986 /* Search loaded objects' symbol tables for a definition of the symbol
987 referred to by UNDEF. *SYM is the symbol table entry containing the
988 reference; it is replaced with the defining symbol, and the base load
989 address of the defining object is returned. SYMBOL_SCOPE is a
990 null-terminated list of object scopes to search; each object's
991 l_searchlist (i.e. the segment of the dependency tree starting at that
992 object) is searched in turn. REFERENCE_NAME should name the object
993 containing the reference; it is used in error messages.
994 TYPE_CLASS describes the type of symbol we are looking for. */
995 enum
996 {
997 /* If necessary add dependency between user and provider object. */
998 DL_LOOKUP_ADD_DEPENDENCY = 1,
999 /* Return most recent version instead of default version for
1000 unversioned lookup. */
1001 DL_LOOKUP_RETURN_NEWEST = 2,
1002 /* Set if dl_lookup* called with GSCOPE lock held. */
1003 DL_LOOKUP_GSCOPE_LOCK = 4,
1004 /* Set if dl_lookup is called for non-lazy relocation processing
1005 from _dl_relocate_object in elf/dl-reloc.c. */
1006 DL_LOOKUP_FOR_RELOCATE = 8,
1007 };
1008
1009 /* Lookup versioned symbol. */
1010 extern lookup_t _dl_lookup_symbol_x (const char *undef,
1011 struct link_map *undef_map,
1012 const ElfW(Sym) **sym,
1013 struct r_scope_elem *symbol_scope[],
1014 const struct r_found_version *version,
1015 int type_class, int flags,
1016 struct link_map *skip_map)
1017 attribute_hidden;
1018
1019
1020 /* Restricted version of _dl_lookup_symbol_x. Searches MAP (and only
1021 MAP) for the symbol UNDEF_NAME, with GNU hash NEW_HASH (computed
1022 with dl_new_hash), symbol version VERSION, and symbol version hash
1023 VERSION_HASH (computed with _dl_elf_hash). Returns a pointer to
1024 the symbol table entry in MAP on success, or NULL on failure. MAP
1025 must have symbol versioning information, or otherwise the result is
1026 undefined. */
1027 const ElfW(Sym) *_dl_lookup_direct (struct link_map *map,
1028 const char *undef_name,
1029 uint32_t new_hash,
1030 const char *version,
1031 uint32_t version_hash) attribute_hidden;
1032
1033 /* Add the new link_map NEW to the end of the namespace list. */
1034 extern void _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
1035 attribute_hidden;
1036
1037 /* Allocate a `struct link_map' for a new object being loaded. */
1038 extern struct link_map *_dl_new_object (char *realname, const char *libname,
1039 int type, struct link_map *loader,
1040 int mode, Lmid_t nsid)
1041 attribute_hidden;
1042
1043 /* Relocate the given object (if it hasn't already been).
1044 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
1045 If RTLD_LAZY is set in RELOC-MODE, don't relocate its PLT. */
1046 extern void _dl_relocate_object (struct link_map *map,
1047 struct r_scope_elem *scope[],
1048 int reloc_mode, int consider_profiling)
1049 attribute_hidden;
1050
1051 /* Protect PT_GNU_RELRO area. */
1052 extern void _dl_protect_relro (struct link_map *map) attribute_hidden;
1053
1054 /* Call _dl_signal_error with a message about an unhandled reloc type.
1055 TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
1056 PLT is nonzero if this was a PLT reloc; it just affects the message. */
1057 extern void _dl_reloc_bad_type (struct link_map *map,
1058 unsigned int type, int plt)
1059 attribute_hidden __attribute__ ((__noreturn__));
1060
1061 /* Resolve conflicts if prelinking. */
1062 extern void _dl_resolve_conflicts (struct link_map *l,
1063 ElfW(Rela) *conflict,
1064 ElfW(Rela) *conflictend)
1065 attribute_hidden;
1066
1067 /* Check the version dependencies of all objects available through
1068 MAP. If VERBOSE print some more diagnostics. */
1069 extern int _dl_check_all_versions (struct link_map *map, int verbose,
1070 int trace_mode) attribute_hidden;
1071
1072 /* Check the version dependencies for MAP. If VERBOSE print some more
1073 diagnostics. */
1074 extern int _dl_check_map_versions (struct link_map *map, int verbose,
1075 int trace_mode) attribute_hidden;
1076
1077 /* Initialize the object in SCOPE by calling the constructors with
1078 ARGC, ARGV, and ENV as the parameters. */
1079 extern void _dl_init (struct link_map *main_map, int argc, char **argv,
1080 char **env) attribute_hidden;
1081
1082 /* Call the finalizer functions of all shared objects whose
1083 initializer functions have completed. */
1084 extern void _dl_fini (void) attribute_hidden;
1085
1086 /* Sort array MAPS according to dependencies of the contained objects. */
1087 extern void _dl_sort_maps (struct link_map **maps, unsigned int nmaps,
1088 char *used, bool for_fini) attribute_hidden;
1089
1090 /* The dynamic linker calls this function before and having changing
1091 any shared object mappings. The `r_state' member of `struct r_debug'
1092 says what change is taking place. This function's address is
1093 the value of the `r_brk' member. */
1094 extern void _dl_debug_state (void);
1095 rtld_hidden_proto (_dl_debug_state)
1096
1097 /* Initialize `struct r_debug' if it has not already been done. The
1098 argument is the run-time load address of the dynamic linker, to be put
1099 in the `r_ldbase' member. Returns the address of the structure. */
1100 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
1101 attribute_hidden;
1102
1103 /* Initialize the basic data structure for the search paths. SOURCE
1104 is either "LD_LIBRARY_PATH" or "--library-path".
1105 GLIBC_HWCAPS_PREPEND adds additional glibc-hwcaps subdirectories to
1106 search. GLIBC_HWCAPS_MASK is used to filter the built-in
1107 subdirectories if not NULL. */
1108 extern void _dl_init_paths (const char *library_path, const char *source,
1109 const char *glibc_hwcaps_prepend,
1110 const char *glibc_hwcaps_mask)
1111 attribute_hidden;
1112
1113 /* Gather the information needed to install the profiling tables and start
1114 the timers. */
1115 extern void _dl_start_profile (void) attribute_hidden;
1116
1117 /* The actual functions used to keep book on the calls. */
1118 extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
1119 rtld_hidden_proto (_dl_mcount)
1120
1121 /* This function is simply a wrapper around the _dl_mcount function
1122 which does not require a FROMPC parameter since this is the
1123 calling function. */
1124 extern void _dl_mcount_wrapper (void *selfpc);
1125
1126 /* Show the members of the auxiliary array passed up from the kernel. */
1127 extern void _dl_show_auxv (void) attribute_hidden;
1128
1129 /* Return all environment variables starting with `LD_', one after the
1130 other. */
1131 extern char *_dl_next_ld_env_entry (char ***position) attribute_hidden;
1132
1133 /* Return an array with the names of the important hardware
1134 capabilities. PREPEND is a colon-separated list of glibc-hwcaps
1135 directories to search first. MASK is a colon-separated list used
1136 to filter the built-in glibc-hwcaps subdirectories. The length of
1137 the array is written to *SZ, and the maximum of all strings length
1138 is written to *MAX_CAPSTRLEN. */
1139 const struct r_strlenpair *_dl_important_hwcaps (const char *prepend,
1140 const char *mask,
1141 size_t *sz,
1142 size_t *max_capstrlen)
1143 attribute_hidden;
1144
1145 /* Look up NAME in ld.so.cache and return the file name stored there,
1146 or null if none is found. Caller must free returned string. */
1147 extern char *_dl_load_cache_lookup (const char *name) attribute_hidden;
1148
1149 /* If the system does not support MAP_COPY we cannot leave the file open
1150 all the time since this would create problems when the file is replaced.
1151 Therefore we provide this function to close the file and open it again
1152 once needed. */
1153 extern void _dl_unload_cache (void) attribute_hidden;
1154
1155 /* System-dependent function to read a file's whole contents in the
1156 most convenient manner available. *SIZEP gets the size of the
1157 file. On error MAP_FAILED is returned. */
1158 extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
1159 int prot) attribute_hidden;
1160
1161 /* System-specific function to do initial startup for the dynamic linker.
1162 After this, file access calls and getenv must work. This is responsible
1163 for setting __libc_enable_secure if we need to be secure (e.g. setuid),
1164 and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
1165 extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
1166 void (*dl_main) (const ElfW(Phdr) *phdr,
1167 ElfW(Word) phnum,
1168 ElfW(Addr) *user_entry,
1169 ElfW(auxv_t) *auxv))
1170 attribute_hidden;
1171
1172 extern void _dl_sysdep_start_cleanup (void) attribute_hidden;
1173
1174
1175 /* Determine next available module ID and set the L l_tls_modid. */
1176 extern void _dl_assign_tls_modid (struct link_map *l) attribute_hidden;
1177
1178 /* Count the modules with TLS segments. */
1179 extern size_t _dl_count_modids (void) attribute_hidden;
1180
1181 /* Calculate offset of the TLS blocks in the static TLS block. */
1182 extern void _dl_determine_tlsoffset (void) attribute_hidden;
1183
1184 /* Calculate the size of the static TLS surplus, when the given
1185 number of audit modules are loaded. */
1186 void _dl_tls_static_surplus_init (size_t naudit) attribute_hidden;
1187
1188 /* This function is called very early from dl_main to set up TLS and
1189 other thread-related data structures. */
1190 void __tls_pre_init_tp (void) attribute_hidden;
1191
1192 /* This function is called after processor-specific initialization of
1193 the TCB and thread pointer via TLS_INIT_TP, to complete very early
1194 initialization of the thread library. */
1195 void __tls_init_tp (void) attribute_hidden;
1196
1197 #ifndef SHARED
1198 /* Set up the TCB for statically linked applications. This is called
1199 early during startup because we always use TLS (for errno and the
1200 stack protector, among other things). */
1201 void __libc_setup_tls (void);
1202
1203 # if ENABLE_STATIC_PIE
1204 /* Relocate static executable with PIE. */
1205 extern void _dl_relocate_static_pie (void) attribute_hidden;
1206
1207 /* Get a pointer to _dl_main_map. */
1208 extern struct link_map * _dl_get_dl_main_map (void)
1209 __attribute__ ((visibility ("hidden")));
1210 # else
1211 # define _dl_relocate_static_pie()
1212 # endif
1213 #endif
1214
1215 /* Initialization of libpthread for statically linked applications.
1216 If libpthread is not linked in, this is an empty function. */
1217 void __pthread_initialize_minimal (void) weak_function;
1218
1219 /* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */
1220 extern void *_dl_allocate_tls (void *mem);
1221 rtld_hidden_proto (_dl_allocate_tls)
1222
1223 /* Get size and alignment requirements of the static TLS block. */
1224 extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp);
1225
1226 extern void _dl_allocate_static_tls (struct link_map *map) attribute_hidden;
1227
1228 /* These are internal entry points to the two halves of _dl_allocate_tls,
1229 only used within rtld.c itself at startup time. */
1230 extern void *_dl_allocate_tls_storage (void) attribute_hidden;
1231 extern void *_dl_allocate_tls_init (void *);
1232 rtld_hidden_proto (_dl_allocate_tls_init)
1233
1234 /* Deallocate memory allocated with _dl_allocate_tls. */
1235 extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb);
1236 rtld_hidden_proto (_dl_deallocate_tls)
1237
1238 extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
1239
1240 /* Find origin of the executable. */
1241 extern const char *_dl_get_origin (void) attribute_hidden;
1242
1243 /* Count DSTs. */
1244 extern size_t _dl_dst_count (const char *name) attribute_hidden;
1245
1246 /* Substitute DST values. */
1247 extern char *_dl_dst_substitute (struct link_map *l, const char *name,
1248 char *result) attribute_hidden;
1249
1250 /* Open the shared object NAME, relocate it, and run its initializer if it
1251 hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
1252 the object is already opened, returns its existing map. */
1253 extern void *_dl_open (const char *name, int mode, const void *caller,
1254 Lmid_t nsid, int argc, char *argv[], char *env[])
1255 attribute_hidden;
1256
1257 /* Free or queue for freeing scope OLD. If other threads might be
1258 in the middle of _dl_fixup, _dl_profile_fixup or dl*sym using the
1259 old scope, OLD can't be freed until no thread is using it. */
1260 extern int _dl_scope_free (void *) attribute_hidden;
1261
1262
1263 /* Add module to slot information data. If DO_ADD is false, only the
1264 required memory is allocated. Must be called with GL
1265 (dl_load_lock) acquired. If the function has already been called
1266 for the link map L with !do_add, then this function will not raise
1267 an exception, otherwise it is possible that it encounters a memory
1268 allocation failure. */
1269 extern void _dl_add_to_slotinfo (struct link_map *l, bool do_add)
1270 attribute_hidden;
1271
1272 /* Update slot information data for at least the generation of the
1273 module with the given index. */
1274 extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid)
1275 attribute_hidden;
1276
1277 /* Look up the module's TLS block as for __tls_get_addr,
1278 but never touch anything. Return null if it's not allocated yet. */
1279 extern void *_dl_tls_get_addr_soft (struct link_map *l) attribute_hidden;
1280
1281 extern int _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
1282 attribute_hidden;
1283
1284 /* Show show of an object. */
1285 extern void _dl_show_scope (struct link_map *new, int from)
1286 attribute_hidden;
1287
1288 extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr);
1289 rtld_hidden_proto (_dl_find_dso_for_object)
1290
1291 /* Initialization which is normally done by the dynamic linker. */
1292 extern void _dl_non_dynamic_init (void)
1293 attribute_hidden;
1294
1295 /* Used by static binaries to check the auxiliary vector. */
1296 extern void _dl_aux_init (ElfW(auxv_t) *av)
1297 attribute_hidden;
1298
1299 /* Initialize the static TLS space for the link map in all existing
1300 threads. */
1301 #if PTHREAD_IN_LIBC
1302 void _dl_init_static_tls (struct link_map *map) attribute_hidden;
1303 #endif
1304 static inline void
1305 dl_init_static_tls (struct link_map *map)
1306 {
1307 #if PTHREAD_IN_LIBC
1308 /* The stack list is available to ld.so, so the initialization can
1309 be handled within ld.so directly. */
1310 _dl_init_static_tls (map);
1311 #else
1312 GL (dl_init_static_tls) (map);
1313 #endif
1314 }
1315
1316 #ifndef SHARED
1317 /* Called before relocating ld.so during static dlopen. This can be
1318 used to partly initialize the dormant ld.so copy in the static
1319 dlopen namespace. */
1320 void __rtld_static_init (struct link_map *map) attribute_hidden;
1321 #endif
1322
1323 /* Return true if the ld.so copy in this namespace is actually active
1324 and working. If false, the dl_open/dlfcn hooks have to be used to
1325 call into the outer dynamic linker (which happens after static
1326 dlopen). */
1327 #ifdef SHARED
1328 static inline bool
1329 rtld_active (void)
1330 {
1331 /* The default-initialized variable does not have a non-zero
1332 dl_init_all_dirs member, so this allows us to recognize an
1333 initialized and active ld.so copy. */
1334 return GLRO(dl_init_all_dirs) != NULL;
1335 }
1336
1337 static inline struct auditstate *
1338 link_map_audit_state (struct link_map *l, size_t index)
1339 {
1340 if (l == &GL (dl_rtld_map))
1341 /* The auditstate array is stored separately. */
1342 return &GL (dl_rtld_auditstate) [index];
1343 else
1344 {
1345 /* The auditstate array follows the link map in memory. */
1346 struct auditstate *base = (struct auditstate *) (l + 1);
1347 return &base[index];
1348 }
1349 }
1350 #endif /* SHARED */
1351
1352 #if PTHREAD_IN_LIBC && defined SHARED
1353 /* Recursive locking implementation for use within the dynamic loader.
1354 Used to define the __rtld_lock_lock_recursive and
1355 __rtld_lock_unlock_recursive via <libc-lock.h>. Initialized to a
1356 no-op dummy implementation early. Similar
1357 to GL (dl_rtld_lock_recursive) and GL (dl_rtld_unlock_recursive)
1358 in !PTHREAD_IN_LIBC builds. */
1359 extern int (*___rtld_mutex_lock) (pthread_mutex_t *) attribute_hidden;
1360 extern int (*___rtld_mutex_unlock) (pthread_mutex_t *lock) attribute_hidden;
1361
1362 /* Called after libc has been loaded, but before RELRO is activated.
1363 Used to initialize the function pointers to the actual
1364 implementations. */
1365 void __rtld_mutex_init (void) attribute_hidden;
1366 #else /* !PTHREAD_IN_LIBC */
1367 static inline void
1368 __rtld_mutex_init (void)
1369 {
1370 /* The initialization happens later (!PTHREAD_IN_LIBC) or is not
1371 needed at all (!SHARED). */
1372 }
1373 #endif /* !PTHREAD_IN_LIBC */
1374
1375 #if THREAD_GSCOPE_IN_TCB
1376 void __thread_gscope_wait (void) attribute_hidden;
1377 # define THREAD_GSCOPE_WAIT() __thread_gscope_wait ()
1378 #endif
1379
1380 __END_DECLS
1381
1382 #endif /* ldsodefs.h */
This page took 0.099529 seconds and 4 git commands to generate.