summaryrefslogtreecommitdiffstats
path: root/cpukit/libdl/rtl-elf.h
blob: 3bbc0bd9ee073b8611a9e702e68b7b451770f5aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 *  COPYRIGHT (c) 2012-2018 Chris Johns <chrisj@rtems.org>
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */
/**
 * @file
 *
 * @ingroup rtems_rtl
 *
 * @brief RTEMS Run-Time Linker ELF Headers
 */

#if !defined (_RTEMS_RTL_ELF_H_)
#define _RTEMS_RTL_ELF_H_

#include <rtems/rtl/rtl-fwd.h>
#include <rtems/rtl/rtl-obj-fwd.h>
#include <rtems/rtl/rtl-sym.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 ** Imported NetBSD ELF Specifics Start.
 **/

/*
 * Do not add '()'. Leave plain.
 */
#if defined(__powerpc64__) || defined(__arch64__) || (__riscv_xlen == 64)
#define ELFSIZE 64
#else
#define ELFSIZE 32
#endif

/*
 * Define _STANDALONE then remove after.
 */
#define _STANDALONE 1

#include <sys/cdefs.h>
#include <sys/exec_elf.h>

#undef _STANDALONE

/**
 ** Imported NetBSD ELF Specifics End.
 **/

/**
 * ELF Relocation status codes.
 */
typedef enum rtems_rtl_elf_rel_status
{
  rtems_rtl_elf_rel_no_error,    /**< There is no error processing the record. */
  rtems_rtl_elf_rel_failure,     /**< There was a failure processing the record. */
  rtems_rtl_elf_rel_tramp_cache, /**< The reloc record may need a trampoliine. */
  rtems_rtl_elf_rel_tramp_add    /**< Add a trampoliine. */
} rtems_rtl_elf_rel_status;

/**
 * Relocation trampoline relocation data.
 */
typedef struct rtems_rtl_mdreloc_trmap
{
  bool   parsing;     /**< The reloc records are being parsed. */
  void*  tampolines;  /**< The trampoline memory. */
  size_t size;        /**< The trampoline size. */
} rtems_rtl_mdreloc_tramp;

/**
 * Maximum string length. This a read buffering limit rather than a
 * specific ELF length. I hope this is ok as I am concerned about
 * some C++ symbol lengths.
 */
#define RTEMS_RTL_ELF_STRING_MAX (256)

/**
 * Architecture specific handler to translate unknown section flags to RTL
 * section flags. If this function returns 0 an error is raised.
 *
 * @param obj The object file being relocated.
 * @param shdr The ELF section header.
 * @retval 0 Unknown or unsupported flags.
 * @retval uint32_t RTL object file flags.
 */
uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
                                      const Elf_Shdr*      shdr);

/**
 * Architecture specific handler to parse the section and add any flags that
 * may be need to handle the section.
 *
 * @param obj The object file being relocated.
 * @param seciton The section index.
 * @param name The name of the section
 * @param shdr The ELF section header.
 * @param flags The standard ELF parsed flags.
 * @retval uint32_t Extra RTL object file flags.
 */
uint32_t rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj,
                                           int                  section,
                                           const char*          name,
                                           const Elf_Shdr*      shdr,
                                           const uint32_t       flags);

/**
 * Architecture specific handler to allocate a section. Some sections are
 * specific to an architecture and need special allocators.
 *
 * @param obj The object file being relocated.
 * @param sect The section data.
 * @retval true The allocator was successful.
 */
bool rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj,
                                       rtems_rtl_obj_sect* sect);

/**
 * Architecture specific handler to free a section. Some sections are
 * specific to an architecture and need special allocators.
 *
 * @param obj The object file being relocated.
 * @param sect The section data.
 * @retval true The allocator was successful.
 */
bool rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj,
                                      rtems_rtl_obj_sect* sect);

