Update.
[glibc.git] / include / link.h
blob5829f3c98fb0603e1254860a0de298dc543da6ab
1 /* Data structure for communication from the run-time dynamic linker for
2 loaded ELF shared objects.
3 Copyright (C) 1995-2002, 2003, 2004 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 <dl-lookupcfg.h>
38 #include <tls.h> /* Defines USE_TLS. */
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; ++dyn)
76 if (dyn->d_tag == DT_DEBUG)
77 r_debug = (struct r_debug *) dyn->d_un.d_ptr;
79 extern ElfW(Dyn) _DYNAMIC[];
82 /* Some internal data structures of the dynamic linker used in the
83 linker map. We only provide forward declarations. */
84 struct libname_list;
85 struct r_found_version;
86 struct r_search_path_elem;
88 /* Forward declaration. */
89 struct link_map;
91 /* Structure to describe a single list of scope elements. The lookup
92 functions get passed an array of pointers to such structures. */
93 struct r_scope_elem
95 /* Array of maps for the scope. */
96 struct link_map **r_list;
97 /* Number of entries in the scope. */
98 unsigned int r_nlist;
102 /* Structure to record search path and allocation mechanism. */
103 struct r_search_path_struct
105 struct r_search_path_elem **dirs;
106 int malloced;
110 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
111 members form a chain of all the shared objects loaded at startup.
113 These data structures exist in space used by the run-time dynamic linker;
114 modifying them may have disastrous results.
116 This data structure might change in future, if necessary. User-level
117 programs must avoid defining objects of this type. */
119 struct link_map
121 /* These first few members are part of the protocol with the debugger.
122 This is the same format used in SVR4. */
124 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
125 char *l_name; /* Absolute file name object was found in. */
126 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
127 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
129 /* All following members are internal to the dynamic linker.
130 They may change without notice. */
132 struct libname_list *l_libname;
133 /* Indexed pointers to dynamic section.
134 [0,DT_NUM) are indexed by the processor-independent tags.
135 [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
136 [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
137 indexed by DT_VERSIONTAGIDX(tagvalue).
138 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
139 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
140 DT_EXTRATAGIDX(tagvalue).
141 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
142 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
143 indexed by DT_VALTAGIDX(tagvalue) and
144 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
145 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
146 are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>. */
148 ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
149 + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
150 const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
151 ElfW(Addr) l_entry; /* Entry point location. */
152 ElfW(Half) l_phnum; /* Number of program header entries. */
153 ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */
155 /* Array of DT_NEEDED dependencies and their dependencies, in
156 dependency order for symbol lookup (with and without
157 duplicates). There is no entry before the dependencies have
158 been loaded. */
159 struct r_scope_elem l_searchlist;
161 /* We need a special searchlist to process objects marked with
162 DT_SYMBOLIC. */
163 struct r_scope_elem l_symbolic_searchlist;
165 /* Dependent object that first caused this object to be loaded. */
166 struct link_map *l_loader;
168 /* Symbol hash table. */
169 Elf_Symndx l_nbuckets;
170 const Elf_Symndx *l_buckets, *l_chain;
172 unsigned int l_opencount; /* Reference count for dlopen/dlclose. */
173 enum /* Where this object came from. */
175 lt_executable, /* The main executable program. */
176 lt_library, /* Library needed by main executable. */
177 lt_loaded /* Extra run-time loaded shared object. */
178 } l_type:2;
179 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
180 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
181 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
182 unsigned int l_reserved:2; /* Reserved for internal use. */
183 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
184 to by `l_phdr' is allocated. */
185 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
186 the l_libname list. */
187 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
188 without associated file. */
189 unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
190 should be called on this link map
191 when relocation finishes. */
192 /* Array with version names. */
193 unsigned int l_nversions;
194 struct r_found_version *l_versions;
196 /* Collected information about own RPATH directories. */
197 struct r_search_path_struct l_rpath_dirs;
199 /* Collected results of relocation while profiling. */
200 ElfW(Addr) *l_reloc_result;
202 /* Pointer to the version information if available. */
203 ElfW(Versym) *l_versyms;
205 /* String specifying the path where this object was found. */
206 const char *l_origin;
208 /* Start and finish of memory map for this object. l_map_start
209 need not be the same as l_addr. */
210 ElfW(Addr) l_map_start, l_map_end;
211 /* End of the executable part of the mapping. */
212 ElfW(Addr) l_text_end;
214 /* Default array for 'l_scope'. */
215 struct r_scope_elem *l_scope_mem[4];
216 /* Size of array allocated for 'l_scope'. */
217 size_t l_scope_max;
218 /* This is an array defining the lookup scope for this link map.
219 There are at most three different scope lists. */
220 struct r_scope_elem **l_scope;
222 /* A similar array, this time only with the local scope. This is
223 used occasionally. */
224 struct r_scope_elem *l_local_scope[2];
226 /* This information is kept to check for sure whether a shared
227 object is the same as one already loaded. */
228 dev_t l_dev;
229 ino64_t l_ino;
231 /* Collected information about own RUNPATH directories. */
232 struct r_search_path_struct l_runpath_dirs;
234 /* List of object in order of the init and fini calls. */
235 struct link_map **l_initfini;
237 /* List of the dependencies introduced through symbol binding. */
238 unsigned int l_reldepsmax;
239 unsigned int l_reldepsact;
240 struct link_map **l_reldeps;
242 /* Various flag words. */
243 ElfW(Word) l_feature_1;
244 ElfW(Word) l_flags_1;
245 ElfW(Word) l_flags;
247 /* Temporarily used in `dl_close'. */
248 unsigned int l_idx;
250 struct link_map_machine l_mach;
252 struct
254 const ElfW(Sym) *sym;
255 int type_class;
256 #ifdef DL_LOOKUP_RETURNS_MAP
257 struct link_map *value;
258 #else
259 ElfW(Addr) value;
260 #endif
261 const ElfW(Sym) *ret;
262 } l_lookup_cache;
264 #ifdef USE_TLS
265 /* Thread-local storage related info. */
267 /* Start of the initialization image. */
268 void *l_tls_initimage;
269 /* Size of the initialization image. */
270 size_t l_tls_initimage_size;
271 /* Size of the TLS block. */
272 size_t l_tls_blocksize;
273 /* Alignment requirement of the TLS block. */
274 size_t l_tls_align;
275 /* Offset of first byte module alignment. */
276 size_t l_tls_firstbyte_offset;
277 # ifndef NO_TLS_OFFSET
278 # define NO_TLS_OFFSET 0
279 # endif
280 /* For objects present at startup time: offset in the static TLS block. */
281 ptrdiff_t l_tls_offset;
282 /* Index of the module in the dtv array. */
283 size_t l_tls_modid;
284 #endif
286 /* Information used to change permission after the relocations are
287 done. */
288 ElfW(Addr) l_relro_addr;
289 size_t l_relro_size;
292 struct dl_phdr_info
294 ElfW(Addr) dlpi_addr;
295 const char *dlpi_name;
296 const ElfW(Phdr) *dlpi_phdr;
297 ElfW(Half) dlpi_phnum;
299 unsigned long long int dlpi_adds;
300 unsigned long long int dlpi_subs;
303 extern int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
304 size_t size, void *data),
305 void *data);
306 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
307 size_t size, void *data),
308 void *data);
310 #endif /* link.h */