Adjusted.
[glibc/pb-stable.git] / include / link.h
blob5cb7f24dc88b3fec12ae8088f61e86d216928931
1 /* Data structure for communication from the run-time dynamic linker for
2 loaded ELF shared objects.
3 Copyright (C) 1995-1999, 2000 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef _LINK_H
22 #define _LINK_H 1
24 #include <features.h>
25 #include <elf.h>
26 #include <dlfcn.h>
27 #include <sys/types.h>
29 /* We use this macro to refer to ELF types independent of the native wordsize.
30 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
31 #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
32 #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
33 #define _ElfW_1(e,w,t) e##w##t
35 #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
37 /* Rendezvous structure used by the run-time dynamic linker to communicate
38 details of shared object loading to the debugger. If the executable's
39 dynamic section has a DT_DEBUG element, the run-time linker sets that
40 element's value to the address where this structure can be found. */
42 struct r_debug
44 int r_version; /* Version number for this protocol. */
46 struct link_map *r_map; /* Head of the chain of loaded objects. */
48 /* This is the address of a function internal to the run-time linker,
49 that will always be called when the linker begins to map in a
50 library or unmap it, and again when the mapping change is complete.
51 The debugger can set a breakpoint at this address if it wants to
52 notice shared object mapping changes. */
53 ElfW(Addr) r_brk;
54 enum
56 /* This state value describes the mapping change taking place when
57 the `r_brk' address is called. */
58 RT_CONSISTENT, /* Mapping change is complete. */
59 RT_ADD, /* Beginning to add a new object. */
60 RT_DELETE /* Beginning to remove an object mapping. */
61 } r_state;
63 ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
66 /* This is the instance of that structure used by the dynamic linker. */
67 extern struct r_debug _r_debug;
69 /* This symbol refers to the "dynamic structure" in the `.dynamic' section
70 of whatever module refers to `_DYNAMIC'. So, to find its own
71 `struct r_debug', a program could do:
72 for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
73 if (dyn->d_tag == DT_DEBUG)
74 r_debug = (struct r_debug *) dyn->d_un.d_ptr;
76 extern ElfW(Dyn) _DYNAMIC[];
79 /* Some internal data structures of the dynamic linker used in the
80 linker map. We only provide forward declarations. */
81 struct libname_list;
82 struct r_found_version;
83 struct r_search_path_elem;
85 /* Forward declaration. */
86 struct link_map;
88 /* Structure to describe a single list of scope elements. The lookup
89 functions get passed an array of pointers to such structures. */
90 struct r_scope_elem
92 /* Array of maps for the scope. */
93 struct link_map **r_list;
94 /* Number of entries in the scope. */
95 unsigned int r_nlist;
97 /* Array of maps which also includes duplicates. */
98 struct link_map **r_duplist;
99 /* Number of elements in this list. */
100 unsigned int r_nduplist;
104 /* Structure to record search path and allocation mechanism. */
105 struct r_search_path_struct
107 struct r_search_path_elem **dirs;
108 int malloced;
112 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
113 members form a chain of all the shared objects loaded at startup.
115 These data structures exist in space used by the run-time dynamic linker;
116 modifying them may have disastrous results.
118 This data structure might change in future, if necessary. User-level
119 programs must avoid defining objects of this type. */
121 struct link_map
123 /* These first few members are part of the protocol with the debugger.
124 This is the same format used in SVR4. */
126 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
127 char *l_name; /* Absolute file name object was found in. */
128 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
129 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
131 /* All following members are internal to the dynamic linker.
132 They may change without notice. */
134 struct libname_list *l_libname;
135 /* Indexed pointers to dynamic section.
136 [0,DT_NUM) are indexed by the processor-independent tags.
137 [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC.
138 [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_EXTRANUM) are indexed
139 by DT_EXTRATAGIDX(tagvalue) and
140 [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM,
141 DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM)
142 are indexed by DT_EXTRATAGIDX(tagvalue) (see <elf.h>). */
144 ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
145 + DT_EXTRANUM];
146 const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
147 ElfW(Addr) l_entry; /* Entry point location. */
148 ElfW(Half) l_phnum; /* Number of program header entries. */
149 ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */
151 /* Array of DT_NEEDED dependencies and their dependencies, in
152 dependency order for symbol lookup (with and without
153 duplicates). There is no entry before the dependencies have
154 been loaded. */
155 struct r_scope_elem l_searchlist;
157 /* We need a special searchlist to process objects marked with
158 DT_SYMBOLIC. */
159 struct r_scope_elem l_symbolic_searchlist;
161 /* Dependent object that first caused this object to be loaded. */
162 struct link_map *l_loader;
164 /* Symbol hash table. */
165 Elf_Symndx l_nbuckets;
166 const Elf_Symndx *l_buckets, *l_chain;
168 unsigned int l_opencount; /* Reference count for dlopen/dlclose. */
169 enum /* Where this object came from. */
171 lt_executable, /* The main executable program. */
172 lt_library, /* Library needed by main executable. */
173 lt_loaded /* Extra run-time loaded shared object. */
174 } l_type:2;
175 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
176 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
177 unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
178 unsigned int l_reserved:2; /* Reserved for internal use. */
179 unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
180 to by `l_phdr' is allocated. */
181 unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in
182 the l_libname list. */
183 unsigned int l_faked:1; /* Nonzero if this is a faked descriptor
184 without associated file. */
186 /* Array with version names. */
187 unsigned int l_nversions;
188 struct r_found_version *l_versions;
190 /* Collected information about own RPATH directories. */
191 struct r_search_path_struct l_rpath_dirs;
193 /* Collected results of relocation while profiling. */
194 ElfW(Addr) *l_reloc_result;
196 /* Pointer to the version information if available. */
197 ElfW(Versym) *l_versyms;
199 /* String specifying the path where this object was found. */
200 const char *l_origin;
202 /* Start and finish of memory map for this object. l_map_start
203 need not be the same as l_addr. */
204 ElfW(Addr) l_map_start, l_map_end;
206 /* This is an array defining the lookup scope for this link map.
207 There are at most three different scope lists. */
208 struct r_scope_elem *l_scope[4];
210 /* A similar array, this time only with the local scope. This is
211 used occasionally. */
212 struct r_scope_elem *l_local_scope[2];
214 /* This information is kept to check for sure whether a shared
215 object is the same as one already loaded. */
216 dev_t l_dev;
217 ino64_t l_ino;
219 /* Collected information about own RUNPATH directories. */
220 struct r_search_path_struct l_runpath_dirs;
222 /* List of object in order of the init and fini calls. */
223 struct link_map **l_initfini;
225 /* List of the dependencies introduced through symbol binding. */
226 unsigned int l_reldepsmax;
227 unsigned int l_reldepsact;
228 struct link_map **l_reldeps;
230 /* Various flag words. */
231 ElfW(Word) l_feature_1;
232 ElfW(Word) l_flags_1;
234 /* Temporarily used in `dl_close'. */
235 unsigned int l_idx;
238 #endif /* link.h */