hurd: XFAIL appearance of sched_param and sched_priority from <sys/types.h>
[glibc.git] / include / link.h
blob5924594548e7ef820595217e7714f7994c533ec1
1 /* Data structure for communication from the run-time dynamic linker for
2 loaded ELF shared objects.
3 Copyright (C) 1995-2018 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, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _PRIVATE_LINK_H
21 #define _PRIVATE_LINK_H 1
23 #ifdef _LINK_H
24 # error this should be impossible
25 #endif
27 # ifndef _ISOMAC
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 # endif
35 #include <elf/link.h>
37 # ifndef _ISOMAC
39 #undef link_map
40 #undef la_objopen
42 struct link_map;
43 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
44 uintptr_t *__cookie);
46 #include <stdint.h>
47 #include <stddef.h>
48 #include <linkmap.h>
49 #include <dl-fileid.h>
50 #include <dl-lookupcfg.h>
51 #include <tls.h>
52 #include <libc-lock.h>
55 /* Some internal data structures of the dynamic linker used in the
56 linker map. We only provide forward declarations. */
57 struct libname_list;
58 struct r_found_version;
59 struct r_search_path_elem;
61 /* Forward declaration. */
62 struct link_map;
64 /* Structure to describe a single list of scope elements. The lookup
65 functions get passed an array of pointers to such structures. */
66 struct r_scope_elem
68 /* Array of maps for the scope. */
69 struct link_map **r_list;
70 /* Number of entries in the scope. */
71 unsigned int r_nlist;
75 /* Structure to record search path and allocation mechanism. */
76 struct r_search_path_struct
78 struct r_search_path_elem **dirs;
79 int malloced;
83 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
84 members form a chain of all the shared objects loaded at startup.
86 These data structures exist in space used by the run-time dynamic linker;
87 modifying them may have disastrous results.
89 This data structure might change in future, if necessary. User-level
90 programs must avoid defining objects of this type. */
92 struct link_map
94 /* These first few members are part of the protocol with the debugger.
95 This is the same format used in SVR4. */
97 ElfW(Addr) l_addr; /* Difference between the address in the ELF
98 file and the addresses in memory. */
99 char *l_name; /* Absolute file name object was found in. */
100 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
101 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
103 /* All following members are internal to the dynamic linker.
104 They may change without notice. */
106 /* This is an element which is only ever different from a pointer to
107 the very same copy of this type for ld.so when it is used in more
108 than one namespace. */
109 struct link_map *l_real;
111 /* Number of the namespace this link map belongs to. */
112 Lmid_t l_ns;
114 struct libname_list *l_libname;
115 /* Indexed pointers to dynamic section.
116 [0,DT_NUM) are indexed by the processor-independent tags.
117 [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
118 [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
119 indexed by DT_VERSIONTAGIDX(tagvalue).
120 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
121 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
122 DT_EXTRATAGIDX(tagvalue).
123 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
124 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
125 indexed by DT_VALTAGIDX(tagvalue) and
126 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
127 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
128 are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>. */
130 ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
131 + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
132 const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
133 ElfW(Addr) l_entry; /* Entry point location. */
134 ElfW(Half) l_phnum; /* Number of program header entries. */
135 ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */
137 /* Array of DT_NEEDED dependencies and their dependencies, in
138 dependency order for symbol lookup (with and without
139 duplicates). There is no entry before the dependencies have
140 been loaded. */
141 struct r_scope_elem l_searchlist;
143 /* We need a special searchlist to process objects marked with
144 DT_SYMBOLIC. */
145 struct r_scope_elem l_symbolic_searchlist;
147 /* Dependent object that first caused this object to be loaded. */
148 struct link_map *l_loader;
150 /* Array with version names. */
151 struct r_found_version *l_versions;
152 unsigned int l_nversions;
154 /* Symbol hash table. */
155 Elf_Symndx l_nbuckets;
156 Elf32_Word l_gnu_bitmask_idxbits;
157 Elf32_Word l_gnu_shift;
158 const ElfW(Addr) *l_gnu_bitmask;
159 union
161 const Elf32_Word *l_gnu_buckets;
162 const Elf_Symndx *l_chain;
164 union
166 const Elf32_Word *l_gnu_chain_zero;
167 const Elf_Symndx *l_buckets;
170 unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */
171 enum /* Where this object came from. */
173 lt_executable, /* The main executable program. */
174 lt_library, /* Library needed by main executable. */
175 lt_loaded /* Extra run-time loaded shared object. */
176 } l_type:2;
177 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
178 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
179 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
180 unsigned int l_reserved:2; /* Reserved for internal use. */
181 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
182 to by `l_phdr' is allocated. */
183 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
184 the l_libname list. */
185 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
186 without associated file. */
187 unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
188 should be called on this link map
189 when relocation finishes. */
190 unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */
191 unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
192 is interested in the PLT interception.*/
193 unsigned int l_removed:1; /* Nozero if the object cannot be used anymore
194 since it is removed. */
195 unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are
196 mprotected or if no holes are present at
197 all. */
198 unsigned int l_symbolic_in_local_scope:1; /* Nonzero if l_local_scope
199 during LD_TRACE_PRELINKING=1
200 contains any DT_SYMBOLIC
201 libraries. */
202 unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be
203 freed, ie. not allocated with
204 the dummy malloc in ld.so. */
206 #include <link_map.h>
208 /* Collected information about own RPATH directories. */
209 struct r_search_path_struct l_rpath_dirs;
211 /* Collected results of relocation while profiling. */
212 struct reloc_result
214 DL_FIXUP_VALUE_TYPE addr;
215 struct link_map *bound;
216 unsigned int boundndx;
217 uint32_t enterexit;
218 unsigned int flags;
219 } *l_reloc_result;
221 /* Pointer to the version information if available. */
222 ElfW(Versym) *l_versyms;
224 /* String specifying the path where this object was found. */
225 const char *l_origin;
227 /* Start and finish of memory map for this object. l_map_start
228 need not be the same as l_addr. */
229 ElfW(Addr) l_map_start, l_map_end;
230 /* End of the executable part of the mapping. */
231 ElfW(Addr) l_text_end;
233 /* Default array for 'l_scope'. */
234 struct r_scope_elem *l_scope_mem[4];
235 /* Size of array allocated for 'l_scope'. */
236 size_t l_scope_max;
237 /* This is an array defining the lookup scope for this link map.
238 There are initially at most three different scope lists. */
239 struct r_scope_elem **l_scope;
241 /* A similar array, this time only with the local scope. This is
242 used occasionally. */
243 struct r_scope_elem *l_local_scope[2];
245 /* This information is kept to check for sure whether a shared
246 object is the same as one already loaded. */
247 struct r_file_id l_file_id;
249 /* Collected information about own RUNPATH directories. */
250 struct r_search_path_struct l_runpath_dirs;
252 /* List of object in order of the init and fini calls. */
253 struct link_map **l_initfini;
255 /* List of the dependencies introduced through symbol binding. */
256 struct link_map_reldeps
258 unsigned int act;
259 struct link_map *list[];
260 } *l_reldeps;
261 unsigned int l_reldepsmax;
263 /* Nonzero if the DSO is used. */
264 unsigned int l_used;
266 /* Various flag words. */
267 ElfW(Word) l_feature_1;
268 ElfW(Word) l_flags_1;
269 ElfW(Word) l_flags;
271 /* Temporarily used in `dl_close'. */
272 int l_idx;
274 struct link_map_machine l_mach;
276 struct
278 const ElfW(Sym) *sym;
279 int type_class;
280 struct link_map *value;
281 const ElfW(Sym) *ret;
282 } l_lookup_cache;
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 #ifndef FORCED_DYNAMIC_TLS_OFFSET
300 # if NO_TLS_OFFSET == 0
301 # define FORCED_DYNAMIC_TLS_OFFSET -1
302 # elif NO_TLS_OFFSET == -1
303 # define FORCED_DYNAMIC_TLS_OFFSET -2
304 # else
305 # error "FORCED_DYNAMIC_TLS_OFFSET is not defined"
306 # endif
307 #endif
308 /* For objects present at startup time: offset in the static TLS block. */
309 ptrdiff_t l_tls_offset;
310 /* Index of the module in the dtv array. */
311 size_t l_tls_modid;
313 /* Number of thread_local objects constructed by this DSO. This is
314 atomically accessed and modified and is not always protected by the load
315 lock. See also: CONCURRENCY NOTES in cxa_thread_atexit_impl.c. */
316 size_t l_tls_dtor_count;
318 /* Information used to change permission after the relocations are
319 done. */
320 ElfW(Addr) l_relro_addr;
321 size_t l_relro_size;
323 unsigned long long int l_serial;
325 /* Audit information. This array apparent must be the last in the
326 structure. Never add something after it. */
327 struct auditstate
329 uintptr_t cookie;
330 unsigned int bindflags;
331 } l_audit[0];
335 #if __ELF_NATIVE_CLASS == 32
336 # define symbind symbind32
337 #elif __ELF_NATIVE_CLASS == 64
338 # define symbind symbind64
339 #else
340 # error "__ELF_NATIVE_CLASS must be defined"
341 #endif
343 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
344 size_t size, void *data),
345 void *data);
346 hidden_proto (__dl_iterate_phdr)
348 /* We use this macro to refer to ELF macros independent of the native
349 wordsize. `ELFW(R_TYPE)' is used in place of `ELF32_R_TYPE' or
350 `ELF64_R_TYPE'. */
351 #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
353 # endif /* !_ISOMAC */
354 #endif /* include/link.h */