]>
Commit | Line | Data |
---|---|---|
a853022c UD |
1 | /* Data structure for communication from the run-time dynamic linker for |
2 | loaded ELF shared objects. | |
6d7e8eda | 3 | Copyright (C) 1995-2023 Free Software Foundation, Inc. |
54d79e99 | 4 | This file is part of the GNU C Library. |
d66e34cd | 5 | |
54d79e99 | 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. | |
d66e34cd | 10 | |
54d79e99 UD |
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. |
d66e34cd | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
d66e34cd RM |
19 | |
20 | #ifndef _LINK_H | |
21 | #define _LINK_H 1 | |
5107cf1d | 22 | |
f166d865 | 23 | #include <features.h> |
d66e34cd | 24 | #include <elf.h> |
a2b08ee5 | 25 | #include <dlfcn.h> |
61e0617a | 26 | #include <sys/types.h> |
d66e34cd | 27 | |
266180eb RM |
28 | /* We use this macro to refer to ELF types independent of the native wordsize. |
29 | `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */ | |
567c63af | 30 | #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type) |
266180eb RM |
31 | #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t) |
32 | #define _ElfW_1(e,w,t) e##w##t | |
5107cf1d UD |
33 | |
34 | #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */ | |
9dcafc55 | 35 | #include <bits/link.h> |
d66e34cd | 36 | |
a93d9e03 L |
37 | /* The legacy rendezvous structure used by the run-time dynamic linker to |
38 | communicate details of shared object loading to the debugger. */ | |
d66e34cd RM |
39 | |
40 | struct r_debug | |
41 | { | |
a93d9e03 L |
42 | /* Version number for this protocol. It should be greater than 0. */ |
43 | int r_version; | |
d66e34cd RM |
44 | |
45 | struct link_map *r_map; /* Head of the chain of loaded objects. */ | |
46 | ||
47 | /* This is the address of a function internal to the run-time linker, | |
48 | that will always be called when the linker begins to map in a | |
49 | library or unmap it, and again when the mapping change is complete. | |
50 | The debugger can set a breakpoint at this address if it wants to | |
51 | notice shared object mapping changes. */ | |
266180eb | 52 | ElfW(Addr) r_brk; |
d66e34cd RM |
53 | enum |
54 | { | |
55 | /* This state value describes the mapping change taking place when | |
56 | the `r_brk' address is called. */ | |
57 | RT_CONSISTENT, /* Mapping change is complete. */ | |
58 | RT_ADD, /* Beginning to add a new object. */ | |
762a2918 | 59 | RT_DELETE /* Beginning to remove an object mapping. */ |
d66e34cd RM |
60 | } r_state; |
61 | ||
266180eb | 62 | ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */ |
d66e34cd RM |
63 | }; |
64 | ||
a93d9e03 | 65 | /* This is the symbol of that structure provided by the dynamic linker. */ |
4d6acc61 RM |
66 | extern struct r_debug _r_debug; |
67 | ||
a93d9e03 L |
68 | /* The extended rendezvous structure used by the run-time dynamic linker |
69 | to communicate details of shared object loading to the debugger. If | |
70 | the executable's dynamic section has a DT_DEBUG element, the run-time | |
71 | linker sets that element's value to the address where this structure | |
72 | can be found. */ | |
73 | ||
74 | struct r_debug_extended | |
75 | { | |
76 | struct r_debug base; | |
77 | ||
78 | /* The following field is added by r_version == 2. */ | |
79 | ||
80 | /* Link to the next r_debug_extended structure. Each r_debug_extended | |
81 | structure represents a different namespace. The first | |
82 | r_debug_extended structure is for the default namespace. */ | |
83 | struct r_debug_extended *r_next; | |
84 | }; | |
85 | ||
d66e34cd RM |
86 | /* This symbol refers to the "dynamic structure" in the `.dynamic' section |
87 | of whatever module refers to `_DYNAMIC'. So, to find its own | |
a93d9e03 | 88 | `struct r_debug_extended', a program could do: |
4a33c2f5 | 89 | for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) |
68337808 | 90 | if (dyn->d_tag == DT_DEBUG) |
a93d9e03 L |
91 | r_debug_extended = (struct r_debug_extended *) dyn->d_un.d_ptr; |
92 | */ | |
266180eb | 93 | extern ElfW(Dyn) _DYNAMIC[]; |
d66e34cd | 94 | |
d66e34cd RM |
95 | /* Structure describing a loaded shared object. The `l_next' and `l_prev' |
96 | members form a chain of all the shared objects loaded at startup. | |
97 | ||
98 | These data structures exist in space used by the run-time dynamic linker; | |
7e6d3809 | 99 | modifying them may have disastrous results. */ |
d66e34cd RM |
100 | |
101 | struct link_map | |
102 | { | |
103 | /* These first few members are part of the protocol with the debugger. | |
104 | This is the same format used in SVR4. */ | |
105 | ||
542f9466 JK |
106 | ElfW(Addr) l_addr; /* Difference between the address in the ELF |
107 | file and the addresses in memory. */ | |
d66e34cd | 108 | char *l_name; /* Absolute file name object was found in. */ |
266180eb | 109 | ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */ |
d66e34cd | 110 | struct link_map *l_next, *l_prev; /* Chain of loaded objects. */ |
d66e34cd | 111 | }; |
fd26970f | 112 | |
48ab1c2f UD |
113 | #ifdef __USE_GNU |
114 | ||
9dcafc55 | 115 | /* Version numbers for la_version handshake interface. */ |
54816ae9 | 116 | #include <bits/link_lavcurrent.h> |
9dcafc55 UD |
117 | |
118 | /* Activity types signaled through la_activity. */ | |
119 | enum | |
120 | { | |
121 | LA_ACT_CONSISTENT, /* Link map consistent again. */ | |
122 | LA_ACT_ADD, /* New object will be added. */ | |
123 | LA_ACT_DELETE /* Objects will be removed. */ | |
124 | }; | |
125 | ||
126 | /* Values representing origin of name for dynamic loading. */ | |
127 | enum | |
128 | { | |
129 | LA_SER_ORIG = 0x01, /* Original name. */ | |
130 | LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */ | |
131 | LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */ | |
132 | LA_SER_CONFIG = 0x08, /* Found through ldconfig. */ | |
133 | LA_SER_DEFAULT = 0x40, /* Default directory. */ | |
134 | LA_SER_SECURE = 0x80 /* Unused. */ | |
135 | }; | |
136 | ||
137 | /* Values for la_objopen return value. */ | |
138 | enum | |
139 | { | |
140 | LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */ | |
141 | LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */ | |
142 | }; | |
143 | ||
144 | /* Values for la_symbind flags parameter. */ | |
145 | enum | |
146 | { | |
147 | LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */ | |
148 | LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */ | |
149 | LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */ | |
150 | LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */ | |
151 | LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous | |
152 | la_symbind call. */ | |
153 | }; | |
154 | ||
48ab1c2f UD |
155 | struct dl_phdr_info |
156 | { | |
157 | ElfW(Addr) dlpi_addr; | |
158 | const char *dlpi_name; | |
159 | const ElfW(Phdr) *dlpi_phdr; | |
160 | ElfW(Half) dlpi_phnum; | |
bed12f78 | 161 | |
d78efd9f | 162 | /* Note: Following members were introduced after the first |
bed12f78 | 163 | version of this structure was available. Check the SIZE |
d78efd9f RM |
164 | argument passed to the dl_iterate_phdr callback to determine |
165 | whether or not each later member is available. */ | |
bed12f78 UD |
166 | |
167 | /* Incremented when a new object may have been added. */ | |
828beb13 | 168 | __extension__ unsigned long long int dlpi_adds; |
bed12f78 | 169 | /* Incremented when an object may have been removed. */ |
828beb13 | 170 | __extension__ unsigned long long int dlpi_subs; |
d78efd9f RM |
171 | |
172 | /* If there is a PT_TLS segment, its module ID as used in | |
173 | TLS relocations, else zero. */ | |
174 | size_t dlpi_tls_modid; | |
175 | ||
176 | /* The address of the calling thread's instance of this module's | |
177 | PT_TLS segment, if it has one and it has been allocated | |
178 | in the calling thread, otherwise a null pointer. */ | |
179 | void *dlpi_tls_data; | |
48ab1c2f UD |
180 | }; |
181 | ||
182 | __BEGIN_DECLS | |
183 | ||
9dcafc55 UD |
184 | extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *, |
185 | size_t, void *), | |
186 | void *__data); | |
187 | ||
188 | ||
189 | /* Prototypes for the ld.so auditing interfaces. These are not | |
190 | defined anywhere in ld.so but instead have to be provided by the | |
191 | auditing DSO. */ | |
192 | extern unsigned int la_version (unsigned int __version); | |
193 | extern void la_activity (uintptr_t *__cookie, unsigned int __flag); | |
194 | extern char *la_objsearch (const char *__name, uintptr_t *__cookie, | |
195 | unsigned int __flag); | |
196 | extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid, | |
197 | uintptr_t *__cookie); | |
198 | extern void la_preinit (uintptr_t *__cookie); | |
199 | extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx, | |
200 | uintptr_t *__refcook, uintptr_t *__defcook, | |
201 | unsigned int *__flags, const char *__symname); | |
202 | extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx, | |
203 | uintptr_t *__refcook, uintptr_t *__defcook, | |
204 | unsigned int *__flags, const char *__symname); | |
205 | extern unsigned int la_objclose (uintptr_t *__cookie); | |
48ab1c2f UD |
206 | |
207 | __END_DECLS | |
208 | ||
209 | #endif | |
210 | ||
d66e34cd | 211 | #endif /* link.h */ |