]>
Commit | Line | Data |
---|---|---|
a853022c | 1 | /* Run-time dynamic linker data structures for loaded ELF shared objects. |
126b06f9 | 2 | Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. |
a853022c 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 | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #ifndef _LDSODEFS_H | |
21 | #define _LDSODEFS_H 1 | |
22 | ||
23 | #include <features.h> | |
24 | ||
25 | #define __need_size_t | |
26 | #define __need_NULL | |
27 | #include <stddef.h> | |
28 | ||
29 | #include <elf.h> | |
30 | #include <dlfcn.h> | |
31 | #include <link.h> | |
32 | ||
33 | __BEGIN_DECLS | |
34 | ||
35 | /* We use this macro to refer to ELF types independent of the native wordsize. | |
36 | `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */ | |
37 | #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type) | |
38 | ||
39 | /* For the version handling we need an array with only names and their | |
40 | hash values. */ | |
41 | struct r_found_version | |
42 | { | |
43 | const char *name; | |
44 | ElfW(Word) hash; | |
45 | ||
46 | int hidden; | |
47 | const char *filename; | |
48 | }; | |
49 | ||
50 | /* We want to cache information about the searches for shared objects. */ | |
51 | ||
52 | enum r_dir_status { unknown, nonexisting, existing }; | |
53 | ||
54 | struct r_search_path_elem | |
55 | { | |
4317f9e1 UD |
56 | /* This link is only used in the `all_dirs' member of `r_search_path'. */ |
57 | struct r_search_path_elem *next; | |
a853022c UD |
58 | |
59 | /* Strings saying where the definition came from. */ | |
60 | const char *what; | |
61 | const char *where; | |
62 | ||
12264bd7 UD |
63 | /* Basename for this search path element. The string must end with |
64 | a slash character. */ | |
4317f9e1 | 65 | const char *dirname; |
12264bd7 | 66 | size_t dirnamelen; |
4317f9e1 | 67 | |
12264bd7 | 68 | enum r_dir_status status[0]; |
4317f9e1 UD |
69 | }; |
70 | ||
71 | struct r_strlenpair | |
72 | { | |
73 | const char *str; | |
74 | size_t len; | |
a853022c UD |
75 | }; |
76 | ||
77 | ||
78 | /* A data structure for a simple single linked list of strings. */ | |
79 | struct libname_list | |
80 | { | |
81 | const char *name; /* Name requested (before search). */ | |
82 | struct libname_list *next; /* Link to next name for this object. */ | |
83 | }; | |
84 | ||
85 | ||
86 | /* Test whether given NAME matches any of the names of the given object. */ | |
87 | static __inline int | |
88 | __attribute__ ((unused)) | |
89 | _dl_name_match_p (const char *__name, struct link_map *__map) | |
90 | { | |
91 | int __found = strcmp (__name, __map->l_name) == 0; | |
92 | struct libname_list *__runp = __map->l_libname; | |
93 | ||
94 | while (! __found && __runp != NULL) | |
95 | if (strcmp (__name, __runp->name) == 0) | |
96 | __found = 1; | |
97 | else | |
98 | __runp = __runp->next; | |
99 | ||
100 | return __found; | |
101 | } | |
102 | ||
103 | /* Function used as argument for `_dl_receive_error' function. The | |
104 | arguments are the error code, error string, and the objname the | |
105 | error occurred in. */ | |
106 | typedef void (*receiver_fct) (int, const char *, const char *); | |
107 | \f | |
108 | /* Internal functions of the run-time dynamic linker. | |
109 | These can be accessed if you link again the dynamic linker | |
110 | as a shared library, as in `-lld' or `/lib/ld.so' explicitly; | |
111 | but are not normally of interest to user programs. | |
112 | ||
113 | The `-ldl' library functions in <dlfcn.h> provide a simple | |
114 | user interface to run-time dynamic linking. */ | |
115 | ||
116 | ||
117 | /* Parameters passed to the dynamic linker. */ | |
118 | extern char **_dl_argv; | |
119 | ||
120 | /* Cached value of `getpagesize ()'. */ | |
121 | extern size_t _dl_pagesize; | |
122 | ||
123 | /* File descriptor referring to the zero-fill device. */ | |
124 | extern int _dl_zerofd; | |
125 | ||
126 | /* Name of the shared object to be profiled (if any). */ | |
127 | extern const char *_dl_profile; | |
128 | /* Map of shared object to be profiled. */ | |
129 | extern struct link_map *_dl_profile_map; | |
5ad49c07 UD |
130 | /* Filename of the output file. */ |
131 | extern const char *_dl_profile_output; | |
a853022c UD |
132 | |
133 | /* If nonzero the appropriate debug information is printed. */ | |
134 | extern int _dl_debug_libs; | |
135 | extern int _dl_debug_impcalls; | |
136 | extern int _dl_debug_bindings; | |
137 | extern int _dl_debug_symbols; | |
138 | extern int _dl_debug_versions; | |
139 | extern int _dl_debug_reloc; | |
140 | extern int _dl_debug_files; | |
141 | ||
e2102c14 UD |
142 | /* Expect cache ID. */ |
143 | extern int _dl_correct_cache_id; | |
144 | ||
4194bc66 RH |
145 | /* Mask for hardware capabilities that are available. */ |
146 | extern unsigned long int _dl_hwcap; | |
147 | ||
12264bd7 UD |
148 | /* Mask for important hardware capabilities we honour. */ |
149 | extern unsigned long int _dl_hwcap_mask; | |
150 | ||
c94a8080 | 151 | /* File descriptor to write debug messages to. */ |
a853022c UD |
152 | extern int _dl_debug_fd; |
153 | ||
310930c1 | 154 | /* Names of shared object for which the RPATH should be ignored. */ |
b0a01055 | 155 | extern const char *_dl_inhibit_rpath; |
310930c1 | 156 | |
a853022c UD |
157 | /* OS-dependent function to open the zero-fill device. */ |
158 | extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */ | |
159 | ||
160 | /* OS-dependent function to write a message on the specified | |
161 | descriptor FD. All arguments are `const char *'; args until a null | |
162 | pointer are concatenated to form the message to print. */ | |
163 | extern void _dl_sysdep_output (int fd, const char *string, ...); | |
164 | ||
165 | /* OS-dependent function to write a debug message on the specified | |
166 | descriptor for this. All arguments are `const char *'; args until | |
167 | a null pointer are concatenated to form the message to print. If | |
168 | NEW_LINE is nonzero it is assumed that the message starts on a new | |
5f623941 | 169 | line. */ |
a853022c UD |
170 | extern void _dl_debug_message (int new_line, const char *string, ...); |
171 | ||
172 | /* OS-dependent function to write a message on the standard output. | |
173 | All arguments are `const char *'; args until a null pointer | |
174 | are concatenated to form the message to print. */ | |
175 | #define _dl_sysdep_message(string, args...) \ | |
176 | _dl_sysdep_output (STDOUT_FILENO, string, ##args) | |
177 | ||
178 | /* OS-dependent function to write a message on the standard error. | |
179 | All arguments are `const char *'; args until a null pointer | |
180 | are concatenated to form the message to print. */ | |
181 | #define _dl_sysdep_error(string, args...) \ | |
182 | _dl_sysdep_output (STDERR_FILENO, string, ##args) | |
183 | ||
184 | /* OS-dependent function to give a fatal error message and exit | |
185 | when the dynamic linker fails before the program is fully linked. | |
186 | All arguments are `const char *'; args until a null pointer | |
187 | are concatenated to form the message to print. */ | |
188 | #define _dl_sysdep_fatal(string, args...) \ | |
189 | do \ | |
190 | { \ | |
191 | _dl_sysdep_output (STDERR_FILENO, string, ##args); \ | |
192 | _exit (127); \ | |
193 | } \ | |
194 | while (1) | |
195 | ||
196 | /* Nonzero if the program should be "secure" (i.e. it's setuid or somesuch). | |
197 | This tells the dynamic linker to ignore environment variables. */ | |
198 | extern int _dl_secure; | |
199 | ||
200 | /* This function is called by all the internal dynamic linker functions | |
201 | when they encounter an error. ERRCODE is either an `errno' code or | |
202 | zero; OBJECT is the name of the problematical shared object, or null if | |
203 | it is a general problem; ERRSTRING is a string describing the specific | |
204 | problem. */ | |
205 | extern void _dl_signal_error (int errcode, | |
206 | const char *object, | |
d0fc4041 | 207 | const char *errstring) |
126b06f9 UD |
208 | internal_function |
209 | __attribute__ ((__noreturn__)); | |
a853022c UD |
210 | |
211 | /* Call OPERATE, catching errors from `dl_signal_error'. If there is no | |
212 | error, *ERRSTRING is set to null. If there is an error, *ERRSTRING is | |
213 | set to a string constructed from the strings passed to _dl_signal_error, | |
214 | and the error code passed is the return value. ERRSTRING if nonzero | |
215 | points to a malloc'ed string which the caller has to free after use. | |
216 | ARGS is passed as argument to OPERATE. */ | |
217 | extern int _dl_catch_error (char **errstring, | |
218 | void (*operate) (void *), | |
d0fc4041 UD |
219 | void *args) |
220 | internal_function; | |
a853022c UD |
221 | |
222 | /* Call OPERATE, receiving errors from `dl_signal_error'. Unlike | |
223 | `_dl_catch_error' the operation is resumed after the OPERATE | |
224 | function returns. | |
225 | ARGS is passed as argument to OPERATE. */ | |
226 | extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *), | |
d0fc4041 UD |
227 | void *args) |
228 | internal_function; | |
a853022c UD |
229 | |
230 | ||
231 | /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via | |
232 | _dl_catch_error. Returns zero for success, nonzero for failure; and | |
233 | arranges for `dlerror' to return the error details. | |
234 | ARGS is passed as argument to OPERATE. */ | |
d0fc4041 UD |
235 | extern int _dlerror_run (void (*operate) (void *), void *args) |
236 | internal_function; | |
a853022c UD |
237 | |
238 | ||
239 | /* Open the shared object NAME and map in its segments. | |
240 | LOADER's DT_RPATH is used in searching for NAME. | |
241 | If the object is already opened, returns its existing map. | |
242 | For preloaded shared objects PRELOADED is set to a non-zero | |
243 | value to allow additional security checks. */ | |
244 | extern struct link_map *_dl_map_object (struct link_map *loader, | |
245 | const char *name, int preloaded, | |
d0fc4041 UD |
246 | int type, int trace_mode) |
247 | internal_function; | |
a853022c UD |
248 | |
249 | /* Call _dl_map_object on the dependencies of MAP, and set up | |
250 | MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously | |
251 | loaded objects that will be inserted into MAP->l_searchlist after MAP | |
252 | but before its dependencies. */ | |
e3e35cfc UD |
253 | extern unsigned int _dl_map_object_deps (struct link_map *map, |
254 | struct link_map **preloads, | |
255 | unsigned int npreloads, | |
256 | int trace_mode, int global_scope) | |
d0fc4041 | 257 | internal_function; |
a853022c UD |
258 | |
259 | /* Cache the locations of MAP's hash table. */ | |
d0fc4041 | 260 | extern void _dl_setup_hash (struct link_map *map) internal_function; |
a853022c UD |
261 | |
262 | ||
263 | /* Open the shared object NAME, relocate it, and run its initializer if it | |
264 | hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If | |
265 | the object is already opened, returns its existing map. */ | |
d0fc4041 UD |
266 | extern struct link_map *_dl_open (const char *name, int mode) |
267 | internal_function; | |
a853022c UD |
268 | |
269 | /* Close an object previously opened by _dl_open. */ | |
d0fc4041 UD |
270 | extern void _dl_close (struct link_map *map) |
271 | internal_function; | |
a853022c UD |
272 | |
273 | ||
274 | /* Search loaded objects' symbol tables for a definition of the symbol | |
275 | referred to by UNDEF. *SYM is the symbol table entry containing the | |
276 | reference; it is replaced with the defining symbol, and the base load | |
277 | address of the defining object is returned. SYMBOL_SCOPE is a | |
278 | null-terminated list of object scopes to search; each object's | |
279 | l_searchlist (i.e. the segment of the dependency tree starting at that | |
280 | object) is searched in turn. REFERENCE_NAME should name the object | |
281 | containing the reference; it is used in error messages. | |
282 | RELOC_TYPE is a machine-dependent reloc type, which is passed to | |
283 | the `elf_machine_lookup_*_p' macros in dl-machine.h to affect which | |
284 | symbols can be chosen. */ | |
285 | extern ElfW(Addr) _dl_lookup_symbol (const char *undef, | |
286 | const ElfW(Sym) **sym, | |
be935610 | 287 | struct r_scope_elem *symbol_scope[], |
a853022c | 288 | const char *reference_name, |
d0fc4041 UD |
289 | int reloc_type) |
290 | internal_function; | |
a853022c UD |
291 | |
292 | /* Lookup versioned symbol. */ | |
293 | extern ElfW(Addr) _dl_lookup_versioned_symbol (const char *undef, | |
294 | const ElfW(Sym) **sym, | |
be935610 | 295 | struct r_scope_elem *symbol_scope[], |
a853022c UD |
296 | const char *reference_name, |
297 | const struct r_found_version *version, | |
d0fc4041 UD |
298 | int reloc_type) |
299 | internal_function; | |
a853022c UD |
300 | |
301 | /* For handling RTLD_NEXT we must be able to skip shared objects. */ | |
302 | extern ElfW(Addr) _dl_lookup_symbol_skip (const char *undef, | |
303 | const ElfW(Sym) **sym, | |
be935610 | 304 | struct r_scope_elem *symbol_scope[], |
a853022c | 305 | const char *reference_name, |
d0fc4041 UD |
306 | struct link_map *skip_this) |
307 | internal_function; | |
a853022c UD |
308 | |
309 | /* For handling RTLD_NEXT with versioned symbols we must be able to | |
310 | skip shared objects. */ | |
311 | extern ElfW(Addr) _dl_lookup_versioned_symbol_skip (const char *undef, | |
312 | const ElfW(Sym) **sym, | |
be935610 | 313 | struct r_scope_elem *symbol_scope[], |
a853022c UD |
314 | const char *reference_name, |
315 | const struct r_found_version *version, | |
d0fc4041 UD |
316 | struct link_map *skip_this) |
317 | internal_function; | |
a853022c UD |
318 | |
319 | /* Locate shared object containing the given address. */ | |
d0fc4041 UD |
320 | extern int _dl_addr (const void *address, Dl_info *info) |
321 | internal_function; | |
a853022c UD |
322 | |
323 | /* Look up symbol NAME in MAP's scope and return its run-time address. */ | |
d0fc4041 UD |
324 | extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name) |
325 | internal_function; | |
a853022c UD |
326 | |
327 | ||
328 | /* Structure describing the dynamic linker itself. */ | |
329 | extern struct link_map _dl_rtld_map; | |
be935610 UD |
330 | /* And a pointer to the map for the main map. */ |
331 | extern struct link_map *_dl_loaded; | |
332 | /* Array representing global scope. */ | |
333 | extern struct r_scope_elem *_dl_global_scope[2]; | |
334 | /* Direct pointer to the searchlist of the main object. */ | |
335 | extern struct r_scope_elem *_dl_main_searchlist; | |
604510f7 UD |
336 | /* Copy of the content of `_dl_main_searchlist'. */ |
337 | extern struct r_scope_elem _dl_initial_searchlist; | |
338 | /* This is zero at program start to signal that the global scope map is | |
339 | allocated by rtld. Later it keeps the size of the map. It might be | |
340 | reset if in _dl_close if the last global object is removed. */ | |
341 | extern size_t _dl_global_scope_alloc; | |
a853022c UD |
342 | |
343 | /* Allocate a `struct link_map' for a new object being loaded, | |
be935610 | 344 | and enter it into the _dl_main_map list. */ |
a853022c | 345 | extern struct link_map *_dl_new_object (char *realname, const char *libname, |
be935610 UD |
346 | int type, struct link_map *loader) |
347 | internal_function; | |
a853022c UD |
348 | |
349 | /* Relocate the given object (if it hasn't already been). | |
350 | SCOPE is passed to _dl_lookup_symbol in symbol lookups. | |
351 | If LAZY is nonzero, don't relocate its PLT. */ | |
352 | extern void _dl_relocate_object (struct link_map *map, | |
be935610 | 353 | struct r_scope_elem *scope[], |
4bae5567 | 354 | int lazy, int consider_profiling); |
a853022c UD |
355 | |
356 | /* Check the version dependencies of all objects available through | |
357 | MAP. If VERBOSE print some more diagnostics. */ | |
d0fc4041 UD |
358 | extern int _dl_check_all_versions (struct link_map *map, int verbose) |
359 | internal_function; | |
a853022c UD |
360 | |
361 | /* Check the version dependencies for MAP. If VERBOSE print some more | |
362 | diagnostics. */ | |
d0fc4041 UD |
363 | extern int _dl_check_map_versions (struct link_map *map, int verbose) |
364 | internal_function; | |
a853022c | 365 | |
be935610 | 366 | /* Return the address of the next initializer function for SCOPE or one of |
a853022c UD |
367 | its dependencies that has not yet been run. When there are no more |
368 | initializers to be run, this returns zero. The functions are returned | |
369 | in the order they should be called. */ | |
be935610 | 370 | extern ElfW(Addr) _dl_init_next (struct r_scope_elem *scope) internal_function; |
a853022c UD |
371 | |
372 | /* Call the finalizer functions of all shared objects whose | |
373 | initializer functions have completed. */ | |
d0fc4041 | 374 | extern void _dl_fini (void) internal_function; |
a853022c UD |
375 | |
376 | /* The dynamic linker calls this function before and having changing | |
377 | any shared object mappings. The `r_state' member of `struct r_debug' | |
378 | says what change is taking place. This function's address is | |
379 | the value of the `r_brk' member. */ | |
380 | extern void _dl_debug_state (void); | |
381 | ||
382 | /* Initialize `struct r_debug' if it has not already been done. The | |
383 | argument is the run-time load address of the dynamic linker, to be put | |
384 | in the `r_ldbase' member. Returns the address of the structure. */ | |
d0fc4041 UD |
385 | extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase) |
386 | internal_function; | |
a853022c UD |
387 | |
388 | /* Initialize the basic data structure for the search paths. */ | |
d0fc4041 | 389 | extern void _dl_init_paths (const char *library_path) internal_function; |
a853022c UD |
390 | |
391 | /* Gather the information needed to install the profiling tables and start | |
392 | the timers. */ | |
d0fc4041 UD |
393 | extern void _dl_start_profile (struct link_map *map, const char *output_dir) |
394 | internal_function; | |
a853022c UD |
395 | |
396 | /* The actual functions used to keep book on the calls. */ | |
c0fb8a56 | 397 | extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc); |
a853022c | 398 | |
5ad49c07 UD |
399 | /* This function is simply a wrapper around the _dl_mcount function |
400 | which does not require a FROMPC parameter since this is the | |
401 | calling function. */ | |
402 | extern void _dl_mcount_wrapper (ElfW(Addr) selfpc); | |
403 | ||
a853022c UD |
404 | |
405 | /* Show the members of the auxiliary array passed up from the kernel. */ | |
d0fc4041 | 406 | extern void _dl_show_auxv (void) internal_function; |
a853022c UD |
407 | |
408 | /* Return all environment variables starting with `LD_', one after the | |
409 | other. */ | |
d0fc4041 | 410 | extern char *_dl_next_ld_env_entry (char ***position) internal_function; |
a853022c | 411 | |
4317f9e1 | 412 | /* Return an array with the names of the important hardware capabilities. */ |
12264bd7 UD |
413 | extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform, |
414 | size_t paltform_len, | |
415 | size_t *sz, | |
d0fc4041 UD |
416 | size_t *max_capstrlen) |
417 | internal_function; | |
4317f9e1 | 418 | |
5ad49c07 UD |
419 | |
420 | /* When we do profiling we have the problem that uses of `dlopen'ed | |
421 | objects don't use the PLT but instead use a pointer to the function. | |
422 | We still want to have profiling data and in these cases we must do | |
423 | the work of calling `_dl_mcount' ourself. The following macros | |
424 | helps do it. */ | |
425 | #define _CALL_DL_FCT(fctp, args) \ | |
426 | ({ if (_dl_profile_map != NULL) \ | |
427 | _dl_mcount_wrapper ((ElfW(Addr)) fctp); \ | |
428 | (*fctp) args; \ | |
429 | }) | |
430 | ||
a853022c UD |
431 | __END_DECLS |
432 | ||
433 | #endif /* ldsodefs.h */ |