]> git.ipfire.org Git - thirdparty/glibc.git/blob - include/link.h
* elf/dl-lookup.c (dl_new_hash): New functions.
[thirdparty/glibc.git] / include / link.h
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,2006 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
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.
10
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.
15
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. */
20
21 #ifndef _PRIVATE_LINK_H
22 #define _PRIVATE_LINK_H 1
23
24 #ifdef _LINK_H
25 # error this should be impossible
26 #endif
27
28 /* Get most of the contents from the public header, but we define a
29 different `struct link_map' type for private use. The la_objopen
30 prototype uses the type, so we have to declare it separately. */
31 #define link_map link_map_public
32 #define la_objopen la_objopen_wrongproto
33 #include <elf/link.h>
34 #undef link_map
35 #undef la_objopen
36
37 struct link_map;
38 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
39 uintptr_t *__cookie);
40
41
42 #include <stddef.h>
43 #include <bits/linkmap.h>
44 #include <dl-lookupcfg.h>
45 #include <tls.h> /* Defines USE_TLS. */
46
47
48 /* Some internal data structures of the dynamic linker used in the
49 linker map. We only provide forward declarations. */
50 struct libname_list;
51 struct r_found_version;
52 struct r_search_path_elem;
53
54 /* Forward declaration. */
55 struct link_map;
56
57 /* Structure to describe a single list of scope elements. The lookup
58 functions get passed an array of pointers to such structures. */
59 struct r_scope_elem
60 {
61 /* Array of maps for the scope. */
62 struct link_map **r_list;
63 /* Number of entries in the scope. */
64 unsigned int r_nlist;
65 };
66
67
68 /* Structure to record search path and allocation mechanism. */
69 struct r_search_path_struct
70 {
71 struct r_search_path_elem **dirs;
72 int malloced;
73 };
74
75
76 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
77 members form a chain of all the shared objects loaded at startup.
78
79 These data structures exist in space used by the run-time dynamic linker;
80 modifying them may have disastrous results.
81
82 This data structure might change in future, if necessary. User-level
83 programs must avoid defining objects of this type. */
84
85 struct link_map
86 {
87 /* These first few members are part of the protocol with the debugger.
88 This is the same format used in SVR4. */
89
90 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
91 char *l_name; /* Absolute file name object was found in. */
92 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
93 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
94
95 /* All following members are internal to the dynamic linker.
96 They may change without notice. */
97
98 /* This is an element which is only ever different from a pointer to
99 the very same copy of this type for ld.so when it is used in more
100 than one namespace. */
101 struct link_map *l_real;
102
103 /* Number of the namespace this link map belongs to. */
104 Lmid_t l_ns;
105
106 struct libname_list *l_libname;
107 /* Indexed pointers to dynamic section.
108 [0,DT_NUM) are indexed by the processor-independent tags.
109 [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
110 [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
111 indexed by DT_VERSIONTAGIDX(tagvalue).
112 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
113 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
114 DT_EXTRATAGIDX(tagvalue).
115 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
116 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
117 indexed by DT_VALTAGIDX(tagvalue) and
118 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
119 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
120 are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>. */
121
122 ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
123 + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
124 const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
125 ElfW(Addr) l_entry; /* Entry point location. */
126 ElfW(Half) l_phnum; /* Number of program header entries. */
127 ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */
128
129 /* Array of DT_NEEDED dependencies and their dependencies, in
130 dependency order for symbol lookup (with and without
131 duplicates). There is no entry before the dependencies have
132 been loaded. */
133 struct r_scope_elem l_searchlist;
134
135 /* We need a special searchlist to process objects marked with
136 DT_SYMBOLIC. */
137 struct r_scope_elem l_symbolic_searchlist;
138
139 /* Dependent object that first caused this object to be loaded. */
140 struct link_map *l_loader;
141
142 /* Symbol hash table. */
143 Elf_Symndx l_nbuckets;
144 Elf32_Word l_gnu_bitmask_idxbits;
145 Elf32_Word l_gnu_shift;
146 const ElfW(Addr) *l_gnu_bitmask;
147 union
148 {
149 const Elf32_Word *l_gnu_buckets;
150 const Elf_Symndx *l_chain;
151 };
152 union
153 {
154 const Elf32_Word *l_gnu_chain_zero;
155 const Elf_Symndx *l_buckets;
156 };
157
158 unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */
159 enum /* Where this object came from. */
160 {
161 lt_executable, /* The main executable program. */
162 lt_library, /* Library needed by main executable. */
163 lt_loaded /* Extra run-time loaded shared object. */
164 } l_type:2;
165 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
166 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
167 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
168 unsigned int l_reserved:2; /* Reserved for internal use. */
169 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
170 to by `l_phdr' is allocated. */
171 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
172 the l_libname list. */
173 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
174 without associated file. */
175 unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
176 should be called on this link map
177 when relocation finishes. */
178 unsigned int l_used:1; /* Nonzero if the DSO is used. */
179 unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */
180 unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
181 is interested in the PLT interception.*/
182 unsigned int l_removed:1; /* Nozero if the object cannot be used anymore
183 since it is removed. */
184
185 /* Array with version names. */
186 unsigned int l_nversions;
187 struct r_found_version *l_versions;
188
189 /* Collected information about own RPATH directories. */
190 struct r_search_path_struct l_rpath_dirs;
191
192 /* Collected results of relocation while profiling. */
193 struct reloc_result
194 {
195 DL_FIXUP_VALUE_TYPE addr;
196 struct link_map *bound;
197 unsigned int boundndx;
198 uint32_t enterexit;
199 unsigned int flags;
200 } *l_reloc_result;
201
202 /* Pointer to the version information if available. */
203 ElfW(Versym) *l_versyms;
204
205 /* String specifying the path where this object was found. */
206 const char *l_origin;
207
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;
213
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;
221
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];
225
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;
230
231 /* Collected information about own RUNPATH directories. */
232 struct r_search_path_struct l_runpath_dirs;
233
234 /* List of object in order of the init and fini calls. */
235 struct link_map **l_initfini;
236
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;
241
242 /* Various flag words. */
243 ElfW(Word) l_feature_1;
244 ElfW(Word) l_flags_1;
245 ElfW(Word) l_flags;
246
247 /* Temporarily used in `dl_close'. */
248 int l_idx;
249
250 struct link_map_machine l_mach;
251
252 struct
253 {
254 const ElfW(Sym) *sym;
255 int type_class;
256 struct link_map *value;
257 const ElfW(Sym) *ret;
258 } l_lookup_cache;
259
260 #ifdef USE_TLS
261 /* Thread-local storage related info. */
262
263 /* Start of the initialization image. */
264 void *l_tls_initimage;
265 /* Size of the initialization image. */
266 size_t l_tls_initimage_size;
267 /* Size of the TLS block. */
268 size_t l_tls_blocksize;
269 /* Alignment requirement of the TLS block. */
270 size_t l_tls_align;
271 /* Offset of first byte module alignment. */
272 size_t l_tls_firstbyte_offset;
273 # ifndef NO_TLS_OFFSET
274 # define NO_TLS_OFFSET 0
275 # endif
276 /* For objects present at startup time: offset in the static TLS block. */
277 ptrdiff_t l_tls_offset;
278 /* Index of the module in the dtv array. */
279 size_t l_tls_modid;
280 #endif
281
282 /* Information used to change permission after the relocations are
283 done. */
284 ElfW(Addr) l_relro_addr;
285 size_t l_relro_size;
286
287 /* Audit information. This array apparent must be the last in the
288 structure. Never add something after it. */
289 struct auditstate
290 {
291 uintptr_t cookie;
292 unsigned int bindflags;
293 } l_audit[0];
294 };
295
296
297 #if __ELF_NATIVE_CLASS == 32
298 # define symbind symbind32
299 #elif __ELF_NATIVE_CLASS == 64
300 # define symbind symbind64
301 #else
302 # error "__ELF_NATIVE_CLASS must be defined"
303 #endif
304
305 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
306 size_t size, void *data),
307 void *data);
308
309 #endif /* include/link.h */