1 /* vi: set sw=4 ts=4: */
3 * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
5 * GNU Lesser General Public License version 2.1 or later.
12 #define RTLD_NEXT ((void*)-1)
16 struct elf_resolve **init_fini;
17 unsigned long nlist; /* Number of entries in init_fini */
21 struct elf_resolve * dyn;
22 struct dyn_elf * next_handle; /* Used by dlopen et al. */
23 struct init_fini init_fini;
24 struct dyn_elf * next;
25 struct dyn_elf * prev;
29 /* Structure to describe a single list of scope elements. The lookup
30 functions get passed an array of pointers to such structures. */
32 struct elf_resolve **r_list; /* Array of maps for the scope. */
33 unsigned int r_nlist; /* Number of entries in the scope. */
34 struct r_scope_elem *next;
38 /* These entries must be in this order to be compatible with the interface used
39 by gdb to obtain the list of symbols. */
40 DL_LOADADDR_TYPE loadaddr; /* Base address shared object is loaded at. */
41 char *libname; /* Absolute file name object was found in. */
42 ElfW(Dyn) *dynamic_addr; /* Dynamic section of the shared object. */
43 struct elf_resolve * next;
44 struct elf_resolve * prev;
45 /* Nothing after this address is used by gdb. */
47 #if defined(USE_TLS) && USE_TLS
48 /* Thread-local storage related info. */
50 /* Start of the initialization image. */
51 void *l_tls_initimage;
52 /* Size of the initialization image. */
53 size_t l_tls_initimage_size;
54 /* Size of the TLS block. */
55 size_t l_tls_blocksize;
56 /* Alignment requirement of the TLS block. */
58 /* Offset of first byte module alignment. */
59 size_t l_tls_firstbyte_offset;
60 # ifndef NO_TLS_OFFSET
61 # define NO_TLS_OFFSET 0
63 /* For objects present at startup time: offset in the static TLS block. */
64 ptrdiff_t l_tls_offset;
65 /* Index of the module in the dtv array. */
67 /* Nonzero if _dl_init_static_tls should be called for this module */
68 unsigned int l_need_tls_init:1;
72 #ifdef __LDSO_STANDALONE_SUPPORT__
73 /* Store the entry point from the ELF header (e_entry) */
76 enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
77 /* This is the local scope of the shared object */
78 struct r_scope_elem symbol_scope;
79 unsigned short usage_count;
80 unsigned short int init_flag;
81 unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
84 #ifdef __LDSO_GNU_HASH_SUPPORT__
85 /* Data needed to support GNU hash style */
86 Elf32_Word l_gnu_bitmask_idxbits;
87 Elf32_Word l_gnu_shift;
88 const ElfW(Addr) *l_gnu_bitmask;
92 const Elf32_Word *l_gnu_chain_zero;
93 const Elf_Symndx *elf_buckets;
96 Elf_Symndx *elf_buckets;
99 struct init_fini_list *init_fini;
100 struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
102 * These are only used with ELF style shared libraries
106 #ifdef __LDSO_GNU_HASH_SUPPORT__
109 const Elf32_Word *l_gnu_buckets;
110 const Elf_Symndx *chains;
115 unsigned long dynamic_info[DYNAMIC_SIZE];
117 unsigned long n_phent;
120 ElfW(Addr) relro_addr;
123 dev_t st_dev; /* device */
124 ino_t st_ino; /* inode */
127 /* this is used to store the address of relocation data words, so
128 * we don't have to calculate it every time, which requires a divide */
129 unsigned long data_words;
133 /* Every loaded module holds a hashtable of function descriptors of
134 functions defined in it, such that it's easy to release the
135 memory when the module is dlclose()d. */
136 struct funcdesc_ht *funcdesc_ht;
140 #define RELOCS_DONE 0x000001
141 #define JMP_RELOCS_DONE 0x000002
142 #define INIT_FUNCS_CALLED 0x000004
143 #define FINI_FUNCS_CALLED 0x000008
144 #define DL_OPENED 0x000010
145 #define DL_RESERVED 0x000020
147 extern struct dyn_elf * _dl_symbol_tables;
148 extern struct elf_resolve * _dl_loaded_modules;
149 extern struct dyn_elf * _dl_handles;
151 extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
152 DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
153 unsigned long dynamic_addr, unsigned long dynamic_size);
155 /* Only need extra arg with some configurations */
156 #if !((defined(USE_TLS) && USE_TLS) || defined __FDPIC__)
157 # define _dl_lookup_hash(n, r, m, c, t) _dl_lookup_hash(n, r, m, c)
159 extern char *_dl_lookup_hash(const char *name, struct r_scope_elem *scope,
160 struct elf_resolve *mytpnt, int type_class,
161 struct elf_resolve **tpntp);
163 static __always_inline char *_dl_find_hash(const char *name, struct r_scope_elem *scope,
164 struct elf_resolve *mytpnt, int type_class,
165 struct elf_resolve **tpntp)
167 return _dl_lookup_hash(name, scope, mytpnt, type_class, tpntp);
170 extern int _dl_linux_dynamic_link(void);
172 extern char * _dl_library_path;
173 extern char * _dl_not_lazy;
175 static __inline__ int _dl_symbol(char * name)
177 if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
182 #define LD_ERROR_NOFILE 1
183 #define LD_ERROR_NOZERO 2
184 #define LD_ERROR_NOTELF 3
185 #define LD_ERROR_NOTMAGIC 4
186 #define LD_ERROR_NOTDYN 5
187 #define LD_ERROR_MMAP_FAILED 6
188 #define LD_ERROR_NODYNAMIC 7
189 #define LD_ERROR_TLS_FAILED 8
190 #define LD_WRONG_RELOCS 9
191 #define LD_BAD_HANDLE 10
192 #define LD_NO_SYMBOL 11
194 #endif /* _LD_HASH_H_ */