![]() |
|
|||
File indexing completed on 2025-05-11 08:24:16
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup rtems_rtl 0007 * 0008 * @brief RTEMS Run-Time Linker ELF Headers 0009 */ 0010 0011 /* 0012 * COPYRIGHT (c) 2012-2018 Chris Johns <chrisj@rtems.org> 0013 * 0014 * Redistribution and use in source and binary forms, with or without 0015 * modification, are permitted provided that the following conditions 0016 * are met: 0017 * 1. Redistributions of source code must retain the above copyright 0018 * notice, this list of conditions and the following disclaimer. 0019 * 2. Redistributions in binary form must reproduce the above copyright 0020 * notice, this list of conditions and the following disclaimer in the 0021 * documentation and/or other materials provided with the distribution. 0022 * 0023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0026 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0027 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0028 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0029 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0030 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0031 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0032 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0033 * POSSIBILITY OF SUCH DAMAGE. 0034 */ 0035 0036 #if !defined (_RTEMS_RTL_ELF_H_) 0037 #define _RTEMS_RTL_ELF_H_ 0038 0039 #include <rtems/rtl/rtl-fwd.h> 0040 #include <rtems/rtl/rtl-obj-fwd.h> 0041 #include <rtems/rtl/rtl-sym.h> 0042 0043 #ifdef __cplusplus 0044 extern "C" { 0045 #endif /* __cplusplus */ 0046 0047 /** 0048 ** Imported NetBSD ELF Specifics Start. 0049 **/ 0050 0051 /* 0052 * Do not add '()'. Leave plain. 0053 */ 0054 #if defined(__powerpc64__) || defined(__aarch64__) || (__riscv_xlen == 64) 0055 #define ELFSIZE 64 0056 #else 0057 #define ELFSIZE 32 0058 #endif 0059 0060 /* 0061 * Define _STANDALONE then remove after. 0062 */ 0063 #define _STANDALONE 1 0064 0065 #include <sys/cdefs.h> 0066 #include <sys/exec_elf.h> 0067 0068 #undef _STANDALONE 0069 0070 /** 0071 ** Imported NetBSD ELF Specifics End. 0072 **/ 0073 0074 /** 0075 * ELF Relocation status codes. 0076 */ 0077 typedef enum rtems_rtl_elf_rel_status 0078 { 0079 rtems_rtl_elf_rel_no_error, /**< There is no error processing the record. */ 0080 rtems_rtl_elf_rel_failure, /**< There was a failure processing the record. */ 0081 rtems_rtl_elf_rel_tramp_cache, /**< The reloc record may need a trampoliine. */ 0082 rtems_rtl_elf_rel_tramp_add /**< Add a trampoliine. */ 0083 } rtems_rtl_elf_rel_status; 0084 0085 /** 0086 * Relocation trampoline relocation data. 0087 */ 0088 typedef struct rtems_rtl_mdreloc_trmap 0089 { 0090 bool parsing; /**< The reloc records are being parsed. */ 0091 void* tampolines; /**< The trampoline memory. */ 0092 size_t size; /**< The trampoline size. */ 0093 } rtems_rtl_mdreloc_tramp; 0094 0095 /** 0096 * Maximum string length. This a read buffering limit rather than a 0097 * specific ELF length. I hope this is ok as I am concerned about 0098 * some C++ symbol lengths. 0099 */ 0100 #define RTEMS_RTL_ELF_STRING_MAX (256) 0101 0102 /** 0103 * Architecture specific handler to translate unknown section flags to RTL 0104 * section flags. If this function returns 0 an error is raised. 0105 * 0106 * @param obj The object file being relocated. 0107 * @param shdr The ELF section header. 0108 * @retval 0 Unknown or unsupported flags. 0109 * @retval uint32_t RTL object file flags. 0110 */ 0111 uint32_t rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, 0112 const Elf_Shdr* shdr); 0113 0114 /** 0115 * Architecture specific handler to parse the section and add any flags that 0116 * may be need to handle the section. 0117 * 0118 * @param obj The object file being relocated. 0119 * @param seciton The section index. 0120 * @param name The name of the section 0121 * @param shdr The ELF section header. 0122 * @param flags The standard ELF parsed flags. 0123 * @retval uint32_t Extra RTL object file flags. 0124 */ 0125 uint32_t rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj, 0126 int section, 0127 const char* name, 0128 const Elf_Shdr* shdr, 0129 const uint32_t flags); 0130 0131 /** 0132 * Architecture specific handler to allocate a section. Some sections are 0133 * specific to an architecture and need special allocators. 0134 * 0135 * @param obj The object file being relocated. 0136 * @param sect The section data. 0137 * @retval true The allocator was successful. 0138 */ 0139 bool rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj, 0140 rtems_rtl_obj_sect* sect); 0141 0142 /** 0143 * Architecture specific handler to free a section. Some sections are 0144 * specific to an architecture and need special allocators. 0145 * 0146 * @param obj The object file being relocated. 0147 * @param sect The section data. 0148 * @retval true The allocator was successful. 0149 */ 0150 bool rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj, 0151 rtems_rtl_obj_sect* sect); 0152 0153 /** 0154 * Architecture specific handler to check is a relocation record's type is 0155 * required to resolve a symbol. 0156 * 0157 * @param type The type field in the relocation record. 0158 * @retval true The relocation record require symbol resolution. 0159 * @retval false The relocation record does not require symbol resolution. 0160 */ 0161 bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type); 0162 0163 /** 0164 * Architecture specific relocation maximum trampoline size. A trampoline entry 0165 * of this size is allocated for each unresolved external. 0166 * 0167 * @return size_t The maximum size of a trampoline for this architecture. 0168 */ 0169 size_t rtems_rtl_elf_relocate_tramp_max_size (void); 0170 0171 /** 0172 * Architecture specific relocation trampoline handler compiled in for a 0173 * specific architecture by the build system. The handler determines if the 0174 * relocation record requires a trampoline. 0175 * 0176 * @param obj The object file being relocated. 0177 * @param rela The ELF relocation record. 0178 * @param sect The section of the object file the relocation is for. 0179 * @param symname The symbol's name. 0180 * @param syminfo The ELF symbol info field. 0181 * @param symvalue If a symbol is referenced, this is the symbols value. 0182 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. 0183 */ 0184 rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj* obj, 0185 const Elf_Rel* rel, 0186 const rtems_rtl_obj_sect* sect, 0187 const char* symname, 0188 const Elf_Byte syminfo, 0189 const Elf_Word symvalue); 0190 0191 /** 0192 * Architecture specific relocation handler compiled in for a specific 0193 * architecture by the build system. The handler applies the relocation 0194 * to the target. 0195 * 0196 * @param obj The object file being relocated. 0197 * @param rela The ELF addend relocation record. 0198 * @param sect The section of the object file the relocation is for. 0199 * @param symname The symbol's name. 0200 * @param syminfo The ELF symbol info field. 0201 * @param symvalue If a symbol is referenced, this is the symbols value. 0202 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. 0203 */ 0204 rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj* obj, 0205 const Elf_Rela* rela, 0206 const rtems_rtl_obj_sect* sect, 0207 const char* symname, 0208 const Elf_Byte syminfo, 0209 const Elf_Word symvalue); 0210 0211 /** 0212 * Architecture specific relocation handler compiled in for a specific 0213 * architecture by the build system. The handler applies the relocation 0214 * to the target. 0215 * 0216 * @param obj The object file being relocated. 0217 * @param rel The ELF relocation record. 0218 * @param sect The section of the object file the relocation is for. 0219 * @param symname The symbol's name. 0220 * @param syminfo The ELF symbol info field. 0221 * @param symvalue If a symbol is referenced, this is the symbols value. 0222 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. 0223 */ 0224 rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rel (rtems_rtl_obj* obj, 0225 const Elf_Rel* rel, 0226 const rtems_rtl_obj_sect* sect, 0227 const char* symname, 0228 const Elf_Byte syminfo, 0229 const Elf_Word symvalue); 0230 0231 /** 0232 * Architecture specific relocation handler compiled in for a specific 0233 * architecture by the build system. The handler applies the relocation 0234 * to the target. 0235 * 0236 * @param obj The object file being relocated. 0237 * @param rela The ELF addend relocation record. 0238 * @param sect The section of the object file the relocation is for. 0239 * @param symname The symbol's name. 0240 * @param syminfo The ELF symbol info field. 0241 * @param symvalue If a symbol is referenced, this is the symbols value. 0242 * @retval rtems_rtl_elf_rel_status The result of the trampoline parsing. 0243 */ 0244 rtems_rtl_elf_rel_status rtems_rtl_elf_relocate_rela (rtems_rtl_obj* obj, 0245 const Elf_Rela* rela, 0246 const rtems_rtl_obj_sect* sect, 0247 const char* symname, 0248 const Elf_Byte syminfo, 0249 const Elf_Word symvalue); 0250 0251 /** 0252 * The ELF format check handler. 0253 * 0254 * @param obj The object being checked. 0255 * @param fd The file descriptor. 0256 */ 0257 bool rtems_rtl_elf_file_check (rtems_rtl_obj* obj, int fd); 0258 0259 /** 0260 * The ELF format load handler. 0261 * 0262 * @param obj The object to load. 0263 * @param fd The file descriptor. 0264 */ 0265 bool rtems_rtl_elf_file_load (rtems_rtl_obj* obj, int fd); 0266 0267 /** 0268 * The ELF format unload handler. 0269 * 0270 * @param obj The object to unload. 0271 */ 0272 bool rtems_rtl_elf_file_unload (rtems_rtl_obj* obj); 0273 0274 /** 0275 * The ELF format signature handler. 0276 * 0277 * @return rtems_rtl_loader_format* The format's signature. 0278 */ 0279 rtems_rtl_loader_format* rtems_rtl_elf_file_sig (void); 0280 0281 #ifdef __cplusplus 0282 } 0283 #endif /* __cplusplus */ 0284 0285 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |