2005-01-28 Martin Schwidefsky <schwidefsky@de.ibm.com>
[glibc.git] / sysdeps / generic / ldsodefs.h
blob29588207d1be9ab83823e4276e3cfb249520cbb0
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2 Copyright (C) 1995-2003, 2004, 2005 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _LDSODEFS_H
21 #define _LDSODEFS_H 1
23 #include <features.h>
25 #include <stdbool.h>
26 #define __need_size_t
27 #define __need_NULL
28 #include <stddef.h>
29 #include <string.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>
42 __BEGIN_DECLS
44 /* We use this macro to refer to ELF types independent of the native wordsize.
45 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
46 #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
48 /* All references to the value of l_info[DT_PLTGOT],
49 l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
50 l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
51 have to be accessed via the D_PTR macro. The macro is needed since for
52 most architectures the entry is already relocated - but for some not
53 and we need to relocate at access time. */
54 #ifdef DL_RO_DYN_SECTION
55 # define D_PTR(map, i) ((map)->i->d_un.d_ptr + (map)->l_addr)
56 #else
57 # define D_PTR(map, i) (map)->i->d_un.d_ptr
58 #endif
60 /* Result of the lookup functions and how to retrieve the base address. */
61 typedef struct link_map *lookup_t;
62 # define LOOKUP_VALUE(map) map
63 # define LOOKUP_VALUE_ADDRESS(map) ((map) ? (map)->l_addr : 0)
65 /* on some architectures a pointer to a function is not just a pointer
66 to the actual code of the function but rather an architecture
67 specific descriptor. */
68 #ifndef ELF_FUNCTION_PTR_IS_SPECIAL
69 # define DL_SYMBOL_ADDRESS(map, ref) \
70 (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
71 # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
72 # define DL_DT_INIT_ADDRESS(map, start) (start)
73 # define DL_DT_FINI_ADDRESS(map, start) (start)
74 #endif
76 /* Unmap a loaded object, called by _dl_close (). */
77 #ifndef DL_UNMAP_IS_SPECIAL
78 # define DL_UNMAP(map) \
79 __munmap ((void *) (map)->l_map_start, \
80 (map)->l_map_end - (map)->l_map_start)
81 #endif
83 /* By default we do not need special support to initialize DSOs loaded
84 by statically linked binaries. */
85 #ifndef DL_STATIC_INIT
86 # define DL_STATIC_INIT(map)
87 #endif
89 /* Reloc type classes as returned by elf_machine_type_class().
90 ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
91 some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
92 satisfied by any symbol in the executable. Some architectures do
93 not support copy relocations. In this case we define the macro to
94 zero so that the code for handling them gets automatically optimized
95 out. */
96 #define ELF_RTYPE_CLASS_PLT 1
97 #ifndef DL_NO_COPY_RELOCS
98 # define ELF_RTYPE_CLASS_COPY 2
99 #else
100 # define ELF_RTYPE_CLASS_COPY 0
101 #endif
103 /* ELF uses the PF_x macros to specify the segment permissions, mmap
104 uses PROT_xxx. In most cases the three macros have the values 1, 2,
105 and 3 but not in a matching order. The following macros allows
106 converting from the PF_x values to PROT_xxx values. */
107 #define PF_TO_PROT \
108 ((PROT_READ << (PF_R * 4)) \
109 | (PROT_WRITE << (PF_W * 4)) \
110 | (PROT_EXEC << (PF_X * 4)) \
111 | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4)) \
112 | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4)) \
113 | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4) \
114 | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4)))
117 /* For the version handling we need an array with only names and their
118 hash values. */
119 struct r_found_version
121 const char *name;
122 ElfW(Word) hash;
124 int hidden;
125 const char *filename;
128 /* We want to cache information about the searches for shared objects. */
130 enum r_dir_status { unknown, nonexisting, existing };
132 struct r_search_path_elem
134 /* This link is only used in the `all_dirs' member of `r_search_path'. */
135 struct r_search_path_elem *next;
137 /* Strings saying where the definition came from. */
138 const char *what;
139 const char *where;
141 /* Basename for this search path element. The string must end with
142 a slash character. */
143 const char *dirname;
144 size_t dirnamelen;
146 enum r_dir_status status[0];
149 struct r_strlenpair
151 const char *str;
152 size_t len;
156 /* A data structure for a simple single linked list of strings. */
157 struct libname_list
159 const char *name; /* Name requested (before search). */
160 struct libname_list *next; /* Link to next name for this object. */
161 int dont_free; /* Flag whether this element should be freed
162 if the object is not entirely unloaded. */
166 /* Bit masks for the objects which valid callers can come from to
167 functions with restricted interface. */
168 enum allowmask
170 allow_libc = 1,
171 allow_libdl = 2,
172 allow_libpthread = 4,
173 allow_ldso = 8
177 /* Type for list of auditing interfaces. */
178 struct La_i86_regs;
179 struct La_i86_retval;
180 struct La_x86_64_regs;
181 struct La_x86_64_retval;
182 struct La_ppc32_regs;
183 struct La_ppc32_retval;
184 struct La_ppc64_regs;
185 struct La_ppc64_retval;
186 struct La_sh_regs;
187 struct La_sh_retval;
188 struct La_m68k_regs;
189 struct La_m68k_retval;
190 struct La_alpha_regs;
191 struct La_alpha_retval;
193 struct audit_ifaces
195 void (*activity) (uintptr_t *, unsigned int);
196 char *(*objsearch) (const char *, uintptr_t *, unsigned int);
197 unsigned int (*objopen) (struct link_map *, Lmid_t, uintptr_t *);
198 void (*preinit) (uintptr_t *);
199 union
201 uintptr_t (*symbind32) (Elf32_Sym *, unsigned int, uintptr_t *,
202 uintptr_t *, unsigned int *, const char *);
203 uintptr_t (*symbind64) (Elf64_Sym *, unsigned int, uintptr_t *,
204 uintptr_t *, unsigned int *, const char *);
206 union
208 Elf32_Addr (*i86_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *,
209 uintptr_t *, struct La_i86_regs *,
210 unsigned int *, const char *name,
211 long int *framesizep);
212 Elf64_Addr (*x86_64_gnu_pltenter) (Elf64_Sym *, unsigned int, uintptr_t *,
213 uintptr_t *, struct La_x86_64_regs *,
214 unsigned int *, const char *name,
215 long int *framesizep);
216 Elf32_Addr (*ppc32_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *,
217 uintptr_t *, struct La_ppc32_regs *,
218 unsigned int *, const char *name,
219 long int *framesizep);
220 Elf64_Addr (*ppc64_gnu_pltenter) (Elf64_Sym *, unsigned int, uintptr_t *,
221 uintptr_t *, struct La_ppc64_regs *,
222 unsigned int *, const char *name,
223 long int *framesizep);
224 uintptr_t (*sh_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *,
225 uintptr_t *, const struct La_sh_regs *,
226 unsigned int *, const char *name,
227 long int *framesizep);
228 Elf32_Addr (*m68k_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *,
229 uintptr_t *, struct La_m68k_regs *,
230 unsigned int *, const char *name,
231 long int *framesizep);
232 Elf64_Addr (*alpha_gnu_pltenter) (Elf64_Sym *, unsigned int, uintptr_t *,
233 uintptr_t *, struct La_alpha_regs *,
234 unsigned int *, const char *name,
235 long int *framesizep);
237 union
239 unsigned int (*i86_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *,
240 uintptr_t *, const struct La_i86_regs *,
241 struct La_i86_retval *, const char *);
242 unsigned int (*x86_64_gnu_pltexit) (Elf64_Sym *, unsigned int, uintptr_t *,
243 uintptr_t *,
244 const struct La_x86_64_regs *,
245 struct La_x86_64_retval *,
246 const char *);
247 unsigned int (*ppc32_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *,
248 uintptr_t *,
249 const struct La_ppc32_regs *,
250 struct La_ppc32_retval *, const char *);
251 unsigned int (*ppc64_gnu_pltexit) (Elf64_Sym *, unsigned int, uintptr_t *,
252 uintptr_t *,
253 const struct La_ppc64_regs *,
254 struct La_ppc64_retval *, const char *);
255 unsigned int (*sh_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *,
256 uintptr_t *, const struct La_sh_regs *,
257 struct La_sh_retval *, const char *);
258 unsigned int (*m68k_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *,
259 uintptr_t *, const struct La_m68k_regs *,
260 struct La_m68k_retval *, const char *);
261 unsigned int (*alpha_gnu_pltexit) (Elf64_Sym *, unsigned int, uintptr_t *,
262 uintptr_t *,
263 const struct La_alpha_regs *,
264 struct La_alpha_retval *, const char *);
266 unsigned int (*objclose) (uintptr_t *);
268 struct audit_ifaces *next;
272 /* Test whether given NAME matches any of the names of the given object. */
273 extern int _dl_name_match_p (const char *__name, struct link_map *__map)
274 internal_function;
276 /* Function used as argument for `_dl_receive_error' function. The
277 arguments are the error code, error string, and the objname the
278 error occurred in. */
279 typedef void (*receiver_fct) (int, const char *, const char *);
281 /* Internal functions of the run-time dynamic linker.
282 These can be accessed if you link again the dynamic linker
283 as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
284 but are not normally of interest to user programs.
286 The `-ldl' library functions in <dlfcn.h> provide a simple
287 user interface to run-time dynamic linking. */
290 #ifndef SHARED
291 # define EXTERN extern
292 # define GL(name) _##name
293 #else
294 # define EXTERN
295 # ifdef IS_IN_rtld
296 # define GL(name) _rtld_local._##name
297 # else
298 # define GL(name) _rtld_global._##name
299 # endif
300 struct rtld_global
302 #endif
303 /* Don't change the order of the following elements. 'dl_loaded'
304 must remain the first element. Forever. */
306 /* Non-shared code has no support for multiple namespaces. */
307 #ifdef SHARED
308 # define DL_NNS 16
309 #else
310 # define DL_NNS 1
311 #endif
312 EXTERN struct link_namespaces
314 /* A pointer to the map for the main map. */
315 struct link_map *_ns_loaded;
316 /* Number of object in the _dl_loaded list. */
317 unsigned int _ns_nloaded;
318 /* Array representing global scope. */
319 struct r_scope_elem *_ns_global_scope[2];
320 /* Direct pointer to the searchlist of the main object. */
321 struct r_scope_elem *_ns_main_searchlist;
322 /* This is zero at program start to signal that the global scope map is
323 allocated by rtld. Later it keeps the size of the map. It might be
324 reset if in _dl_close if the last global object is removed. */
325 size_t _ns_global_scope_alloc;
326 /* Keep track of changes to each namespace' list. */
327 struct r_debug _ns_debug;
328 } _dl_ns[DL_NNS];
330 /* During the program run we must not modify the global data of
331 loaded shared object simultanously in two threads. Therefore we
332 protect `_dl_open' and `_dl_close' in dl-close.c.
334 This must be a recursive lock since the initializer function of
335 the loaded object might as well require a call to this function.
336 At this time it is not anymore a problem to modify the tables. */
337 __rtld_lock_define_recursive (EXTERN, _dl_load_lock)
339 /* Incremented whenever something may have been added to dl_loaded. */
340 EXTERN unsigned long long _dl_load_adds;
342 #ifndef MAP_ANON
343 /* File descriptor referring to the zero-fill device. */
344 EXTERN int _dl_zerofd;
345 #endif
347 /* The object to be initialized first. */
348 EXTERN struct link_map *_dl_initfirst;
350 #if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
351 /* Start time on CPU clock. */
352 EXTERN hp_timing_t _dl_cpuclock_offset;
353 #endif
355 /* Map of shared object to be profiled. */
356 EXTERN struct link_map *_dl_profile_map;
358 /* Counters for the number of relocations performed. */
359 EXTERN unsigned long int _dl_num_relocations;
360 EXTERN unsigned long int _dl_num_cache_relocations;
362 /* List of search directories. */
363 EXTERN struct r_search_path_elem *_dl_all_dirs;
365 #ifdef _LIBC_REENTRANT
366 EXTERN void **(*_dl_error_catch_tsd) (void) __attribute__ ((const));
367 #endif
369 /* Structure describing the dynamic linker itself. We need to
370 reserve memory for the data the audit libraries need. */
371 EXTERN struct link_map _dl_rtld_map;
372 #ifdef SHARED
373 struct auditstate audit_data[DL_NNS];
374 #endif
376 #if defined SHARED && defined _LIBC_REENTRANT \
377 && defined __rtld_lock_default_lock_recursive
378 EXTERN void (*_dl_rtld_lock_recursive) (void *);
379 EXTERN void (*_dl_rtld_unlock_recursive) (void *);
380 #endif
382 /* Prevailing state of the stack, PF_X indicating it's executable. */
383 EXTERN ElfW(Word) _dl_stack_flags;
385 /* If loading a shared object requires that we make the stack executable
386 when it was not, we do it by calling this function.
387 It returns an errno code or zero on success. */
388 EXTERN int (*_dl_make_stack_executable_hook) (void **) internal_function;
390 /* Keep the conditional TLS members at the end so the layout of the
391 structure used by !USE_TLS code matches the prefix of the layout in
392 the USE_TLS rtld. Note that `struct link_map' is conditionally
393 defined as well, so _dl_rtld_map needs to be last before this. */
394 #ifdef USE_TLS
395 /* Highest dtv index currently needed. */
396 EXTERN size_t _dl_tls_max_dtv_idx;
397 /* Flag signalling whether there are gaps in the module ID allocation. */
398 EXTERN bool _dl_tls_dtv_gaps;
399 /* Information about the dtv slots. */
400 EXTERN struct dtv_slotinfo_list
402 size_t len;
403 struct dtv_slotinfo_list *next;
404 struct dtv_slotinfo
406 size_t gen;
407 bool is_static;
408 struct link_map *map;
409 } slotinfo[0];
410 } *_dl_tls_dtv_slotinfo_list;
411 /* Number of modules in the static TLS block. */
412 EXTERN size_t _dl_tls_static_nelem;
413 /* Size of the static TLS block. */
414 EXTERN size_t _dl_tls_static_size;
415 /* Size actually allocated in the static TLS block. */
416 EXTERN size_t _dl_tls_static_used;
417 /* Alignment requirement of the static TLS block. */
418 EXTERN size_t _dl_tls_static_align;
420 /* Number of additional entries in the slotinfo array of each slotinfo
421 list element. A large number makes it almost certain take we never
422 have to iterate beyond the first element in the slotinfo list. */
423 # define TLS_SLOTINFO_SURPLUS (62)
425 /* Number of additional slots in the dtv allocated. */
426 # define DTV_SURPLUS (14)
428 /* Initial dtv of the main thread, not allocated with normal malloc. */
429 EXTERN void *_dl_initial_dtv;
430 /* Generation counter for the dtv. */
431 EXTERN size_t _dl_tls_generation;
433 EXTERN void (*_dl_init_static_tls) (struct link_map *);
434 #endif
436 #ifdef SHARED
438 # define __rtld_global_attribute__
439 # ifdef IS_IN_rtld
440 # ifdef HAVE_VISIBILITY_ATTRIBUTE
441 # ifdef HAVE_SDATA_SECTION
442 # define __rtld_local_attribute__ \
443 __attribute__ ((visibility ("hidden"), section (".sdata")))
444 # undef __rtld_global_attribute__
445 # define __rtld_global_attribute__ __attribute__ ((section (".sdata")))
446 # else
447 # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
448 # endif
449 # else
450 # define __rtld_local_attribute__
451 # endif
452 extern struct rtld_global _rtld_local __rtld_local_attribute__;
453 # undef __rtld_local_attribute__
454 # endif
455 extern struct rtld_global _rtld_global __rtld_global_attribute__;
456 # undef __rtld_global_attribute__
457 #endif
459 #ifndef SHARED
460 # define GLRO(name) _##name
461 #else
462 # ifdef IS_IN_rtld
463 # define GLRO(name) _rtld_local_ro._##name
464 # else
465 # define GLRO(name) _rtld_global_ro._##name
466 # endif
467 struct rtld_global_ro
469 #endif
471 /* If nonzero the appropriate debug information is printed. */
472 EXTERN int _dl_debug_mask;
473 #define DL_DEBUG_LIBS (1 << 0)
474 #define DL_DEBUG_IMPCALLS (1 << 1)
475 #define DL_DEBUG_BINDINGS (1 << 2)
476 #define DL_DEBUG_SYMBOLS (1 << 3)
477 #define DL_DEBUG_VERSIONS (1 << 4)
478 #define DL_DEBUG_RELOC (1 << 5)
479 #define DL_DEBUG_FILES (1 << 6)
480 #define DL_DEBUG_STATISTICS (1 << 7)
481 #define DL_DEBUG_UNUSED (1 << 8)
482 /* These two are used only internally. */
483 #define DL_DEBUG_HELP (1 << 9)
484 #define DL_DEBUG_PRELINK (1 << 10)
486 /* Cached value of `getpagesize ()'. */
487 EXTERN size_t _dl_pagesize;
489 /* OS version. */
490 EXTERN unsigned int _dl_osversion;
491 /* Platform name. */
492 EXTERN const char *_dl_platform;
493 EXTERN size_t _dl_platformlen;
495 /* Copy of the content of `_dl_main_searchlist' at startup time. */
496 EXTERN struct r_scope_elem _dl_initial_searchlist;
498 /* CLK_TCK as reported by the kernel. */
499 EXTERN int _dl_clktck;
501 /* If nonzero print warnings messages. */
502 EXTERN int _dl_verbose;
504 /* File descriptor to write debug messages to. */
505 EXTERN int _dl_debug_fd;
507 /* Do we do lazy relocations? */
508 EXTERN int _dl_lazy;
510 /* Nonzero if runtime lookups should not update the .got/.plt. */
511 EXTERN int _dl_bind_not;
513 /* Nonzero if references should be treated as weak during runtime
514 linking. */
515 EXTERN int _dl_dynamic_weak;
517 /* Default floating-point control word. */
518 EXTERN fpu_control_t _dl_fpu_control;
520 /* Expected cache ID. */
521 EXTERN int _dl_correct_cache_id;
523 /* Mask for hardware capabilities that are available. */
524 EXTERN unsigned long int _dl_hwcap;
526 /* Mask for important hardware capabilities we honour. */
527 EXTERN unsigned long int _dl_hwcap_mask;
529 /* Get architecture specific definitions. */
530 #define PROCINFO_DECL
531 #ifndef PROCINFO_CLASS
532 # define PROCINFO_CLASS EXTERN
533 #endif
534 #include <dl-procinfo.c>
536 /* Names of shared object for which the RPATH should be ignored. */
537 EXTERN const char *_dl_inhibit_rpath;
539 /* Location of the binary. */
540 EXTERN const char *_dl_origin_path;
542 /* -1 if the dynamic linker should honor library load bias,
543 0 if not, -2 use the default (honor biases for normal
544 binaries, don't honor for PIEs). */
545 EXTERN ElfW(Addr) _dl_use_load_bias;
547 /* Name of the shared object to be profiled (if any). */
548 EXTERN const char *_dl_profile;
549 /* Filename of the output file. */
550 EXTERN const char *_dl_profile_output;
551 /* Name of the object we want to trace the prelinking. */
552 EXTERN const char *_dl_trace_prelink;
553 /* Map of shared object to be prelink traced. */
554 EXTERN struct link_map *_dl_trace_prelink_map;
556 /* All search directories defined at startup. */
557 EXTERN struct r_search_path_elem *_dl_init_all_dirs;
559 #if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
560 /* Overhead of a high-precision timing measurement. */
561 EXTERN hp_timing_t _dl_hp_timing_overhead;
562 #endif
564 #ifdef NEED_DL_SYSINFO
565 /* Syscall handling improvements. This is very specific to x86. */
566 EXTERN uintptr_t _dl_sysinfo;
567 #endif
569 #if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
570 /* The vsyscall page is a virtual DSO pre-mapped by the kernel.
571 This points to its ELF header. */
572 EXTERN const ElfW(Ehdr) *_dl_sysinfo_dso;
573 #endif
575 #ifdef SHARED
576 /* We add a function table to _rtld_global which is then used to
577 call the function instead of going through the PLT. The result
578 is that we can avoid exporting the functions and we do not jump
579 PLT relocations in libc.so. */
580 void (*_dl_debug_printf) (const char *, ...)
581 __attribute__ ((__format__ (__printf__, 1, 2)));
582 int (internal_function *_dl_catch_error) (const char **, const char **,
583 void (*) (void *), void *);
584 void (internal_function *_dl_signal_error) (int, const char *, const char *,
585 const char *);
586 void (*_dl_mcount) (ElfW(Addr) frompc, ElfW(Addr) selfpc);
587 lookup_t (internal_function *_dl_lookup_symbol_x) (const char *,
588 struct link_map *,
589 const ElfW(Sym) **,
590 struct r_scope_elem *[],
591 const struct r_found_version *,
592 int, int,
593 struct link_map *);
594 int (*_dl_check_caller) (const void *, enum allowmask);
595 void *(*_dl_open) (const char *file, int mode, const void *caller_dlopen,
596 Lmid_t nsid, int argc, char *argv[], char *env[]);
597 void (*_dl_close) (void *map);
599 /* List of auditing interfaces. */
600 struct audit_ifaces *_dl_audit;
601 unsigned int _dl_naudit;
603 # define __rtld_global_attribute__
604 # ifdef IS_IN_rtld
605 # ifdef HAVE_VISIBILITY_ATTRIBUTE
606 # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
607 # else
608 # define __rtld_local_attribute__
609 # endif
610 extern struct rtld_global_ro _rtld_local_ro
611 attribute_relro __rtld_local_attribute__;
612 extern struct rtld_global_ro _rtld_global_ro
613 attribute_relro __rtld_global_attribute__;
614 # undef __rtld_local_attribute__
615 # else
616 /* We cheat a bit here. We declare the variable as as const even
617 though it is at startup. */
618 extern const struct rtld_global_ro _rtld_global_ro
619 attribute_relro __rtld_global_attribute__;
620 # endif
621 # undef __rtld_global_attribute__
622 #endif
623 #undef EXTERN
625 #ifdef IS_IN_rtld
626 /* This is the initial value of GL(dl_error_catch_tsd).
627 A non-TLS libpthread will change it. */
628 extern void **_dl_initial_error_catch_tsd (void) __attribute__ ((const))
629 attribute_hidden;
630 #endif
632 /* This is the initial value of GL(dl_make_stack_executable_hook).
633 A threads library can change it. */
634 extern int _dl_make_stack_executable (void **stack_endp) internal_function;
635 rtld_hidden_proto (_dl_make_stack_executable)
637 /* Variable pointing to the end of the stack (or close to it). This value
638 must be constant over the runtime of the application. Some programs
639 might use the variable which results in copy relocations on some
640 platforms. But this does not matter, ld.so can always use the local
641 copy. */
642 extern void *__libc_stack_end attribute_relro;
643 rtld_hidden_proto (__libc_stack_end)
645 /* Parameters passed to the dynamic linker. */
646 extern int _dl_argc attribute_hidden attribute_relro;
647 extern char **_dl_argv
648 #ifndef DL_ARGV_NOT_RELRO
649 attribute_relro
650 #endif
652 #ifdef IS_IN_rtld
653 extern char **_dl_argv_internal attribute_hidden
654 # ifndef DL_ARGV_NOT_RELRO
655 attribute_relro
656 # endif
658 # define rtld_progname (INTUSE(_dl_argv)[0])
659 #else
660 # define rtld_progname _dl_argv[0]
661 #endif
663 /* The array with message we print as a last resort. */
664 extern const char _dl_out_of_memory[];
665 #ifdef IS_IN_rtld
666 /* XXX #ifdef should go away. */
667 extern const char _dl_out_of_memory_internal[] attribute_hidden;
668 #endif
670 /* Flag set at startup and cleared when the last initializer has run. */
671 extern int _dl_starting_up;
672 weak_extern (_dl_starting_up)
673 #ifdef IS_IN_rtld
674 extern int _dl_starting_up_internal attribute_hidden;
675 #endif
677 /* OS-dependent function to open the zero-fill device. */
678 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
681 /* Write message on the debug file descriptor. The parameters are
682 interpreted as for a `printf' call. All the lines start with a
683 tag showing the PID. */
684 extern void _dl_debug_printf (const char *fmt, ...)
685 __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
687 /* Write message on the debug file descriptor. The parameters are
688 interpreted as for a `printf' call. All the lines buf the first
689 start with a tag showing the PID. */
690 extern void _dl_debug_printf_c (const char *fmt, ...)
691 __attribute__ ((__format__ (__printf__, 1, 2)));
694 /* Write a message on the specified descriptor FD. The parameters are
695 interpreted as for a `printf' call. */
696 extern void _dl_dprintf (int fd, const char *fmt, ...)
697 __attribute__ ((__format__ (__printf__, 2, 3)))
698 attribute_hidden;
700 /* Write a message on the specified descriptor standard output. The
701 parameters are interpreted as for a `printf' call. */
702 #define _dl_printf(fmt, args...) \
703 _dl_dprintf (STDOUT_FILENO, fmt, ##args)
705 /* Write a message on the specified descriptor standard error. The
706 parameters are interpreted as for a `printf' call. */
707 #define _dl_error_printf(fmt, args...) \
708 _dl_dprintf (STDERR_FILENO, fmt, ##args)
710 /* Write a message on the specified descriptor standard error and exit
711 the program. The parameters are interpreted as for a `printf' call. */
712 #define _dl_fatal_printf(fmt, args...) \
713 do \
715 _dl_dprintf (STDERR_FILENO, fmt, ##args); \
716 _exit (127); \
718 while (1)
721 /* This function is called by all the internal dynamic linker functions
722 when they encounter an error. ERRCODE is either an `errno' code or
723 zero; OBJECT is the name of the problematical shared object, or null if
724 it is a general problem; ERRSTRING is a string describing the specific
725 problem. */
726 extern void _dl_signal_error (int errcode, const char *object,
727 const char *occurred, const char *errstring)
728 internal_function __attribute__ ((__noreturn__)) attribute_hidden;
730 /* Like _dl_signal_error, but may return when called in the context of
731 _dl_receive_error. */
732 extern void _dl_signal_cerror (int errcode, const char *object,
733 const char *occation, const char *errstring)
734 internal_function;
736 /* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike
737 `_dl_catch_error' the operation is resumed after the OPERATE
738 function returns.
739 ARGS is passed as argument to OPERATE. */
740 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
741 void *args)
742 internal_function;
745 /* Open the shared object NAME and map in its segments.
746 LOADER's DT_RPATH is used in searching for NAME.
747 If the object is already opened, returns its existing map.
748 For preloaded shared objects PRELOADED is set to a non-zero
749 value to allow additional security checks. */
750 extern struct link_map *_dl_map_object (struct link_map *loader,
751 const char *name, int preloaded,
752 int type, int trace_mode, int mode,
753 Lmid_t nsid)
754 internal_function attribute_hidden;
756 /* Call _dl_map_object on the dependencies of MAP, and set up
757 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
758 loaded objects that will be inserted into MAP->l_searchlist after MAP
759 but before its dependencies. */
760 extern void _dl_map_object_deps (struct link_map *map,
761 struct link_map **preloads,
762 unsigned int npreloads, int trace_mode,
763 int open_mode)
764 internal_function attribute_hidden;
766 /* Cache the locations of MAP's hash table. */
767 extern void _dl_setup_hash (struct link_map *map)
768 internal_function attribute_hidden;
771 /* Collect the directories in the search path for LOADER's dependencies.
772 The data structure is defined in <dlfcn.h>. If COUNTING is true,
773 SI->dls_cnt and SI->dls_size are set; if false, those must be as set
774 by a previous call with COUNTING set, and SI must point to SI->dls_size
775 bytes to be used in filling in the result. */
776 extern void _dl_rtld_di_serinfo (struct link_map *loader,
777 Dl_serinfo *si, bool counting)
778 internal_function;
781 /* Search loaded objects' symbol tables for a definition of the symbol
782 referred to by UNDEF. *SYM is the symbol table entry containing the
783 reference; it is replaced with the defining symbol, and the base load
784 address of the defining object is returned. SYMBOL_SCOPE is a
785 null-terminated list of object scopes to search; each object's
786 l_searchlist (i.e. the segment of the dependency tree starting at that
787 object) is searched in turn. REFERENCE_NAME should name the object
788 containing the reference; it is used in error messages.
789 TYPE_CLASS describes the type of symbol we are looking for. */
790 enum
792 /* If necessary add dependency between user and provider object. */
793 DL_LOOKUP_ADD_DEPENDENCY = 1,
794 /* Return most recent version instead of default version for
795 unversioned lookup. */
796 DL_LOOKUP_RETURN_NEWEST = 2
799 /* Lookup versioned symbol. */
800 extern lookup_t _dl_lookup_symbol_x (const char *undef,
801 struct link_map *undef_map,
802 const ElfW(Sym) **sym,
803 struct r_scope_elem *symbol_scope[],
804 const struct r_found_version *version,
805 int type_class, int explicit,
806 struct link_map *skip_map)
807 internal_function attribute_hidden;
810 /* Look up symbol NAME in MAP's scope and return its run-time address. */
811 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name)
812 internal_function;
814 /* Allocate a `struct link_map' for a new object being loaded,
815 and enter it into the _dl_main_map list. */
816 extern struct link_map *_dl_new_object (char *realname, const char *libname,
817 int type, struct link_map *loader,
818 int mode, Lmid_t nsid)
819 internal_function attribute_hidden;
821 /* Relocate the given object (if it hasn't already been).
822 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
823 If LAZY is nonzero, don't relocate its PLT. */
824 extern void _dl_relocate_object (struct link_map *map,
825 struct r_scope_elem *scope[],
826 int lazy, int consider_profiling)
827 attribute_hidden;
829 /* Protect PT_GNU_RELRO area. */
830 extern void _dl_protect_relro (struct link_map *map)
831 internal_function attribute_hidden;
833 /* Call _dl_signal_error with a message about an unhandled reloc type.
834 TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
835 PLT is nonzero if this was a PLT reloc; it just affects the message. */
836 extern void _dl_reloc_bad_type (struct link_map *map,
837 unsigned int type, int plt)
838 internal_function __attribute__ ((__noreturn__));
840 /* Resolve conflicts if prelinking. */
841 extern void _dl_resolve_conflicts (struct link_map *l,
842 ElfW(Rela) *conflict,
843 ElfW(Rela) *conflictend);
845 /* Check the version dependencies of all objects available through
846 MAP. If VERBOSE print some more diagnostics. */
847 extern int _dl_check_all_versions (struct link_map *map, int verbose,
848 int trace_mode)
849 internal_function;
851 /* Check the version dependencies for MAP. If VERBOSE print some more
852 diagnostics. */
853 extern int _dl_check_map_versions (struct link_map *map, int verbose,
854 int trace_mode)
855 internal_function;
857 /* Initialize the object in SCOPE by calling the constructors with
858 ARGC, ARGV, and ENV as the parameters. */
859 extern void _dl_init (struct link_map *main_map, int argc, char **argv,
860 char **env) internal_function attribute_hidden;
862 /* Call the finalizer functions of all shared objects whose
863 initializer functions have completed. */
864 extern void _dl_fini (void) internal_function;
866 /* The dynamic linker calls this function before and having changing
867 any shared object mappings. The `r_state' member of `struct r_debug'
868 says what change is taking place. This function's address is
869 the value of the `r_brk' member. */
870 extern void _dl_debug_state (void);
871 rtld_hidden_proto (_dl_debug_state)
873 /* Initialize `struct r_debug' if it has not already been done. The
874 argument is the run-time load address of the dynamic linker, to be put
875 in the `r_ldbase' member. Returns the address of the structure. */
876 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
877 internal_function;
879 /* Initialize the basic data structure for the search paths. */
880 extern void _dl_init_paths (const char *library_path) internal_function;
882 /* Gather the information needed to install the profiling tables and start
883 the timers. */
884 extern void _dl_start_profile (void) internal_function attribute_hidden;
886 /* The actual functions used to keep book on the calls. */
887 extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
888 extern void _dl_mcount_internal (ElfW(Addr) frompc, ElfW(Addr) selfpc)
889 attribute_hidden;
891 /* This function is simply a wrapper around the _dl_mcount function
892 which does not require a FROMPC parameter since this is the
893 calling function. */
894 extern void _dl_mcount_wrapper (void *selfpc);
896 /* Show the members of the auxiliary array passed up from the kernel. */
897 extern void _dl_show_auxv (void) internal_function;
899 /* Return all environment variables starting with `LD_', one after the
900 other. */
901 extern char *_dl_next_ld_env_entry (char ***position) internal_function;
903 /* Return an array with the names of the important hardware capabilities. */
904 extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
905 size_t paltform_len,
906 size_t *sz,
907 size_t *max_capstrlen)
908 internal_function;
910 /* Look up NAME in ld.so.cache and return the file name stored there,
911 or null if none is found. */
912 extern const char *_dl_load_cache_lookup (const char *name)
913 internal_function;
915 /* If the system does not support MAP_COPY we cannot leave the file open
916 all the time since this would create problems when the file is replaced.
917 Therefore we provide this function to close the file and open it again
918 once needed. */
919 extern void _dl_unload_cache (void) attribute_hidden;
921 /* System-dependent function to read a file's whole contents in the
922 most convenient manner available. *SIZEP gets the size of the
923 file. On error MAP_FAILED is returned. */
924 extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
925 int prot)
926 internal_function attribute_hidden;
928 /* System-specific function to do initial startup for the dynamic linker.
929 After this, file access calls and getenv must work. This is responsible
930 for setting __libc_enable_secure if we need to be secure (e.g. setuid),
931 and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
932 extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
933 void (*dl_main) (const ElfW(Phdr) *phdr,
934 ElfW(Word) phnum,
935 ElfW(Addr) *user_entry))
936 attribute_hidden;
938 extern void _dl_sysdep_start_cleanup (void)
939 internal_function attribute_hidden;
942 /* Determine next available module ID. */
943 extern size_t _dl_next_tls_modid (void) internal_function attribute_hidden;
945 /* Calculate offset of the TLS blocks in the static TLS block. */
946 extern void _dl_determine_tlsoffset (void) internal_function attribute_hidden;
948 /* Set up the data structures for TLS, when they were not set up at startup.
949 Returns nonzero on malloc failure.
950 This is called from _dl_map_object_from_fd or by libpthread. */
951 extern int _dl_tls_setup (void) internal_function;
952 rtld_hidden_proto (_dl_tls_setup)
954 /* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */
955 extern void *_dl_allocate_tls (void *mem) internal_function;
956 rtld_hidden_proto (_dl_allocate_tls)
958 /* Get size and alignment requirements of the static TLS block. */
959 extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp)
960 internal_function;
962 extern void _dl_allocate_static_tls (struct link_map *map)
963 internal_function attribute_hidden;
965 /* These are internal entry points to the two halves of _dl_allocate_tls,
966 only used within rtld.c itself at startup time. */
967 extern void *_dl_allocate_tls_storage (void)
968 internal_function attribute_hidden;
969 extern void *_dl_allocate_tls_init (void *) internal_function;
970 rtld_hidden_proto (_dl_allocate_tls_init)
972 /* Deallocate memory allocated with _dl_allocate_tls. */
973 extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb) internal_function;
974 rtld_hidden_proto (_dl_deallocate_tls)
976 #if defined USE_TLS
977 extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
978 #endif
980 /* Find origin of the executable. */
981 extern const char *_dl_get_origin (void) attribute_hidden;
983 /* Count DSTs. */
984 extern size_t _dl_dst_count (const char *name, int is_path) attribute_hidden;
986 /* Substitute DST values. */
987 extern char *_dl_dst_substitute (struct link_map *l, const char *name,
988 char *result, int is_path) attribute_hidden;
990 /* Check validity of the caller. */
991 extern int _dl_check_caller (const void *caller, enum allowmask mask)
992 attribute_hidden;
994 /* Open the shared object NAME, relocate it, and run its initializer if it
995 hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
996 the object is already opened, returns its existing map. */
997 extern void *_dl_open (const char *name, int mode, const void *caller,
998 Lmid_t nsid, int argc, char *argv[], char *env[])
999 attribute_hidden;
1001 /* Add module to slot information data. */
1002 extern void _dl_add_to_slotinfo (struct link_map *l) attribute_hidden;
1004 /* Update slot information data for at least the generation of the
1005 module with the given index. */
1006 extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid);
1008 __END_DECLS
1010 #endif /* ldsodefs.h */