]>
Commit | Line | Data |
---|---|---|
7e6d3809 UD |
1 | /* Data structure for communication from the run-time dynamic linker for |
2 | loaded ELF shared objects. | |
f7a9f785 | 3 | Copyright (C) 1995-2016 Free Software Foundation, Inc. |
7e6d3809 UD |
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 | |
41bdb6e2 AJ |
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. | |
7e6d3809 UD |
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 | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
7e6d3809 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
7e6d3809 | 19 | |
d78efd9f RM |
20 | #ifndef _PRIVATE_LINK_H |
21 | #define _PRIVATE_LINK_H 1 | |
7e6d3809 | 22 | |
d78efd9f RM |
23 | #ifdef _LINK_H |
24 | # error this should be impossible | |
25 | #endif | |
26 | ||
27 | /* Get most of the contents from the public header, but we define a | |
28 | different `struct link_map' type for private use. The la_objopen | |
29 | prototype uses the type, so we have to declare it separately. */ | |
30 | #define link_map link_map_public | |
31 | #define la_objopen la_objopen_wrongproto | |
32 | #include <elf/link.h> | |
33 | #undef link_map | |
34 | #undef la_objopen | |
35 | ||
36 | struct link_map; | |
37 | extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid, | |
38 | uintptr_t *__cookie); | |
7e6d3809 | 39 | |
e054f494 | 40 | #include <stdint.h> |
d78efd9f | 41 | #include <stddef.h> |
522e02ab | 42 | #include <linkmap.h> |
c01ae97e | 43 | #include <dl-fileid.h> |
a334319f | 44 | #include <dl-lookupcfg.h> |
b52bbc1b | 45 | #include <tls.h> |
ec999b8e | 46 | #include <libc-lock.h> |
7e6d3809 | 47 | |
7e6d3809 UD |
48 | |
49 | /* Some internal data structures of the dynamic linker used in the | |
50 | linker map. We only provide forward declarations. */ | |
51 | struct libname_list; | |
52 | struct r_found_version; | |
53 | struct r_search_path_elem; | |
54 | ||
55 | /* Forward declaration. */ | |
56 | struct link_map; | |
57 | ||
58 | /* Structure to describe a single list of scope elements. The lookup | |
59 | functions get passed an array of pointers to such structures. */ | |
60 | struct r_scope_elem | |
61 | { | |
62 | /* Array of maps for the scope. */ | |
63 | struct link_map **r_list; | |
64 | /* Number of entries in the scope. */ | |
65 | unsigned int r_nlist; | |
7e6d3809 UD |
66 | }; |
67 | ||
68 | ||
f55727ca UD |
69 | /* Structure to record search path and allocation mechanism. */ |
70 | struct r_search_path_struct | |
71 | { | |
72 | struct r_search_path_elem **dirs; | |
73 | int malloced; | |
74 | }; | |
75 | ||
76 | ||
7e6d3809 UD |
77 | /* Structure describing a loaded shared object. The `l_next' and `l_prev' |
78 | members form a chain of all the shared objects loaded at startup. | |
79 | ||
80 | These data structures exist in space used by the run-time dynamic linker; | |
81 | modifying them may have disastrous results. | |
82 | ||
83 | This data structure might change in future, if necessary. User-level | |
84 | programs must avoid defining objects of this type. */ | |
85 | ||
86 | struct link_map | |
87 | { | |
88 | /* These first few members are part of the protocol with the debugger. | |
89 | This is the same format used in SVR4. */ | |
90 | ||
542f9466 JK |
91 | ElfW(Addr) l_addr; /* Difference between the address in the ELF |
92 | file and the addresses in memory. */ | |
7e6d3809 UD |
93 | char *l_name; /* Absolute file name object was found in. */ |
94 | ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */ | |
95 | struct link_map *l_next, *l_prev; /* Chain of loaded objects. */ | |
96 | ||
97 | /* All following members are internal to the dynamic linker. | |
98 | They may change without notice. */ | |
99 | ||
c0f62c56 UD |
100 | /* This is an element which is only ever different from a pointer to |
101 | the very same copy of this type for ld.so when it is used in more | |
102 | than one namespace. */ | |
103 | struct link_map *l_real; | |
104 | ||
105 | /* Number of the namespace this link map belongs to. */ | |
106 | Lmid_t l_ns; | |
107 | ||
7e6d3809 UD |
108 | struct libname_list *l_libname; |
109 | /* Indexed pointers to dynamic section. | |
110 | [0,DT_NUM) are indexed by the processor-independent tags. | |
111 | [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC. | |
32e6df36 UD |
112 | [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are |
113 | indexed by DT_VERSIONTAGIDX(tagvalue). | |
7e6d3809 | 114 | [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM, |
32e6df36 UD |
115 | DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by |
116 | DT_EXTRATAGIDX(tagvalue). | |
117 | [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM, | |
118 | DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are | |
119 | indexed by DT_VALTAGIDX(tagvalue) and | |
120 | [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM, | |
121 | DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM) | |
122 | are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>. */ | |
7e6d3809 UD |
123 | |
124 | ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM | |
11bf311e | 125 | + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM]; |
7e6d3809 UD |
126 | const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */ |
127 | ElfW(Addr) l_entry; /* Entry point location. */ | |
128 | ElfW(Half) l_phnum; /* Number of program header entries. */ | |
871b9158 | 129 | ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */ |
7e6d3809 UD |
130 | |
131 | /* Array of DT_NEEDED dependencies and their dependencies, in | |
132 | dependency order for symbol lookup (with and without | |
133 | duplicates). There is no entry before the dependencies have | |
134 | been loaded. */ | |
135 | struct r_scope_elem l_searchlist; | |
136 | ||
137 | /* We need a special searchlist to process objects marked with | |
138 | DT_SYMBOLIC. */ | |
139 | struct r_scope_elem l_symbolic_searchlist; | |
140 | ||
141 | /* Dependent object that first caused this object to be loaded. */ | |
142 | struct link_map *l_loader; | |
143 | ||
341c566f UD |
144 | /* Array with version names. */ |
145 | struct r_found_version *l_versions; | |
146 | unsigned int l_nversions; | |
147 | ||
7e6d3809 UD |
148 | /* Symbol hash table. */ |
149 | Elf_Symndx l_nbuckets; | |
871b9158 UD |
150 | Elf32_Word l_gnu_bitmask_idxbits; |
151 | Elf32_Word l_gnu_shift; | |
152 | const ElfW(Addr) *l_gnu_bitmask; | |
153 | union | |
154 | { | |
155 | const Elf32_Word *l_gnu_buckets; | |
156 | const Elf_Symndx *l_chain; | |
157 | }; | |
158 | union | |
159 | { | |
160 | const Elf32_Word *l_gnu_chain_zero; | |
161 | const Elf_Symndx *l_buckets; | |
162 | }; | |
7e6d3809 | 163 | |
c0f62c56 | 164 | unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */ |
7e6d3809 UD |
165 | enum /* Where this object came from. */ |
166 | { | |
167 | lt_executable, /* The main executable program. */ | |
168 | lt_library, /* Library needed by main executable. */ | |
169 | lt_loaded /* Extra run-time loaded shared object. */ | |
170 | } l_type:2; | |
171 | unsigned int l_relocated:1; /* Nonzero if object's relocations done. */ | |
172 | unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */ | |
173 | unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */ | |
174 | unsigned int l_reserved:2; /* Reserved for internal use. */ | |
175 | unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed | |
176 | to by `l_phdr' is allocated. */ | |
c91bc73e UD |
177 | unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in |
178 | the l_libname list. */ | |
a881e0a0 UD |
179 | unsigned int l_faked:1; /* Nonzero if this is a faked descriptor |
180 | without associated file. */ | |
adc12574 UD |
181 | unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls) |
182 | should be called on this link map | |
183 | when relocation finishes. */ | |
9dcafc55 UD |
184 | unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */ |
185 | unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module | |
186 | is interested in the PLT interception.*/ | |
20fe49b9 UD |
187 | unsigned int l_removed:1; /* Nozero if the object cannot be used anymore |
188 | since it is removed. */ | |
9be09e06 UD |
189 | unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are |
190 | mprotected or if no holes are present at | |
191 | all. */ | |
4ad43b62 UD |
192 | unsigned int l_symbolic_in_local_scope:1; /* Nonzero if l_local_scope |
193 | during LD_TRACE_PRELINKING=1 | |
194 | contains any DT_SYMBOLIC | |
195 | libraries. */ | |
0479b305 AS |
196 | unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be |
197 | freed, ie. not allocated with | |
198 | the dummy malloc in ld.so. */ | |
9dcafc55 | 199 | |
7e6d3809 | 200 | /* Collected information about own RPATH directories. */ |
f55727ca | 201 | struct r_search_path_struct l_rpath_dirs; |
7e6d3809 UD |
202 | |
203 | /* Collected results of relocation while profiling. */ | |
9dcafc55 UD |
204 | struct reloc_result |
205 | { | |
6aa10807 | 206 | DL_FIXUP_VALUE_TYPE addr; |
9dcafc55 UD |
207 | struct link_map *bound; |
208 | unsigned int boundndx; | |
209 | uint32_t enterexit; | |
210 | unsigned int flags; | |
211 | } *l_reloc_result; | |
7e6d3809 UD |
212 | |
213 | /* Pointer to the version information if available. */ | |
214 | ElfW(Versym) *l_versyms; | |
215 | ||
216 | /* String specifying the path where this object was found. */ | |
217 | const char *l_origin; | |
218 | ||
219 | /* Start and finish of memory map for this object. l_map_start | |
220 | need not be the same as l_addr. */ | |
221 | ElfW(Addr) l_map_start, l_map_end; | |
eec8b6ca UD |
222 | /* End of the executable part of the mapping. */ |
223 | ElfW(Addr) l_text_end; | |
7e6d3809 | 224 | |
b98e518f | 225 | /* Default array for 'l_scope'. */ |
c0a777e8 | 226 | struct r_scope_elem *l_scope_mem[4]; |
b98e518f UD |
227 | /* Size of array allocated for 'l_scope'. */ |
228 | size_t l_scope_max; | |
7e6d3809 | 229 | /* This is an array defining the lookup scope for this link map. |
c69136ae | 230 | There are initially at most three different scope lists. */ |
c0a777e8 | 231 | struct r_scope_elem **l_scope; |
7e6d3809 UD |
232 | |
233 | /* A similar array, this time only with the local scope. This is | |
234 | used occasionally. */ | |
235 | struct r_scope_elem *l_local_scope[2]; | |
236 | ||
237 | /* This information is kept to check for sure whether a shared | |
238 | object is the same as one already loaded. */ | |
c01ae97e | 239 | struct r_file_id l_file_id; |
7e6d3809 UD |
240 | |
241 | /* Collected information about own RUNPATH directories. */ | |
f55727ca | 242 | struct r_search_path_struct l_runpath_dirs; |
7e6d3809 UD |
243 | |
244 | /* List of object in order of the init and fini calls. */ | |
245 | struct link_map **l_initfini; | |
246 | ||
247 | /* List of the dependencies introduced through symbol binding. */ | |
385b4cf4 UD |
248 | struct link_map_reldeps |
249 | { | |
250 | unsigned int act; | |
251 | struct link_map *list[]; | |
252 | } *l_reldeps; | |
2af63968 UD |
253 | unsigned int l_reldepsmax; |
254 | ||
255 | /* Nonzero if the DSO is used. */ | |
256 | unsigned int l_used; | |
bf8b3e74 UD |
257 | |
258 | /* Various flag words. */ | |
259 | ElfW(Word) l_feature_1; | |
260 | ElfW(Word) l_flags_1; | |
ec70c011 | 261 | ElfW(Word) l_flags; |
69c33254 UD |
262 | |
263 | /* Temporarily used in `dl_close'. */ | |
20fe49b9 | 264 | int l_idx; |
370f00c3 UD |
265 | |
266 | struct link_map_machine l_mach; | |
680254fe UD |
267 | |
268 | struct | |
269 | { | |
270 | const ElfW(Sym) *sym; | |
cf5a372e | 271 | int type_class; |
680254fe | 272 | struct link_map *value; |
680254fe UD |
273 | const ElfW(Sym) *ret; |
274 | } l_lookup_cache; | |
5d6feea8 UD |
275 | |
276 | /* Thread-local storage related info. */ | |
277 | ||
5d6feea8 UD |
278 | /* Start of the initialization image. */ |
279 | void *l_tls_initimage; | |
280 | /* Size of the initialization image. */ | |
281 | size_t l_tls_initimage_size; | |
282 | /* Size of the TLS block. */ | |
283 | size_t l_tls_blocksize; | |
877e0d8e | 284 | /* Alignment requirement of the TLS block. */ |
3fb55878 | 285 | size_t l_tls_align; |
99fe3b0e UD |
286 | /* Offset of first byte module alignment. */ |
287 | size_t l_tls_firstbyte_offset; | |
11bf311e UD |
288 | #ifndef NO_TLS_OFFSET |
289 | # define NO_TLS_OFFSET 0 | |
4c533566 UD |
290 | #endif |
291 | #ifndef FORCED_DYNAMIC_TLS_OFFSET | |
292 | # if NO_TLS_OFFSET == 0 | |
67cbf9a2 | 293 | # define FORCED_DYNAMIC_TLS_OFFSET -1 |
4c533566 UD |
294 | # elif NO_TLS_OFFSET == -1 |
295 | # define FORCED_DYNAMIC_TLS_OFFSET -2 | |
296 | # else | |
297 | # error "FORCED_DYNAMIC_TLS_OFFSET is not defined" | |
298 | # endif | |
11bf311e | 299 | #endif |
5d6feea8 UD |
300 | /* For objects present at startup time: offset in the static TLS block. */ |
301 | ptrdiff_t l_tls_offset; | |
302 | /* Index of the module in the dtv array. */ | |
303 | size_t l_tls_modid; | |
ed20b3d9 | 304 | |
90b37cac SP |
305 | /* Number of thread_local objects constructed by this DSO. This is |
306 | atomically accessed and modified and is not always protected by the load | |
307 | lock. See also: CONCURRENCY NOTES in cxa_thread_atexit_impl.c. */ | |
ba384f6e SP |
308 | size_t l_tls_dtor_count; |
309 | ||
ed20b3d9 UD |
310 | /* Information used to change permission after the relocations are |
311 | done. */ | |
312 | ElfW(Addr) l_relro_addr; | |
313 | size_t l_relro_size; | |
9dcafc55 | 314 | |
b90395e6 UD |
315 | unsigned long long int l_serial; |
316 | ||
9dcafc55 UD |
317 | /* Audit information. This array apparent must be the last in the |
318 | structure. Never add something after it. */ | |
319 | struct auditstate | |
320 | { | |
321 | uintptr_t cookie; | |
322 | unsigned int bindflags; | |
323 | } l_audit[0]; | |
324 | }; | |
325 | ||
9dcafc55 UD |
326 | |
327 | #if __ELF_NATIVE_CLASS == 32 | |
328 | # define symbind symbind32 | |
9dcafc55 UD |
329 | #elif __ELF_NATIVE_CLASS == 64 |
330 | # define symbind symbind64 | |
331 | #else | |
332 | # error "__ELF_NATIVE_CLASS must be defined" | |
333 | #endif | |
334 | ||
48ab1c2f UD |
335 | extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, |
336 | size_t size, void *data), | |
337 | void *data); | |
338 | ||
81b035fe L |
339 | /* We use this macro to refer to ELF macros independent of the native |
340 | wordsize. `ELFW(R_TYPE)' is used in place of `ELF32_R_TYPE' or | |
341 | `ELF64_R_TYPE'. */ | |
342 | #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type) | |
343 | ||
d78efd9f | 344 | #endif /* include/link.h */ |