]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/generic/ldsodefs.h
Consistently use page_shift in sysdeps/unix/sysv/linux/mmap64.c.
[thirdparty/glibc.git] / sysdeps / generic / ldsodefs.h
CommitLineData
a42195db 1/* Run-time dynamic linker data structures for loaded ELF shared objects.
568035b7 2 Copyright (C) 1995-2013 Free Software Foundation, Inc.
a42195db
UD
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
41bdb6e2
AJ
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.
a42195db
UD
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
41bdb6e2 13 Lesser General Public License for more details.
a42195db 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
a42195db
UD
18
19#ifndef _LDSODEFS_H
20#define _LDSODEFS_H 1
21
22#include <features.h>
23
3fb55878 24#include <stdbool.h>
a42195db
UD
25#define __need_size_t
26#define __need_NULL
27#include <stddef.h>
ef52edfc 28#include <string.h>
e054f494 29#include <stdint.h>
a42195db
UD
30
31#include <elf.h>
32#include <dlfcn.h>
5688da55 33#include <fpu_control.h>
d6b5d570 34#include <sys/mman.h>
a42195db 35#include <link.h>
c0282c06 36#include <dl-lookupcfg.h>
ce460d04 37#include <dl-sysdep.h>
c12aa801 38#include <bits/libc-lock.h>
5688da55 39#include <hp-timing.h>
535b764d 40#include <tls.h>
0e077a7e 41#include <kernel-features.h>
a42195db
UD
42
43__BEGIN_DECLS
44
9bac1d86
L
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
a42195db
UD
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)
54
55/* All references to the value of l_info[DT_PLTGOT],
56 l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
88fdf42f 57 l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
42ba2c11 58 have to be accessed via the D_PTR macro. The macro is needed since for
88fdf42f
AJ
59 most architectures the entry is already relocated - but for some not
60 and we need to relocate at access time. */
a42195db 61#ifdef DL_RO_DYN_SECTION
9dcafc55 62# define D_PTR(map, i) ((map)->i->d_un.d_ptr + (map)->l_addr)
a42195db 63#else
9dcafc55 64# define D_PTR(map, i) (map)->i->d_un.d_ptr
a42195db
UD
65#endif
66
9dcafc55 67/* Result of the lookup functions and how to retrieve the base address. */
c0282c06 68typedef struct link_map *lookup_t;
93b53ca2
UD
69#define LOOKUP_VALUE(map) map
70#define LOOKUP_VALUE_ADDRESS(map) ((map) ? (map)->l_addr : 0)
c0282c06 71
0b3cf801 72/* On some architectures a pointer to a function is not just a pointer
c0282c06
UD
73 to the actual code of the function but rather an architecture
74 specific descriptor. */
75#ifndef ELF_FUNCTION_PTR_IS_SPECIAL
09bf6406 76# define DL_SYMBOL_ADDRESS(map, ref) \
c0282c06 77 (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
09bf6406 78# define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
40306912
UD
79# define DL_DT_INIT_ADDRESS(map, start) (start)
80# define DL_DT_FINI_ADDRESS(map, start) (start)
09bf6406
UD
81#endif
82
0b3cf801
UD
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 \
2ac9ca73 86 && ((((SYM)->st_shndx == SHN_UNDEF || (SYM)->st_size == 0) \
0b3cf801
UD
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))
90
09bf6406
UD
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)
c0282c06
UD
96#endif
97
beb5387c
UD
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
103
cf5a372e
UD
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
18ef464b
UD
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. */
cf5a372e 111#define ELF_RTYPE_CLASS_PLT 1
18ef464b
UD
112#ifndef DL_NO_COPY_RELOCS
113# define ELF_RTYPE_CLASS_COPY 2
114#else
115# define ELF_RTYPE_CLASS_COPY 0
116#endif
cf5a372e 117
9d63abbc
UD
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)))
130
b9375348
SP
131/* The filename itself, or the main program name, if available. */
132#define DSO_FILENAME(name) ((name)[0] ? (name) \
133 : (rtld_progname ?: "<main program>"))
134
135#define RTLD_PROGNAME (rtld_progname ?: "<program name unknown>")
9d63abbc 136
a42195db
UD
137/* For the version handling we need an array with only names and their
138 hash values. */
139struct r_found_version
140 {
141 const char *name;
142 ElfW(Word) hash;
143
144 int hidden;
145 const char *filename;
146 };
147
148/* We want to cache information about the searches for shared objects. */
149
150enum r_dir_status { unknown, nonexisting, existing };
151
152struct r_search_path_elem
153 {
154 /* This link is only used in the `all_dirs' member of `r_search_path'. */
155 struct r_search_path_elem *next;
156
157 /* Strings saying where the definition came from. */
158 const char *what;
159 const char *where;
160
161 /* Basename for this search path element. The string must end with
162 a slash character. */
163 const char *dirname;
164 size_t dirnamelen;
165
166 enum r_dir_status status[0];
167 };
168
169struct r_strlenpair
170 {
171 const char *str;
172 size_t len;
173 };
174
175
176/* A data structure for a simple single linked list of strings. */
177struct libname_list
178 {
179 const char *name; /* Name requested (before search). */
180 struct libname_list *next; /* Link to next name for this object. */
752a2a50
UD
181 int dont_free; /* Flag whether this element should be freed
182 if the object is not entirely unloaded. */
a42195db
UD
183 };
184
185
eec8b6ca
UD
186/* Bit masks for the objects which valid callers can come from to
187 functions with restricted interface. */
188enum allowmask
189 {
190 allow_libc = 1,
191 allow_libdl = 2,
192 allow_libpthread = 4,
193 allow_ldso = 8
194 };
195
196
9dcafc55
UD
197struct audit_ifaces
198{
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
204 {
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 *);
209 };
210 union
211 {
dc936e2b
RM
212#ifdef ARCH_PLTENTER_MEMBERS
213 ARCH_PLTENTER_MEMBERS;
214#endif
9dcafc55
UD
215 };
216 union
217 {
dc936e2b
RM
218#ifdef ARCH_PLTEXIT_MEMBERS
219 ARCH_PLTEXIT_MEMBERS;
220#endif
9dcafc55
UD
221 };
222 unsigned int (*objclose) (uintptr_t *);
223
224 struct audit_ifaces *next;
225};
226
227
a42195db 228/* Test whether given NAME matches any of the names of the given object. */
871b9158 229extern int _dl_name_match_p (const char *__name, const struct link_map *__map)
dd272e57 230 internal_function;
a42195db 231
55c4ce68
UD
232/* Compute next higher prime number. */
233extern unsigned long int _dl_higher_prime_number (unsigned long int n)
234 internal_function;
235
a42195db
UD
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. */
239typedef void (*receiver_fct) (int, const char *, const char *);
240\f
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.
245
246 The `-ldl' library functions in <dlfcn.h> provide a simple
247 user interface to run-time dynamic linking. */
248
249
d6b5d570
UD
250#ifndef SHARED
251# define EXTERN extern
252# define GL(name) _##name
253#else
254# define EXTERN
403e0597 255# ifdef IS_IN_rtld
0d01dace
UD
256# define GL(name) _rtld_local._##name
257# else
258# define GL(name) _rtld_global._##name
259# endif
d6b5d570
UD
260struct rtld_global
261{
262#endif
263 /* Don't change the order of the following elements. 'dl_loaded'
264 must remain the first element. Forever. */
265
c0f62c56
UD
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
273 {
9dcafc55 274 /* A pointer to the map for the main map. */
c0f62c56
UD
275 struct link_map *_ns_loaded;
276 /* Number of object in the _dl_loaded list. */
277 unsigned int _ns_nloaded;
c0f62c56
UD
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;
415ac3df
UD
284 /* Search table for unique objects. */
285 struct unique_sym_table
286 {
bea9b193 287 __rtld_lock_define_recursive (, lock)
415ac3df
UD
288 struct unique_sym
289 {
290 uint32_t hashval;
291 const char *name;
292 const ElfW(Sym) *sym;
5e4287d1 293 const struct link_map *map;
415ac3df
UD
294 } *entries;
295 size_t size;
296 size_t n_elements;
297 void (*free) (void *);
298 } _ns_unique_sym_table;
29f97654
UD
299 /* Keep track of changes to each namespace' list. */
300 struct r_debug _ns_debug;
c0f62c56 301 } _dl_ns[DL_NNS];
22c83193
UD
302 /* One higher than index of last used namespace. */
303 EXTERN size_t _dl_nns;
d6b5d570 304
5688da55
UD
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.
308
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. */
d3c9f895 312 __rtld_lock_define_recursive (EXTERN, _dl_load_lock)
5a2a1d75
AS
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)
5688da55 317
bed12f78
UD
318 /* Incremented whenever something may have been added to dl_loaded. */
319 EXTERN unsigned long long _dl_load_adds;
bed12f78 320
d6b5d570
UD
321 /* The object to be initialized first. */
322 EXTERN struct link_map *_dl_initfirst;
323
67eb7235 324#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
ccdf0cab 325 /* Start time on CPU clock. */
5688da55
UD
326 EXTERN hp_timing_t _dl_cpuclock_offset;
327#endif
328
d6b5d570
UD
329 /* Map of shared object to be profiled. */
330 EXTERN struct link_map *_dl_profile_map;
d6b5d570
UD
331
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;
335
d6b5d570
UD
336 /* List of search directories. */
337 EXTERN struct r_search_path_elem *_dl_all_dirs;
d6b5d570 338
68dc80ca
RM
339#ifdef _LIBC_REENTRANT
340 EXTERN void **(*_dl_error_catch_tsd) (void) __attribute__ ((const));
341#endif
342
9dcafc55
UD
343 /* Structure describing the dynamic linker itself. We need to
344 reserve memory for the data the audit libraries need. */
d6b5d570 345 EXTERN struct link_map _dl_rtld_map;
9dcafc55
UD
346#ifdef SHARED
347 struct auditstate audit_data[DL_NNS];
348#endif
ce460d04 349
334fcf2a
UD
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
355
ecdeaac0
RM
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. */
d1fc817e 359 EXTERN int (*_dl_make_stack_executable_hook) (void **) internal_function;
ecdeaac0 360
9be09e06
UD
361 /* Prevailing state of the stack, PF_X indicating it's executable. */
362 EXTERN ElfW(Word) _dl_stack_flags;
363
11bf311e
UD
364 /* Flag signalling whether there are gaps in the module ID allocation. */
365 EXTERN bool _dl_tls_dtv_gaps;
9be09e06
UD
366 /* Highest dtv index currently needed. */
367 EXTERN size_t _dl_tls_max_dtv_idx;
68dc80ca
RM
368 /* Information about the dtv slots. */
369 EXTERN struct dtv_slotinfo_list
370 {
371 size_t len;
372 struct dtv_slotinfo_list *next;
373 struct dtv_slotinfo
374 {
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;
387
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. */
11bf311e 391#define TLS_SLOTINFO_SURPLUS (62)
68dc80ca
RM
392
393/* Number of additional slots in the dtv allocated. */
11bf311e 394#define DTV_SURPLUS (14)
68dc80ca
RM
395
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;
adc12574
UD
400
401 EXTERN void (*_dl_init_static_tls) (struct link_map *);
68dc80ca 402
df94b641
UD
403 EXTERN void (*_dl_wait_lookup_done) (void);
404
e4eb675d
UD
405 /* Scopes to free after next THREAD_GSCOPE_WAIT (). */
406 EXTERN struct dl_scope_free_list
407 {
408 size_t count;
385b4cf4 409 void *list[50];
e4eb675d 410 } *_dl_scope_free_list;
d6b5d570
UD
411#ifdef SHARED
412};
5fe14d96 413# define __rtld_global_attribute__
403e0597 414# ifdef IS_IN_rtld
11bf311e
UD
415# ifdef HAVE_SDATA_SECTION
416# define __rtld_local_attribute__ \
0d01dace 417 __attribute__ ((visibility ("hidden"), section (".sdata")))
11bf311e
UD
418# undef __rtld_global_attribute__
419# define __rtld_global_attribute__ __attribute__ ((section (".sdata")))
0d01dace 420# else
11bf311e 421# define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
0d01dace
UD
422# endif
423extern struct rtld_global _rtld_local __rtld_local_attribute__;
021723ab 424# undef __rtld_local_attribute__
0d01dace 425# endif
5fe14d96 426extern struct rtld_global _rtld_global __rtld_global_attribute__;
021723ab 427# undef __rtld_global_attribute__
d6b5d570 428#endif
20c37dfd
UD
429
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
438struct rtld_global_ro
439{
440#endif
441
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)
7a11603d 452#define DL_DEBUG_UNUSED (1 << 8)
73d7af4f 453#define DL_DEBUG_SCOPES (1 << 9)
20c37dfd 454/* These two are used only internally. */
73d7af4f
UD
455#define DL_DEBUG_HELP (1 << 10)
456#define DL_DEBUG_PRELINK (1 << 11)
20c37dfd 457
20c37dfd
UD
458 /* OS version. */
459 EXTERN unsigned int _dl_osversion;
460 /* Platform name. */
461 EXTERN const char *_dl_platform;
462 EXTERN size_t _dl_platformlen;
463
9be09e06
UD
464 /* Cached value of `getpagesize ()'. */
465 EXTERN size_t _dl_pagesize;
466
73d65cc3
SP
467 /* Do we read from ld.so.cache? */
468 EXTERN int _dl_inhibit_cache;
469
c31e278f
UD
470 /* Copy of the content of `_dl_main_searchlist' at startup time. */
471 EXTERN struct r_scope_elem _dl_initial_searchlist;
472
20c37dfd
UD
473 /* CLK_TCK as reported by the kernel. */
474 EXTERN int _dl_clktck;
475
476 /* If nonzero print warnings messages. */
477 EXTERN int _dl_verbose;
478
dd70526e
UD
479 /* File descriptor to write debug messages to. */
480 EXTERN int _dl_debug_fd;
481
20c37dfd
UD
482 /* Do we do lazy relocations? */
483 EXTERN int _dl_lazy;
484
485 /* Nonzero if runtime lookups should not update the .got/.plt. */
486 EXTERN int _dl_bind_not;
487
488 /* Nonzero if references should be treated as weak during runtime
489 linking. */
490 EXTERN int _dl_dynamic_weak;
491
492 /* Default floating-point control word. */
493 EXTERN fpu_control_t _dl_fpu_control;
494
495 /* Expected cache ID. */
496 EXTERN int _dl_correct_cache_id;
497
498 /* Mask for hardware capabilities that are available. */
404a4e2f 499 EXTERN uint64_t _dl_hwcap;
20c37dfd
UD
500
501 /* Mask for important hardware capabilities we honour. */
404a4e2f 502 EXTERN uint64_t _dl_hwcap_mask;
20c37dfd 503
c7683a6d
RH
504 /* Pointer to the auxv list supplied to the program at startup. */
505 EXTERN ElfW(auxv_t) *_dl_auxv;
506
c31e278f
UD
507 /* Get architecture specific definitions. */
508#define PROCINFO_DECL
ee600e3f
UD
509#ifndef PROCINFO_CLASS
510# define PROCINFO_CLASS EXTERN
511#endif
c31e278f
UD
512#include <dl-procinfo.c>
513
20c37dfd
UD
514 /* Names of shared object for which the RPATH should be ignored. */
515 EXTERN const char *_dl_inhibit_rpath;
516
517 /* Location of the binary. */
518 EXTERN const char *_dl_origin_path;
519
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;
524
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;
c31e278f
UD
533
534 /* All search directories defined at startup. */
535 EXTERN struct r_search_path_elem *_dl_init_all_dirs;
536
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
20c37dfd
UD
541
542#ifdef NEED_DL_SYSINFO
543 /* Syscall handling improvements. This is very specific to x86. */
544 EXTERN uintptr_t _dl_sysinfo;
30e32d23 545#endif
20c37dfd 546
7775448e 547#ifdef NEED_DL_SYSINFO_DSO
20c37dfd
UD
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;
404a4e2f
RM
551
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;
20c37dfd
UD
555#endif
556
557#ifdef SHARED
154d10bd
UD
558 /* We add a function table to _rtld_global which is then used to
559 call the function instead of going through the PLT. The result
560 is that we can avoid exporting the functions and we do not jump
561 PLT relocations in libc.so. */
154d10bd
UD
562 void (*_dl_debug_printf) (const char *, ...)
563 __attribute__ ((__format__ (__printf__, 1, 2)));
564 int (internal_function *_dl_catch_error) (const char **, const char **,
6dffebd8 565 bool *, void (*) (void *), void *);
154d10bd
UD
566 void (internal_function *_dl_signal_error) (int, const char *, const char *,
567 const char *);
154d10bd 568 void (*_dl_mcount) (ElfW(Addr) frompc, ElfW(Addr) selfpc);
021723ab
UD
569 lookup_t (internal_function *_dl_lookup_symbol_x) (const char *,
570 struct link_map *,
571 const ElfW(Sym) **,
572 struct r_scope_elem *[],
573 const struct r_found_version *,
574 int, int,
575 struct link_map *);
eec8b6ca 576 int (*_dl_check_caller) (const void *, enum allowmask);
9dcafc55
UD
577 void *(*_dl_open) (const char *file, int mode, const void *caller_dlopen,
578 Lmid_t nsid, int argc, char *argv[], char *env[]);
579 void (*_dl_close) (void *map);
93025f93 580 void *(*_dl_tls_get_addr_soft) (struct link_map *);
7c22c7ec
UD
581#ifdef HAVE_DL_DISCOVER_OSVERSION
582 int (*_dl_discover_osversion) (void);
583#endif
154d10bd 584
9dcafc55
UD
585 /* List of auditing interfaces. */
586 struct audit_ifaces *_dl_audit;
587 unsigned int _dl_naudit;
9be09e06
UD
588
589 /* 0 if internal pointer values should not be guarded, 1 if they should. */
590 EXTERN int _dl_pointer_guard;
20c37dfd
UD
591};
592# define __rtld_global_attribute__
593# ifdef IS_IN_rtld
11bf311e 594# define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
20c37dfd
UD
595extern struct rtld_global_ro _rtld_local_ro
596 attribute_relro __rtld_local_attribute__;
20c37dfd
UD
597extern struct rtld_global_ro _rtld_global_ro
598 attribute_relro __rtld_global_attribute__;
021723ab 599# undef __rtld_local_attribute__
154d10bd
UD
600# else
601/* We cheat a bit here. We declare the variable as as const even
602 though it is at startup. */
603extern const struct rtld_global_ro _rtld_global_ro
604 attribute_relro __rtld_global_attribute__;
605# endif
021723ab 606# undef __rtld_global_attribute__
20c37dfd 607#endif
d6b5d570
UD
608#undef EXTERN
609
3d3436ae
RM
610#ifndef SHARED
611/* dl-support.c defines these and initializes them early on. */
dc0a0263 612extern const ElfW(Phdr) *_dl_phdr;
3d3436ae
RM
613extern size_t _dl_phnum;
614#endif
615
68dc80ca
RM
616#ifdef IS_IN_rtld
617/* This is the initial value of GL(dl_error_catch_tsd).
618 A non-TLS libpthread will change it. */
619extern void **_dl_initial_error_catch_tsd (void) __attribute__ ((const))
620 attribute_hidden;
621#endif
622
ecdeaac0
RM
623/* This is the initial value of GL(dl_make_stack_executable_hook).
624 A threads library can change it. */
d1fc817e 625extern int _dl_make_stack_executable (void **stack_endp) internal_function;
ecdeaac0
RM
626rtld_hidden_proto (_dl_make_stack_executable)
627
ea4f25a7
UD
628/* Variable pointing to the end of the stack (or close to it). This value
629 must be constant over the runtime of the application. Some programs
630 might use the variable which results in copy relocations on some
631 platforms. But this does not matter, ld.so can always use the local
632 copy. */
5d5722e8
ST
633extern void *__libc_stack_end
634#ifndef LIBC_STACK_END_NOT_RELRO
635 attribute_relro
636#endif
637 ;
ea4f25a7
UD
638rtld_hidden_proto (__libc_stack_end)
639
d6b5d570 640/* Parameters passed to the dynamic linker. */
392a6b52 641extern int _dl_argc attribute_hidden attribute_relro;
33ab3b66
UD
642extern char **_dl_argv
643#ifndef DL_ARGV_NOT_RELRO
644 attribute_relro
645#endif
646 ;
403e0597 647#ifdef IS_IN_rtld
8347c74c
RM
648extern unsigned int _dl_skip_args attribute_hidden
649# ifndef DL_ARGV_NOT_RELRO
650 attribute_relro
651# endif
652 ;
653extern unsigned int _dl_skip_args_internal attribute_hidden
654# ifndef DL_ARGV_NOT_RELRO
655 attribute_relro
656# endif
657 ;
33ab3b66
UD
658extern char **_dl_argv_internal attribute_hidden
659# ifndef DL_ARGV_NOT_RELRO
660 attribute_relro
661# endif
662 ;
e6caf4e1
UD
663# define rtld_progname (INTUSE(_dl_argv)[0])
664#else
665# define rtld_progname _dl_argv[0]
666#endif
d6b5d570 667
5bbcba0d
RM
668/* Flag set at startup and cleared when the last initializer has run. */
669extern int _dl_starting_up;
670weak_extern (_dl_starting_up)
b5b9cfc4 671#ifdef IS_IN_rtld
5bbcba0d
RM
672extern int _dl_starting_up_internal attribute_hidden;
673#endif
f55727ca 674
965cb60a 675/* Random data provided by the kernel. */
d09580b1 676extern void *_dl_random attribute_hidden attribute_relro;
965cb60a 677
a42195db
UD
678/* OS-dependent function to open the zero-fill device. */
679extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
680
b5ba0659
UD
681
682/* Write message on the debug file descriptor. The parameters are
683 interpreted as for a `printf' call. All the lines start with a
684 tag showing the PID. */
685extern void _dl_debug_printf (const char *fmt, ...)
154d10bd 686 __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
b5ba0659
UD
687
688/* Write message on the debug file descriptor. The parameters are
689 interpreted as for a `printf' call. All the lines buf the first
690 start with a tag showing the PID. */
691extern void _dl_debug_printf_c (const char *fmt, ...)
692 __attribute__ ((__format__ (__printf__, 1, 2)));
693
694
695/* Write a message on the specified descriptor FD. The parameters are
696 interpreted as for a `printf' call. */
697extern void _dl_dprintf (int fd, const char *fmt, ...)
6ce3881d
RM
698 __attribute__ ((__format__ (__printf__, 2, 3)))
699 attribute_hidden;
b5ba0659
UD
700
701/* Write a message on the specified descriptor standard output. The
702 parameters are interpreted as for a `printf' call. */
703#define _dl_printf(fmt, args...) \
704 _dl_dprintf (STDOUT_FILENO, fmt, ##args)
705
706/* Write a message on the specified descriptor standard error. The
707 parameters are interpreted as for a `printf' call. */
708#define _dl_error_printf(fmt, args...) \
709 _dl_dprintf (STDERR_FILENO, fmt, ##args)
710
711/* Write a message on the specified descriptor standard error and exit
712 the program. The parameters are interpreted as for a `printf' call. */
713#define _dl_fatal_printf(fmt, args...) \
a42195db
UD
714 do \
715 { \
b5ba0659 716 _dl_dprintf (STDERR_FILENO, fmt, ##args); \
a42195db
UD
717 _exit (127); \
718 } \
719 while (1)
720
a42195db
UD
721
722/* This function is called by all the internal dynamic linker functions
723 when they encounter an error. ERRCODE is either an `errno' code or
724 zero; OBJECT is the name of the problematical shared object, or null if
725 it is a general problem; ERRSTRING is a string describing the specific
726 problem. */
8e17ea58 727extern void _dl_signal_error (int errcode, const char *object,
407fe3bb 728 const char *occurred, const char *errstring)
6ce3881d 729 internal_function __attribute__ ((__noreturn__)) attribute_hidden;
a42195db
UD
730
731/* Like _dl_signal_error, but may return when called in the context of
732 _dl_receive_error. */
407fe3bb
UD
733extern void _dl_signal_cerror (int errcode, const char *object,
734 const char *occation, const char *errstring)
a42195db
UD
735 internal_function;
736
737/* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike
738 `_dl_catch_error' the operation is resumed after the OPERATE
739 function returns.
740 ARGS is passed as argument to OPERATE. */
741extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
742 void *args)
743 internal_function;
744
745
746/* Open the shared object NAME and map in its segments.
747 LOADER's DT_RPATH is used in searching for NAME.
8e9f92e9 748 If the object is already opened, returns its existing map. */
a42195db 749extern struct link_map *_dl_map_object (struct link_map *loader,
8e9f92e9 750 const char *name,
c0f62c56
UD
751 int type, int trace_mode, int mode,
752 Lmid_t nsid)
6ce3881d 753 internal_function attribute_hidden;
a42195db
UD
754
755/* Call _dl_map_object on the dependencies of MAP, and set up
756 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
757 loaded objects that will be inserted into MAP->l_searchlist after MAP
758 but before its dependencies. */
759extern void _dl_map_object_deps (struct link_map *map,
760 struct link_map **preloads,
87837aac
UD
761 unsigned int npreloads, int trace_mode,
762 int open_mode)
6ce3881d 763 internal_function attribute_hidden;
a42195db
UD
764
765/* Cache the locations of MAP's hash table. */
6ce3881d
RM
766extern void _dl_setup_hash (struct link_map *map)
767 internal_function attribute_hidden;
a42195db
UD
768
769
45e4762c
RM
770/* Collect the directories in the search path for LOADER's dependencies.
771 The data structure is defined in <dlfcn.h>. If COUNTING is true,
772 SI->dls_cnt and SI->dls_size are set; if false, those must be as set
773 by a previous call with COUNTING set, and SI must point to SI->dls_size
774 bytes to be used in filling in the result. */
775extern void _dl_rtld_di_serinfo (struct link_map *loader,
776 Dl_serinfo *si, bool counting)
777 internal_function;
778
779
a42195db
UD
780/* Search loaded objects' symbol tables for a definition of the symbol
781 referred to by UNDEF. *SYM is the symbol table entry containing the
782 reference; it is replaced with the defining symbol, and the base load
783 address of the defining object is returned. SYMBOL_SCOPE is a
784 null-terminated list of object scopes to search; each object's
785 l_searchlist (i.e. the segment of the dependency tree starting at that
786 object) is searched in turn. REFERENCE_NAME should name the object
787 containing the reference; it is used in error messages.
cf5a372e 788 TYPE_CLASS describes the type of symbol we are looking for. */
f9f2a150
UD
789enum
790 {
791 /* If necessary add dependency between user and provider object. */
792 DL_LOOKUP_ADD_DEPENDENCY = 1,
793 /* Return most recent version instead of default version for
794 unversioned lookup. */
b90395e6
UD
795 DL_LOOKUP_RETURN_NEWEST = 2,
796 /* Set if dl_lookup* called with GSCOPE lock held. */
797 DL_LOOKUP_GSCOPE_LOCK = 4,
f9f2a150
UD
798 };
799
a42195db 800/* Lookup versioned symbol. */
021723ab
UD
801extern lookup_t _dl_lookup_symbol_x (const char *undef,
802 struct link_map *undef_map,
803 const ElfW(Sym) **sym,
804 struct r_scope_elem *symbol_scope[],
805 const struct r_found_version *version,
4e35ef2c 806 int type_class, int flags,
021723ab 807 struct link_map *skip_map)
6ce3881d 808 internal_function attribute_hidden;
a42195db 809
a42195db
UD
810
811/* Look up symbol NAME in MAP's scope and return its run-time address. */
812extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name)
813 internal_function;
814
f0967738
AK
815/* Add the new link_map NEW to the end of the namespace list. */
816extern void _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
817 internal_function attribute_hidden;
818
819/* Allocate a `struct link_map' for a new object being loaded. */
a42195db 820extern struct link_map *_dl_new_object (char *realname, const char *libname,
1fc07491 821 int type, struct link_map *loader,
c0f62c56 822 int mode, Lmid_t nsid)
6ce3881d 823 internal_function attribute_hidden;
a42195db
UD
824
825/* Relocate the given object (if it hasn't already been).
826 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
2ca285b0 827 If RTLD_LAZY is set in RELOC-MODE, don't relocate its PLT. */
a42195db
UD
828extern void _dl_relocate_object (struct link_map *map,
829 struct r_scope_elem *scope[],
2ca285b0 830 int reloc_mode, int consider_profiling)
6ce3881d 831 attribute_hidden;
a42195db 832
e8648a5a
UD
833/* Protect PT_GNU_RELRO area. */
834extern void _dl_protect_relro (struct link_map *map)
835 internal_function attribute_hidden;
836
a42195db
UD
837/* Call _dl_signal_error with a message about an unhandled reloc type.
838 TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
839 PLT is nonzero if this was a PLT reloc; it just affects the message. */
840extern void _dl_reloc_bad_type (struct link_map *map,
ea41b926
UD
841 unsigned int type, int plt)
842 internal_function __attribute__ ((__noreturn__));
a42195db 843
32e6df36
UD
844/* Resolve conflicts if prelinking. */
845extern void _dl_resolve_conflicts (struct link_map *l,
846 ElfW(Rela) *conflict,
847 ElfW(Rela) *conflictend);
848
a42195db
UD
849/* Check the version dependencies of all objects available through
850 MAP. If VERBOSE print some more diagnostics. */
145b8413
UD
851extern int _dl_check_all_versions (struct link_map *map, int verbose,
852 int trace_mode)
a42195db
UD
853 internal_function;
854
855/* Check the version dependencies for MAP. If VERBOSE print some more
856 diagnostics. */
145b8413
UD
857extern int _dl_check_map_versions (struct link_map *map, int verbose,
858 int trace_mode)
a42195db
UD
859 internal_function;
860
dacc8ffa
UD
861/* Initialize the object in SCOPE by calling the constructors with
862 ARGC, ARGV, and ENV as the parameters. */
863extern void _dl_init (struct link_map *main_map, int argc, char **argv,
154d10bd 864 char **env) internal_function attribute_hidden;
a42195db
UD
865
866/* Call the finalizer functions of all shared objects whose
867 initializer functions have completed. */
868extern void _dl_fini (void) internal_function;
869
c3381f3e 870/* Sort array MAPS according to dependencies of the contained objects. */
c8835729
MP
871extern void _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used,
872 Lmid_t ns)
c3381f3e
UD
873 internal_function;
874
a42195db
UD
875/* The dynamic linker calls this function before and having changing
876 any shared object mappings. The `r_state' member of `struct r_debug'
877 says what change is taking place. This function's address is
878 the value of the `r_brk' member. */
7e46ec8c
UD
879extern void _dl_debug_state (void);
880rtld_hidden_proto (_dl_debug_state)
a42195db
UD
881
882/* Initialize `struct r_debug' if it has not already been done. The
883 argument is the run-time load address of the dynamic linker, to be put
884 in the `r_ldbase' member. Returns the address of the structure. */
29f97654 885extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
a42195db
UD
886 internal_function;
887
888/* Initialize the basic data structure for the search paths. */
889extern void _dl_init_paths (const char *library_path) internal_function;
890
891/* Gather the information needed to install the profiling tables and start
892 the timers. */
53bfdc1c 893extern void _dl_start_profile (void) internal_function attribute_hidden;
a42195db
UD
894
895/* The actual functions used to keep book on the calls. */
896extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
9360906d
UD
897extern void _dl_mcount_internal (ElfW(Addr) frompc, ElfW(Addr) selfpc)
898 attribute_hidden;
a42195db
UD
899
900/* This function is simply a wrapper around the _dl_mcount function
901 which does not require a FROMPC parameter since this is the
902 calling function. */
903extern void _dl_mcount_wrapper (void *selfpc);
904
905/* Show the members of the auxiliary array passed up from the kernel. */
906extern void _dl_show_auxv (void) internal_function;
907
908/* Return all environment variables starting with `LD_', one after the
909 other. */
910extern char *_dl_next_ld_env_entry (char ***position) internal_function;
911
912/* Return an array with the names of the important hardware capabilities. */
913extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
914 size_t paltform_len,
915 size_t *sz,
916 size_t *max_capstrlen)
917 internal_function;
918
48896b9d
AJ
919/* Look up NAME in ld.so.cache and return the file name stored there,
920 or null if none is found. */
921extern const char *_dl_load_cache_lookup (const char *name)
922 internal_function;
923
924/* If the system does not support MAP_COPY we cannot leave the file open
925 all the time since this would create problems when the file is replaced.
926 Therefore we provide this function to close the file and open it again
927 once needed. */
154d10bd 928extern void _dl_unload_cache (void) attribute_hidden;
48896b9d 929
40b07f5b
UD
930/* System-dependent function to read a file's whole contents in the
931 most convenient manner available. *SIZEP gets the size of the
932 file. On error MAP_FAILED is returned. */
48896b9d
AJ
933extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
934 int prot)
6ce3881d 935 internal_function attribute_hidden;
48896b9d
AJ
936
937/* System-specific function to do initial startup for the dynamic linker.
938 After this, file access calls and getenv must work. This is responsible
939 for setting __libc_enable_secure if we need to be secure (e.g. setuid),
940 and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
941extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
942 void (*dl_main) (const ElfW(Phdr) *phdr,
943 ElfW(Word) phnum,
3a56ea26
AK
944 ElfW(Addr) *user_entry,
945 ElfW(auxv_t) *auxv))
6ce3881d 946 attribute_hidden;
48896b9d
AJ
947
948extern void _dl_sysdep_start_cleanup (void)
6ce3881d 949 internal_function attribute_hidden;
48896b9d
AJ
950
951
3fb55878 952/* Determine next available module ID. */
68dc80ca 953extern size_t _dl_next_tls_modid (void) internal_function attribute_hidden;
3fb55878
UD
954
955/* Calculate offset of the TLS blocks in the static TLS block. */
68dc80ca
RM
956extern void _dl_determine_tlsoffset (void) internal_function attribute_hidden;
957
958/* Set up the data structures for TLS, when they were not set up at startup.
959 Returns nonzero on malloc failure.
960 This is called from _dl_map_object_from_fd or by libpthread. */
961extern int _dl_tls_setup (void) internal_function;
962rtld_hidden_proto (_dl_tls_setup)
3fb55878 963
9a1eb38e
UD
964/* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */
965extern void *_dl_allocate_tls (void *mem) internal_function;
733f25e6 966rtld_hidden_proto (_dl_allocate_tls)
9a1eb38e
UD
967
968/* Get size and alignment requirements of the static TLS block. */
969extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp)
970 internal_function;
a816b435 971
adc12574 972extern void _dl_allocate_static_tls (struct link_map *map)
545dbc93
RM
973 internal_function attribute_hidden;
974
a816b435
RM
975/* These are internal entry points to the two halves of _dl_allocate_tls,
976 only used within rtld.c itself at startup time. */
977extern void *_dl_allocate_tls_storage (void)
68dc80ca 978 internal_function attribute_hidden;
209a8ca3 979extern void *_dl_allocate_tls_init (void *) internal_function;
68dc80ca 980rtld_hidden_proto (_dl_allocate_tls_init)
e4138261
UD
981
982/* Deallocate memory allocated with _dl_allocate_tls. */
9a1eb38e 983extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb) internal_function;
733f25e6 984rtld_hidden_proto (_dl_deallocate_tls)
3fb55878 985
adc12574 986extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
adc12574 987
154d10bd
UD
988/* Find origin of the executable. */
989extern const char *_dl_get_origin (void) attribute_hidden;
990
991/* Count DSTs. */
992extern size_t _dl_dst_count (const char *name, int is_path) attribute_hidden;
993
994/* Substitute DST values. */
995extern char *_dl_dst_substitute (struct link_map *l, const char *name,
996 char *result, int is_path) attribute_hidden;
997
eec8b6ca
UD
998/* Check validity of the caller. */
999extern int _dl_check_caller (const void *caller, enum allowmask mask)
1000 attribute_hidden;
1001
9dcafc55
UD
1002/* Open the shared object NAME, relocate it, and run its initializer if it
1003 hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
1004 the object is already opened, returns its existing map. */
1005extern void *_dl_open (const char *name, int mode, const void *caller,
1006 Lmid_t nsid, int argc, char *argv[], char *env[])
1007 attribute_hidden;
1008
e4eb675d
UD
1009/* Free or queue for freeing scope OLD. If other threads might be
1010 in the middle of _dl_fixup, _dl_profile_fixup or dl*sym using the
1011 old scope, OLD can't be freed until no thread is using it. */
385b4cf4 1012extern int _dl_scope_free (void *) attribute_hidden;
e4eb675d 1013
9dcafc55
UD
1014/* Add module to slot information data. */
1015extern void _dl_add_to_slotinfo (struct link_map *l) attribute_hidden;
1016
1017/* Update slot information data for at least the generation of the
1018 module with the given index. */
1019extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid);
1020
d78efd9f
RM
1021/* Look up the module's TLS block as for __tls_get_addr,
1022 but never touch anything. Return null if it's not allocated yet. */
93025f93 1023extern void *_dl_tls_get_addr_soft (struct link_map *l) attribute_hidden;
d78efd9f 1024
9be09e06
UD
1025extern int _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
1026 internal_function attribute_hidden;
d78efd9f 1027
73d7af4f 1028/* Show show of an object. */
174baab3 1029extern void _dl_show_scope (struct link_map *new, int from);
73d7af4f 1030
be179c8a
SP
1031extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr)
1032 internal_function;
1033rtld_hidden_proto (_dl_find_dso_for_object)
1034
bc16e260
RM
1035/* Initialization which is normally done by the dynamic linker. */
1036extern void _dl_non_dynamic_init (void) internal_function;
1037
1038/* Used by static binaries to check the auxiliary vector. */
1039extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function;
1040
1041
a42195db
UD
1042__END_DECLS
1043
1044#endif /* ldsodefs.h */