Expand PMF_FN_* macros.
[netbsd-mini2440.git] / libexec / ld.elf_so / rtld.h
blob5579dee9edd68d81169c16fd0c78b8bb04df9329
1 /* $NetBSD: rtld.h,v 1.81 2009/09/24 21:21:34 pooka Exp $ */
3 /*
4 * Copyright 1996 John D. Polstra.
5 * Copyright 1996 Matt Thomas <matt@3am-software.com>
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by John Polstra.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef RTLD_H
35 #define RTLD_H
37 #include <dlfcn.h>
38 #include <stdbool.h>
39 #include <stddef.h>
40 #include <sys/param.h>
41 #include <sys/types.h>
42 #include <sys/queue.h>
43 #include <sys/exec_elf.h>
44 #include "rtldenv.h"
45 #include "link.h"
47 #if defined(_RTLD_SOURCE)
49 #ifndef RTLD_DEFAULT_LIBRARY_PATH
50 #define RTLD_DEFAULT_LIBRARY_PATH "/usr/lib"
51 #endif
52 #define _PATH_LD_HINTS "/etc/ld.so.conf"
54 extern size_t _rtld_pagesz;
56 #define round_down(x) ((x) & ~(_rtld_pagesz - 1))
57 #define round_up(x) round_down((x) + _rtld_pagesz - 1)
59 #define NEW(type) ((type *) xmalloc(sizeof(type)))
60 #define CNEW(type) ((type *) xcalloc(sizeof(type)))
62 #endif /* _RTLD_SOURCE */
65 * C++ has mandated the use of the following keywords for its new boolean
66 * type. We might as well follow their lead.
68 struct Struct_Obj_Entry;
70 typedef struct Struct_Objlist_Entry {
71 SIMPLEQ_ENTRY(Struct_Objlist_Entry) link;
72 struct Struct_Obj_Entry *obj;
73 } Objlist_Entry;
75 typedef SIMPLEQ_HEAD(Struct_Objlist, Struct_Objlist_Entry) Objlist;
77 typedef struct Struct_Needed_Entry {
78 struct Struct_Needed_Entry *next;
79 struct Struct_Obj_Entry *obj;
80 unsigned long name; /* Offset of name in string table */
81 } Needed_Entry;
83 typedef struct _rtld_search_path_t {
84 struct _rtld_search_path_t *sp_next;
85 const char *sp_path;
86 size_t sp_pathlen;
87 } Search_Path;
90 #define RTLD_MAX_ENTRY 10
91 #define RTLD_MAX_LIBRARY 4
92 #define RTLD_MAX_CTL 2
93 typedef struct _rtld_library_xform_t {
94 struct _rtld_library_xform_t *next;
95 char *name;
96 const char *ctlname;
97 struct {
98 char *value;
99 char *library[RTLD_MAX_LIBRARY];
100 } entry[RTLD_MAX_ENTRY];
101 } Library_Xform;
104 * Shared object descriptor.
106 * Items marked with "(%)" are dynamically allocated, and must be freed
107 * when the structure is destroyed.
110 #define RTLD_MAGIC 0xd550b87a
111 #define RTLD_VERSION 1
112 #define RTLD_MAIN 0x800
114 typedef struct Struct_Obj_Entry {
115 Elf32_Word magic; /* Magic number (sanity check) */
116 Elf32_Word version; /* Version number of struct format */
118 struct Struct_Obj_Entry *next;
119 char *path; /* Pathname of underlying file (%) */
120 int refcount;
121 int dl_refcount; /* Number of times loaded by dlopen */
123 /* These items are computed by map_object() or by digest_phdr(). */
124 caddr_t mapbase; /* Base address of mapped region */
125 size_t mapsize; /* Size of mapped region in bytes */
126 size_t textsize; /* Size of text segment in bytes */
127 Elf_Addr vaddrbase; /* Base address in shared object file */
128 caddr_t relocbase; /* Reloc const = mapbase - *vaddrbase */
129 Elf_Dyn *dynamic; /* Dynamic section */
130 caddr_t entry; /* Entry point */
131 const Elf_Phdr *__junk001;
132 size_t pathlen; /* Pathname length */
133 void *ehdr;
135 /* Items from the dynamic section. */
136 Elf_Addr *pltgot; /* PLTGOT table */
137 const Elf_Rel *rel; /* Relocation entries */
138 const Elf_Rel *rellim; /* Limit of Relocation entries */
139 const Elf_Rela *rela; /* Relocation entries */
140 const Elf_Rela *relalim; /* Limit of Relocation entries */
141 const Elf_Rel *pltrel; /* PLT relocation entries */
142 const Elf_Rel *pltrellim; /* Limit of PLT relocation entries */
143 const Elf_Rela *pltrela; /* PLT relocation entries */
144 const Elf_Rela *pltrelalim; /* Limit of PLT relocation entries */
145 const Elf_Sym *symtab; /* Symbol table */
146 const char *strtab; /* String table */
147 unsigned long strsize; /* Size in bytes of string table */
148 #ifdef __mips__
149 Elf_Word local_gotno; /* Number of local GOT entries */
150 Elf_Word symtabno; /* Number of dynamic symbols */
151 Elf_Word gotsym; /* First dynamic symbol in GOT */
152 #endif
154 const Elf_Word *buckets; /* Hash table buckets array */
155 unsigned long nbuckets; /* Number of buckets */
156 const Elf_Word *chains; /* Hash table chain array */
157 unsigned long nchains; /* Number of chains */
159 Search_Path *rpaths; /* Search path specified in object */
160 Needed_Entry *needed; /* Shared objects needed by this (%) */
162 void (*init)(void); /* Initialization function to call */
163 void (*fini)(void); /* Termination function to call */
165 /* Entry points for dlopen() and friends. */
166 void *(*dlopen)(const char *, int);
167 void *(*dlsym)(void *, const char *);
168 char *(*dlerror)(void);
169 int (*dlclose)(void *);
170 int (*dladdr)(const void *, Dl_info *);
171 int (*dlinfo)(void *, int, void *);
173 u_int32_t mainprog:1, /* True if this is the main program */
174 rtld:1, /* True if this is the dynamic linker */
175 textrel:1, /* True if there are relocations to
176 * text seg */
177 symbolic:1, /* True if generated with
178 * "-Bsymbolic" */
179 printed:1, /* True if ldd has printed it */
180 isdynamic:1, /* True if this is a pure PIC object */
181 mainref:1, /* True if on _rtld_list_main */
182 globalref:1, /* True if on _rtld_list_global */
183 init_done:1, /* True if .init has been added */
184 init_called:1, /* True if .init function has been
185 * called */
186 fini_called:1, /* True if .fini function has been
187 * called */
188 initfirst:1; /* True if object's .init/.fini take
189 * priority over others */
191 struct link_map linkmap; /* for GDB */
193 /* These items are computed by map_object() or by digest_phdr(). */
194 const char *interp; /* Pathname of the interpreter, if any */
195 Objlist dldags; /* Object belongs to these dlopened DAGs (%) */
196 Objlist dagmembers; /* DAG has these members (%) */
197 dev_t dev; /* Object's filesystem's device */
198 ino_t ino; /* Object's inode number */
199 } Obj_Entry;
201 #if defined(_RTLD_SOURCE)
203 extern struct r_debug _rtld_debug;
204 extern Search_Path *_rtld_default_paths;
205 extern Obj_Entry *_rtld_objlist;
206 extern Obj_Entry **_rtld_objtail;
207 extern Obj_Entry *_rtld_objmain;
208 extern Obj_Entry _rtld_objself;
209 extern Search_Path *_rtld_paths;
210 extern Library_Xform *_rtld_xforms;
211 extern bool _rtld_trust;
212 extern Objlist _rtld_list_global;
213 extern Objlist _rtld_list_main;
214 extern Elf_Sym _rtld_sym_zero;
216 /* rtld.c */
219 * We export these symbols using _rtld_symbol_lookup and is_exported.
221 char *dlerror(void);
222 void *dlopen(const char *, int);
223 void *dlsym(void *, const char *);
224 int dlclose(void *);
225 int dladdr(const void *, Dl_info *);
226 int dlinfo(void *, int, void *);
228 void _rtld_error(const char *, ...)
229 __attribute__((__format__(__printf__,1,2)));
230 void _rtld_die(void) __attribute__((__noreturn__));
231 void *_rtld_objmain_sym(const char *);
232 void _rtld_debug_state(void);
233 void _rtld_linkmap_add(Obj_Entry *);
234 void _rtld_linkmap_delete(Obj_Entry *);
235 void _rtld_objlist_push_head(Objlist *, Obj_Entry *);
236 void _rtld_objlist_push_tail(Objlist *, Obj_Entry *);
237 Objlist_Entry *_rtld_objlist_find(Objlist *, const Obj_Entry *);
239 /* expand.c */
240 size_t _rtld_expand_path(char *, size_t, const char *, const char *,\
241 const char *);
243 /* headers.c */
244 void _rtld_digest_dynamic(const char *, Obj_Entry *);
245 Obj_Entry *_rtld_digest_phdr(const Elf_Phdr *, int, caddr_t);
247 /* load.c */
248 Obj_Entry *_rtld_load_object(const char *, int);
249 int _rtld_load_needed_objects(Obj_Entry *, int);
250 int _rtld_preload(const char *);
252 /* path.c */
253 void _rtld_add_paths(const char *, Search_Path **, const char *);
254 void _rtld_process_hints(const char *, Search_Path **, Library_Xform **,
255 const char *);
256 int _rtld_sysctl(const char *, void *, size_t *);
258 /* reloc.c */
259 int _rtld_do_copy_relocations(const Obj_Entry *);
260 int _rtld_relocate_objects(Obj_Entry *, bool);
261 int _rtld_relocate_nonplt_objects(const Obj_Entry *);
262 int _rtld_relocate_plt_lazy(const Obj_Entry *);
263 int _rtld_relocate_plt_objects(const Obj_Entry *);
264 void _rtld_setup_pltgot(const Obj_Entry *);
266 /* search.c */
267 Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int);
269 /* symbol.c */
270 unsigned long _rtld_elf_hash(const char *);
271 const Elf_Sym *_rtld_symlook_obj(const char *, unsigned long,
272 const Obj_Entry *, bool);
273 const Elf_Sym *_rtld_find_symdef(unsigned long, const Obj_Entry *,
274 const Obj_Entry **, bool);
275 const Elf_Sym *_rtld_symlook_list(const char *, unsigned long,
276 const Objlist *, const Obj_Entry **, bool);
277 const Elf_Sym *_rtld_symlook_default(const char *, unsigned long,
278 const Obj_Entry *, const Obj_Entry **, bool);
279 const Elf_Sym *_rtld_symlook_needed(const char *, unsigned long,
280 const Needed_Entry *, const Obj_Entry **, bool);
282 /* map_object.c */
283 Obj_Entry *_rtld_map_object(const char *, int, const struct stat *);
284 void _rtld_obj_free(Obj_Entry *);
285 Obj_Entry *_rtld_obj_new(void);
287 /* function descriptors */
288 #ifdef __HAVE_FUNCTION_DESCRIPTORS
289 Elf_Addr _rtld_function_descriptor_alloc(const Obj_Entry *,
290 const Elf_Sym *, Elf_Addr);
291 const void *_rtld_function_descriptor_function(const void *);
292 #endif /* __HAVE_FUNCTION_DESCRIPTORS */
294 #endif /* _RTLD_SOURCE */
296 #endif /* RTLD_H */