1 /* vi: set sw=4 ts=4: */ 2 /* 3 * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org> 4 * 5 * GNU Lesser General Public License version 2.1 or later. 6 */ 7 8 #ifndef _DL_HASH_H 9 #define _DL_HASH_H 10 11 #include "dl-hash-arch.h" 12 13 #ifndef RTLD_NEXT 14 #define RTLD_NEXT ((void*)-1) 15 #endif 16 17 struct init_fini { 18 struct elf_resolve **init_fini; 19 unsigned long nlist; /* Number of entries in init_fini */ 20 }; 21 22 struct dyn_elf { 23 struct elf_resolve * dyn; 24 struct dyn_elf * next_handle; /* Used by dlopen et al. */ 25 struct init_fini init_fini; 26 struct dyn_elf * next; 27 struct dyn_elf * prev; 28 }; 29 30 struct symbol_ref { 31 const ElfW(Sym) *sym; 32 struct elf_resolve *tpnt; 33 }; 34 35 /* Structure to describe a single list of scope elements. The lookup 36 functions get passed an array of pointers to such structures. */ 37 struct r_scope_elem { 38 struct elf_resolve **r_list; /* Array of maps for the scope. */ 39 unsigned int r_nlist; /* Number of entries in the scope. */ 40 struct r_scope_elem *next; 41 }; 42 43 struct elf_resolve { 44 /* These entries must be in this order to be compatible with the interface used 45 by gdb to obtain the list of symbols. */ 46 DL_LOADADDR_TYPE loadaddr; /* Base address shared object is loaded at. */ 47 char *libname; /* Absolute file name object was found in. */ 48 ElfW(Dyn) *dynamic_addr; /* Dynamic section of the shared object. */ 49 struct elf_resolve * next; 50 struct elf_resolve * prev; 51 /* Nothing after this address is used by gdb. */ 52 53 #if defined(USE_TLS) && USE_TLS 54 /* Thread-local storage related info. */ 55 56 /* Start of the initialization image. */ 57 void *l_tls_initimage; 58 /* Size of the initialization image. */ 59 size_t l_tls_initimage_size; 60 /* Size of the TLS block. */ 61 size_t l_tls_blocksize; 62 /* Alignment requirement of the TLS block. */ 63 size_t l_tls_align; 64 /* Offset of first byte module alignment. */ 65 size_t l_tls_firstbyte_offset; 66 # ifndef NO_TLS_OFFSET 67 # define NO_TLS_OFFSET 0 68 # endif 69 /* For objects present at startup time: offset in the static TLS block. */ 70 ptrdiff_t l_tls_offset; 71 /* Index of the module in the dtv array. */ 72 size_t l_tls_modid; 73 /* Nonzero if _dl_init_static_tls should be called for this module */ 74 unsigned int l_need_tls_init:1; 75 #endif 76 77 ElfW(Addr) mapaddr; 78 #ifdef __LDSO_STANDALONE_SUPPORT__ 79 /* Store the entry point from the ELF header (e_entry) */ 80 ElfW(Addr) l_entry; 81 #endif 82 enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype; 83 /* This is the local scope of the shared object */ 84 struct r_scope_elem symbol_scope; 85 unsigned short usage_count; 86 unsigned short int init_flag; 87 unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */ 88 Elf_Symndx nbucket; 89 90 #ifdef __LDSO_GNU_HASH_SUPPORT__ 91 /* Data needed to support GNU hash style */ 92 Elf32_Word l_gnu_bitmask_idxbits; 93 Elf32_Word l_gnu_shift; 94 const ElfW(Addr) *l_gnu_bitmask; 95 96 union 97 { 98 const Elf32_Word *l_gnu_chain_zero; 99 const Elf_Symndx *elf_buckets; 100 }; 101 #else 102 Elf_Symndx *elf_buckets; 103 #endif 104 105 struct init_fini_list *init_fini; 106 struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */ 107 /* 108 * These are only used with ELF style shared libraries 109 */ 110 Elf_Symndx nchain; 111 112 #ifdef __LDSO_GNU_HASH_SUPPORT__ 113 union 114 { 115 const Elf32_Word *l_gnu_buckets; 116 const Elf_Symndx *chains; 117 }; 118 #else 119 Elf_Symndx *chains; 120 #endif 121 unsigned long dynamic_info[DYNAMIC_SIZE]; 122 123 unsigned long n_phent; 124 ElfW(Phdr) * ppnt; 125 126 ElfW(Addr) relro_addr; 127 size_t relro_size; 128 129 dev_t st_dev; /* device */ 130 ino_t st_ino; /* inode */ 131 132 #ifdef __powerpc__ 133 /* this is used to store the address of relocation data words, so 134 * we don't have to calculate it every time, which requires a divide */ 135 unsigned long data_words; 136 #endif 137 138 #ifdef __FDPIC__ 139 /* Every loaded module holds a hashtable of function descriptors of 140 functions defined in it, such that it's easy to release the 141 memory when the module is dlclose()d. */ 142 struct funcdesc_ht *funcdesc_ht; 143 #endif 144 #ifdef __DSBT__ 145 /* Information for DSBT */ 146 void **dsbt_table; 147 unsigned long dsbt_size; 148 unsigned long dsbt_index; 149 #endif 150 struct link_map_arch l_arch; 151 }; 152 153 #define RELOCS_DONE 0x000001 154 #define JMP_RELOCS_DONE 0x000002 155 #define INIT_FUNCS_CALLED 0x000004 156 #define FINI_FUNCS_CALLED 0x000008 157 #define DL_OPENED 0x000010 158 #define DL_RESERVED 0x000020 159 160 extern struct dyn_elf * _dl_symbol_tables; 161 extern struct elf_resolve * _dl_loaded_modules; 162 extern struct dyn_elf * _dl_handles; 163 164 extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname, 165 DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info, 166 unsigned long dynamic_addr, unsigned long dynamic_size); 167 168 extern char *_dl_find_hash(const char *name, struct r_scope_elem *scope, 169 struct elf_resolve *mytpnt, int type_class, 170 struct symbol_ref *symbol); 171 172 extern char * _dl_library_path; 173 174 #define LD_ERROR_NOFILE 1 175 #define LD_ERROR_NOZERO 2 176 #define LD_ERROR_NOTELF 3 177 #define LD_ERROR_NOTMAGIC 4 178 #define LD_ERROR_NOTDYN 5 179 #define LD_ERROR_MMAP_FAILED 6 180 #define LD_ERROR_NODYNAMIC 7 181 #define LD_ERROR_TLS_FAILED 8 182 #define LD_WRONG_RELOCS 9 183 #define LD_BAD_HANDLE 10 184 #define LD_NO_SYMBOL 11 185 186 #endif /* _DL_HASH_H */ 187