[BZ #3427]
[glibc.git] / include / link.h
blobb45deabf7f6b029073908217ec70bb48a4c64c92
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.
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 _PRIVATE_LINK_H
22 #define _PRIVATE_LINK_H 1
24 #ifdef _LINK_H
25 # error this should be impossible
26 #endif
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
37 struct link_map;
38 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
39 uintptr_t *__cookie);
42 #include <stddef.h>
43 #include <bits/linkmap.h>
44 #include <dl-lookupcfg.h>
45 #include <tls.h>
46 #include <bits/libc-lock.h>
47 #include <rtld-lowlevel.h>
50 /* Some internal data structures of the dynamic linker used in the
51 linker map. We only provide forward declarations. */
52 struct libname_list;
53 struct r_found_version;
54 struct r_search_path_elem;
56 /* Forward declaration. */
57 struct link_map;
59 /* Structure to describe a single list of scope elements. The lookup
60 functions get passed an array of pointers to such structures. */
61 struct r_scope_elem
63 /* Array of maps for the scope. */
64 struct link_map **r_list;
65 /* Number of entries in the scope. */
66 unsigned int r_nlist;
70 /* Structure to record search path and allocation mechanism. */
71 struct r_search_path_struct
73 struct r_search_path_elem **dirs;
74 int malloced;
78 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
79 members form a chain of all the shared objects loaded at startup.
81 These data structures exist in space used by the run-time dynamic linker;
82 modifying them may have disastrous results.
84 This data structure might change in future, if necessary. User-level
85 programs must avoid defining objects of this type. */
87 struct link_map
89 /* These first few members are part of the protocol with the debugger.
90 This is the same format used in SVR4. */
92 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
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. */
97 /* All following members are internal to the dynamic linker.
98 They may change without notice. */
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;
105 /* Number of the namespace this link map belongs to. */
106 Lmid_t l_ns;
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.
112 [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
113 indexed by DT_VERSIONTAGIDX(tagvalue).
114 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
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>. */
124 ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
125 + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
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. */
129 ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */
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;
137 /* We need a special searchlist to process objects marked with
138 DT_SYMBOLIC. */
139 struct r_scope_elem l_symbolic_searchlist;
141 /* Dependent object that first caused this object to be loaded. */
142 struct link_map *l_loader;
144 /* Symbol hash table. */
145 Elf_Symndx l_nbuckets;
146 Elf32_Word l_gnu_bitmask_idxbits;
147 Elf32_Word l_gnu_shift;
148 const ElfW(Addr) *l_gnu_bitmask;
149 union
151 const Elf32_Word *l_gnu_buckets;
152 const Elf_Symndx *l_chain;
154 union
156 const Elf32_Word *l_gnu_chain_zero;
157 const Elf_Symndx *l_buckets;
160 unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */
161 enum /* Where this object came from. */
163 lt_executable, /* The main executable program. */
164 lt_library, /* Library needed by main executable. */
165 lt_loaded /* Extra run-time loaded shared object. */
166 } l_type:2;
167 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
168 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
169 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
170 unsigned int l_reserved:2; /* Reserved for internal use. */
171 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
172 to by `l_phdr' is allocated. */
173 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
174 the l_libname list. */
175 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
176 without associated file. */
177 unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
178 should be called on this link map
179 when relocation finishes. */
180 unsigned int l_used:1; /* Nonzero if the DSO is used. */
181 unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */
182 unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
183 is interested in the PLT interception.*/
184 unsigned int l_removed:1; /* Nozero if the object cannot be used anymore
185 since it is removed. */
187 /* Array with version names. */
188 unsigned int l_nversions;
189 struct r_found_version *l_versions;
191 /* Collected information about own RPATH directories. */
192 struct r_search_path_struct l_rpath_dirs;
194 /* Collected results of relocation while profiling. */
195 struct reloc_result
197 DL_FIXUP_VALUE_TYPE addr;
198 struct link_map *bound;
199 unsigned int boundndx;
200 uint32_t enterexit;
201 unsigned int flags;
202 } *l_reloc_result;
204 /* Pointer to the version information if available. */
205 ElfW(Versym) *l_versyms;
207 /* String specifying the path where this object was found. */
208 const char *l_origin;
210 /* Start and finish of memory map for this object. l_map_start
211 need not be the same as l_addr. */
212 ElfW(Addr) l_map_start, l_map_end;
213 /* End of the executable part of the mapping. */
214 ElfW(Addr) l_text_end;
216 /* Default array for 'l_scope'. */
217 struct r_scope_elem *l_scope_mem[4];
218 /* Size of array allocated for 'l_scope'. */
219 size_t l_scope_max;
220 /* This is an array defining the lookup scope for this link map.
221 There are initially at most three different scope lists. */
222 struct r_scope_elem **l_scope;
223 /* We need to protect using the SCOPEREC. */
224 __rtld_mrlock_define (, l_scope_lock)
226 /* A similar array, this time only with the local scope. This is
227 used occasionally. */
228 struct r_scope_elem *l_local_scope[2];
230 /* This information is kept to check for sure whether a shared
231 object is the same as one already loaded. */
232 dev_t l_dev;
233 ino64_t l_ino;
235 /* Collected information about own RUNPATH directories. */
236 struct r_search_path_struct l_runpath_dirs;
238 /* List of object in order of the init and fini calls. */
239 struct link_map **l_initfini;
241 /* List of the dependencies introduced through symbol binding. */
242 unsigned int l_reldepsmax;
243 unsigned int l_reldepsact;
244 struct link_map **l_reldeps;
246 /* Various flag words. */
247 ElfW(Word) l_feature_1;
248 ElfW(Word) l_flags_1;
249 ElfW(Word) l_flags;
251 /* Temporarily used in `dl_close'. */
252 int l_idx;
254 struct link_map_machine l_mach;
256 struct
258 const ElfW(Sym) *sym;
259 int type_class;
260 struct link_map *value;
261 const ElfW(Sym) *ret;
262 } l_lookup_cache;
264 /* Thread-local storage related info. */
266 /* Start of the initialization image. */
267 void *l_tls_initimage;
268 /* Size of the initialization image. */
269 size_t l_tls_initimage_size;
270 /* Size of the TLS block. */
271 size_t l_tls_blocksize;
272 /* Alignment requirement of the TLS block. */
273 size_t l_tls_align;
274 /* Offset of first byte module alignment. */
275 size_t l_tls_firstbyte_offset;
276 #ifndef NO_TLS_OFFSET
277 # define NO_TLS_OFFSET 0
278 #endif
279 /* For objects present at startup time: offset in the static TLS block. */
280 ptrdiff_t l_tls_offset;
281 /* Index of the module in the dtv array. */
282 size_t l_tls_modid;
284 /* Information used to change permission after the relocations are
285 done. */
286 ElfW(Addr) l_relro_addr;
287 size_t l_relro_size;
289 /* Audit information. This array apparent must be the last in the
290 structure. Never add something after it. */
291 struct auditstate
293 uintptr_t cookie;
294 unsigned int bindflags;
295 } l_audit[0];
299 #if __ELF_NATIVE_CLASS == 32
300 # define symbind symbind32
301 #elif __ELF_NATIVE_CLASS == 64
302 # define symbind symbind64
303 #else
304 # error "__ELF_NATIVE_CLASS must be defined"
305 #endif
307 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
308 size_t size, void *data),
309 void *data);
311 #endif /* include/link.h */