Consolidate conditionals in mp sin/cos functions
[glibc.git] / sysdeps / generic / ldsodefs.h
blobe7b0516aaf5e3dc9d374c5f0c453c9f93cdd8712
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2 Copyright (C) 1995-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _LDSODEFS_H
20 #define _LDSODEFS_H 1
22 #include <features.h>
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>
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 <bits/libc-lock.h>
39 #include <hp-timing.h>
40 #include <tls.h>
41 #include <kernel-features.h>
43 __BEGIN_DECLS
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))
51 /* We use this macro to refer to ELF types independent of the native wordsize.
52 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
53 #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
55 /* All references to the value of l_info[DT_PLTGOT],
56 l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
57 l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
58 have to be accessed via the D_PTR macro. The macro is needed since for
59 most architectures the entry is already relocated - but for some not
60 and we need to relocate at access time. */
61 #ifdef DL_RO_DYN_SECTION
62 # define D_PTR(map, i) ((map)->i->d_un.d_ptr + (map)->l_addr)
63 #else
64 # define D_PTR(map, i) (map)->i->d_un.d_ptr
65 #endif
67 /* Result of the lookup functions and how to retrieve the base address. */
68 typedef struct link_map *lookup_t;
69 #define LOOKUP_VALUE(map) map
70 #define LOOKUP_VALUE_ADDRESS(map) ((map) ? (map)->l_addr : 0)
72 /* On some architectures a pointer to a function is not just a pointer
73 to the actual code of the function but rather an architecture
74 specific descriptor. */
75 #ifndef ELF_FUNCTION_PTR_IS_SPECIAL
76 # define DL_SYMBOL_ADDRESS(map, ref) \
77 (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
78 # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
79 # define DL_DT_INIT_ADDRESS(map, start) (start)
80 # define DL_DT_FINI_ADDRESS(map, start) (start)
81 #endif
83 /* On some architectures dladdr can't use st_size of all symbols this way. */
84 #define DL_ADDR_SYM_MATCH(L, SYM, MATCHSYM, ADDR) \
85 ((ADDR) >= (L)->l_addr + (SYM)->st_value \
86 && ((((SYM)->st_shndx == SHN_UNDEF || (SYM)->st_size == 0) \
87 && (ADDR) == (L)->l_addr + (SYM)->st_value) \
88 || (ADDR) < (L)->l_addr + (SYM)->st_value + (SYM)->st_size) \
89 && ((MATCHSYM) == NULL || (MATCHSYM)->st_value < (SYM)->st_value))
91 /* Unmap a loaded object, called by _dl_close (). */
92 #ifndef DL_UNMAP_IS_SPECIAL
93 # define DL_UNMAP(map) \
94 __munmap ((void *) (map)->l_map_start, \
95 (map)->l_map_end - (map)->l_map_start)
96 #endif
98 /* By default we do not need special support to initialize DSOs loaded
99 by statically linked binaries. */
100 #ifndef DL_STATIC_INIT
101 # define DL_STATIC_INIT(map)
102 #endif
104 /* Reloc type classes as returned by elf_machine_type_class().
105 ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
106 some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
107 satisfied by any symbol in the executable. Some architectures do
108 not support copy relocations. In this case we define the macro to
109 zero so that the code for handling them gets automatically optimized
110 out. */
111 #define ELF_RTYPE_CLASS_PLT 1
112 #ifndef DL_NO_COPY_RELOCS
113 # define ELF_RTYPE_CLASS_COPY 2
114 #else
115 # define ELF_RTYPE_CLASS_COPY 0
116 #endif
118 /* ELF uses the PF_x macros to specify the segment permissions, mmap
119 uses PROT_xxx. In most cases the three macros have the values 1, 2,
120 and 3 but not in a matching order. The following macros allows
121 converting from the PF_x values to PROT_xxx values. */
122 #define PF_TO_PROT \
123 ((PROT_READ << (PF_R * 4)) \
124 | (PROT_WRITE << (PF_W * 4)) \
125 | (PROT_EXEC << (PF_X * 4)) \
126 | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4)) \
127 | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4)) \
128 | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4) \
129 | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4)))
131 /* The filename itself, or the main program name, if available. */
132 #define DSO_FILENAME(name) ((name)[0] ? (name) \
133 : (rtld_progname ?: "<main program>"))
135 #define RTLD_PROGNAME (rtld_progname ?: "<program name unknown>")
137 /* For the version handling we need an array with only names and their
138 hash values. */
139 struct r_found_version
141 const char *name;
142 ElfW(Word) hash;
144 int hidden;
145 const char *filename;
148 /* We want to cache information about the searches for shared objects. */
150 enum r_dir_status { unknown, nonexisting, existing };
152 struct r_search_path_elem
154 /* This link is only used in the `all_dirs' member of `r_search_path'. */
155 struct r_search_path_elem *next;
157 /* Strings saying where the definition came from. */
158 const char *what;
159 const char *where;
161 /* Basename for this search path element. The string must end with
162 a slash character. */
163 const char *dirname;
164 size_t dirnamelen;
166 enum r_dir_status status[0];
169 struct r_strlenpair
171 const char *str;
172 size_t len;
176 /* A data structure for a simple single linked list of strings. */
177 struct libname_list
179 const char *name; /* Name requested (before search). */
180 struct libname_list *next; /* Link to next name for this object. */
181 int dont_free; /* Flag whether this element should be freed
182 if the object is not entirely unloaded. */
186 /* Bit masks for the objects which valid callers can come from to
187 functions with restricted interface. */
188 enum allowmask
190 allow_libc = 1,
191 allow_libdl = 2,
192 allow_libpthread = 4,
193 allow_ldso = 8
197 struct audit_ifaces
199 void (*activity) (uintptr_t *, unsigned int);
200 char *(*objsearch) (const char *, uintptr_t *, unsigned int);
201 unsigned int (*objopen) (struct link_map *, Lmid_t, uintptr_t *);
202 void (*preinit) (uintptr_t *);
203 union
205 uintptr_t (*symbind32) (Elf32_Sym *, unsigned int, uintptr_t *,
206 uintptr_t *, unsigned int *, const char *);
207 uintptr_t (*symbind64) (Elf64_Sym *, unsigned int, uintptr_t *,
208 uintptr_t *, unsigned int *, const char *);
210 union
212 #ifdef ARCH_PLTENTER_MEMBERS
213 ARCH_PLTENTER_MEMBERS;
214 #endif
216 union
218 #ifdef ARCH_PLTEXIT_MEMBERS
219 ARCH_PLTEXIT_MEMBERS;
220 #endif
222 unsigned int (*objclose) (uintptr_t *);
224 struct audit_ifaces *next;
228 /* Test whether given NAME matches any of the names of the given object. */
229 extern int _dl_name_match_p (const char *__name, const struct link_map *__map)
230 internal_function;
232 /* Compute next higher prime number. */
233 extern unsigned long int _dl_higher_prime_number (unsigned long int n)
234 internal_function;
236 /* Function used as argument for `_dl_receive_error' function. The
237 arguments are the error code, error string, and the objname the
238 error occurred in. */
239 typedef void (*receiver_fct) (int, const char *, const char *);
241 /* Internal functions of the run-time dynamic linker.
242 These can be accessed if you link again the dynamic linker
243 as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
244 but are not normally of interest to user programs.
246 The `-ldl' library functions in <dlfcn.h> provide a simple
247 user interface to run-time dynamic linking. */
250 #ifndef SHARED
251 # define EXTERN extern
252 # define GL(name) _##name
253 #else
254 # define EXTERN
255 # ifdef IS_IN_rtld
256 # define GL(name) _rtld_local._##name
257 # else
258 # define GL(name) _rtld_global._##name
259 # endif
260 struct rtld_global
262 #endif
263 /* Don't change the order of the following elements. 'dl_loaded'
264 must remain the first element. Forever. */
266 /* Non-shared code has no support for multiple namespaces. */
267 #ifdef SHARED
268 # define DL_NNS 16
269 #else
270 # define DL_NNS 1
271 #endif
272 EXTERN struct link_namespaces
274 /* A pointer to the map for the main map. */
275 struct link_map *_ns_loaded;
276 /* Number of object in the _dl_loaded list. */
277 unsigned int _ns_nloaded;
278 /* Direct pointer to the searchlist of the main object. */
279 struct r_scope_elem *_ns_main_searchlist;
280 /* This is zero at program start to signal that the global scope map is
281 allocated by rtld. Later it keeps the size of the map. It might be
282 reset if in _dl_close if the last global object is removed. */
283 size_t _ns_global_scope_alloc;
284 /* Search table for unique objects. */
285 struct unique_sym_table
287 __rtld_lock_define_recursive (, lock)
288 struct unique_sym
290 uint32_t hashval;
291 const char *name;
292 const ElfW(Sym) *sym;
293 const struct link_map *map;
294 } *entries;
295 size_t size;
296 size_t n_elements;
297 void (*free) (void *);
298 } _ns_unique_sym_table;
299 /* Keep track of changes to each namespace' list. */
300 struct r_debug _ns_debug;
301 } _dl_ns[DL_NNS];
302 /* One higher than index of last used namespace. */
303 EXTERN size_t _dl_nns;
305 /* During the program run we must not modify the global data of
306 loaded shared object simultanously in two threads. Therefore we
307 protect `_dl_open' and `_dl_close' in dl-close.c.
309 This must be a recursive lock since the initializer function of
310 the loaded object might as well require a call to this function.
311 At this time it is not anymore a problem to modify the tables. */
312 __rtld_lock_define_recursive (EXTERN, _dl_load_lock)
313 /* This lock is used to keep __dl_iterate_phdr from inspecting the
314 list of loaded objects while an object is added to or removed
315 from that list. */
316 __rtld_lock_define_recursive (EXTERN, _dl_load_write_lock)
318 /* Incremented whenever something may have been added to dl_loaded. */
319 EXTERN unsigned long long _dl_load_adds;
321 /* The object to be initialized first. */
322 EXTERN struct link_map *_dl_initfirst;
324 #if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
325 /* Start time on CPU clock. */
326 EXTERN hp_timing_t _dl_cpuclock_offset;
327 #endif
329 /* Map of shared object to be profiled. */
330 EXTERN struct link_map *_dl_profile_map;
332 /* Counters for the number of relocations performed. */
333 EXTERN unsigned long int _dl_num_relocations;
334 EXTERN unsigned long int _dl_num_cache_relocations;
336 /* List of search directories. */
337 EXTERN struct r_search_path_elem *_dl_all_dirs;
339 #ifdef _LIBC_REENTRANT
340 EXTERN void **(*_dl_error_catch_tsd) (void) __attribute__ ((const));
341 #endif
343 /* Structure describing the dynamic linker itself. We need to
344 reserve memory for the data the audit libraries need. */
345 EXTERN struct link_map _dl_rtld_map;
346 #ifdef SHARED
347 struct auditstate audit_data[DL_NNS];
348 #endif
350 #if defined SHARED && defined _LIBC_REENTRANT \
351 && defined __rtld_lock_default_lock_recursive
352 EXTERN void (*_dl_rtld_lock_recursive) (void *);
353 EXTERN void (*_dl_rtld_unlock_recursive) (void *);
354 #endif
356 /* If loading a shared object requires that we make the stack executable
357 when it was not, we do it by calling this function.
358 It returns an errno code or zero on success. */
359 EXTERN int (*_dl_make_stack_executable_hook) (void **) internal_function;
361 /* Prevailing state of the stack, PF_X indicating it's executable. */
362 EXTERN ElfW(Word) _dl_stack_flags;
364 /* Flag signalling whether there are gaps in the module ID allocation. */
365 EXTERN bool _dl_tls_dtv_gaps;
366 /* Highest dtv index currently needed. */
367 EXTERN size_t _dl_tls_max_dtv_idx;
368 /* Information about the dtv slots. */
369 EXTERN struct dtv_slotinfo_list
371 size_t len;
372 struct dtv_slotinfo_list *next;
373 struct dtv_slotinfo
375 size_t gen;
376 struct link_map *map;
377 } slotinfo[0];
378 } *_dl_tls_dtv_slotinfo_list;
379 /* Number of modules in the static TLS block. */
380 EXTERN size_t _dl_tls_static_nelem;
381 /* Size of the static TLS block. */
382 EXTERN size_t _dl_tls_static_size;
383 /* Size actually allocated in the static TLS block. */
384 EXTERN size_t _dl_tls_static_used;
385 /* Alignment requirement of the static TLS block. */
386 EXTERN size_t _dl_tls_static_align;
388 /* Number of additional entries in the slotinfo array of each slotinfo
389 list element. A large number makes it almost certain take we never
390 have to iterate beyond the first element in the slotinfo list. */
391 #define TLS_SLOTINFO_SURPLUS (62)
393 /* Number of additional slots in the dtv allocated. */
394 #define DTV_SURPLUS (14)
396 /* Initial dtv of the main thread, not allocated with normal malloc. */
397 EXTERN void *_dl_initial_dtv;
398 /* Generation counter for the dtv. */
399 EXTERN size_t _dl_tls_generation;
401 EXTERN void (*_dl_init_static_tls) (struct link_map *);
403 EXTERN void (*_dl_wait_lookup_done) (void);
405 /* Scopes to free after next THREAD_GSCOPE_WAIT (). */
406 EXTERN struct dl_scope_free_list
408 size_t count;
409 void *list[50];
410 } *_dl_scope_free_list;
411 #ifdef SHARED
413 # define __rtld_global_attribute__
414 # ifdef IS_IN_rtld
415 # ifdef HAVE_SDATA_SECTION
416 # define __rtld_local_attribute__ \
417 __attribute__ ((visibility ("hidden"), section (".sdata")))
418 # undef __rtld_global_attribute__
419 # define __rtld_global_attribute__ __attribute__ ((section (".sdata")))
420 # else
421 # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
422 # endif
423 extern struct rtld_global _rtld_local __rtld_local_attribute__;
424 # undef __rtld_local_attribute__
425 # endif
426 extern struct rtld_global _rtld_global __rtld_global_attribute__;
427 # undef __rtld_global_attribute__
428 #endif
430 #ifndef SHARED
431 # define GLRO(name) _##name
432 #else
433 # ifdef IS_IN_rtld
434 # define GLRO(name) _rtld_local_ro._##name
435 # else
436 # define GLRO(name) _rtld_global_ro._##name
437 # endif
438 struct rtld_global_ro
440 #endif
442 /* If nonzero the appropriate debug information is printed. */
443 EXTERN int _dl_debug_mask;
444 #define DL_DEBUG_LIBS (1 << 0)
445 #define DL_DEBUG_IMPCALLS (1 << 1)
446 #define DL_DEBUG_BINDINGS (1 << 2)
447 #define DL_DEBUG_SYMBOLS (1 << 3)
448 #define DL_DEBUG_VERSIONS (1 << 4)
449 #define DL_DEBUG_RELOC (1 << 5)
450 #define DL_DEBUG_FILES (1 << 6)
451 #define DL_DEBUG_STATISTICS (1 << 7)
452 #define DL_DEBUG_UNUSED (1 << 8)
453 #define DL_DEBUG_SCOPES (1 << 9)
454 /* These two are used only internally. */
455 #define DL_DEBUG_HELP (1 << 10)
456 #define DL_DEBUG_PRELINK (1 << 11)
458 /* OS version. */
459 EXTERN unsigned int _dl_osversion;
460 /* Platform name. */
461 EXTERN const char *_dl_platform;
462 EXTERN size_t _dl_platformlen;
464 /* Cached value of `getpagesize ()'. */
465 EXTERN size_t _dl_pagesize;
467 /* Do we read from ld.so.cache? */
468 EXTERN int _dl_inhibit_cache;
470 /* Copy of the content of `_dl_main_searchlist' at startup time. */
471 EXTERN struct r_scope_elem _dl_initial_searchlist;
473 /* CLK_TCK as reported by the kernel. */
474 EXTERN int _dl_clktck;
476 /* If nonzero print warnings messages. */
477 EXTERN int _dl_verbose;
479 /* File descriptor to write debug messages to. */
480 EXTERN int _dl_debug_fd;
482 /* Do we do lazy relocations? */
483 EXTERN int _dl_lazy;
485 /* Nonzero if runtime lookups should not update the .got/.plt. */
486 EXTERN int _dl_bind_not;
488 /* Nonzero if references should be treated as weak during runtime
489 linking. */
490 EXTERN int _dl_dynamic_weak;
492 /* Default floating-point control word. */
493 EXTERN fpu_control_t _dl_fpu_control;
495 /* Expected cache ID. */
496 EXTERN int _dl_correct_cache_id;
498 /* Mask for hardware capabilities that are available. */
499 EXTERN uint64_t _dl_hwcap;
501 /* Mask for important hardware capabilities we honour. */
502 EXTERN uint64_t _dl_hwcap_mask;
504 /* Pointer to the auxv list supplied to the program at startup. */
505 EXTERN ElfW(auxv_t) *_dl_auxv;
507 /* Get architecture specific definitions. */
508 #define PROCINFO_DECL
509 #ifndef PROCINFO_CLASS
510 # define PROCINFO_CLASS EXTERN
511 #endif
512 #include <dl-procinfo.c>
514 /* Names of shared object for which the RPATH should be ignored. */
515 EXTERN const char *_dl_inhibit_rpath;
517 /* Location of the binary. */
518 EXTERN const char *_dl_origin_path;
520 /* -1 if the dynamic linker should honor library load bias,
521 0 if not, -2 use the default (honor biases for normal
522 binaries, don't honor for PIEs). */
523 EXTERN ElfW(Addr) _dl_use_load_bias;
525 /* Name of the shared object to be profiled (if any). */
526 EXTERN const char *_dl_profile;
527 /* Filename of the output file. */
528 EXTERN const char *_dl_profile_output;
529 /* Name of the object we want to trace the prelinking. */
530 EXTERN const char *_dl_trace_prelink;
531 /* Map of shared object to be prelink traced. */
532 EXTERN struct link_map *_dl_trace_prelink_map;
534 /* All search directories defined at startup. */
535 EXTERN struct r_search_path_elem *_dl_init_all_dirs;
537 #if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
538 /* Overhead of a high-precision timing measurement. */
539 EXTERN hp_timing_t _dl_hp_timing_overhead;
540 #endif
542 #ifdef NEED_DL_SYSINFO
543 /* Syscall handling improvements. This is very specific to x86. */
544 EXTERN uintptr_t _dl_sysinfo;
545 #endif
547 #ifdef NEED_DL_SYSINFO_DSO
548 /* The vsyscall page is a virtual DSO pre-mapped by the kernel.
549 This points to its ELF header. */
550 EXTERN const ElfW(Ehdr) *_dl_sysinfo_dso;
552 /* At startup time we set up the normal DSO data structure for it,
553 and this points to it. */
554 EXTERN struct link_map *_dl_sysinfo_map;
555 #endif
557 /* Mask for more hardware capabilities that are available on some
558 platforms. */
559 EXTERN uint64_t _dl_hwcap2;
561 #ifdef SHARED
562 /* We add a function table to _rtld_global which is then used to
563 call the function instead of going through the PLT. The result
564 is that we can avoid exporting the functions and we do not jump
565 PLT relocations in libc.so. */
566 void (*_dl_debug_printf) (const char *, ...)
567 __attribute__ ((__format__ (__printf__, 1, 2)));
568 int (internal_function *_dl_catch_error) (const char **, const char **,
569 bool *, void (*) (void *), void *);
570 void (internal_function *_dl_signal_error) (int, const char *, const char *,
571 const char *);
572 void (*_dl_mcount) (ElfW(Addr) frompc, ElfW(Addr) selfpc);
573 lookup_t (internal_function *_dl_lookup_symbol_x) (const char *,
574 struct link_map *,
575 const ElfW(Sym) **,
576 struct r_scope_elem *[],
577 const struct r_found_version *,
578 int, int,
579 struct link_map *);
580 int (*_dl_check_caller) (const void *, enum allowmask);
581 void *(*_dl_open) (const char *file, int mode, const void *caller_dlopen,
582 Lmid_t nsid, int argc, char *argv[], char *env[]);
583 void (*_dl_close) (void *map);
584 void *(*_dl_tls_get_addr_soft) (struct link_map *);
585 #ifdef HAVE_DL_DISCOVER_OSVERSION
586 int (*_dl_discover_osversion) (void);
587 #endif
589 /* List of auditing interfaces. */
590 struct audit_ifaces *_dl_audit;
591 unsigned int _dl_naudit;
593 /* 0 if internal pointer values should not be guarded, 1 if they should. */
594 EXTERN int _dl_pointer_guard;
596 # define __rtld_global_attribute__
597 # ifdef IS_IN_rtld
598 # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
599 extern struct rtld_global_ro _rtld_local_ro
600 attribute_relro __rtld_local_attribute__;
601 extern struct rtld_global_ro _rtld_global_ro
602 attribute_relro __rtld_global_attribute__;
603 # undef __rtld_local_attribute__
604 # else
605 /* We cheat a bit here. We declare the variable as as const even
606 though it is at startup. */
607 extern const struct rtld_global_ro _rtld_global_ro
608 attribute_relro __rtld_global_attribute__;
609 # endif
610 # undef __rtld_global_attribute__
611 #endif
612 #undef EXTERN
614 #ifndef SHARED
615 /* dl-support.c defines these and initializes them early on. */
616 extern const ElfW(Phdr) *_dl_phdr;
617 extern size_t _dl_phnum;
618 #endif
620 #ifdef IS_IN_rtld
621 /* This is the initial value of GL(dl_error_catch_tsd).
622 A non-TLS libpthread will change it. */
623 extern void **_dl_initial_error_catch_tsd (void) __attribute__ ((const))
624 attribute_hidden;
625 #endif
627 /* This is the initial value of GL(dl_make_stack_executable_hook).
628 A threads library can change it. */
629 extern int _dl_make_stack_executable (void **stack_endp) internal_function;
630 rtld_hidden_proto (_dl_make_stack_executable)
632 /* Variable pointing to the end of the stack (or close to it). This value
633 must be constant over the runtime of the application. Some programs
634 might use the variable which results in copy relocations on some
635 platforms. But this does not matter, ld.so can always use the local
636 copy. */
637 extern void *__libc_stack_end
638 #ifndef LIBC_STACK_END_NOT_RELRO
639 attribute_relro
640 #endif
642 rtld_hidden_proto (__libc_stack_end)
644 /* Parameters passed to the dynamic linker. */
645 extern int _dl_argc attribute_hidden attribute_relro;
646 extern char **_dl_argv
647 #ifndef DL_ARGV_NOT_RELRO
648 attribute_relro
649 #endif
651 #ifdef IS_IN_rtld
652 extern unsigned int _dl_skip_args attribute_hidden
653 # ifndef DL_ARGV_NOT_RELRO
654 attribute_relro
655 # endif
657 extern unsigned int _dl_skip_args_internal attribute_hidden
658 # ifndef DL_ARGV_NOT_RELRO
659 attribute_relro
660 # endif
662 extern char **_dl_argv_internal attribute_hidden
663 # ifndef DL_ARGV_NOT_RELRO
664 attribute_relro
665 # endif
667 # define rtld_progname (INTUSE(_dl_argv)[0])
668 #else
669 # define rtld_progname _dl_argv[0]
670 #endif
672 /* Flag set at startup and cleared when the last initializer has run. */
673 extern int _dl_starting_up;
674 weak_extern (_dl_starting_up)
675 #ifdef IS_IN_rtld
676 extern int _dl_starting_up_internal attribute_hidden;
677 #endif
679 /* Random data provided by the kernel. */
680 extern void *_dl_random attribute_hidden attribute_relro;
682 /* OS-dependent function to open the zero-fill device. */
683 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
686 /* Write message on the debug file descriptor. The parameters are
687 interpreted as for a `printf' call. All the lines start with a
688 tag showing the PID. */
689 extern void _dl_debug_printf (const char *fmt, ...)
690 __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
692 /* Write message on the debug file descriptor. The parameters are
693 interpreted as for a `printf' call. All the lines buf the first
694 start with a tag showing the PID. */
695 extern void _dl_debug_printf_c (const char *fmt, ...)
696 __attribute__ ((__format__ (__printf__, 1, 2)));
699 /* Write a message on the specified descriptor FD. The parameters are
700 interpreted as for a `printf' call. */
701 extern void _dl_dprintf (int fd, const char *fmt, ...)
702 __attribute__ ((__format__ (__printf__, 2, 3)))
703 attribute_hidden;
705 /* Write a message on the specified descriptor standard output. The
706 parameters are interpreted as for a `printf' call. */
707 #define _dl_printf(fmt, args...) \
708 _dl_dprintf (STDOUT_FILENO, fmt, ##args)
710 /* Write a message on the specified descriptor standard error. The
711 parameters are interpreted as for a `printf' call. */
712 #define _dl_error_printf(fmt, args...) \
713 _dl_dprintf (STDERR_FILENO, fmt, ##args)
715 /* Write a message on the specified descriptor standard error and exit
716 the program. The parameters are interpreted as for a `printf' call. */
717 #define _dl_fatal_printf(fmt, args...) \
718 do \
720 _dl_dprintf (STDERR_FILENO, fmt, ##args); \
721 _exit (127); \
723 while (1)
726 /* This function is called by all the internal dynamic linker functions
727 when they encounter an error. ERRCODE is either an `errno' code or
728 zero; OBJECT is the name of the problematical shared object, or null if
729 it is a general problem; ERRSTRING is a string describing the specific
730 problem. */
731 extern void _dl_signal_error (int errcode, const char *object,
732 const char *occurred, const char *errstring)
733 internal_function __attribute__ ((__noreturn__)) attribute_hidden;
735 /* Like _dl_signal_error, but may return when called in the context of
736 _dl_receive_error. */
737 extern void _dl_signal_cerror (int errcode, const char *object,
738 const char *occation, const char *errstring)
739 internal_function;
741 /* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike
742 `_dl_catch_error' the operation is resumed after the OPERATE
743 function returns.
744 ARGS is passed as argument to OPERATE. */
745 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
746 void *args)
747 internal_function;
750 /* Open the shared object NAME and map in its segments.
751 LOADER's DT_RPATH is used in searching for NAME.
752 If the object is already opened, returns its existing map. */
753 extern struct link_map *_dl_map_object (struct link_map *loader,
754 const char *name,
755 int type, int trace_mode, int mode,
756 Lmid_t nsid)
757 internal_function attribute_hidden;
759 /* Call _dl_map_object on the dependencies of MAP, and set up
760 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
761 loaded objects that will be inserted into MAP->l_searchlist after MAP
762 but before its dependencies. */
763 extern void _dl_map_object_deps (struct link_map *map,
764 struct link_map **preloads,
765 unsigned int npreloads, int trace_mode,
766 int open_mode)
767 internal_function attribute_hidden;
769 /* Cache the locations of MAP's hash table. */
770 extern void _dl_setup_hash (struct link_map *map)
771 internal_function attribute_hidden;
774 /* Collect the directories in the search path for LOADER's dependencies.
775 The data structure is defined in <dlfcn.h>. If COUNTING is true,
776 SI->dls_cnt and SI->dls_size are set; if false, those must be as set
777 by a previous call with COUNTING set, and SI must point to SI->dls_size
778 bytes to be used in filling in the result. */
779 extern void _dl_rtld_di_serinfo (struct link_map *loader,
780 Dl_serinfo *si, bool counting)
781 internal_function;
784 /* Search loaded objects' symbol tables for a definition of the symbol
785 referred to by UNDEF. *SYM is the symbol table entry containing the
786 reference; it is replaced with the defining symbol, and the base load
787 address of the defining object is returned. SYMBOL_SCOPE is a
788 null-terminated list of object scopes to search; each object's
789 l_searchlist (i.e. the segment of the dependency tree starting at that
790 object) is searched in turn. REFERENCE_NAME should name the object
791 containing the reference; it is used in error messages.
792 TYPE_CLASS describes the type of symbol we are looking for. */
793 enum
795 /* If necessary add dependency between user and provider object. */
796 DL_LOOKUP_ADD_DEPENDENCY = 1,
797 /* Return most recent version instead of default version for
798 unversioned lookup. */
799 DL_LOOKUP_RETURN_NEWEST = 2,
800 /* Set if dl_lookup* called with GSCOPE lock held. */
801 DL_LOOKUP_GSCOPE_LOCK = 4,
804 /* Lookup versioned symbol. */
805 extern lookup_t _dl_lookup_symbol_x (const char *undef,
806 struct link_map *undef_map,
807 const ElfW(Sym) **sym,
808 struct r_scope_elem *symbol_scope[],
809 const struct r_found_version *version,
810 int type_class, int flags,
811 struct link_map *skip_map)
812 internal_function attribute_hidden;
815 /* Look up symbol NAME in MAP's scope and return its run-time address. */
816 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name)
817 internal_function;
819 /* Add the new link_map NEW to the end of the namespace list. */
820 extern void _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
821 internal_function attribute_hidden;
823 /* Allocate a `struct link_map' for a new object being loaded. */
824 extern struct link_map *_dl_new_object (char *realname, const char *libname,
825 int type, struct link_map *loader,
826 int mode, Lmid_t nsid)
827 internal_function attribute_hidden;
829 /* Relocate the given object (if it hasn't already been).
830 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
831 If RTLD_LAZY is set in RELOC-MODE, don't relocate its PLT. */
832 extern void _dl_relocate_object (struct link_map *map,
833 struct r_scope_elem *scope[],
834 int reloc_mode, int consider_profiling)
835 attribute_hidden;
837 /* Protect PT_GNU_RELRO area. */
838 extern void _dl_protect_relro (struct link_map *map)
839 internal_function attribute_hidden;
841 /* Call _dl_signal_error with a message about an unhandled reloc type.
842 TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
843 PLT is nonzero if this was a PLT reloc; it just affects the message. */
844 extern void _dl_reloc_bad_type (struct link_map *map,
845 unsigned int type, int plt)
846 internal_function __attribute__ ((__noreturn__));
848 /* Resolve conflicts if prelinking. */
849 extern void _dl_resolve_conflicts (struct link_map *l,
850 ElfW(Rela) *conflict,
851 ElfW(Rela) *conflictend);
853 /* Check the version dependencies of all objects available through
854 MAP. If VERBOSE print some more diagnostics. */
855 extern int _dl_check_all_versions (struct link_map *map, int verbose,
856 int trace_mode)
857 internal_function;
859 /* Check the version dependencies for MAP. If VERBOSE print some more
860 diagnostics. */
861 extern int _dl_check_map_versions (struct link_map *map, int verbose,
862 int trace_mode)
863 internal_function;
865 /* Initialize the object in SCOPE by calling the constructors with
866 ARGC, ARGV, and ENV as the parameters. */
867 extern void _dl_init (struct link_map *main_map, int argc, char **argv,
868 char **env) internal_function attribute_hidden;
870 /* Call the finalizer functions of all shared objects whose
871 initializer functions have completed. */
872 extern void _dl_fini (void) internal_function;
874 /* Sort array MAPS according to dependencies of the contained objects. */
875 extern void _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used,
876 Lmid_t ns)
877 internal_function;
879 /* The dynamic linker calls this function before and having changing
880 any shared object mappings. The `r_state' member of `struct r_debug'
881 says what change is taking place. This function's address is
882 the value of the `r_brk' member. */
883 extern void _dl_debug_state (void);
884 rtld_hidden_proto (_dl_debug_state)
886 /* Initialize `struct r_debug' if it has not already been done. The
887 argument is the run-time load address of the dynamic linker, to be put
888 in the `r_ldbase' member. Returns the address of the structure. */
889 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
890 internal_function;
892 /* Initialize the basic data structure for the search paths. */
893 extern void _dl_init_paths (const char *library_path) internal_function;
895 /* Gather the information needed to install the profiling tables and start
896 the timers. */
897 extern void _dl_start_profile (void) internal_function attribute_hidden;
899 /* The actual functions used to keep book on the calls. */
900 extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
901 extern void _dl_mcount_internal (ElfW(Addr) frompc, ElfW(Addr) selfpc)
902 attribute_hidden;
904 /* This function is simply a wrapper around the _dl_mcount function
905 which does not require a FROMPC parameter since this is the
906 calling function. */
907 extern void _dl_mcount_wrapper (void *selfpc);
909 /* Show the members of the auxiliary array passed up from the kernel. */
910 extern void _dl_show_auxv (void) internal_function;
912 /* Return all environment variables starting with `LD_', one after the
913 other. */
914 extern char *_dl_next_ld_env_entry (char ***position) internal_function;
916 /* Return an array with the names of the important hardware capabilities. */
917 extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
918 size_t paltform_len,
919 size_t *sz,
920 size_t *max_capstrlen)
921 internal_function;
923 /* Look up NAME in ld.so.cache and return the file name stored there,
924 or null if none is found. */
925 extern const char *_dl_load_cache_lookup (const char *name)
926 internal_function;
928 /* If the system does not support MAP_COPY we cannot leave the file open
929 all the time since this would create problems when the file is replaced.
930 Therefore we provide this function to close the file and open it again
931 once needed. */
932 extern void _dl_unload_cache (void) attribute_hidden;
934 /* System-dependent function to read a file's whole contents in the
935 most convenient manner available. *SIZEP gets the size of the
936 file. On error MAP_FAILED is returned. */
937 extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
938 int prot)
939 internal_function attribute_hidden;
941 /* System-specific function to do initial startup for the dynamic linker.
942 After this, file access calls and getenv must work. This is responsible
943 for setting __libc_enable_secure if we need to be secure (e.g. setuid),
944 and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
945 extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
946 void (*dl_main) (const ElfW(Phdr) *phdr,
947 ElfW(Word) phnum,
948 ElfW(Addr) *user_entry,
949 ElfW(auxv_t) *auxv))
950 attribute_hidden;
952 extern void _dl_sysdep_start_cleanup (void)
953 internal_function attribute_hidden;
956 /* Determine next available module ID. */
957 extern size_t _dl_next_tls_modid (void) internal_function attribute_hidden;
959 /* Calculate offset of the TLS blocks in the static TLS block. */
960 extern void _dl_determine_tlsoffset (void) internal_function attribute_hidden;
962 /* Set up the data structures for TLS, when they were not set up at startup.
963 Returns nonzero on malloc failure.
964 This is called from _dl_map_object_from_fd or by libpthread. */
965 extern int _dl_tls_setup (void) internal_function;
966 rtld_hidden_proto (_dl_tls_setup)
968 /* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */
969 extern void *_dl_allocate_tls (void *mem) internal_function;
970 rtld_hidden_proto (_dl_allocate_tls)
972 /* Get size and alignment requirements of the static TLS block. */
973 extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp)
974 internal_function;
976 extern void _dl_allocate_static_tls (struct link_map *map)
977 internal_function attribute_hidden;
979 /* These are internal entry points to the two halves of _dl_allocate_tls,
980 only used within rtld.c itself at startup time. */
981 extern void *_dl_allocate_tls_storage (void)
982 internal_function attribute_hidden;
983 extern void *_dl_allocate_tls_init (void *) internal_function;
984 rtld_hidden_proto (_dl_allocate_tls_init)
986 /* Deallocate memory allocated with _dl_allocate_tls. */
987 extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb) internal_function;
988 rtld_hidden_proto (_dl_deallocate_tls)
990 extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
992 /* Find origin of the executable. */
993 extern const char *_dl_get_origin (void) attribute_hidden;
995 /* Count DSTs. */
996 extern size_t _dl_dst_count (const char *name, int is_path) attribute_hidden;
998 /* Substitute DST values. */
999 extern char *_dl_dst_substitute (struct link_map *l, const char *name,
1000 char *result, int is_path) attribute_hidden;
1002 /* Check validity of the caller. */
1003 extern int _dl_check_caller (const void *caller, enum allowmask mask)
1004 attribute_hidden;
1006 /* Open the shared object NAME, relocate it, and run its initializer if it
1007 hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
1008 the object is already opened, returns its existing map. */
1009 extern void *_dl_open (const char *name, int mode, const void *caller,
1010 Lmid_t nsid, int argc, char *argv[], char *env[])
1011 attribute_hidden;
1013 /* Free or queue for freeing scope OLD. If other threads might be
1014 in the middle of _dl_fixup, _dl_profile_fixup or dl*sym using the
1015 old scope, OLD can't be freed until no thread is using it. */
1016 extern int _dl_scope_free (void *) attribute_hidden;
1018 /* Add module to slot information data. */
1019 extern void _dl_add_to_slotinfo (struct link_map *l) attribute_hidden;
1021 /* Update slot information data for at least the generation of the
1022 module with the given index. */
1023 extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid);
1025 /* Look up the module's TLS block as for __tls_get_addr,
1026 but never touch anything. Return null if it's not allocated yet. */
1027 extern void *_dl_tls_get_addr_soft (struct link_map *l) attribute_hidden;
1029 extern int _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
1030 internal_function attribute_hidden;
1032 /* Show show of an object. */
1033 extern void _dl_show_scope (struct link_map *new, int from);
1035 extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr)
1036 internal_function;
1037 rtld_hidden_proto (_dl_find_dso_for_object)
1039 /* Initialization which is normally done by the dynamic linker. */
1040 extern void _dl_non_dynamic_init (void) internal_function;
1042 /* Used by static binaries to check the auxiliary vector. */
1043 extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function;
1046 __END_DECLS
1048 #endif /* ldsodefs.h */