Change all _ISxxx to _ISwxxx.
[glibc.git] / elf / link.h
blob06aac2e805e44ba6753d10cd8792a622969f10ad
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2 Copyright (C) 1995, 1996, 1997 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 _LINK_H
22 #define _LINK_H 1
23 #include <features.h>
25 #define __need_size_t
26 #include <stddef.h>
28 #include <elf.h>
30 __BEGIN_DECLS
32 /* We use this macro to refer to ELF types independent of the native wordsize.
33 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
34 #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
35 #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
36 #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
37 #define _ElfW_1(e,w,t) e##w##t
38 #include <elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
40 /* Rendezvous structure used by the run-time dynamic linker to communicate
41 details of shared object loading to the debugger. If the executable's
42 dynamic section has a DT_DEBUG element, the run-time linker sets that
43 element's value to the address where this structure can be found. */
45 struct r_debug
47 int r_version; /* Version number for this protocol. */
49 struct link_map *r_map; /* Head of the chain of loaded objects. */
51 /* This is the address of a function internal to the run-time linker,
52 that will always be called when the linker begins to map in a
53 library or unmap it, and again when the mapping change is complete.
54 The debugger can set a breakpoint at this address if it wants to
55 notice shared object mapping changes. */
56 ElfW(Addr) r_brk;
57 enum
59 /* This state value describes the mapping change taking place when
60 the `r_brk' address is called. */
61 RT_CONSISTENT, /* Mapping change is complete. */
62 RT_ADD, /* Beginning to add a new object. */
63 RT_DELETE, /* Beginning to remove an object mapping. */
64 } r_state;
66 ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
69 /* This is the instance of that structure used by the dynamic linker. */
70 extern struct r_debug _r_debug;
72 /* This symbol refers to the "dynamic structure" in the `.dynamic' section
73 of whatever module refers to `_DYNAMIC'. So, to find its own
74 `struct r_debug', a program could do:
75 for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL)
76 if (dyn->d_tag == DT_DEBUG) r_debug = (struct r_debug) dyn->d_un.d_ptr;
79 extern ElfW(Dyn) _DYNAMIC[];
82 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
83 members form a chain of all the shared objects loaded at startup.
85 These data structures exist in space used by the run-time dynamic linker;
86 modifying them may have disastrous results. */
88 struct link_map
90 /* These first few members are part of the protocol with the debugger.
91 This is the same format used in SVR4. */
93 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
94 char *l_name; /* Absolute file name object was found in. */
95 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
96 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
98 /* All following members are internal to the dynamic linker.
99 They may change without notice. */
101 const char *l_libname; /* Name requested (before search). */
102 /* Indexed pointers to dynamic section.
103 [0,DT_NUM) are indexed by the processor-independent tags.
104 [DT_NUM,DT_NUM+DT_PROCNUM) are indexed by the tag minus DT_LOPROC.
105 [DT_NUM+DT_PROCNUM,DT_NUM+DT_PROCNUM+DT_EXTRANUM) are indexed
106 by DT_EXTRATAGIDX(tagvalue) and
107 [DT_NUM+DT_PROCNUM+DT_VERSIONTAGNUM,
108 DT_NUM+DT_PROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM)
109 are indexed by DT_EXTRATAGIDX(tagvalue) (see <elf.h>). */
111 ElfW(Dyn) *l_info[DT_NUM + DT_PROCNUM + DT_VERSIONTAGNUM + DT_EXTRANUM];
112 const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
113 ElfW(Addr) l_entry; /* Entry point location. */
114 ElfW(Half) l_phnum; /* Number of program header entries. */
116 /* Array of DT_NEEDED dependencies and their dependencies, in
117 dependency order for symbol lookup. This is null before the
118 dependencies have been loaded. */
119 struct link_map **l_searchlist;
120 unsigned int l_nsearchlist;
122 /* We keep another list in which we keep duplicates. This is
123 needed in _dl_lookup_symbol_skip to implemented RTLD_NEXT. */
124 struct link_map **l_dupsearchlist;
125 unsigned int l_ndupsearchlist;
127 /* Dependent object that first caused this object to be loaded. */
128 struct link_map *l_loader;
130 /* Symbol hash table. */
131 ElfW(Symndx) l_nbuckets;
132 const ElfW(Symndx) *l_buckets, *l_chain;
134 unsigned int l_opencount; /* Reference count for dlopen/dlclose. */
135 enum /* Where this object came from. */
137 lt_executable, /* The main executable program. */
138 lt_library, /* Library needed by main executable. */
139 lt_loaded, /* Extra run-time loaded shared object. */
140 } l_type:2;
141 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
142 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
143 unsigned int l_init_running:1; /* Nonzero while DT_INIT function runs. */
144 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
145 unsigned int l_reserved:2; /* Reserved for internal use. */
149 /* Function used as argument for `_dl_receive_error' function. The
150 arguments are the error string and the objname the error occurred
151 in. */
152 typedef void (*receiver_fct) (const char *, const char *);
154 /* Internal functions of the run-time dynamic linker.
155 These can be accessed if you link again the dynamic linker
156 as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
157 but are not normally of interest to user programs.
159 The `-ldl' library functions in <dlfcn.h> provide a simple
160 user interface to run-time dynamic linking. */
163 /* Cached value of `getpagesize ()'. */
164 extern size_t _dl_pagesize;
166 /* File descriptor referring to the zero-fill device. */
167 extern int _dl_zerofd;
169 /* OS-dependent function to open the zero-fill device. */
170 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
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 extern void _dl_sysdep_message (const char *string, ...);
177 /* OS-dependent function to write a message on the standard error.
178 All arguments are `const char *'; args until a null pointer
179 are concatenated to form the message to print. */
180 extern void _dl_sysdep_error (const char *string, ...);
182 /* OS-dependent function to give a fatal error message and exit
183 when the dynamic linker fails before the program is fully linked.
184 All arguments are `const char *'; args until a null pointer
185 are concatenated to form the message to print. */
186 extern void _dl_sysdep_fatal (const char *string, ...)
187 __attribute__ ((__noreturn__));
189 /* Nonzero if the program should be "secure" (i.e. it's setuid or somesuch).
190 This tells the dynamic linker to ignore environment variables. */
191 extern int _dl_secure;
193 /* This function is called by all the internal dynamic linker functions
194 when they encounter an error. ERRCODE is either an `errno' code or
195 zero; OBJECT is the name of the problematical shared object, or null if
196 it is a general problem; ERRSTRING is a string describing the specific
197 problem. */
198 extern void _dl_signal_error (int errcode,
199 const char *object,
200 const char *errstring);
202 /* Call OPERATE, catching errors from `dl_signal_error'. If there is no
203 error, *ERRSTRING is set to null. If there is an error, *ERRSTRING and
204 *OBJECT are set to the strings passed to _dl_signal_error, and the error
205 code passed is the return value. ERRSTRING if nonzero points to a
206 malloc'ed string which the caller has to free after use. */
207 extern int _dl_catch_error (char **errstring,
208 const char **object,
209 void (*operate) (void));
211 /* Call OPERATE, receiving errors from `dl_signal_error'. Unlike
212 `_dl_catch_error' the operation is resumed after the OPERATE
213 function returns. */
214 extern void _dl_receive_error (receiver_fct fct, void (*operate) (void));
217 /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
218 _dl_catch_error. Returns zero for success, nonzero for failure; and
219 arranges for `dlerror' to return the error details. */
220 extern int _dlerror_run (void (*operate) (void));
223 /* Open the shared object NAME and map in its segments.
224 LOADER's DT_RPATH is used in searching for NAME.
225 If the object is already opened, returns its existing map. */
226 extern struct link_map *_dl_map_object (struct link_map *loader,
227 const char *name, int type,
228 int trace_mode);
230 /* Call _dl_map_object on the dependencies of MAP, and set up
231 MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
232 loaded objects that will be inserted into MAP->l_searchlist after MAP
233 but before its dependencies. */
234 extern void _dl_map_object_deps (struct link_map *map,
235 struct link_map **preloads,
236 unsigned int npreloads, int trace_mode);
238 /* Cache the locations of MAP's hash table. */
239 extern void _dl_setup_hash (struct link_map *map);
242 /* Open the shared object NAME, relocate it, and run its initializer if it
243 hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
244 the object is already opened, returns its existing map. */
245 extern struct link_map *_dl_open (const char *name, int mode);
247 /* Close an object previously opened by _dl_open. */
248 extern void _dl_close (struct link_map *map);
251 /* Search loaded objects' symbol tables for a definition of the symbol
252 referred to by UNDEF. *SYM is the symbol table entry containing the
253 reference; it is replaced with the defining symbol, and the base load
254 address of the defining object is returned. SYMBOL_SCOPE is a
255 null-terminated list of object scopes to search; each object's
256 l_searchlist (i.e. the segment of the dependency tree starting at that
257 object) is searched in turn. REFERENCE_NAME should name the object
258 containing the reference; it is used in error messages. FLAGS is a
259 set of flags: */
260 #define DL_LOOKUP_NOEXEC 1 /* Don't search the executable for a
261 definition; this is used for copy
262 relocs. */
263 #define DL_LOOKUP_NOPLT 2 /* The reference must not be resolved
264 to a PLT entry. */
265 extern ElfW(Addr) _dl_lookup_symbol (const char *undef,
266 const ElfW(Sym) **sym,
267 struct link_map *symbol_scope[],
268 const char *reference_name,
269 int flags);
271 /* For handling RTLD_NEXT we must be able to skip shared objects. */
272 extern ElfW(Addr) _dl_lookup_symbol_skip (const char *undef,
273 const ElfW(Sym) **sym,
274 struct link_map *symbol_scope[],
275 const char *reference_name,
276 struct link_map *skip_this,
277 int flags);
279 /* Look up symbol NAME in MAP's scope and return its run-time address. */
280 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name);
283 /* Structure describing the dynamic linker itself. */
284 extern struct link_map _dl_rtld_map;
286 /* The list of objects currently loaded is the third element of the
287 `_dl_default_scope' array, and the fourth element is always null.
288 This leaves two slots before it that are used when resolving
289 DT_SYMBOLIC objects' references one after it for normal references
290 (see below). */
291 #define _dl_loaded (_dl_default_scope[2])
292 extern struct link_map *_dl_default_scope[5];
294 /* Null-terminated list of objects in the dynamic `global scope'. The
295 list starts at [2]; i.e. &_dl_global_scope[2] is the argument
296 passed to _dl_lookup_symbol to search the global scope. To search
297 a specific object and its dependencies in preference to the global
298 scope, fill in the [1] slot and pass its address; for two specific
299 object scopes, fill [0] and [1]. The list is double-terminated; to
300 search the global scope and then a specific object and its
301 dependencies, set *_dl_global_scope_end. This variable initially
302 points to _dl_default_scope, and _dl_loaded is always kept in [2]
303 of this list. A new list is malloc'd when new objects are loaded
304 with RTLD_GLOBAL. */
305 extern struct link_map **_dl_global_scope, **_dl_global_scope_end;
306 extern size_t _dl_global_scope_alloc; /* Number of slots malloc'd. */
308 /* Hack _dl_global_scope[0] and [1] as necessary, and return a pointer into
309 _dl_global_scope that should be passed to _dl_lookup_symbol for symbol
310 references made in the object MAP's relocations. */
311 extern struct link_map **_dl_object_relocation_scope (struct link_map *map);
314 /* Allocate a `struct link_map' for a new object being loaded,
315 and enter it into the _dl_loaded list. */
316 extern struct link_map *_dl_new_object (char *realname, const char *libname,
317 int type);
319 /* Relocate the given object (if it hasn't already been).
320 SCOPE is passed to _dl_lookup_symbol in symbol lookups.
321 If LAZY is nonzero, don't relocate its PLT. */
322 extern void _dl_relocate_object (struct link_map *map,
323 struct link_map *scope[],
324 int lazy);
326 /* Return the address of the next initializer function for MAP or one of
327 its dependencies that has not yet been run. When there are no more
328 initializers to be run, this returns zero. The functions are returned
329 in the order they should be called. */
330 extern ElfW(Addr) _dl_init_next (struct link_map *map);
332 /* Call the finalizer functions of all shared objects whose
333 initializer functions have completed. */
334 extern void _dl_fini (void);
336 /* The dynamic linker calls this function before and having changing
337 any shared object mappings. The `r_state' member of `struct r_debug'
338 says what change is taking place. This function's address is
339 the value of the `r_brk' member. */
340 extern void _dl_debug_state (void);
342 /* Initialize `struct r_debug' if it has not already been done. The
343 argument is the run-time load address of the dynamic linker, to be put
344 in the `r_ldbase' member. Returns the address of the structure. */
345 extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase);
347 __END_DECLS
349 #endif /* link.h */