resolve.h revision 1.24
1/* $OpenBSD: resolve.h,v 1.24 2003/05/30 01:13:53 drahn Exp $ */ 2 3/* 4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed under OpenBSD by 17 * Per Fogelstrom, Opsycon AB, Sweden. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 */ 34 35#ifndef _RESOLVE_H_ 36#define _RESOLVE_H_ 37 38#include <link.h> 39 40struct load_list { 41 struct load_list *next; 42 void *start; 43 size_t size; 44 int prot; 45 Elf_Addr moff; 46 long foff; 47}; 48 49/* 50 * Structure describing a loaded object. 51 * The head of this struct must be compatible 52 * with struct link_map in sys/link.h 53 */ 54typedef struct elf_object { 55 Elf_Addr load_addr; /* Real load address */ 56 char *load_name; /* Pointer to object name */ 57 Elf_Dyn *load_dyn; /* Pointer to object dynamic data */ 58 struct elf_object *next; 59 struct elf_object *prev; 60/* End struct link_map compatible */ 61 Elf_Addr load_offs; /* Load offset from link address */ 62 63 struct load_list *load_list; 64 65 u_int32_t load_size; 66 Elf_Addr got_addr; 67 Elf_Addr got_start; 68 size_t got_size; 69 Elf_Addr plt_start; 70 size_t plt_size; 71 72 union { 73 u_long info[DT_NUM + DT_PROCNUM]; 74 struct { 75 Elf_Addr null; /* Not used */ 76 Elf_Addr needed; /* Not used */ 77 Elf_Addr pltrelsz; 78 Elf_Addr *pltgot; 79 Elf_Addr *hash; 80 const char *strtab; 81 const Elf_Sym *symtab; 82 Elf_RelA *rela; 83 Elf_Addr relasz; 84 Elf_Addr relaent; 85 Elf_Addr strsz; 86 Elf_Addr syment; 87 void (*init)(void); 88 void (*fini)(void); 89 const char *soname; 90 const char *rpath; 91 Elf_Addr symbolic; 92 Elf_Rel *rel; 93 Elf_Addr relsz; 94 Elf_Addr relent; 95 Elf_Addr pltrel; 96 Elf_Addr debug; 97 Elf_Addr textrel; 98 Elf_Addr jmprel; 99 Elf_Addr bind_now; 100 } u; 101 } Dyn; 102#define dyn Dyn.u 103 104 struct elf_object *dep_next; /* Shadow objects for resolve search */ 105 106 int status; 107#define STAT_RELOC_DONE 1 108#define STAT_GOT_DONE 2 109#define STAT_INIT_DONE 4 110 111 Elf_Phdr *phdrp; 112 int phdrc; 113 114 int refcount; 115 int obj_type; 116#define OBJTYPE_LDR 1 117#define OBJTYPE_EXE 2 118#define OBJTYPE_LIB 3 119#define OBJTYPE_DLO 4 120 121 Elf_Word *buckets; 122 u_int32_t nbuckets; 123 Elf_Word *chains; 124 u_int32_t nchains; 125 Elf_Dyn *dynamic; 126 127 struct dep_node *first_child; 128 struct dep_node *last_child; 129} elf_object_t; 130 131struct dep_node { 132 struct dep_node *next_sibling; 133 elf_object_t *data; 134}; 135 136extern void _dl_rt_resolve(void); 137 138extern elf_object_t *_dl_add_object(const char *objname, Elf_Dyn *dynp, 139 const u_long *, const int objtype, 140 const long laddr, const long loff); 141extern void _dl_remove_object(elf_object_t *object); 142 143extern elf_object_t *_dl_lookup_object(const char *objname); 144extern elf_object_t *_dl_load_shlib(const char *, elf_object_t *, int); 145extern void _dl_unload_shlib(elf_object_t *object); 146 147extern int _dl_md_reloc(elf_object_t *object, int rel, int relsz); 148extern void _dl_md_reloc_got(elf_object_t *object, int lazy); 149 150Elf_Addr _dl_find_symbol(const char *name, elf_object_t *startlook, 151 const Elf_Sym **ref, int flags, int sym_size, const char *module_name); 152/* 153 * defines for _dl_find_symbol() flag field, three bits of meaning 154 * myself - clear: search all objects, set: search only this object 155 * warnnotfound - clear: no warning, set: warn if not found 156 * inplt - clear: possible plt ref set: real matching function. 157 * 158 * inplt - due to how ELF handles function addresses in shared libraries 159 * &func may actually refer to the plt entry in the main program 160 * rather than the actual function address in the .so file. 161 * This rather bizarre behavior is documented in the SVR4 ABI. 162 * when getting the function address to relocate a PLT entry 163 * the 'real' function address is necessary, not the possible PLT address. 164 */ 165/* myself */ 166#define SYM_SEARCH_ALL 0 167#define SYM_SEARCH_SELF 1 168/* warnnotfound */ 169#define SYM_NOWARNNOTFOUND 0 170#define SYM_WARNNOTFOUND 2 171/* inplt */ 172#define SYM_NOTPLT 0 173#define SYM_PLT 4 174 175void _dl_rtld(elf_object_t *object); 176void _dl_call_init(elf_object_t *object); 177void _dl_link_sub(elf_object_t *dep, elf_object_t *p); 178 179extern elf_object_t *_dl_objects; 180extern elf_object_t *_dl_last_object; 181 182extern const char *_dl_progname; 183extern struct r_debug *_dl_debug_map; 184 185extern int _dl_pagesz; 186extern int _dl_errno; 187 188extern char *_dl_libpath; 189extern char *_dl_preload; 190extern char *_dl_bindnow; 191extern char *_dl_traceld; 192extern char *_dl_debug; 193 194#define DL_DEB(P) do { if (_dl_debug) _dl_printf P ; } while (0) 195 196#define DL_NOT_FOUND 1 197#define DL_CANT_OPEN 2 198#define DL_NOT_ELF 3 199#define DL_CANT_OPEN_REF 4 200#define DL_CANT_MMAP 5 201#define DL_NO_SYMBOL 6 202#define DL_INVALID_HANDLE 7 203#define DL_INVALID_CTL 8 204 205#define ELF_ROUND(x,malign) (((x) + (malign)-1) & ~((malign)-1)) 206#define ELF_TRUNC(x,malign) ((x) & ~((malign)-1)) 207 208#endif /* _RESOLVE_H_ */ 209