OSDN Git Service

- fix asm and volatile keywords
[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   ElfW(Addr) mapaddr;    /* Address at which ELF segments (either main app and DSO) are mapped into */
38   enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
39   struct dyn_elf * symbol_scope;
40   unsigned short usage_count;
41   unsigned short int init_flag;
42   unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
43   Elf_Symndx nbucket;
44
45 #ifdef __LDSO_GNU_HASH_SUPPORT__
46   /* Data needed to support GNU hash style */
47   Elf32_Word l_gnu_bitmask_idxbits;
48   Elf32_Word l_gnu_shift;
49   const ElfW(Addr) *l_gnu_bitmask;
50
51   union
52   {
53     const Elf32_Word *l_gnu_chain_zero;
54     const Elf_Symndx *elf_buckets;
55   };
56 #else
57   Elf_Symndx *elf_buckets;
58 #endif
59
60   struct init_fini_list *init_fini;
61   struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
62   /*
63    * These are only used with ELF style shared libraries
64    */
65   Elf_Symndx nchain;
66
67 #ifdef __LDSO_GNU_HASH_SUPPORT__
68   union
69   {
70     const Elf32_Word *l_gnu_buckets;
71     const Elf_Symndx *chains;
72   };
73 #else
74   Elf_Symndx *chains;
75 #endif
76   unsigned long dynamic_info[DYNAMIC_SIZE];
77
78   unsigned long n_phent;
79   ElfW(Phdr) * ppnt;
80
81   ElfW(Addr) relro_addr;
82   size_t relro_size;
83
84   dev_t st_dev;      /* device */
85   ino_t st_ino;      /* inode */
86
87 #ifdef __powerpc__
88   /* this is used to store the address of relocation data words, so
89    * we don't have to calculate it every time, which requires a divide */
90   unsigned long data_words;
91 #endif
92
93 #ifdef __FDPIC__
94   /* Every loaded module holds a hashtable of function descriptors of
95      functions defined in it, such that it's easy to release the
96      memory when the module is dlclose()d.  */
97   struct funcdesc_ht *funcdesc_ht;
98 #endif
99 };
100
101 #define RELOCS_DONE         0x000001
102 #define JMP_RELOCS_DONE     0x000002
103 #define INIT_FUNCS_CALLED   0x000004
104 #define FINI_FUNCS_CALLED   0x000008
105 #define DL_OPENED           0x000010
106
107 extern struct dyn_elf     * _dl_symbol_tables;
108 extern struct elf_resolve * _dl_loaded_modules;
109 extern struct dyn_elf     * _dl_handles;
110
111 extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
112         DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
113         unsigned long dynamic_addr, unsigned long dynamic_size);
114
115 extern char * _dl_lookup_hash(const char * name, struct dyn_elf * rpnt,
116                               struct elf_resolve *mytpnt, int type_class
117 #ifdef __FDPIC__
118                               , struct elf_resolve **tpntp
119 #endif
120                               );
121
122 static __always_inline char *_dl_find_hash(const char *name, struct dyn_elf *rpnt,
123                                            struct elf_resolve *mytpnt, int type_class)
124 {
125 #ifdef __FDPIC__
126         return _dl_lookup_hash(name, rpnt, mytpnt, type_class, NULL);
127 #else
128         return _dl_lookup_hash(name, rpnt, mytpnt, type_class);
129 #endif
130 }
131
132 extern int _dl_linux_dynamic_link(void);
133
134 extern char * _dl_library_path;
135 extern char * _dl_not_lazy;
136
137 static inline int _dl_symbol(char * name)
138 {
139   if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
140     return 0;
141   return 1;
142 }
143
144 #define LD_ERROR_NOFILE 1
145 #define LD_ERROR_NOZERO 2
146 #define LD_ERROR_NOTELF 3
147 #define LD_ERROR_NOTMAGIC 4
148 #define LD_ERROR_NOTDYN 5
149 #define LD_ERROR_MMAP_FAILED 6
150 #define LD_ERROR_NODYNAMIC 7
151 #define LD_WRONG_RELOCS 8
152 #define LD_BAD_HANDLE 9
153 #define LD_NO_SYMBOL 10
154
155 #endif /* _LD_HASH_H_ */