* misc/error.c [_LIBC]: Include <stdbool.h> and <stdint.h>.
[glibc.git] / include / link.h
blob0c352640969220ab0b37159f8b075bcbcf4743f4
1 /* Data structure for communication from the run-time dynamic linker for
2 loaded ELF shared objects.
3 Copyright (C) 1995-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _LINK_H
22 #define _LINK_H 1
24 #include <elf.h>
25 #include <dlfcn.h>
26 #include <stddef.h>
27 #include <sys/types.h>
29 /* We use this macro to refer to ELF types independent of the native wordsize.
30 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
31 #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
32 #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
33 #define _ElfW_1(e,w,t) e##w##t
35 #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
36 #include <bits/link.h>
37 #include <bits/linkmap.h>
38 #include <dl-lookupcfg.h>
39 #include <tls.h> /* Defines USE_TLS. */
41 /* Rendezvous structure used by the run-time dynamic linker to communicate
42 details of shared object loading to the debugger. If the executable's
43 dynamic section has a DT_DEBUG element, the run-time linker sets that
44 element's value to the address where this structure can be found. */
46 struct r_debug
48 int r_version; /* Version number for this protocol. */
50 struct link_map *r_map; /* Head of the chain of loaded objects. */
52 /* This is the address of a function internal to the run-time linker,
53 that will always be called when the linker begins to map in a
54 library or unmap it, and again when the mapping change is complete.
55 The debugger can set a breakpoint at this address if it wants to
56 notice shared object mapping changes. */
57 ElfW(Addr) r_brk;
58 enum
60 /* This state value describes the mapping change taking place when
61 the `r_brk' address is called. */
62 RT_CONSISTENT, /* Mapping change is complete. */
63 RT_ADD, /* Beginning to add a new object. */
64 RT_DELETE /* Beginning to remove an object mapping. */
65 } r_state;
67 ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
70 /* This is the instance of that structure used by the dynamic linker. */
71 extern struct r_debug _r_debug;
73 /* This symbol refers to the "dynamic structure" in the `.dynamic' section
74 of whatever module refers to `_DYNAMIC'. So, to find its own
75 `struct r_debug', a program could do:
76 for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
77 if (dyn->d_tag == DT_DEBUG)
78 r_debug = (struct r_debug *) dyn->d_un.d_ptr;
80 extern ElfW(Dyn) _DYNAMIC[];
83 /* Some internal data structures of the dynamic linker used in the
84 linker map. We only provide forward declarations. */
85 struct libname_list;
86 struct r_found_version;
87 struct r_search_path_elem;
89 /* Forward declaration. */
90 struct link_map;
92 /* Structure to describe a single list of scope elements. The lookup
93 functions get passed an array of pointers to such structures. */
94 struct r_scope_elem
96 /* Array of maps for the scope. */
97 struct link_map **r_list;
98 /* Number of entries in the scope. */
99 unsigned int r_nlist;
103 /* Structure to record search path and allocation mechanism. */
104 struct r_search_path_struct
106 struct r_search_path_elem **dirs;
107 int malloced;
111 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
112 members form a chain of all the shared objects loaded at startup.
114 These data structures exist in space used by the run-time dynamic linker;
115 modifying them may have disastrous results.
117 This data structure might change in future, if necessary. User-level
118 programs must avoid defining objects of this type. */
120 struct link_map
122 /* These first few members are part of the protocol with the debugger.
123 This is the same format used in SVR4. */
125 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
126 char *l_name; /* Absolute file name object was found in. */
127 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
128 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
130 /* All following members are internal to the dynamic linker.
131 They may change without notice. */
133 /* This is an element which is only ever different from a pointer to
134 the very same copy of this type for ld.so when it is used in more
135 than one namespace. */
136 struct link_map *l_real;
138 /* Number of the namespace this link map belongs to. */
139 Lmid_t l_ns;
141 struct libname_list *l_libname;
142 /* Indexed pointers to dynamic section.
143 [0,DT_NUM) are indexed by the processor-independent tags.
144 [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
145 [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
146 indexed by DT_VERSIONTAGIDX(tagvalue).
147 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
148 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
149 DT_EXTRATAGIDX(tagvalue).
150 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
151 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
152 indexed by DT_VALTAGIDX(tagvalue) and
153 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
154 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
155 are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>. */
157 ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
158 + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
159 const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
160 ElfW(Addr) l_entry; /* Entry point location. */
161 ElfW(Half) l_phnum; /* Number of program header entries. */
162 ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */
164 /* Array of DT_NEEDED dependencies and their dependencies, in
165 dependency order for symbol lookup (with and without
166 duplicates). There is no entry before the dependencies have
167 been loaded. */
168 struct r_scope_elem l_searchlist;
170 /* We need a special searchlist to process objects marked with
171 DT_SYMBOLIC. */
172 struct r_scope_elem l_symbolic_searchlist;
174 /* Dependent object that first caused this object to be loaded. */
175 struct link_map *l_loader;
177 /* Symbol hash table. */
178 Elf_Symndx l_nbuckets;
179 const Elf_Symndx *l_buckets, *l_chain;
181 unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */
182 enum /* Where this object came from. */
184 lt_executable, /* The main executable program. */
185 lt_library, /* Library needed by main executable. */
186 lt_loaded /* Extra run-time loaded shared object. */
187 } l_type:2;
188 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
189 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
190 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
191 unsigned int l_reserved:2; /* Reserved for internal use. */
192 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
193 to by `l_phdr' is allocated. */
194 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
195 the l_libname list. */
196 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
197 without associated file. */
198 unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
199 should be called on this link map
200 when relocation finishes. */
201 unsigned int l_used:1; /* Nonzero if the DSO is used. */
202 unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */
203 unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
204 is interested in the PLT interception.*/
205 unsigned int l_removed:1; /* Nozero if the object cannot be used anymore
206 since it is removed. */
208 /* Array with version names. */
209 unsigned int l_nversions;
210 struct r_found_version *l_versions;
212 /* Collected information about own RPATH directories. */
213 struct r_search_path_struct l_rpath_dirs;
215 /* Collected results of relocation while profiling. */
216 struct reloc_result
218 DL_FIXUP_VALUE_TYPE addr;
219 struct link_map *bound;
220 unsigned int boundndx;
221 uint32_t enterexit;
222 unsigned int flags;
223 } *l_reloc_result;
225 /* Pointer to the version information if available. */
226 ElfW(Versym) *l_versyms;
228 /* String specifying the path where this object was found. */
229 const char *l_origin;
231 /* Start and finish of memory map for this object. l_map_start
232 need not be the same as l_addr. */
233 ElfW(Addr) l_map_start, l_map_end;
234 /* End of the executable part of the mapping. */
235 ElfW(Addr) l_text_end;
237 /* Default array for 'l_scope'. */
238 struct r_scope_elem *l_scope_mem[4];
239 /* Size of array allocated for 'l_scope'. */
240 size_t l_scope_max;
241 /* This is an array defining the lookup scope for this link map.
242 There are at most three different scope lists. */
243 struct r_scope_elem **l_scope;
245 /* A similar array, this time only with the local scope. This is
246 used occasionally. */
247 struct r_scope_elem *l_local_scope[2];
249 /* This information is kept to check for sure whether a shared
250 object is the same as one already loaded. */
251 dev_t l_dev;
252 ino64_t l_ino;
254 /* Collected information about own RUNPATH directories. */
255 struct r_search_path_struct l_runpath_dirs;
257 /* List of object in order of the init and fini calls. */
258 struct link_map **l_initfini;
260 /* List of the dependencies introduced through symbol binding. */
261 unsigned int l_reldepsmax;
262 unsigned int l_reldepsact;
263 struct link_map **l_reldeps;
265 /* Various flag words. */
266 ElfW(Word) l_feature_1;
267 ElfW(Word) l_flags_1;
268 ElfW(Word) l_flags;
270 /* Temporarily used in `dl_close'. */
271 int l_idx;
273 struct link_map_machine l_mach;
275 struct
277 const ElfW(Sym) *sym;
278 int type_class;
279 struct link_map *value;
280 const ElfW(Sym) *ret;
281 } l_lookup_cache;
283 #ifdef USE_TLS
284 /* Thread-local storage related info. */
286 /* Start of the initialization image. */
287 void *l_tls_initimage;
288 /* Size of the initialization image. */
289 size_t l_tls_initimage_size;
290 /* Size of the TLS block. */
291 size_t l_tls_blocksize;
292 /* Alignment requirement of the TLS block. */
293 size_t l_tls_align;
294 /* Offset of first byte module alignment. */
295 size_t l_tls_firstbyte_offset;
296 # ifndef NO_TLS_OFFSET
297 # define NO_TLS_OFFSET 0
298 # endif
299 /* For objects present at startup time: offset in the static TLS block. */
300 ptrdiff_t l_tls_offset;
301 /* Index of the module in the dtv array. */
302 size_t l_tls_modid;
303 #endif
305 /* Information used to change permission after the relocations are
306 done. */
307 ElfW(Addr) l_relro_addr;
308 size_t l_relro_size;
310 /* Audit information. This array apparent must be the last in the
311 structure. Never add something after it. */
312 struct auditstate
314 uintptr_t cookie;
315 unsigned int bindflags;
316 } l_audit[0];
319 /* Version numbers for la_version handshake interface. */
320 #define LAV_CURRENT 1
322 /* Activity types signaled through la_activity. */
323 enum
325 LA_ACT_CONSISTENT,
326 LA_ACT_ADD,
327 LA_ACT_DELETE
330 /* Values representing origin of name for dynamic loading. */
331 enum
333 LA_SER_ORIG = 0x01, /* Original name. */
334 LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
335 LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
336 LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
337 LA_SER_DEFAULT = 0x40, /* Default directory. */
338 LA_SER_SECURE = 0x80 /* Unused. */
341 /* Values for la_objopen return value. */
342 enum
344 LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
345 LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
348 /* Values for la_symbind flags parameter. */
349 enum
351 LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
352 LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
353 LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
354 LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
355 LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
356 la_symbind call. */
359 #if __ELF_NATIVE_CLASS == 32
360 # define symbind symbind32
361 #elif __ELF_NATIVE_CLASS == 64
362 # define symbind symbind64
363 #else
364 # error "__ELF_NATIVE_CLASS must be defined"
365 #endif
367 struct dl_phdr_info
369 ElfW(Addr) dlpi_addr;
370 const char *dlpi_name;
371 const ElfW(Phdr) *dlpi_phdr;
372 ElfW(Half) dlpi_phnum;
374 unsigned long long int dlpi_adds;
375 unsigned long long int dlpi_subs;
378 extern int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
379 size_t size, void *data),
380 void *data);
381 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
382 size_t size, void *data),
383 void *data);
385 #endif /* link.h */