(res_isourserver): Fix cast.
[glibc/pb-stable.git] / sysdeps / generic / ldsodefs.h
blobbcdcf7dd4fda243cdacf646c669264a8a29b00ec
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2 Copyright (C) 1995-1999, 2000, 2001 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. */
20 #ifndef _LDSODEFS_H
21 #define _LDSODEFS_H 1
23 #include <features.h>
25 #define __need_size_t
26 #define __need_NULL
27 #include <stddef.h>
28 #include <string.h>
30 #include <elf.h>
31 #include <dlfcn.h>
32 #include <link.h>
33 #include <dl-lookupcfg.h>
35 __BEGIN_DECLS
37 /* We use this macro to refer to ELF types independent of the native wordsize.
38 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
39 #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
41 /* All references to the value of l_info[DT_PLTGOT],
42 l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
43 l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
44 have to be accessed via the D_PTR macro. The macro is needed since for
45 most architectures the entry is already relocated - but for some not
46 and we need to relocate at access time. */
47 #ifdef DL_RO_DYN_SECTION
48 # define D_PTR(map,i) (map->i->d_un.d_ptr + map->l_addr)
49 #else
50 # define D_PTR(map,i) map->i->d_un.d_ptr
51 #endif
53 /* On some platforms more information than just the address of the symbol
54 is needed from the lookup functions. In this case we return the whole
55 link map. */
56 #ifdef DL_LOOKUP_RETURNS_MAP
57 typedef struct link_map *lookup_t;
58 # define LOOKUP_VALUE(map) map
59 # define LOOKUP_VALUE_ADDRESS(map) (map ? map->l_addr : 0)
60 #else
61 typedef ElfW(Addr) lookup_t;
62 # define LOOKUP_VALUE(map) map->l_addr
63 # define LOOKUP_VALUE_ADDRESS(address) address
64 #endif
66 /* on some architectures a pointer to a function is not just a pointer
67 to the actual code of the function but rather an architecture
68 specific descriptor. */
69 #ifndef ELF_FUNCTION_PTR_IS_SPECIAL
70 # define DL_SYMBOL_ADDRESS(map, ref) \
71 (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
72 # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
73 # define DL_DT_INIT_ADDRESS(map, start) (start)
74 # define DL_DT_FINI_ADDRESS(map, start) (start)
75 #endif
77 /* Unmap a loaded object, called by _dl_close (). */
78 #ifndef DL_UNMAP_IS_SPECIAL
79 # define DL_UNMAP(map) \
80 __munmap ((void *) (map)->l_map_start, \
81 (map)->l_map_end - (map)->l_map_start)
82 #endif
84 /* By default we do not need special support to initialize DSOs loaded
85 by statically linked binaries. */
86 #ifndef DL_STATIC_INIT
87 # define DL_STATIC_INIT(map)
88 #endif
90 /* For the version handling we need an array with only names and their
91 hash values. */
92 struct r_found_version
94 const char *name;
95 ElfW(Word) hash;
97 int hidden;
98 const char *filename;
101 /* We want to cache information about the searches for shared objects. */
103 enum r_dir_status { unknown, nonexisting, existing };
105 struct r_search_path_elem
107 /* This link is only used in the `all_dirs' member of `r_search_path'. */
108 struct r_search_path_elem *next;
110 /* Strings saying where the definition came from. */
111 const char *what;
112 const char *where;
114 /* Basename for this search path element. The string must end with
115 a slash character. */
116 const char *dirname;
117 size_t dirnamelen;
119 enum r_dir_status status[0];
122 struct r_strlenpair
124 const char *str;
125 size_t len;
129 /* A data structure for a simple single linked list of strings. */
130 struct libname_list
132 const char *name; /* Name requested (before search). */
133 struct libname_list *next; /* Link to next name for this object. */
134 int dont_free; /* Flag whether this element should be freed
135 if the object is not entirely unloaded. */
139 /* Test whether given NAME matches any of the names of the given object. */
140 static __inline int
141 __attribute__ ((unused))
142 _dl_name_match_p (const char *__name, struct link_map *__map)
144 int __found = strcmp (__name, __map->l_name) == 0;
145 struct libname_list *__runp = __map->l_libname;
147 while (! __found && __runp != NULL)
148 if (strcmp (__name, __runp->name) == 0)
149 __found = 1;
150 else
151 __runp = __runp->next;
153 return __found;
156 /* Function used as argument for `_dl_receive_error' function. The
157 arguments are the error code, error string, and the objname the
158 error occurred in. */
159 typedef void (*receiver_fct) (int, const char *, const char *);
161 /* Internal functions of the run-time dynamic linker.
162 These can be accessed if you link again the dynamic linker
163 as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
164 but are not normally of interest to user programs.
166 The `-ldl' library functions in <dlfcn.h> provide a simple
167 user interface to run-time dynamic linking. */
170 /* Parameters passed to the dynamic linker. */
171 extern char **_dl_argv;
173 /* Cached value of `getpagesize ()'. */
174 extern size_t _dl_pagesize;
176 /* OS version. */
177 extern unsigned int _dl_osversion;
179 /* File descriptor referring to the zero-fill device. */
180 extern int _dl_zerofd;
182 /* Name of the shared object to be profiled (if any). */
183 extern const char *_dl_profile;
184 /* Map of shared object to be profiled. */
185 extern struct link_map *_dl_profile_map;
186 /* Filename of the output file. */
187 extern const char *_dl_profile_output;
189 /* If nonzero the appropriate debug information is printed. */
190 extern int _dl_debug_mask;
191 #define DL_DEBUG_LIBS (1 << 0)
192 #define DL_DEBUG_IMPCALLS (1 << 1)
193 #define DL_DEBUG_BINDINGS (1 << 2)
194 #define DL_DEBUG_SYMBOLS (1 << 3)
195 #define DL_DEBUG_VERSIONS (1 << 4)
196 #define DL_DEBUG_RELOC (1 << 5)
197 #define DL_DEBUG_FILES (1 << 6)
198 #define DL_DEBUG_STATISTICS (1 << 7)
200 /* Expect cache ID. */
201 extern int _dl_correct_cache_id;
203 /* Mask for hardware capabilities that are available. */
204 extern unsigned long int _dl_hwcap;
206 /* Mask for important hardware capabilities we honour. */
207 extern unsigned long int _dl_hwcap_mask;
209 /* File descriptor to write debug messages to. */
210 extern int _dl_debug_fd;
212 /* Names of shared object for which the RPATH should be ignored. */
213 extern const char *_dl_inhibit_rpath;
215 /* Nonzero if references should be treated as weak during runtime linking. */
216 extern int _dl_dynamic_weak;
218 /* The array with message we print as a last resort. */
219 extern const char _dl_out_of_memory[];
221 /* Nonzero if runtime lookups should not update the .got/.plt. */
222 extern int _dl_bind_not;
224 /* List of search directories. */
225 extern struct r_search_path_elem *_dl_all_dirs;
226 extern struct r_search_path_elem *_dl_init_all_dirs;
228 /* OS-dependent function to open the zero-fill device. */
229 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
232 /* Write message on the debug file descriptor. The parameters are
233 interpreted as for a `printf' call. All the lines start with a
234 tag showing the PID. */
235 extern void _dl_debug_printf (const char *fmt, ...)
236 __attribute__ ((__format__ (__printf__, 1, 2)));
238 /* Write message on the debug file descriptor. The parameters are
239 interpreted as for a `printf' call. All the lines buf the first
240 start with a tag showing the PID. */
241 extern void _dl_debug_printf_c (const char *fmt, ...)
242 __attribute__ ((__format__ (__printf__, 1, 2)));
245 /* Write a message on the specified descriptor FD. The parameters are
246 interpreted as for a `printf' call. */
247 extern void _dl_dprintf (int fd, const char *fmt, ...)
248 __attribute__ ((__format__ (__printf__, 2, 3)));
250 /* Write a message on the specified descriptor standard output. The
251 parameters are interpreted as for a `printf' call. */
252 #define _dl_printf(fmt, args...) \
253 _dl_dprintf (STDOUT_FILENO, fmt, ##args)
255 /* Write a message on the specified descriptor standard error. The
256 parameters are interpreted as for a `printf' call. */
257 #define _dl_error_printf(fmt, args...) \
258 _dl_dprintf (STDERR_FILENO, fmt, ##args)
260 /* Write a message on the specified descriptor standard error and exit
261 the program. The parameters are interpreted as for a `printf' call. */
262 #define _dl_fatal_printf(fmt, args...) \
263 do \
265 _dl_dprintf (STDERR_FILENO, fmt, ##args); \
266 _exit (127); \
268 while (1)
271 /* This function is called by all the internal dynamic linker functions
272 when they encounter an error. ERRCODE is either an `errno' code or
273 zero; OBJECT is the name of the problematical shared object, or null if
274 it is a general problem; ERRSTRING is a string describing the specific
275 problem. */
276 extern void _dl_signal_error (int errcode, const char *object,
277 const char *errstring)
278 internal_function
279 __attribute__ ((__noreturn__));
281 /* Like _dl_signal_error, but may return when called in the context of
282 _dl_receive_error. */
283 extern void _dl_signal_cerror (int errcode,
284 const char *object,
285 const char *errstring)
286 internal_function;
288 /* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike
289 `_dl_catch_error' the operation is resumed after the OPERATE
290 function returns.
291 ARGS is passed as argument to OPERATE. */
292 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
293 void *args)
294 internal_function;
297 /* Open the shared object NAME and map in its segments.
298 LOADER's DT_RPATH is used in searching for NAME.
299 If the object is already opened, returns its existing map.
300 For preloaded shared objects PRELOADED is set to a non-zero
301 value to allow additional security checks. */
302 extern struct link_map *_dl_map_object (struct link_map *loader,
303 const char *name, int preloaded,
304 int type, int trace_mode, int mode)
305 internal_function;
307 /* Call _dl_map_object on the dependencies of MAP, and set up
308 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
309 loaded objects that will be inserted into MAP->l_searchlist after MAP
310 but before its dependencies. */
311 extern void _dl_map_object_deps (struct link_map *map,
312 struct link_map **preloads,
313 unsigned int npreloads, int trace_mode)
314 internal_function;
316 /* Cache the locations of MAP's hash table. */
317 extern void _dl_setup_hash (struct link_map *map) internal_function;
320 /* Search loaded objects' symbol tables for a definition of the symbol
321 referred to by UNDEF. *SYM is the symbol table entry containing the
322 reference; it is replaced with the defining symbol, and the base load
323 address of the defining object is returned. SYMBOL_SCOPE is a
324 null-terminated list of object scopes to search; each object's
325 l_searchlist (i.e. the segment of the dependency tree starting at that
326 object) is searched in turn. REFERENCE_NAME should name the object
327 containing the reference; it is used in error messages.
328 RELOC_TYPE is a machine-dependent reloc type, which is passed to
329 the `elf_machine_lookup_*_p' macros in dl-machine.h to affect which
330 symbols can be chosen. */
331 extern lookup_t _dl_lookup_symbol (const char *undef,
332 struct link_map *undef_map,
333 const ElfW(Sym) **sym,
334 struct r_scope_elem *symbol_scope[],
335 int reloc_type, int explicit)
336 internal_function;
338 /* Lookup versioned symbol. */
339 extern lookup_t _dl_lookup_versioned_symbol (const char *undef,
340 struct link_map *undef_map,
341 const ElfW(Sym) **sym,
342 struct r_scope_elem *symbol_scope[],
343 const struct r_found_version *version,
344 int reloc_type, int explicit)
345 internal_function;
347 /* For handling RTLD_NEXT we must be able to skip shared objects. */
348 extern lookup_t _dl_lookup_symbol_skip (const char *undef,
349 struct link_map *undef_map,
350 const ElfW(Sym) **sym,
351 struct r_scope_elem *symbol_scope[],
352 struct link_map *skip_this)
353 internal_function;
355 /* For handling RTLD_NEXT with versioned symbols we must be able to
356 skip shared objects. */
357 extern lookup_t _dl_lookup_versioned_symbol_skip (const char *undef,
358 struct link_map *undef_map,
359 const ElfW(Sym) **sym,
360 struct r_scope_elem *symbol_scope[],
361 const struct r_found_version *version,
362 struct link_map *skip_this)
363 internal_function;
365 /* Look up symbol NAME in MAP's scope and return its run-time address. */
366 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name)
367 internal_function;
370 /* Structure describing the dynamic linker itself. */
371 extern struct link_map _dl_rtld_map;
372 /* And a pointer to the map for the main map. */
373 extern struct link_map *_dl_loaded;
374 /* Number of object in the _dl_loaded list. */
375 extern unsigned int _dl_nloaded;
376 /* Array representing global scope. */
377 extern struct r_scope_elem *_dl_global_scope[2];
378 /* Direct pointer to the searchlist of the main object. */
379 extern struct r_scope_elem *_dl_main_searchlist;
380 /* Copy of the content of `_dl_main_searchlist'. */
381 extern struct r_scope_elem _dl_initial_searchlist;
382 /* This is zero at program start to signal that the global scope map is
383 allocated by rtld. Later it keeps the size of the map. It might be
384 reset if in _dl_close if the last global object is removed. */
385 extern size_t _dl_global_scope_alloc;
387 /* Allocate a `struct link_map' for a new object being loaded,
388 and enter it into the _dl_main_map list. */
389 extern struct link_map *_dl_new_object (char *realname, const char *libname,
390 int type, struct link_map *loader)
391 internal_function;
393 /* Relocate the given object (if it hasn't already been).
394 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
395 If LAZY is nonzero, don't relocate its PLT. */
396 extern void _dl_relocate_object (struct link_map *map,
397 struct r_scope_elem *scope[],
398 int lazy, int consider_profiling);
400 /* Call _dl_signal_error with a message about an unhandled reloc type.
401 TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
402 PLT is nonzero if this was a PLT reloc; it just affects the message. */
403 extern void _dl_reloc_bad_type (struct link_map *map,
404 uint_fast8_t type, int plt)
405 internal_function
406 __attribute__ ((__noreturn__));
408 /* Check the version dependencies of all objects available through
409 MAP. If VERBOSE print some more diagnostics. */
410 extern int _dl_check_all_versions (struct link_map *map, int verbose,
411 int trace_mode)
412 internal_function;
414 /* Check the version dependencies for MAP. If VERBOSE print some more
415 diagnostics. */
416 extern int _dl_check_map_versions (struct link_map *map, int verbose,
417 int trace_mode)
418 internal_function;
420 /* Initialize the object in SCOPE by calling the constructors with
421 ARGC, ARGV, and ENV as the parameters. */
422 extern void _dl_init (struct link_map *main_map, int argc, char **argv,
423 char **env) internal_function;
425 /* Call the finalizer functions of all shared objects whose
426 initializer functions have completed. */
427 extern void _dl_fini (void) internal_function;
429 /* The dynamic linker calls this function before and having changing
430 any shared object mappings. The `r_state' member of `struct r_debug'
431 says what change is taking place. This function's address is
432 the value of the `r_brk' member. */
433 extern void _dl_debug_state (void);
435 /* Initialize `struct r_debug' if it has not already been done. The
436 argument is the run-time load address of the dynamic linker, to be put
437 in the `r_ldbase' member. Returns the address of the structure. */
438 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase)
439 internal_function;
441 /* Initialize the basic data structure for the search paths. */
442 extern void _dl_init_paths (const char *library_path) internal_function;
444 /* Gather the information needed to install the profiling tables and start
445 the timers. */
446 extern void _dl_start_profile (struct link_map *map, const char *output_dir)
447 internal_function;
449 /* The actual functions used to keep book on the calls. */
450 extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
452 /* This function is simply a wrapper around the _dl_mcount function
453 which does not require a FROMPC parameter since this is the
454 calling function. */
455 extern void _dl_mcount_wrapper (void *selfpc);
457 /* Show the members of the auxiliary array passed up from the kernel. */
458 extern void _dl_show_auxv (void) internal_function;
460 /* Return all environment variables starting with `LD_', one after the
461 other. */
462 extern char *_dl_next_ld_env_entry (char ***position) internal_function;
464 /* Return an array with the names of the important hardware capabilities. */
465 extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
466 size_t paltform_len,
467 size_t *sz,
468 size_t *max_capstrlen)
469 internal_function;
471 /* Look up NAME in ld.so.cache and return the file name stored there,
472 or null if none is found. */
473 extern const char *_dl_load_cache_lookup (const char *name)
474 internal_function;
476 /* If the system does not support MAP_COPY we cannot leave the file open
477 all the time since this would create problems when the file is replaced.
478 Therefore we provide this function to close the file and open it again
479 once needed. */
480 extern void _dl_unload_cache (void);
482 /* System-dependent function to read a file's whole contents
483 in the most convenient manner available. */
484 extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
485 int prot)
486 internal_function;
488 /* System-specific function to do initial startup for the dynamic linker.
489 After this, file access calls and getenv must work. This is responsible
490 for setting __libc_enable_secure if we need to be secure (e.g. setuid),
491 and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
492 extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
493 void (*dl_main) (const ElfW(Phdr) *phdr,
494 ElfW(Word) phnum,
495 ElfW(Addr) *user_entry));
497 extern void _dl_sysdep_start_cleanup (void)
498 internal_function;
501 __END_DECLS
503 #endif /* ldsodefs.h */