* elf/rtld.c (_dl_start): Set bootstrap_map.l_relocated even
[glibc.git] / include / link.h
blob965419126dfdaf07f257f2963bd88caf44e8c921
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_opencount; /* Counter for direct and indirect usage. */
182 unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */
183 enum /* Where this object came from. */
185 lt_executable, /* The main executable program. */
186 lt_library, /* Library needed by main executable. */
187 lt_loaded /* Extra run-time loaded shared object. */
188 } l_type:2;
189 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
190 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
191 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
192 unsigned int l_reserved:2; /* Reserved for internal use. */
193 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
194 to by `l_phdr' is allocated. */
195 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
196 the l_libname list. */
197 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
198 without associated file. */
199 unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
200 should be called on this link map
201 when relocation finishes. */
202 unsigned int l_used:1; /* Nonzero if the DSO is used. */
203 unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */
204 unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
205 is interested in the PLT interception.*/
207 /* Array with version names. */
208 unsigned int l_nversions;
209 struct r_found_version *l_versions;
211 /* Collected information about own RPATH directories. */
212 struct r_search_path_struct l_rpath_dirs;
214 /* Collected results of relocation while profiling. */
215 struct reloc_result
217 DL_FIXUP_VALUE_TYPE addr;
218 struct link_map *bound;
219 unsigned int boundndx;
220 uint32_t enterexit;
221 unsigned int flags;
222 } *l_reloc_result;
224 /* Pointer to the version information if available. */
225 ElfW(Versym) *l_versyms;
227 /* String specifying the path where this object was found. */
228 const char *l_origin;
230 /* Start and finish of memory map for this object. l_map_start
231 need not be the same as l_addr. */
232 ElfW(Addr) l_map_start, l_map_end;
233 /* End of the executable part of the mapping. */
234 ElfW(Addr) l_text_end;
236 /* Default array for 'l_scope'. */
237 struct r_scope_elem *l_scope_mem[4];
238 /* Size of array allocated for 'l_scope'. */
239 size_t l_scope_max;
240 /* This is an array defining the lookup scope for this link map.
241 There are at most three different scope lists. */
242 struct r_scope_elem **l_scope;
244 /* A similar array, this time only with the local scope. This is
245 used occasionally. */
246 struct r_scope_elem *l_local_scope[2];
248 /* This information is kept to check for sure whether a shared
249 object is the same as one already loaded. */
250 dev_t l_dev;
251 ino64_t l_ino;
253 /* Collected information about own RUNPATH directories. */
254 struct r_search_path_struct l_runpath_dirs;
256 /* List of object in order of the init and fini calls. */
257 struct link_map **l_initfini;
259 /* List of the dependencies introduced through symbol binding. */
260 unsigned int l_reldepsmax;
261 unsigned int l_reldepsact;
262 struct link_map **l_reldeps;
264 /* Various flag words. */
265 ElfW(Word) l_feature_1;
266 ElfW(Word) l_flags_1;
267 ElfW(Word) l_flags;
269 /* Temporarily used in `dl_close'. */
270 unsigned int l_idx;
272 struct link_map_machine l_mach;
274 struct
276 const ElfW(Sym) *sym;
277 int type_class;
278 struct link_map *value;
279 const ElfW(Sym) *ret;
280 } l_lookup_cache;
282 #ifdef USE_TLS
283 /* Thread-local storage related info. */
285 /* Start of the initialization image. */
286 void *l_tls_initimage;
287 /* Size of the initialization image. */
288 size_t l_tls_initimage_size;
289 /* Size of the TLS block. */
290 size_t l_tls_blocksize;
291 /* Alignment requirement of the TLS block. */
292 size_t l_tls_align;
293 /* Offset of first byte module alignment. */
294 size_t l_tls_firstbyte_offset;
295 # ifndef NO_TLS_OFFSET
296 # define NO_TLS_OFFSET 0
297 # endif
298 /* For objects present at startup time: offset in the static TLS block. */
299 ptrdiff_t l_tls_offset;
300 /* Index of the module in the dtv array. */
301 size_t l_tls_modid;
302 #endif
304 /* Information used to change permission after the relocations are
305 done. */
306 ElfW(Addr) l_relro_addr;
307 size_t l_relro_size;
309 /* Audit information. This array apparent must be the last in the
310 structure. Never add something after it. */
311 struct auditstate
313 uintptr_t cookie;
314 unsigned int bindflags;
315 } l_audit[0];
318 /* Version numbers for la_version handshake interface. */
319 #define LAV_CURRENT 1
321 /* Activity types signaled through la_activity. */
322 enum
324 LA_ACT_CONSISTENT,
325 LA_ACT_ADD,
326 LA_ACT_DELETE
329 /* Values representing origin of name for dynamic loading. */
330 enum
332 LA_SER_ORIG = 0x01, /* Original name. */
333 LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
334 LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
335 LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
336 LA_SER_DEFAULT = 0x40, /* Default directory. */
337 LA_SER_SECURE = 0x80 /* Unused. */
340 /* Values for la_objopen return value. */
341 enum
343 LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
344 LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
347 /* Values for la_symbind flags parameter. */
348 enum
350 LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
351 LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
352 LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
353 LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
354 LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
355 la_symbind call. */
358 #if __ELF_NATIVE_CLASS == 32
359 # define symbind symbind32
360 #elif __ELF_NATIVE_CLASS == 64
361 # define symbind symbind64
362 #else
363 # error "__ELF_NATIVE_CLASS must be defined"
364 #endif
366 struct dl_phdr_info
368 ElfW(Addr) dlpi_addr;
369 const char *dlpi_name;
370 const ElfW(Phdr) *dlpi_phdr;
371 ElfW(Half) dlpi_phnum;
373 unsigned long long int dlpi_adds;
374 unsigned long long int dlpi_subs;
377 extern int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
378 size_t size, void *data),
379 void *data);
380 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
381 size_t size, void *data),
382 void *data);
384 #endif /* link.h */