OSDN Git Service

a1237b09f8b847f28464c041d42c8499f8c53338
[uclinux-h8/uClibc.git] / ldso / include / dl-elf.h
1 #ifndef LINUXELF_H
2 #define LINUXELF_H
3
4 #include <dl-string.h> /* before elf.h to get ELF_USES_RELOCA right */
5 #include <elf.h>
6 #include <link.h>
7
8 /* Forward declarations for stuff defined in ld_hash.h */
9 struct dyn_elf;
10 struct elf_resolve;
11
12 #include <dl-defs.h>
13 #ifdef __LDSO_CACHE_SUPPORT__
14 extern int _dl_map_cache(void);
15 extern int _dl_unmap_cache(void);
16 #else
17 static inline void _dl_map_cache(void) { }
18 static inline void _dl_unmap_cache(void) { }
19 #endif
20
21
22 /* Function prototypes for non-static stuff in readelflib1.c */
23 extern void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
24         unsigned long rel_addr, unsigned long rel_size);
25 extern int _dl_parse_relocation_information(struct dyn_elf *rpnt,
26         unsigned long rel_addr, unsigned long rel_size);
27 extern struct elf_resolve * _dl_load_shared_library(int secure,
28         struct dyn_elf **rpnt, struct elf_resolve *tpnt, char *full_libname,
29         int trace_loaded_objects);
30 extern struct elf_resolve * _dl_load_elf_shared_library(int secure,
31         struct dyn_elf **rpnt, char *libname);
32 extern struct elf_resolve *_dl_check_if_named_library_is_loaded(const char *full_libname,
33         int trace_loaded_objects);
34 extern int _dl_linux_resolve(void);
35 extern int _dl_fixup(struct dyn_elf *rpnt, int flag);
36 extern void _dl_protect_relro (struct elf_resolve *l);
37
38 /*
39  * Datatype of a relocation on this platform
40  */
41 #ifdef ELF_USES_RELOCA
42 # define ELF_RELOC      ElfW(Rela)
43 # define DT_RELOC_TABLE_ADDR    DT_RELA
44 # define DT_RELOC_TABLE_SIZE    DT_RELASZ
45 # define DT_RELOCCOUNT          DT_RELACOUNT
46 # define UNSUPPORTED_RELOC_TYPE DT_REL
47 # define UNSUPPORTED_RELOC_STR  "REL"
48 #else
49 # define ELF_RELOC      ElfW(Rel)
50 # define DT_RELOC_TABLE_ADDR    DT_REL
51 # define DT_RELOC_TABLE_SIZE    DT_RELSZ
52 # define DT_RELOCCOUNT          DT_RELCOUNT
53 # define UNSUPPORTED_RELOC_TYPE DT_RELA
54 # define UNSUPPORTED_RELOC_STR  "RELA"
55 #endif
56
57 /* OS and/or GNU dynamic extensions */
58 #define OS_NUM 1
59 #define DT_RELCONT_IDX DT_NUM
60
61 #ifndef ARCH_DYNAMIC_INFO
62   /* define in arch specific code, if needed */
63 # define ARCH_NUM 0
64 #endif
65
66 #define DYNAMIC_SIZE (DT_NUM+OS_NUM+ARCH_NUM)
67
68 extern void _dl_parse_dynamic_info(Elf32_Dyn *dpnt, unsigned long dynamic_info[], void *debug_addr);
69
70 static inline __attribute__((always_inline))
71 void __dl_parse_dynamic_info(Elf32_Dyn *dpnt, unsigned long dynamic_info[], void *debug_addr)
72 {
73         for (; dpnt->d_tag; dpnt++) {
74                 if (dpnt->d_tag < DT_NUM) {
75                         dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val;
76 #ifndef __mips__
77                         if (dpnt->d_tag == DT_DEBUG)
78                                 dpnt->d_un.d_val = (unsigned long)debug_addr;
79 #endif
80                         if (dpnt->d_tag == DT_BIND_NOW)
81                                 dynamic_info[DT_BIND_NOW] = 1;
82                         if (dpnt->d_tag == DT_FLAGS &&
83                             (dpnt->d_un.d_val & DF_BIND_NOW))
84                                 dynamic_info[DT_BIND_NOW] = 1;
85                         if (dpnt->d_tag == DT_TEXTREL)
86                                 dynamic_info[DT_TEXTREL] = 1;
87                 } else if (dpnt->d_tag < DT_LOPROC) {
88                         if (dpnt->d_tag == DT_RELOCCOUNT)
89                                 dynamic_info[DT_RELCONT_IDX] = dpnt->d_un.d_val;
90                         if (dpnt->d_tag == DT_FLAGS_1 &&
91                             (dpnt->d_un.d_val & DF_1_NOW))
92                                 dynamic_info[DT_BIND_NOW] = 1;
93                 }
94 #ifdef ARCH_DYNAMIC_INFO
95                 else {
96                         ARCH_DYNAMIC_INFO(dpnt, dynamic_info, debug_addr);
97                 }
98 #endif
99         }
100 }
101
102 /* Reloc type classes as returned by elf_machine_type_class().
103    ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
104    some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
105    satisfied by any symbol in the executable.  Some architectures do
106    not support copy relocations.  In this case we define the macro to
107    zero so that the code for handling them gets automatically optimized
108    out.  */
109 #ifdef DL_NO_COPY_RELOCS
110 # define ELF_RTYPE_CLASS_COPY   (0x0)
111 #else
112 # define ELF_RTYPE_CLASS_COPY   (0x2)
113 #endif
114 #define ELF_RTYPE_CLASS_PLT     (0x1)
115
116
117 /* Convert between the Linux flags for page protections and the
118    ones specified in the ELF standard. */
119 #define LXFLAGS(X) ( (((X) & PF_R) ? PROT_READ : 0) | \
120                     (((X) & PF_W) ? PROT_WRITE : 0) | \
121                     (((X) & PF_X) ? PROT_EXEC : 0))
122
123
124 #endif  /* LINUXELF_H */