/**
 * Architecture specific handler to check is a relocation record's type is
 * required to resolve a symbol.
 *
 * @param type The type field in the relocation record.
 * @retval true The relocation record require symbol resolution.
 * @retval false The relocation record does not require symbol resolution.
 */
bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type);

/**
 * Architecture specific relocation maximum trampoline size. A trampoline entry
 * of this size is allocated for each unresolved external.
 *
 * @return size_t The maximum size of a trampoline for this architecture.
 */
size_t rtems_rtl_elf_relocate_tramp_max_size (void);

/**
 * Architecture specific relocation trampoline handler compiled in for a
 * specific architecture by the build system. The handler determines if the
 * relocation record requires a trampoline.
 *
 * @param obj The object file being relocated.
 * @param rela The ELF relocation record.
 * @param sect The section of the object file the relocation is for.
 * @param symname The symbol's name.
 * @param syminfo The ELF symbol info field.
 * @param symvalue If a symbol is referenced, this is the symbols value.
 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
 */
rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
                                                           const Elf_Rel*            rel,
                                                           const rtems_rtl_obj_sect* sect,
                                                           const char*               symname,
                                                           const Elf_Byte            syminfo,
                                                           const Elf_Word            symvalue);

/**
 * Architecture specific relocation handler compiled in for a specific
 * architecture by the build system. The handler applies the relocation
 * to the target.
 *
 * @param obj The object file being relocated.
 * @param rela The ELF addend relocation record.
 * @param sect The section of the object file the relocation is for.
 * @param symname The symbol's name.
 * @param syminfo The ELF symbol info field.
 * @param symvalue If a symbol is referenced, this is the symbols value.
 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
 */
rtems_rtl_elf_rel_status  rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
                                                             const Elf_Rela*           rela,
                                                             const rtems_rtl_obj_sect* sect,
                                                             const char*               symname,
                                                             const Elf_Byte            syminfo,
                                                             const Elf_Word            symvalue);

/**
 * Architecture specific relocation handler compiled in for a specific
 * architecture by the build system. The handler applies the relocation
 * to the target.
 *
 * @param obj The object file being relocated.
 * @param rel The ELF relocation record.
 * @param sect The section of the object file the relocation is for.
 * @param symname The symbol's name.
 * @param syminfo The ELF symbol info field.
 * @param symvalue If a symbol is referenced, this is the symbols value.
 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
 */
rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
                                                     const Elf_Rel*            rel,
                                                     const rtems_rtl_obj_sect* sect,
                                                     const char*               symname,
                                                     const Elf_Byte            syminfo,
                                                     const Elf_Word            symvalue);

/**
 * Architecture specific relocation handler compiled in for a specific
 * architecture by the build system. The handler applies the relocation
 * to the target.
 *
 * @param obj The object file being relocated.
 * @param rela The ELF addend relocation record.
 * @param sect The section of the object file the relocation is for.
 * @param symname The symbol's name.
 * @param syminfo The ELF symbol info field.
 * @param symvalue If a symbol is referenced, this is the symbols value.
 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
 */
rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
                                                      const Elf_Rela*           rela,
                                                      const rtems_rtl_obj_sect* sect,
                                                      const char*               symname,
                                                      const Elf_Byte            syminfo,
                                                      const Elf_Word            symvalue);

/**
 * The ELF format check handler.
 *
 * @param obj The object being checked.
 * @param fd The file descriptor.
 */
bool rtems_rtl_elf_file_check (rtems_rtl_obj* obj, int fd);

/**
 * The ELF format load handler.
 *
 * @param obj The object to load.
 * @param fd The file descriptor.
 */
bool rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd);

/**
 * The ELF format unload handler.
 *
 * @param obj The object to unload.
 */
bool rtems_rtl_elf_file_unload (rtems_rtl_obj* obj);

/**
 * The ELF format signature handler.
 *
 * @return rtems_rtl_loader_format* The format's signature.
 */
rtems_rtl_loader_format* rtems_rtl_elf_file_sig (void);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif