1 |
2 |
drasko |
/* Data structure for communication from the run-time dynamic linker for
|
2 |
|
|
loaded ELF shared objects.
|
3 |
|
|
Copyright (C) 1995-2001, 2004, 2005, 2006 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 _LINK_H
|
22 |
|
|
#define _LINK_H 1
|
23 |
|
|
|
24 |
|
|
#include <features.h>
|
25 |
|
|
#include <elf.h>
|
26 |
|
|
#include <dlfcn.h>
|
27 |
|
|
#include <sys/types.h>
|
28 |
|
|
#if defined _LIBC && defined __UCLIBC_HAS_THREADS_NATIVE__
|
29 |
|
|
#include <tls.h>
|
30 |
|
|
#endif
|
31 |
|
|
|
32 |
|
|
/* We use this macro to refer to ELF types independent of the native wordsize.
|
33 |
|
|
`ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
|
34 |
|
|
#define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
|
35 |
|
|
#define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
|
36 |
|
|
#define _ElfW_1(e,w,t) e##w##t
|
37 |
|
|
|
38 |
|
|
#include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
|
39 |
|
|
|
40 |
|
|
/* Rendezvous structure used by the run-time dynamic linker to communicate
|
41 |
|
|
details of shared object loading to the debugger. If the executable's
|
42 |
|
|
dynamic section has a DT_DEBUG element, the run-time linker sets that
|
43 |
|
|
element's value to the address where this structure can be found. */
|
44 |
|
|
|
45 |
|
|
struct r_debug
|
46 |
|
|
{
|
47 |
|
|
int r_version; /* Version number for this protocol. */
|
48 |
|
|
|
49 |
|
|
struct link_map *r_map; /* Head of the chain of loaded objects. */
|
50 |
|
|
|
51 |
|
|
/* This is the address of a function internal to the run-time linker,
|
52 |
|
|
that will always be called when the linker begins to map in a
|
53 |
|
|
library or unmap it, and again when the mapping change is complete.
|
54 |
|
|
The debugger can set a breakpoint at this address if it wants to
|
55 |
|
|
notice shared object mapping changes. */
|
56 |
|
|
ElfW(Addr) r_brk;
|
57 |
|
|
enum
|
58 |
|
|
{
|
59 |
|
|
/* This state value describes the mapping change taking place when
|
60 |
|
|
the `r_brk' address is called. */
|
61 |
|
|
RT_CONSISTENT, /* Mapping change is complete. */
|
62 |
|
|
RT_ADD, /* Beginning to add a new object. */
|
63 |
|
|
RT_DELETE /* Beginning to remove an object mapping. */
|
64 |
|
|
} r_state;
|
65 |
|
|
|
66 |
|
|
ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
|
67 |
|
|
};
|
68 |
|
|
|
69 |
|
|
/* This is the instance of that structure used by the dynamic linker. */
|
70 |
|
|
extern struct r_debug _r_debug;
|
71 |
|
|
|
72 |
|
|
/* This symbol refers to the "dynamic structure" in the `.dynamic' section
|
73 |
|
|
of whatever module refers to `_DYNAMIC'. So, to find its own
|
74 |
|
|
`struct r_debug', a program could do:
|
75 |
|
|
for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
|
76 |
|
|
if (dyn->d_tag == DT_DEBUG)
|
77 |
|
|
r_debug = (struct r_debug *) dyn->d_un.d_ptr;
|
78 |
|
|
*/
|
79 |
|
|
extern ElfW(Dyn) _DYNAMIC[];
|
80 |
|
|
|
81 |
|
|
#ifdef __FDPIC__
|
82 |
|
|
# include <bits/elf-fdpic.h>
|
83 |
|
|
#endif
|
84 |
|
|
|
85 |
|
|
/* Structure describing a loaded shared object. The `l_next' and `l_prev'
|
86 |
|
|
members form a chain of all the shared objects loaded at startup.
|
87 |
|
|
|
88 |
|
|
These data structures exist in space used by the run-time dynamic linker;
|
89 |
|
|
modifying them may have disastrous results. */
|
90 |
|
|
|
91 |
|
|
struct link_map
|
92 |
|
|
{
|
93 |
|
|
/* These first few members are part of the protocol with the debugger.
|
94 |
|
|
This is the same format used in SVR4. */
|
95 |
|
|
|
96 |
|
|
#ifdef __FDPIC__
|
97 |
|
|
struct elf32_fdpic_loadaddr l_addr;
|
98 |
|
|
#else
|
99 |
|
|
ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
|
100 |
|
|
#endif
|
101 |
|
|
char *l_name; /* Absolute file name object was found in. */
|
102 |
|
|
ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
|
103 |
|
|
struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
|
104 |
|
|
|
105 |
|
|
#ifdef USE_TLS
|
106 |
|
|
/* Thread-local storage related info. */
|
107 |
|
|
|
108 |
|
|
/* Start of the initialization image. */
|
109 |
|
|
void *l_tls_initimage;
|
110 |
|
|
/* Size of the initialization image. */
|
111 |
|
|
size_t l_tls_initimage_size;
|
112 |
|
|
/* Size of the TLS block. */
|
113 |
|
|
size_t l_tls_blocksize;
|
114 |
|
|
/* Alignment requirement of the TLS block. */
|
115 |
|
|
size_t l_tls_align;
|
116 |
|
|
/* Offset of first byte module alignment. */
|
117 |
|
|
size_t l_tls_firstbyte_offset;
|
118 |
|
|
# ifndef NO_TLS_OFFSET
|
119 |
|
|
# define NO_TLS_OFFSET 0
|
120 |
|
|
# endif
|
121 |
|
|
/* For objects present at startup time: offset in the static TLS block. */
|
122 |
|
|
ptrdiff_t l_tls_offset;
|
123 |
|
|
/* Index of the module in the dtv array. */
|
124 |
|
|
size_t l_tls_modid;
|
125 |
|
|
/* Nonzero if _dl_init_static_tls should be called for this module */
|
126 |
|
|
unsigned int l_need_tls_init:1;
|
127 |
|
|
#endif
|
128 |
|
|
};
|
129 |
|
|
|
130 |
|
|
#ifdef __USE_GNU
|
131 |
|
|
|
132 |
|
|
#if 0
|
133 |
|
|
/* Version numbers for la_version handshake interface. */
|
134 |
|
|
#define LAV_CURRENT 1
|
135 |
|
|
|
136 |
|
|
/* Activity types signaled through la_activity. */
|
137 |
|
|
enum
|
138 |
|
|
{
|
139 |
|
|
LA_ACT_CONSISTENT, /* Link map consistent again. */
|
140 |
|
|
LA_ACT_ADD, /* New object will be added. */
|
141 |
|
|
LA_ACT_DELETE /* Objects will be removed. */
|
142 |
|
|
};
|
143 |
|
|
|
144 |
|
|
/* Values representing origin of name for dynamic loading. */
|
145 |
|
|
enum
|
146 |
|
|
{
|
147 |
|
|
LA_SER_ORIG = 0x01, /* Original name. */
|
148 |
|
|
LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
|
149 |
|
|
LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
|
150 |
|
|
LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
|
151 |
|
|
LA_SER_DEFAULT = 0x40, /* Default directory. */
|
152 |
|
|
LA_SER_SECURE = 0x80 /* Unused. */
|
153 |
|
|
};
|
154 |
|
|
|
155 |
|
|
/* Values for la_objopen return value. */
|
156 |
|
|
enum
|
157 |
|
|
{
|
158 |
|
|
LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
|
159 |
|
|
LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
|
160 |
|
|
};
|
161 |
|
|
|
162 |
|
|
/* Values for la_symbind flags parameter. */
|
163 |
|
|
enum
|
164 |
|
|
{
|
165 |
|
|
LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
|
166 |
|
|
LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
|
167 |
|
|
LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
|
168 |
|
|
LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
|
169 |
|
|
LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
|
170 |
|
|
la_symbind call. */
|
171 |
|
|
};
|
172 |
|
|
#endif
|
173 |
|
|
|
174 |
|
|
struct dl_phdr_info
|
175 |
|
|
{
|
176 |
|
|
#ifdef __FDPIC__
|
177 |
|
|
struct elf32_fdpic_loadaddr dlpi_addr;
|
178 |
|
|
#else
|
179 |
|
|
ElfW(Addr) dlpi_addr;
|
180 |
|
|
#endif
|
181 |
|
|
const char *dlpi_name;
|
182 |
|
|
const ElfW(Phdr) *dlpi_phdr;
|
183 |
|
|
ElfW(Half) dlpi_phnum;
|
184 |
|
|
|
185 |
|
|
#if 0
|
186 |
|
|
/* Note: Following members were introduced after the first
|
187 |
|
|
version of this structure was available. Check the SIZE
|
188 |
|
|
argument passed to the dl_iterate_phdr callback to determine
|
189 |
|
|
whether or not each later member is available. */
|
190 |
|
|
|
191 |
|
|
/* Incremented when a new object may have been added. */
|
192 |
|
|
unsigned long long int dlpi_adds;
|
193 |
|
|
/* Incremented when an object may have been removed. */
|
194 |
|
|
unsigned long long int dlpi_subs;
|
195 |
|
|
|
196 |
|
|
/* If there is a PT_TLS segment, its module ID as used in
|
197 |
|
|
TLS relocations, else zero. */
|
198 |
|
|
size_t dlpi_tls_modid;
|
199 |
|
|
|
200 |
|
|
/* The address of the calling thread's instance of this module's
|
201 |
|
|
PT_TLS segment, if it has one and it has been allocated
|
202 |
|
|
in the calling thread, otherwise a null pointer. */
|
203 |
|
|
void *dlpi_tls_data;
|
204 |
|
|
#endif
|
205 |
|
|
};
|
206 |
|
|
|
207 |
|
|
__BEGIN_DECLS
|
208 |
|
|
|
209 |
|
|
extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
|
210 |
|
|
size_t, void *),
|
211 |
|
|
void *__data);
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
#if 0
|
215 |
|
|
/* Prototypes for the ld.so auditing interfaces. These are not
|
216 |
|
|
defined anywhere in ld.so but instead have to be provided by the
|
217 |
|
|
auditing DSO. */
|
218 |
|
|
extern unsigned int la_version (unsigned int __version);
|
219 |
|
|
extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
|
220 |
|
|
extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
|
221 |
|
|
unsigned int __flag);
|
222 |
|
|
extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
|
223 |
|
|
uintptr_t *__cookie);
|
224 |
|
|
extern void la_preinit (uintptr_t *__cookie);
|
225 |
|
|
extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
|
226 |
|
|
uintptr_t *__refcook, uintptr_t *__defcook,
|
227 |
|
|
unsigned int *__flags, const char *__symname);
|
228 |
|
|
extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
|
229 |
|
|
uintptr_t *__refcook, uintptr_t *__defcook,
|
230 |
|
|
unsigned int *__flags, const char *__symname);
|
231 |
|
|
extern unsigned int la_objclose (uintptr_t *__cookie);
|
232 |
|
|
#endif
|
233 |
|
|
|
234 |
|
|
__END_DECLS
|
235 |
|
|
|
236 |
|
|
#endif
|
237 |
|
|
|
238 |
|
|
#endif /* link.h */
|