Prepare use if IFUNC functions outside libc.so.
[platform/upstream/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-2006, 2007 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>
46 #include <bits/libc-lock.h>
47
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;
66 };
67
68
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
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
91     ElfW(Addr) l_addr;          /* Base address shared object is loaded at.  */
92     char *l_name;               /* Absolute file name object was found in.  */
93     ElfW(Dyn) *l_ld;            /* Dynamic section of the shared object.  */
94     struct link_map *l_next, *l_prev; /* Chain of loaded objects.  */
95
96     /* All following members are internal to the dynamic linker.
97        They may change without notice.  */
98
99     /* This is an element which is only ever different from a pointer to
100        the very same copy of this type for ld.so when it is used in more
101        than one namespace.  */
102     struct link_map *l_real;
103
104     /* Number of the namespace this link map belongs to.  */
105     Lmid_t l_ns;
106
107     struct libname_list *l_libname;
108     /* Indexed pointers to dynamic section.
109        [0,DT_NUM) are indexed by the processor-independent tags.
110        [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
111        [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are
112        indexed by DT_VERSIONTAGIDX(tagvalue).
113        [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
114         DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by
115        DT_EXTRATAGIDX(tagvalue).
116        [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM,
117         DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are
118        indexed by DT_VALTAGIDX(tagvalue) and
119        [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM,
120         DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM)
121        are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>.  */
122
123     ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
124                       + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
125     const ElfW(Phdr) *l_phdr;   /* Pointer to program header table in core.  */
126     ElfW(Addr) l_entry;         /* Entry point location.  */
127     ElfW(Half) l_phnum;         /* Number of program header entries.  */
128     ElfW(Half) l_ldnum;         /* Number of dynamic segment entries.  */
129
130     /* Array of DT_NEEDED dependencies and their dependencies, in
131        dependency order for symbol lookup (with and without
132        duplicates).  There is no entry before the dependencies have
133        been loaded.  */
134     struct r_scope_elem l_searchlist;
135
136     /* We need a special searchlist to process objects marked with
137        DT_SYMBOLIC.  */
138     struct r_scope_elem l_symbolic_searchlist;
139
140     /* Dependent object that first caused this object to be loaded.  */
141     struct link_map *l_loader;
142
143     /* Array with version names.  */
144     struct r_found_version *l_versions;
145     unsigned int l_nversions;
146
147     /* Symbol hash table.  */
148     Elf_Symndx l_nbuckets;
149     Elf32_Word l_gnu_bitmask_idxbits;
150     Elf32_Word l_gnu_shift;
151     const ElfW(Addr) *l_gnu_bitmask;
152     union
153     {
154       const Elf32_Word *l_gnu_buckets;
155       const Elf_Symndx *l_chain;
156     };
157     union
158     {
159       const Elf32_Word *l_gnu_chain_zero;
160       const Elf_Symndx *l_buckets;
161     };
162
163     unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose.  */
164     enum                        /* Where this object came from.  */
165       {
166         lt_executable,          /* The main executable program.  */
167         lt_library,             /* Library needed by main executable.  */
168         lt_loaded               /* Extra run-time loaded shared object.  */
169       } l_type:2;
170     unsigned int l_relocated:1; /* Nonzero if object's relocations done.  */
171     unsigned int l_init_called:1; /* Nonzero if DT_INIT function called.  */
172     unsigned int l_global:1;    /* Nonzero if object in _dl_global_scope.  */
173     unsigned int l_reserved:2;  /* Reserved for internal use.  */
174     unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
175                                         to by `l_phdr' is allocated.  */
176     unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
177                                       the l_libname list.  */
178     unsigned int l_faked:1;     /* Nonzero if this is a faked descriptor
179                                    without associated file.  */
180     unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
181                                        should be called on this link map
182                                        when relocation finishes.  */
183     unsigned int l_used:1;      /* Nonzero if the DSO is used.  */
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.*/
187     unsigned int l_removed:1;   /* Nozero if the object cannot be used anymore
188                                    since it is removed.  */
189     unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are
190                                     mprotected or if no holes are present at
191                                     all.  */
192
193     /* Collected information about own RPATH directories.  */
194     struct r_search_path_struct l_rpath_dirs;
195
196     /* Collected results of relocation while profiling.  */
197     struct reloc_result
198     {
199       DL_FIXUP_VALUE_TYPE addr;
200       struct link_map *bound;
201       unsigned int boundndx;
202       uint32_t enterexit;
203       unsigned int flags;
204     } *l_reloc_result;
205
206     /* Pointer to the version information if available.  */
207     ElfW(Versym) *l_versyms;
208
209     /* String specifying the path where this object was found.  */
210     const char *l_origin;
211
212     /* Start and finish of memory map for this object.  l_map_start
213        need not be the same as l_addr.  */
214     ElfW(Addr) l_map_start, l_map_end;
215     /* End of the executable part of the mapping.  */
216     ElfW(Addr) l_text_end;
217
218     /* Default array for 'l_scope'.  */
219     struct r_scope_elem *l_scope_mem[4];
220     /* Size of array allocated for 'l_scope'.  */
221     size_t l_scope_max;
222     /* This is an array defining the lookup scope for this link map.
223        There are initially at most three different scope lists.  */
224     struct r_scope_elem **l_scope;
225
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];
229
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;
234
235     /* Collected information about own RUNPATH directories.  */
236     struct r_search_path_struct l_runpath_dirs;
237
238     /* List of object in order of the init and fini calls.  */
239     struct link_map **l_initfini;
240
241     /* List of the dependencies introduced through symbol binding.  */
242     unsigned int l_reldepsmax;
243     struct link_map_reldeps
244       {
245         unsigned int act;
246         struct link_map *list[];
247       } *l_reldeps;
248
249     /* Various flag words.  */
250     ElfW(Word) l_feature_1;
251     ElfW(Word) l_flags_1;
252     ElfW(Word) l_flags;
253
254     /* Temporarily used in `dl_close'.  */
255     int l_idx;
256
257     struct link_map_machine l_mach;
258
259     struct
260     {
261       const ElfW(Sym) *sym;
262       int type_class;
263       struct link_map *value;
264       const ElfW(Sym) *ret;
265     } l_lookup_cache;
266
267     /* Thread-local storage related info.  */
268
269     /* Start of the initialization image.  */
270     void *l_tls_initimage;
271     /* Size of the initialization image.  */
272     size_t l_tls_initimage_size;
273     /* Size of the TLS block.  */
274     size_t l_tls_blocksize;
275     /* Alignment requirement of the TLS block.  */
276     size_t l_tls_align;
277     /* Offset of first byte module alignment.  */
278     size_t l_tls_firstbyte_offset;
279 #ifndef NO_TLS_OFFSET
280 # define NO_TLS_OFFSET  0
281 #endif
282 #ifndef FORCED_DYNAMIC_TLS_OFFSET
283 # if NO_TLS_OFFSET == 0
284 #  define FORCED_DYNAMIC_TLS_OFFSET 1
285 # elif NO_TLS_OFFSET == -1
286 #  define FORCED_DYNAMIC_TLS_OFFSET -2
287 # else
288 #  error "FORCED_DYNAMIC_TLS_OFFSET is not defined"
289 # endif
290 #endif
291     /* For objects present at startup time: offset in the static TLS block.  */
292     ptrdiff_t l_tls_offset;
293     /* Index of the module in the dtv array.  */
294     size_t l_tls_modid;
295
296     /* Information used to change permission after the relocations are
297        done.  */
298     ElfW(Addr) l_relro_addr;
299     size_t l_relro_size;
300
301     unsigned long long int l_serial;
302
303     /* Audit information.  This array apparent must be the last in the
304        structure.  Never add something after it.  */
305     struct auditstate
306     {
307       uintptr_t cookie;
308       unsigned int bindflags;
309     } l_audit[0];
310   };
311
312
313 #if __ELF_NATIVE_CLASS == 32
314 # define symbind symbind32
315 #elif __ELF_NATIVE_CLASS == 64
316 # define symbind symbind64
317 #else
318 # error "__ELF_NATIVE_CLASS must be defined"
319 #endif
320
321 extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
322                                                size_t size, void *data),
323                               void *data);
324
325 #endif /* include/link.h */