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