1 | /* |
---|
2 | * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | /** |
---|
9 | * @file |
---|
10 | * |
---|
11 | * @ingroup rtems_rtl |
---|
12 | * |
---|
13 | * @brief RTEMS Run-Time Linker ELF Headers |
---|
14 | */ |
---|
15 | |
---|
16 | #if !defined (_RTEMS_RTL_ELF_H_) |
---|
17 | #define _RTEMS_RTL_ELF_H_ |
---|
18 | |
---|
19 | #include "rtl-fwd.h" |
---|
20 | #include "rtl-obj-fwd.h" |
---|
21 | #include "rtl-sym.h" |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif /* __cplusplus */ |
---|
26 | |
---|
27 | /** |
---|
28 | ** Imported NetBSD ELF Specifics Start. |
---|
29 | **/ |
---|
30 | |
---|
31 | /* |
---|
32 | * Do not add '()'. Leave plain. |
---|
33 | */ |
---|
34 | #if defined(__powerpc64__) || defined(__arch64__) |
---|
35 | #define ELFSIZE 64 |
---|
36 | #else |
---|
37 | #define ELFSIZE 32 |
---|
38 | #endif |
---|
39 | |
---|
40 | /* |
---|
41 | * Define _STANDALONE then remove after. |
---|
42 | */ |
---|
43 | #define _STANDALONE 1 |
---|
44 | |
---|
45 | #include <sys/cdefs.h> |
---|
46 | #include <sys/exec_elf.h> |
---|
47 | |
---|
48 | #undef _STANDALONE |
---|
49 | |
---|
50 | /** |
---|
51 | ** Imported NetBSD ELF Specifics End. |
---|
52 | **/ |
---|
53 | |
---|
54 | /** |
---|
55 | * Maximum string length. This a read buffering limit rather than a |
---|
56 | * specific ELF length. I hope this is ok as I am concerned about |
---|
57 | * some C++ symbol lengths. |
---|
58 | */ |
---|
59 | #define RTEMS_RTL_ELF_STRING_MAX (256) |
---|
60 | |
---|
61 | /** |
---|
62 | * Architecture specific handler to translate unknown section flags to RTL |
---|
63 | * section flags. |
---|
64 | * |
---|
65 | * @param obj The object file being relocated. |
---|
66 | * @param shdr The ELF section header. |
---|
67 | * @retval 0 Unknown or unsupported flags. |
---|
68 | * @retval uint32_t RTL object file flags. |
---|
69 | */ |
---|
70 | uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj, |
---|
71 | const Elf_Shdr* shdr); |
---|
72 | |
---|
73 | /** |
---|
74 | * Architecture specific handler to check is a relocation record's type is |
---|
75 | * required to resolve a symbol. |
---|
76 | * |
---|
77 | * @param type The type field in the relocation record. |
---|
78 | * @retval true The relocation record require symbol resolution. |
---|
79 | * @retval false The relocation record does not require symbol resolution. |
---|
80 | */ |
---|
81 | bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type); |
---|
82 | |
---|
83 | /** |
---|
84 | * Architecture specific relocation handler compiled in for a specific |
---|
85 | * architecture by the build system. The handler applies the relocation |
---|
86 | * to the target. |
---|
87 | * |
---|
88 | * @param obj The object file being relocated. |
---|
89 | * @param rel The ELF relocation record. |
---|
90 | * @param sect The section of the object file the relocation is for. |
---|
91 | * @param symname The symbol's name. |
---|
92 | * @param syminfo The ELF symbol info field. |
---|
93 | * @param symvalue If a symbol is referenced, this is the symbols value. |
---|
94 | * @retval bool The relocation has been applied. |
---|
95 | * @retval bool The relocation could not be applied. |
---|
96 | */ |
---|
97 | bool rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj, |
---|
98 | const Elf_Rel* rel, |
---|
99 | const rtems_rtl_obj_sect_t* sect, |
---|
100 | const char* symname, |
---|
101 | const Elf_Byte syminfo, |
---|
102 | const Elf_Word symvalue); |
---|
103 | |
---|
104 | /** |
---|
105 | * Architecture specific relocation handler compiled in for a specific |
---|
106 | * architecture by the build system. The handler applies the relocation |
---|
107 | * to the target. |
---|
108 | * |
---|
109 | * @param obj The object file being relocated. |
---|
110 | * @param rela The ELF addend relocation record. |
---|
111 | * @param sect The section of the object file the relocation is for. |
---|
112 | * @param symname The symbol's name. |
---|
113 | * @param syminfo The ELF symbol info field. |
---|
114 | * @param symvalue If a symbol is referenced, this is the symbols value. |
---|
115 | * @retval bool The relocation has been applied. |
---|
116 | * @retval bool The relocation could not be applied. |
---|
117 | */ |
---|
118 | bool rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj, |
---|
119 | const Elf_Rela* rela, |
---|
120 | const rtems_rtl_obj_sect_t* sect, |
---|
121 | const char* symname, |
---|
122 | const Elf_Byte syminfo, |
---|
123 | const Elf_Word symvalue); |
---|
124 | |
---|
125 | /** |
---|
126 | * Find the symbol. The symbol is passed as an ELF type symbol with the name |
---|
127 | * and the value returned is the absolute address of the symbol. |
---|
128 | * |
---|
129 | * If the symbol type is STT_NOTYPE the symbol references a global symbol. The |
---|
130 | * gobal symbol table is searched to find it and that value returned. If the |
---|
131 | * symbol is local to the object module the section for the symbol is located |
---|
132 | * and it's base added to the symbol's value giving an absolute location. |
---|
133 | * |
---|
134 | * @param obj The object the symbol is being resolved for. |
---|
135 | * @param sym The ELF type symbol. |
---|
136 | * @param symname The sym's name read from the symbol string table. |
---|
137 | * @param value Return the value of the symbol. Only valid if the return value |
---|
138 | * is true. |
---|
139 | * @retval true The symbol resolved. |
---|
140 | * @retval false The symbol could not be result. The RTL error is set. |
---|
141 | */ |
---|
142 | bool rtems_rtl_elf_find_symbol (rtems_rtl_obj_t* obj, |
---|
143 | const Elf_Sym* sym, |
---|
144 | const char* symname, |
---|
145 | Elf_Word* value); |
---|
146 | |
---|
147 | /** |
---|
148 | * The ELF format check handler. |
---|
149 | * |
---|
150 | * @param obj The object being checked. |
---|
151 | * @param fd The file descriptor. |
---|
152 | */ |
---|
153 | bool rtems_rtl_elf_file_check (rtems_rtl_obj_t* obj, int fd); |
---|
154 | |
---|
155 | /** |
---|
156 | * The ELF format load handler. |
---|
157 | * |
---|
158 | * @param obj The object to load. |
---|
159 | * @param fd The file descriptor. |
---|
160 | */ |
---|
161 | bool rtems_rtl_elf_file_load (rtems_rtl_obj_t* obj, int fd); |
---|
162 | |
---|
163 | /** |
---|
164 | * The ELF format unload handler. |
---|
165 | * |
---|
166 | * @param obj The object to unload. |
---|
167 | */ |
---|
168 | bool rtems_rtl_elf_file_unload (rtems_rtl_obj_t* obj); |
---|
169 | |
---|
170 | /** |
---|
171 | * The ELF format signature handler. |
---|
172 | * |
---|
173 | * @return rtems_rtl_loader_format_t* The format's signature. |
---|
174 | */ |
---|
175 | rtems_rtl_loader_format_t* rtems_rtl_elf_file_sig (void); |
---|
176 | |
---|
177 | #ifdef __cplusplus |
---|
178 | } |
---|
179 | #endif /* __cplusplus */ |
---|
180 | |
---|
181 | #endif |
---|