![]() |
|
|||
File indexing completed on 2025-05-11 08:24:12
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* 0004 * COPYRIGHT (c) 2012, 2019 Chris Johns <chrisj@rtems.org> 0005 * 0006 * Redistribution and use in source and binary forms, with or without 0007 * modification, are permitted provided that the following conditions 0008 * are met: 0009 * 1. Redistributions of source code must retain the above copyright 0010 * notice, this list of conditions and the following disclaimer. 0011 * 2. Redistributions in binary form must reproduce the above copyright 0012 * notice, this list of conditions and the following disclaimer in the 0013 * documentation and/or other materials provided with the distribution. 0014 * 0015 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0016 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0017 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0018 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0019 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0020 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0021 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0024 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0025 * POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 /** 0028 * @file 0029 * 0030 * @ingroup rtems_rtl 0031 * 0032 * @brief RTEMS Run-Time Linker Object File Unresolved Relocations Table. 0033 * 0034 * The unresolved relocation table holds relocations in a loaded object file 0035 * which reference unresolved external symbols. The support is needed to allow 0036 * dependent object files to load. In the case of dependent object files one 0037 * will have unresolved externals until the dependent object file is also 0038 * loaded. There is no load order that resolves this. 0039 * 0040 * The unresolved relocation table is a single table used by all object files 0041 * with unresolved symbols. It made of blocks linked together where blocks are 0042 * allocated as requiered. The table is always maintained compacted. That is as 0043 * relocations are resolved and removed the table is compacted. The only 0044 * pointer in the table is the object file poniter. This is used to identify 0045 * which object the relocation belongs to. There are no linking or back 0046 * pointers in the unresolved relocations table. The table is scanned for each 0047 * object file's relocations. This is not fast but the table should be small 0048 * and if it happens to grow large you have other more pressing issues to 0049 * resolve in your application. 0050 * 0051 * The table holds two (2) types of records: 0052 * 0053 * # Symbol name strings. 0054 * # Relocations. 0055 * 0056 * The symbol name a relocation references is held in a specific symbol name 0057 * string record in the table the relocation record references. The record 0058 * counts the number of references and the string is removed from the table 0059 * when the reference count reaches 0. There can be many relocations 0060 * referencing the symbol. The strings are referenced by a single 16bit 0061 * unsigned integer which is the count of the string in the table. 0062 * 0063 * The section the relocation is for in the object is the section number. The 0064 * relocation data is series of machine word sized fields: 0065 * 0066 * # Offset in the section. 0067 * # Relocation info (format specific) 0068 * # Additional format specific data. 0069 */ 0070 0071 #if !defined (_RTEMS_RTL_UNRESOLVED_H_) 0072 #define _RTEMS_RTL_UNRESOLVED_H_ 0073 0074 #include <rtems.h> 0075 #include <rtems/chain.h> 0076 #include "rtl-obj-fwd.h" 0077 0078 #ifdef __cplusplus 0079 extern "C" { 0080 #endif /* __cplusplus */ 0081 0082 /** 0083 * Hack to work around machine size. This needs to be cleaned up 0084 * to better support 64bit targets. 0085 */ 0086 typedef uint32_t rtems_rtl_word; 0087 0088 /** 0089 * The types of records in the blocks. 0090 */ 0091 typedef enum rtems_rtl_unresolved_rtype 0092 { 0093 rtems_rtl_unresolved_empty = 0, /**< The records is empty. Must always be 0 */ 0094 rtems_rtl_unresolved_symbol = 1, /**< The record is a symbol. */ 0095 rtems_rtl_unresolved_reloc = 2, /**< The record is a relocation record. */ 0096 rtems_rtl_trampoline_reloc = 3 /**< The record is a trampoline relocation record. */ 0097 } rtems_rtl_unresolved_rtype; 0098 0099 /** 0100 * Unresolved external symbol flags. 0101 */ 0102 #define RTEMS_RTL_UNRESOLV_SYM_SEARCH_ARCHIVE (1 << 0) /**< Search the archive. */ 0103 #define RTEMS_RTL_UNRESOLV_SYM_HAS_ERROR (1 << 1) /**< The symbol load 0104 * has an error. */ 0105 0106 /** 0107 * Unresolved externals symbols. The symbols are reference counted and separate 0108 * from the relocation records because a number of records could reference the 0109 * same symbol. 0110 * 0111 * The name is extended in the allocator of the record in the unresolved data 0112 * block. The 10 is a minimum that is added to by joining more than one record. 0113 */ 0114 typedef struct rtems_rtl_unresolv_symbol 0115 { 0116 uint16_t refs; /**< The number of references to this name. */ 0117 uint16_t flags; /**< Flags to manage the symbol. */ 0118 uint16_t length; /**< The length of this name. */ 0119 const char name[]; /**< The symbol name. */ 0120 } rtems_rtl_unresolv_symbol; 0121 0122 /** 0123 * Unresolved externals symbols require the relocation records to be held 0124 * and referenced. 0125 */ 0126 typedef struct rtems_rtl_unresolv_reloc 0127 { 0128 rtems_rtl_obj* obj; /**< The relocation's object file. */ 0129 uint16_t flags; /**< Format specific flags. */ 0130 uint16_t name; /**< The symbol's name. */ 0131 uint16_t sect; /**< The target section. */ 0132 rtems_rtl_word rel[3]; /**< Relocation record. */ 0133 } rtems_rtl_unresolv_reloc; 0134 0135 /** 0136 * Trampolines require the relocation records to be held 0137 */ 0138 typedef struct rtems_rtl_tramp_reloc 0139 { 0140 rtems_rtl_obj* obj; /**< The relocation's object file. */ 0141 uint16_t flags; /**< Format specific flags. */ 0142 uint16_t sect; /**< The target section. */ 0143 rtems_rtl_word symvalue; /**< The symbol's value. */ 0144 rtems_rtl_word rel[3]; /**< Relocation record. */ 0145 } rtems_rtl_tramp_reloc; 0146 0147 /** 0148 * Unresolved externals records. 0149 */ 0150 typedef struct rtems_rtl_unresolv_rec 0151 { 0152 rtems_rtl_unresolved_rtype type; 0153 union 0154 { 0155 rtems_rtl_unresolv_symbol name; /**< The symbol, or */ 0156 rtems_rtl_unresolv_reloc reloc; /**< The relocation record. */ 0157 rtems_rtl_tramp_reloc tramp; /**< The trampoline relocation record. */ 0158 } rec; 0159 } rtems_rtl_unresolv_rec; 0160 0161 /** 0162 * Unresolved blocks. 0163 */ 0164 typedef struct rtems_rtl_unresolv_block 0165 { 0166 rtems_chain_node link; /**< Blocks are chained. */ 0167 uint32_t recs; /**< The number of records in the block. */ 0168 rtems_rtl_unresolv_rec rec[]; /**< The records. More follow. */ 0169 } rtems_rtl_unresolv_block; 0170 0171 /** 0172 * Unresolved table holds the names and relocations. 0173 */ 0174 typedef struct rtems_rtl_unresolved 0175 { 0176 uint32_t marker; /**< Block marker. */ 0177 size_t block_recs; /**< The records per blocks allocated. */ 0178 rtems_chain_control blocks; /**< List of blocks. */ 0179 } rtems_rtl_unresolved; 0180 0181 /** 0182 * The iterator function used to iterate over the unresolved table. 0183 * 0184 * @param rec The current iterator. 0185 * @param data The user data. 0186 * @retval true The iterator has finished. 0187 * @retval false The iterator has not finished. Keep iterating. 0188 */ 0189 typedef bool rtems_rtl_unresolved_iterator (rtems_rtl_unresolv_rec* rec, 0190 void* data); 0191 0192 /** 0193 * Open an unresolved relocation table. 0194 * 0195 * @param unresolv The unresolved table to open. 0196 * @param block_records The number of records per block allocated. 0197 * @retval true The table is open. 0198 * @retval false The unresolved relocation table could not created. The RTL 0199 * error has the error. 0200 */ 0201 bool rtems_rtl_unresolved_table_open (rtems_rtl_unresolved* unresolved, 0202 size_t block_records); 0203 0204 /** 0205 * Close the table and erase the blocks. 0206 * 0207 * @param unreolved Close the unresolved table. 0208 */ 0209 void rtems_rtl_unresolved_table_close (rtems_rtl_unresolved* unresolved); 0210 0211 /** 0212 * Iterate over the table of unresolved entries. 0213 */ 0214 bool rtems_rtl_unresolved_iterate (rtems_rtl_unresolved_iterator iterator, 0215 void* data); 0216 0217 /** 0218 * Add a relocation to the list of unresolved relocations. 0219 * 0220 * @param unresolved The unresolved symbol table. 0221 * @param obj The object table the symbols are for. 0222 * @param flags Format specific flags. 0223 * @param name The symbol name the relocation references. 0224 * @param sect The target section number the relocation references. 0225 * @param rel The format specific relocation data. 0226 * @retval true The relocation has been added. 0227 * @retval false The relocation could not be added. 0228 */ 0229 bool rtems_rtl_unresolved_add (rtems_rtl_obj* obj, 0230 const uint16_t flags, 0231 const char* name, 0232 const uint16_t sect, 0233 const rtems_rtl_word* rel); 0234 0235 /** 0236 * Resolve the unresolved symbols. 0237 */ 0238 void rtems_rtl_unresolved_resolve (void); 0239 0240 /** 0241 * Remove a relocation from the list of unresolved relocations. 0242 * 0243 * @param unresolved The unresolved symbol table. 0244 * @param obj The object table the symbols are for. 0245 * @param esyms The exported symbol table. 0246 * @param size The size of the table in bytes. 0247 */ 0248 bool rtems_rtl_unresolved_remove (rtems_rtl_obj* obj, 0249 const char* name, 0250 const uint16_t sect, 0251 const rtems_rtl_word* rel); 0252 0253 /** 0254 * Set all symbols to be archive searchable. This is done when the available 0255 * archives have been refreshed and there are new archives to search for. 0256 */ 0257 void rtems_rtl_unresolved_set_archive_search (void); 0258 0259 /** 0260 * Dump the RTL unresolved data. 0261 */ 0262 void rtems_rtl_unresolved_dump (void); 0263 0264 #ifdef __cplusplus 0265 } 0266 #endif /* __cplusplus */ 0267 0268 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |