Add protected symbols support for all architectures
[uclibc-ng.git] / ldso / include / dl-hash.h
blobd1f9accc58c86ab2be9b86209035d0eba29d816f
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
5 * GNU Lesser General Public License version 2.1 or later.
6 */
8 #ifndef _LD_HASH_H_
9 #define _LD_HASH_H_
11 #ifndef RTLD_NEXT
12 #define RTLD_NEXT ((void*)-1)
13 #endif
15 struct init_fini {
16 struct elf_resolve **init_fini;
17 unsigned long nlist; /* Number of entries in init_fini */
20 struct dyn_elf {
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;
28 struct symbol_ref {
29 const ElfW(Sym) *sym;
30 struct elf_resolve *tpnt;
33 struct elf_resolve {
34 /* These entries must be in this order to be compatible with the interface used
35 by gdb to obtain the list of symbols. */
36 DL_LOADADDR_TYPE loadaddr; /* Base address shared object is loaded at. */
37 char *libname; /* Absolute file name object was found in. */
38 ElfW(Dyn) *dynamic_addr; /* Dynamic section of the shared object. */
39 struct elf_resolve * next;
40 struct elf_resolve * prev;
41 /* Nothing after this address is used by gdb. */
43 #if defined(USE_TLS) && USE_TLS
44 /* Thread-local storage related info. */
46 /* Start of the initialization image. */
47 void *l_tls_initimage;
48 /* Size of the initialization image. */
49 size_t l_tls_initimage_size;
50 /* Size of the TLS block. */
51 size_t l_tls_blocksize;
52 /* Alignment requirement of the TLS block. */
53 size_t l_tls_align;
54 /* Offset of first byte module alignment. */
55 size_t l_tls_firstbyte_offset;
56 # ifndef NO_TLS_OFFSET
57 # define NO_TLS_OFFSET 0
58 # endif
59 /* For objects present at startup time: offset in the static TLS block. */
60 ptrdiff_t l_tls_offset;
61 /* Index of the module in the dtv array. */
62 size_t l_tls_modid;
63 /* Nonzero if _dl_init_static_tls should be called for this module */
64 unsigned int l_need_tls_init:1;
65 #endif
67 ElfW(Addr) mapaddr;
68 enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
69 struct dyn_elf * symbol_scope;
70 unsigned short usage_count;
71 unsigned short int init_flag;
72 unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
73 Elf_Symndx nbucket;
75 #ifdef __LDSO_GNU_HASH_SUPPORT__
76 /* Data needed to support GNU hash style */
77 Elf32_Word l_gnu_bitmask_idxbits;
78 Elf32_Word l_gnu_shift;
79 const ElfW(Addr) *l_gnu_bitmask;
81 union
83 const Elf32_Word *l_gnu_chain_zero;
84 const Elf_Symndx *elf_buckets;
86 #else
87 Elf_Symndx *elf_buckets;
88 #endif
90 struct init_fini_list *init_fini;
91 struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
93 * These are only used with ELF style shared libraries
95 Elf_Symndx nchain;
97 #ifdef __LDSO_GNU_HASH_SUPPORT__
98 union
100 const Elf32_Word *l_gnu_buckets;
101 const Elf_Symndx *chains;
103 #else
104 Elf_Symndx *chains;
105 #endif
106 unsigned long dynamic_info[DYNAMIC_SIZE];
108 unsigned long n_phent;
109 ElfW(Phdr) * ppnt;
111 ElfW(Addr) relro_addr;
112 size_t relro_size;
114 dev_t st_dev; /* device */
115 ino_t st_ino; /* inode */
117 #ifdef __powerpc__
118 /* this is used to store the address of relocation data words, so
119 * we don't have to calculate it every time, which requires a divide */
120 unsigned long data_words;
121 #endif
123 #ifdef __FDPIC__
124 /* Every loaded module holds a hashtable of function descriptors of
125 functions defined in it, such that it's easy to release the
126 memory when the module is dlclose()d. */
127 struct funcdesc_ht *funcdesc_ht;
128 #endif
131 #define RELOCS_DONE 0x000001
132 #define JMP_RELOCS_DONE 0x000002
133 #define INIT_FUNCS_CALLED 0x000004
134 #define FINI_FUNCS_CALLED 0x000008
135 #define DL_OPENED 0x000010
137 extern struct dyn_elf * _dl_symbol_tables;
138 extern struct elf_resolve * _dl_loaded_modules;
139 extern struct dyn_elf * _dl_handles;
141 extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
142 DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
143 unsigned long dynamic_addr, unsigned long dynamic_size);
145 extern char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt,
146 struct elf_resolve *mytpnt, int type_class,
147 struct symbol_ref *symbol);
148 static __always_inline char *_dl_find_hash(const char *name, struct dyn_elf *rpnt,
149 struct elf_resolve *mytpnt, int type_class,
150 struct symbol_ref *symbol)
152 return _dl_lookup_hash(name, rpnt, mytpnt, type_class, symbol);
155 extern int _dl_linux_dynamic_link(void);
157 extern char * _dl_library_path;
158 extern char * _dl_not_lazy;
160 static __inline__ int _dl_symbol(char * name)
162 if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
163 return 0;
164 return 1;
167 #define LD_ERROR_NOFILE 1
168 #define LD_ERROR_NOZERO 2
169 #define LD_ERROR_NOTELF 3
170 #define LD_ERROR_NOTMAGIC 4
171 #define LD_ERROR_NOTDYN 5
172 #define LD_ERROR_MMAP_FAILED 6
173 #define LD_ERROR_NODYNAMIC 7
174 #define LD_ERROR_TLS_FAILED 8
175 #define LD_WRONG_RELOCS 9
176 #define LD_BAD_HANDLE 10
177 #define LD_NO_SYMBOL 11
179 #endif /* _LD_HASH_H_ */