source: rtems/cpukit/libdl/rtl-elf.h

Last change on this file was a4c5da6, checked in by Hesham Almatary <Hesham.Almatary@…>, on Nov 11, 2019 at 11:06:27 AM

riscv: preliminarily support for libdl

Support for targets compiled with -fno-pic and -mno-relax

  • Property mode set to 100644
File size: 9.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 2012-2018 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 <rtems/rtl/rtl-fwd.h>
20#include <rtems/rtl/rtl-obj-fwd.h>
21#include <rtems/rtl/rtl-sym.h>
22
23#ifdef __cplusplus
24extern "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__) || (__riscv_xlen == 64)
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 * ELF Relocation status codes.
56 */
57typedef enum rtems_rtl_elf_rel_status
58{
59  rtems_rtl_elf_rel_no_error,    /**< There is no error processing the record. */
60  rtems_rtl_elf_rel_failure,     /**< There was a failure processing the record. */
61  rtems_rtl_elf_rel_tramp_cache, /**< The reloc record may need a trampoliine. */
62  rtems_rtl_elf_rel_tramp_add    /**< Add a trampoliine. */
63} rtems_rtl_elf_rel_status;
64
65/**
66 * Relocation trampoline relocation data.
67 */
68typedef struct rtems_rtl_mdreloc_trmap
69{
70  bool   parsing;     /**< The reloc records are being parsed. */
71  void*  tampolines;  /**< The trampoline memory. */
72  size_t size;        /**< The trampoline size. */
73} rtems_rtl_mdreloc_tramp;
74
75/**
76 * Maximum string length. This a read buffering limit rather than a
77 * specific ELF length. I hope this is ok as I am concerned about
78 * some C++ symbol lengths.
79 */
80#define RTEMS_RTL_ELF_STRING_MAX (256)
81
82/**
83 * Architecture specific handler to translate unknown section flags to RTL
84 * section flags. If this function returns 0 an error is raised.
85 *
86 * @param obj The object file being relocated.
87 * @param shdr The ELF section header.
88 * @retval 0 Unknown or unsupported flags.
89 * @retval uint32_t RTL object file flags.
90 */
91uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
92                                      const Elf_Shdr*      shdr);
93
94/**
95 * Architecture specific handler to parse the section and add any flags that
96 * may be need to handle the section.
97 *
98 * @param obj The object file being relocated.
99 * @param seciton The section index.
100 * @param name The name of the section
101 * @param shdr The ELF section header.
102 * @param flags The standard ELF parsed flags.
103 * @retval uint32_t Extra RTL object file flags.
104 */
105uint32_t rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj,
106                                           int                  section,
107                                           const char*          name,
108                                           const Elf_Shdr*      shdr,
109                                           const uint32_t       flags);
110
111/**
112 * Architecture specific handler to allocate a section. Some sections are
113 * specific to an architecture and need special allocators.
114 *
115 * @param obj The object file being relocated.
116 * @param sect The section data.
117 * @retval true The allocator was successful.
118 */
119bool rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj,
120                                       rtems_rtl_obj_sect* sect);
121
122/**
123 * Architecture specific handler to free a section. Some sections are
124 * specific to an architecture and need special allocators.
125 *
126 * @param obj The object file being relocated.
127 * @param sect The section data.
128 * @retval true The allocator was successful.
129 */
130bool rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj,
131                                      rtems_rtl_obj_sect* sect);
132
133/**
134 * Architecture specific handler to check is a relocation record's type is
135 * required to resolve a symbol.
136 *
137 * @param type The type field in the relocation record.
138 * @retval true The relocation record require symbol resolution.
139 * @retval false The relocation record does not require symbol resolution.
140 */
141bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type);
142
143/**
144 * Architecture specific relocation maximum trampoline size. A trampoline entry
145 * of this size is allocated for each unresolved external.
146 *
147 * @return size_t The maximum size of a trampoline for this architecture.
148 */
149size_t rtems_rtl_elf_relocate_tramp_max_size (void);
150
151/**
152 * Architecture specific relocation trampoline handler compiled in for a
153 * specific architecture by the build system. The handler determines if the
154 * relocation record requires a trampoline.
155 *
156 * @param obj The object file being relocated.
157 * @param rela The ELF relocation record.
158 * @param sect The section of the object file the relocation is for.
159 * @param symname The symbol's name.
160 * @param syminfo The ELF symbol info field.
161 * @param symvalue If a symbol is referenced, this is the symbols value.
162 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
163 */
164rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
165                                                           const Elf_Rel*            rel,
166                                                           const rtems_rtl_obj_sect* sect,
167                                                           const char*               symname,
168                                                           const Elf_Byte            syminfo,
169                                                           const Elf_Word            symvalue);
170
171/**
172 * Architecture specific relocation handler compiled in for a specific
173 * architecture by the build system. The handler applies the relocation
174 * to the target.
175 *
176 * @param obj The object file being relocated.
177 * @param rela The ELF addend relocation record.
178 * @param sect The section of the object file the relocation is for.
179 * @param symname The symbol's name.
180 * @param syminfo The ELF symbol info field.
181 * @param symvalue If a symbol is referenced, this is the symbols value.
182 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
183 */
184rtems_rtl_elf_rel_status  rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
185                                                             const Elf_Rela*           rela,
186                                                             const rtems_rtl_obj_sect* sect,
187                                                             const char*               symname,
188                                                             const Elf_Byte            syminfo,
189                                                             const Elf_Word            symvalue);
190
191/**
192 * Architecture specific relocation handler compiled in for a specific
193 * architecture by the build system. The handler applies the relocation
194 * to the target.
195 *
196 * @param obj The object file being relocated.
197 * @param rel The ELF relocation record.
198 * @param sect The section of the object file the relocation is for.
199 * @param symname The symbol's name.
200 * @param syminfo The ELF symbol info field.
201 * @param symvalue If a symbol is referenced, this is the symbols value.
202 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
203 */
204rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
205                                                     const Elf_Rel*            rel,
206                                                     const rtems_rtl_obj_sect* sect,
207                                                     const char*               symname,
208                                                     const Elf_Byte            syminfo,
209                                                     const Elf_Word            symvalue);
210
211/**
212 * Architecture specific relocation handler compiled in for a specific
213 * architecture by the build system. The handler applies the relocation
214 * to the target.
215 *
216 * @param obj The object file being relocated.
217 * @param rela The ELF addend relocation record.
218 * @param sect The section of the object file the relocation is for.
219 * @param symname The symbol's name.
220 * @param syminfo The ELF symbol info field.
221 * @param symvalue If a symbol is referenced, this is the symbols value.
222 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing.
223 */
224rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
225                                                      const Elf_Rela*           rela,
226                                                      const rtems_rtl_obj_sect* sect,
227                                                      const char*               symname,
228                                                      const Elf_Byte            syminfo,
229                                                      const Elf_Word            symvalue);
230
231/**
232 * The ELF format check handler.
233 *
234 * @param obj The object being checked.
235 * @param fd The file descriptor.
236 */
237bool rtems_rtl_elf_file_check (rtems_rtl_obj* obj, int fd);
238
239/**
240 * The ELF format load handler.
241 *
242 * @param obj The object to load.
243 * @param fd The file descriptor.
244 */
245bool rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd);
246
247/**
248 * The ELF format unload handler.
249 *
250 * @param obj The object to unload.
251 */
252bool rtems_rtl_elf_file_unload (rtems_rtl_obj* obj);
253
254/**
255 * The ELF format signature handler.
256 *
257 * @return rtems_rtl_loader_format* The format's signature.
258 */
259rtems_rtl_loader_format* rtems_rtl_elf_file_sig (void);
260
261#ifdef __cplusplus
262}
263#endif /* __cplusplus */
264
265#endif
Note: See TracBrowser for help on using the repository browser.