OSDN Git Service

ldso: Rework global scope handling and symbol lookup mechanism
[uclinux-h8/uClibc.git] / ldso / include / dl-hash.h
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 _LD_HASH_H_
9 #define _LD_HASH_H_
10
11 #ifndef RTLD_NEXT
12 #define RTLD_NEXT       ((void*)-1)
13 #endif
14
15 struct init_fini {
16         struct elf_resolve **init_fini;
17         unsigned long nlist; /* Number of entries in init_fini */
18 };
19
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;
26 };
27
28
29 /* Structure to describe a single list of scope elements.  The lookup
30    functions get passed an array of pointers to such structures.  */
31 struct r_scope_elem {
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;
35 };
36
37 struct elf_resolve {
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. */
46
47 #if defined(USE_TLS) && USE_TLS
48   /* Thread-local storage related info.  */
49
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.  */
57   size_t l_tls_align;
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
62 # endif
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.  */
66   size_t l_tls_modid;
67   /* Nonzero if _dl_init_static_tls should be called for this module */
68   unsigned int l_need_tls_init:1;
69 #endif
70
71   ElfW(Addr) mapaddr;
72 #ifdef __LDSO_STANDALONE_SUPPORT__
73   /* Store the entry point from the ELF header (e_entry) */
74   ElfW(Addr) l_entry;
75 #endif
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. */
82   Elf_Symndx nbucket;
83
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;
89
90   union
91   {
92     const Elf32_Word *l_gnu_chain_zero;
93     const Elf_Symndx *elf_buckets;
94   };
95 #else
96   Elf_Symndx *elf_buckets;
97 #endif
98
99   struct init_fini_list *init_fini;
100   struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
101   /*
102    * These are only used with ELF style shared libraries
103    */
104   Elf_Symndx nchain;
105
106 #ifdef __LDSO_GNU_HASH_SUPPORT__
107   union
108   {
109     const Elf32_Word *l_gnu_buckets;
110     const Elf_Symndx *chains;
111   };
112 #else
113   Elf_Symndx *chains;
114 #endif
115   unsigned long dynamic_info[DYNAMIC_SIZE];
116
117   unsigned long n_phent;
118   ElfW(Phdr) * ppnt;
119
120   ElfW(Addr) relro_addr;
121   size_t relro_size;
122
123   dev_t st_dev;      /* device */
124   ino_t st_ino;      /* inode */
125
126 #ifdef __powerpc__
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;
130 #endif
131
132 #ifdef __FDPIC__
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;
137 #endif
138 };
139
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
146
147 extern struct dyn_elf     * _dl_symbol_tables;
148 extern struct elf_resolve * _dl_loaded_modules;
149 extern struct dyn_elf     * _dl_handles;
150
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);
154
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)
158 #endif
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);
162
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)
166 {
167         return _dl_lookup_hash(name, scope, mytpnt, type_class, tpntp);
168 }
169
170 extern int _dl_linux_dynamic_link(void);
171
172 extern char * _dl_library_path;
173 extern char * _dl_not_lazy;
174
175 static __inline__ int _dl_symbol(char * name)
176 {
177   if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
178     return 0;
179   return 1;
180 }
181
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
193
194 #endif /* _LD_HASH_H_ */