OSDN Git Service

22042145e5bbc33efe2da2c14eb746409a2c3296
[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 struct elf_resolve {
29   /* These entries must be in this order to be compatible with the interface used
30      by gdb to obtain the list of symbols. */
31   DL_LOADADDR_TYPE loadaddr;    /* Base address shared object is loaded at.  */
32   char *libname;                /* Absolute file name object was found in.  */
33   ElfW(Dyn) *dynamic_addr;      /* Dynamic section of the shared object.  */
34   struct elf_resolve * next;
35   struct elf_resolve * prev;
36   /* Nothing after this address is used by gdb. */
37
38 #if USE_TLS
39   /* Thread-local storage related info.  */
40
41   /* Start of the initialization image.  */
42   void *l_tls_initimage;
43   /* Size of the initialization image.  */
44   size_t l_tls_initimage_size;
45   /* Size of the TLS block.  */
46   size_t l_tls_blocksize;
47   /* Alignment requirement of the TLS block.  */
48   size_t l_tls_align;
49   /* Offset of first byte module alignment.  */
50   size_t l_tls_firstbyte_offset;
51 # ifndef NO_TLS_OFFSET
52 #  define NO_TLS_OFFSET 0
53 # endif
54   /* For objects present at startup time: offset in the static TLS block.  */
55   ptrdiff_t l_tls_offset;
56   /* Index of the module in the dtv array.  */
57   size_t l_tls_modid;
58   /* Nonzero if _dl_init_static_tls should be called for this module */
59   unsigned int l_need_tls_init:1;
60 #endif
61
62   ElfW(Addr) mapaddr;
63   enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
64   struct dyn_elf * symbol_scope;
65   unsigned short usage_count;
66   unsigned short int init_flag;
67   unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
68   Elf_Symndx nbucket;
69
70 #ifdef __LDSO_GNU_HASH_SUPPORT__
71   /* Data needed to support GNU hash style */
72   Elf32_Word l_gnu_bitmask_idxbits;
73   Elf32_Word l_gnu_shift;
74   const ElfW(Addr) *l_gnu_bitmask;
75
76   union
77   {
78     const Elf32_Word *l_gnu_chain_zero;
79     const Elf_Symndx *elf_buckets;
80   };
81 #else
82   Elf_Symndx *elf_buckets;
83 #endif
84
85   struct init_fini_list *init_fini;
86   struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
87   /*
88    * These are only used with ELF style shared libraries
89    */
90   Elf_Symndx nchain;
91
92 #ifdef __LDSO_GNU_HASH_SUPPORT__
93   union
94   {
95     const Elf32_Word *l_gnu_buckets;
96     const Elf_Symndx *chains;
97   };
98 #else
99   Elf_Symndx *chains;
100 #endif
101   unsigned long dynamic_info[DYNAMIC_SIZE];
102
103   unsigned long n_phent;
104   ElfW(Phdr) * ppnt;
105
106   ElfW(Addr) relro_addr;
107   size_t relro_size;
108
109   dev_t st_dev;      /* device */
110   ino_t st_ino;      /* inode */
111
112 #ifdef __powerpc__
113   /* this is used to store the address of relocation data words, so
114    * we don't have to calculate it every time, which requires a divide */
115   unsigned long data_words;
116 #endif
117
118 #ifdef __FDPIC__
119   /* Every loaded module holds a hashtable of function descriptors of
120      functions defined in it, such that it's easy to release the
121      memory when the module is dlclose()d.  */
122   struct funcdesc_ht *funcdesc_ht;
123 #endif
124 };
125
126 #define RELOCS_DONE         0x000001
127 #define JMP_RELOCS_DONE     0x000002
128 #define INIT_FUNCS_CALLED   0x000004
129 #define FINI_FUNCS_CALLED   0x000008
130 #define DL_OPENED           0x000010
131
132 extern struct dyn_elf     * _dl_symbol_tables;
133 extern struct elf_resolve * _dl_loaded_modules;
134 extern struct dyn_elf     * _dl_handles;
135
136 extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
137         DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
138         unsigned long dynamic_addr, unsigned long dynamic_size);
139
140 /* Only need extra arg with some configurations */
141 #if !(USE_TLS || defined __FDPIC__)
142 # define _dl_lookup_hash(n, r, m, c, t) _dl_lookup_hash(n, r, m, c)
143 #endif
144 extern char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt,
145         struct elf_resolve *mytpnt, int type_class,
146         struct elf_resolve **tpntp);
147
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 elf_resolve **tpntp)
151 {
152         return _dl_lookup_hash(name, rpnt, mytpnt, type_class, tpntp);
153 }
154
155 extern int _dl_linux_dynamic_link(void);
156
157 extern char * _dl_library_path;
158 extern char * _dl_not_lazy;
159
160 static __inline__ int _dl_symbol(char * name)
161 {
162   if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
163     return 0;
164   return 1;
165 }
166
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
178
179 #endif /* _LD_HASH_H_ */