1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2 Copyright (C) 1995, 1996, 1997, 1998 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 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.
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.
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. */
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)
39 /* For the version handling we need an array with only names and their
41 struct r_found_version
50 /* We want to cache information about the searches for shared objects. */
52 enum r_dir_status { unknown, nonexisting, existing };
54 struct r_search_path_elem
59 enum r_dir_status dirstatus;
61 size_t machdirnamelen;
62 enum r_dir_status machdirstatus;
64 /* Strings saying where the definition came from. */
68 /* This link is only used in the `all_dirs' member of `r_search_path'. */
69 struct r_search_path_elem *next;
73 /* A data structure for a simple single linked list of strings. */
76 const char *name; /* Name requested (before search). */
77 struct libname_list *next; /* Link to next name for this object. */
81 /* Test whether given NAME matches any of the names of the given object. */
83 __attribute__ ((unused))
84 _dl_name_match_p (const char *__name, struct link_map *__map)
86 int __found = strcmp (__name, __map->l_name) == 0;
87 struct libname_list *__runp = __map->l_libname;
89 while (! __found && __runp != NULL)
90 if (strcmp (__name, __runp->name) == 0)
93 __runp = __runp->next;
98 /* Function used as argument for `_dl_receive_error' function. The
99 arguments are the error code, error string, and the objname the
100 error occurred in. */
101 typedef void (*receiver_fct) (int, const char *, const char *);
103 /* Internal functions of the run-time dynamic linker.
104 These can be accessed if you link again the dynamic linker
105 as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
106 but are not normally of interest to user programs.
108 The `-ldl' library functions in <dlfcn.h> provide a simple
109 user interface to run-time dynamic linking. */
112 /* Parameters passed to the dynamic linker. */
113 extern char **_dl_argv;
115 /* Cached value of `getpagesize ()'. */
116 extern size_t _dl_pagesize;
118 /* File descriptor referring to the zero-fill device. */
119 extern int _dl_zerofd;
121 /* Name of the shared object to be profiled (if any). */
122 extern const char *_dl_profile;
123 /* Map of shared object to be profiled. */
124 extern struct link_map *_dl_profile_map;
126 /* If nonzero the appropriate debug information is printed. */
127 extern int _dl_debug_libs;
128 extern int _dl_debug_impcalls;
129 extern int _dl_debug_bindings;
130 extern int _dl_debug_symbols;
131 extern int _dl_debug_versions;
132 extern int _dl_debug_reloc;
133 extern int _dl_debug_files;
135 /* File deccriptor to write debug messages to. */
136 extern int _dl_debug_fd;
138 /* OS-dependent function to open the zero-fill device. */
139 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
141 /* OS-dependent function to write a message on the specified
142 descriptor FD. All arguments are `const char *'; args until a null
143 pointer are concatenated to form the message to print. */
144 extern void _dl_sysdep_output (int fd, const char *string, ...);
146 /* OS-dependent function to write a debug message on the specified
147 descriptor for this. All arguments are `const char *'; args until
148 a null pointer are concatenated to form the message to print. If
149 NEW_LINE is nonzero it is assumed that the message starts on a new
151 extern void _dl_debug_message (int new_line, const char *string, ...);
153 /* OS-dependent function to write a message on the standard output.
154 All arguments are `const char *'; args until a null pointer
155 are concatenated to form the message to print. */
156 #define _dl_sysdep_message(string, args...) \
157 _dl_sysdep_output (STDOUT_FILENO, string, ##args)
159 /* OS-dependent function to write a message on the standard error.
160 All arguments are `const char *'; args until a null pointer
161 are concatenated to form the message to print. */
162 #define _dl_sysdep_error(string, args...) \
163 _dl_sysdep_output (STDERR_FILENO, string, ##args)
165 /* OS-dependent function to give a fatal error message and exit
166 when the dynamic linker fails before the program is fully linked.
167 All arguments are `const char *'; args until a null pointer
168 are concatenated to form the message to print. */
169 #define _dl_sysdep_fatal(string, args...) \
172 _dl_sysdep_output (STDERR_FILENO, string, ##args); \
177 /* Nonzero if the program should be "secure" (i.e. it's setuid or somesuch).
178 This tells the dynamic linker to ignore environment variables. */
179 extern int _dl_secure;
181 /* This function is called by all the internal dynamic linker functions
182 when they encounter an error. ERRCODE is either an `errno' code or
183 zero; OBJECT is the name of the problematical shared object, or null if
184 it is a general problem; ERRSTRING is a string describing the specific
186 extern void _dl_signal_error (int errcode,
188 const char *errstring);
190 /* Call OPERATE, catching errors from `dl_signal_error'. If there is no
191 error, *ERRSTRING is set to null. If there is an error, *ERRSTRING is
192 set to a string constructed from the strings passed to _dl_signal_error,
193 and the error code passed is the return value. ERRSTRING if nonzero
194 points to a malloc'ed string which the caller has to free after use.
195 ARGS is passed as argument to OPERATE. */
196 extern int _dl_catch_error (char **errstring,
197 void (*operate) (void *),
200 /* Call OPERATE, receiving errors from `dl_signal_error'. Unlike
201 `_dl_catch_error' the operation is resumed after the OPERATE
203 ARGS is passed as argument to OPERATE. */
204 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
208 /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
209 _dl_catch_error. Returns zero for success, nonzero for failure; and
210 arranges for `dlerror' to return the error details.
211 ARGS is passed as argument to OPERATE. */
212 extern int _dlerror_run (void (*operate) (void *), void *args);
215 /* Open the shared object NAME and map in its segments.
216 LOADER's DT_RPATH is used in searching for NAME.
217 If the object is already opened, returns its existing map.
218 For preloaded shared objects PRELOADED is set to a non-zero
219 value to allow additional security checks. */
220 extern struct link_map *_dl_map_object (struct link_map *loader,
221 const char *name, int preloaded,
222 int type, int trace_mode);
224 /* Call _dl_map_object on the dependencies of MAP, and set up
225 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
226 loaded objects that will be inserted into MAP->l_searchlist after MAP
227 but before its dependencies. */
228 extern void _dl_map_object_deps (struct link_map *map,
229 struct link_map **preloads,
230 unsigned int npreloads, int trace_mode);
232 /* Cache the locations of MAP's hash table. */
233 extern void _dl_setup_hash (struct link_map *map);
236 /* Open the shared object NAME, relocate it, and run its initializer if it
237 hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
238 the object is already opened, returns its existing map. */
239 extern struct link_map *_dl_open (const char *name, int mode);
241 /* Close an object previously opened by _dl_open. */
242 extern void _dl_close (struct link_map *map);
245 /* Search loaded objects' symbol tables for a definition of the symbol
246 referred to by UNDEF. *SYM is the symbol table entry containing the
247 reference; it is replaced with the defining symbol, and the base load
248 address of the defining object is returned. SYMBOL_SCOPE is a
249 null-terminated list of object scopes to search; each object's
250 l_searchlist (i.e. the segment of the dependency tree starting at that
251 object) is searched in turn. REFERENCE_NAME should name the object
252 containing the reference; it is used in error messages.
253 RELOC_TYPE is a machine-dependent reloc type, which is passed to
254 the `elf_machine_lookup_*_p' macros in dl-machine.h to affect which
255 symbols can be chosen. */
256 extern ElfW(Addr) _dl_lookup_symbol (const char *undef,
257 const ElfW(Sym) **sym,
258 struct link_map *symbol_scope[],
259 const char *reference_name,
262 /* Lookup versioned symbol. */
263 extern ElfW(Addr) _dl_lookup_versioned_symbol (const char *undef,
264 const ElfW(Sym) **sym,
265 struct link_map *symbol_scope[],
266 const char *reference_name,
267 const struct r_found_version *version,
270 /* For handling RTLD_NEXT we must be able to skip shared objects. */
271 extern ElfW(Addr) _dl_lookup_symbol_skip (const char *undef,
272 const ElfW(Sym) **sym,
273 struct link_map *symbol_scope[],
274 const char *reference_name,
275 struct link_map *skip_this);
277 /* For handling RTLD_NEXT with versioned symbols we must be able to
278 skip shared objects. */
279 extern ElfW(Addr) _dl_lookup_versioned_symbol_skip (const char *undef,
280 const ElfW(Sym) **sym,
281 struct link_map *symbol_scope[],
282 const char *reference_name,
283 const struct r_found_version *version,
284 struct link_map *skip_this);
286 /* Locate shared object containing the given address. */
287 extern int _dl_addr (const void *address, Dl_info *info);
289 /* Look up symbol NAME in MAP's scope and return its run-time address. */
290 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name);
293 /* Structure describing the dynamic linker itself. */
294 extern struct link_map _dl_rtld_map;
296 /* The list of objects currently loaded is the third element of the
297 `_dl_default_scope' array, and the fourth element is always null.
298 This leaves two slots before it that are used when resolving
299 DT_SYMBOLIC objects' references one after it for normal references
301 #define _dl_loaded (_dl_default_scope[2])
302 extern struct link_map *_dl_default_scope[5];
304 /* Null-terminated list of objects in the dynamic `global scope'. The
305 list starts at [2]; i.e. &_dl_global_scope[2] is the argument
306 passed to _dl_lookup_symbol to search the global scope. To search
307 a specific object and its dependencies in preference to the global
308 scope, fill in the [1] slot and pass its address; for two specific
309 object scopes, fill [0] and [1]. The list is double-terminated; to
310 search the global scope and then a specific object and its
311 dependencies, set *_dl_global_scope_end. This variable initially
312 points to _dl_default_scope, and _dl_loaded is always kept in [2]
313 of this list. A new list is malloc'd when new objects are loaded
315 extern struct link_map **_dl_global_scope, **_dl_global_scope_end;
316 extern size_t _dl_global_scope_alloc; /* Number of slots malloc'd. */
318 /* Hack _dl_global_scope[0] and [1] as necessary, and return a pointer into
319 _dl_global_scope that should be passed to _dl_lookup_symbol for symbol
320 references made in the object MAP's relocations. */
321 extern struct link_map **_dl_object_relocation_scope (struct link_map *map);
324 /* Allocate a `struct link_map' for a new object being loaded,
325 and enter it into the _dl_loaded list. */
326 extern struct link_map *_dl_new_object (char *realname, const char *libname,
329 /* Relocate the given object (if it hasn't already been).
330 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
331 If LAZY is nonzero, don't relocate its PLT. */
332 extern void _dl_relocate_object (struct link_map *map,
333 struct link_map *scope[],
336 /* Check the version dependencies of all objects available through
337 MAP. If VERBOSE print some more diagnostics. */
338 extern int _dl_check_all_versions (struct link_map *map, int verbose);
340 /* Check the version dependencies for MAP. If VERBOSE print some more
342 extern int _dl_check_map_versions (struct link_map *map, int verbose);
344 /* Return the address of the next initializer function for MAP or one of
345 its dependencies that has not yet been run. When there are no more
346 initializers to be run, this returns zero. The functions are returned
347 in the order they should be called. */
348 extern ElfW(Addr) _dl_init_next (struct link_map *map);
350 /* Call the finalizer functions of all shared objects whose
351 initializer functions have completed. */
352 extern void _dl_fini (void);
354 /* The dynamic linker calls this function before and having changing
355 any shared object mappings. The `r_state' member of `struct r_debug'
356 says what change is taking place. This function's address is
357 the value of the `r_brk' member. */
358 extern void _dl_debug_state (void);
360 /* Initialize `struct r_debug' if it has not already been done. The
361 argument is the run-time load address of the dynamic linker, to be put
362 in the `r_ldbase' member. Returns the address of the structure. */
363 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase);
365 /* Initialize the basic data structure for the search paths. */
366 extern void _dl_init_paths (const char *library_path);
368 /* Gather the information needed to install the profiling tables and start
370 extern void _dl_start_profile (struct link_map *map, const char *output_dir);
372 /* The actual functions used to keep book on the calls. */
373 extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
376 /* Show the members of the auxiliary array passed up from the kernel. */
377 extern void _dl_show_auxv (void);
379 /* Return all environment variables starting with `LD_', one after the
381 extern char *_dl_next_ld_env_entry (char ***position);
385 #endif /* ldsodefs.h */