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 Object File Unresolved Relocations Table. |
---|
14 | * |
---|
15 | * The unresolved relocation table holds relocations in a loaded object file |
---|
16 | * which reference unresolved external symbols. The support is needed to allow |
---|
17 | * dependent object files to load. In the case of dependent object files one |
---|
18 | * will have unresolved externals until the dependent object file is also |
---|
19 | * loaded. There is no load order that resolves this. |
---|
20 | * |
---|
21 | * The unresolved relocation table is a single table used by all object files |
---|
22 | * with unresolved symbols. It made of blocks linked together where blocks are |
---|
23 | * allocated as requiered. The table is always maintained compacted. That is as |
---|
24 | * relocations are resolved and removed the table is compacted. The only |
---|
25 | * pointer in the table is the object file poniter. This is used to identify |
---|
26 | * which object the relocation belongs to. There are no linking or back |
---|
27 | * pointers in the unresolved relocations table. The table is scanned for each |
---|
28 | * object file's relocations. This is not fast but the table should be small |
---|
29 | * and if it happens to grow large you have other more pressing issues to |
---|
30 | * resolve in your application. |
---|
31 | * |
---|
32 | * The table holds two (2) types of records: |
---|
33 | * |
---|
34 | * # Symbol name strings. |
---|
35 | * # Relocations. |
---|
36 | * |
---|
37 | * The symbol name a relocation references is held in a specific symbol name |
---|
38 | * string record in the table the relocation record references. The record |
---|
39 | * counts the number of references and the string is removed from the table |
---|
40 | * when the reference count reaches 0. There can be many relocations |
---|
41 | * referencing the symbol. The strings are referenced by a single 16bit |
---|
42 | * unsigned integer which is the count of the string in the table. |
---|
43 | * |
---|
44 | * The section the relocation is for in the object is the section number. The |
---|
45 | * relocation data is series of machine word sized fields: |
---|
46 | * |
---|
47 | * # Offset in the section. |
---|
48 | * # Relocation info (format specific) |
---|
49 | * # Additional format specific data. |
---|
50 | */ |
---|
51 | |
---|
52 | #if !defined (_RTEMS_RTL_UNRESOLVED_H_) |
---|
53 | #define _RTEMS_RTL_UNRESOLVED_H_ |
---|
54 | |
---|
55 | #include <rtems.h> |
---|
56 | #include "rtl-obj-fwd.h" |
---|
57 | |
---|
58 | #ifdef __cplusplus |
---|
59 | extern "C" { |
---|
60 | #endif /* __cplusplus */ |
---|
61 | |
---|
62 | /** |
---|
63 | * Hack to work around machine size. This needs to be cleaned up |
---|
64 | * to better support 64bit targets. |
---|
65 | */ |
---|
66 | typedef uint32_t rtems_rtl_word; |
---|
67 | |
---|
68 | /** |
---|
69 | * The types of records in the blocks. |
---|
70 | */ |
---|
71 | typedef enum rtems_rtl_unresolved_rtype |
---|
72 | { |
---|
73 | rtems_rtl_unresolved_empty = 0, /**< The records is empty. Must always be 0 */ |
---|
74 | rtems_rtl_unresolved_symbol = 1, /**< The record is a symbol. */ |
---|
75 | rtems_rtl_unresolved_reloc = 2 /**< The record is a relocation record. */ |
---|
76 | } rtems_rtl_unresolved_rtype; |
---|
77 | |
---|
78 | /** |
---|
79 | * Unresolved external symbol flags. |
---|
80 | */ |
---|
81 | #define RTEMS_RTL_UNRESOLV_SYM_SEARCH_ARCHIVE (1 << 0) /**< Search the archive. */ |
---|
82 | |
---|
83 | /** |
---|
84 | * Unresolved externals symbols. The symbols are reference counted and separate |
---|
85 | * from the relocation records because a number of records could reference the |
---|
86 | * same symbol. |
---|
87 | * |
---|
88 | * The name is extended in the allocator of the record in the unresolved data |
---|
89 | * block. The 10 is a minimum that is added to by joining more than one record. |
---|
90 | */ |
---|
91 | typedef struct rtems_rtl_unresolv_symbol |
---|
92 | { |
---|
93 | uint16_t refs; /**< The number of references to this name. */ |
---|
94 | uint16_t flags; /**< Flags to manage the symbol. */ |
---|
95 | uint16_t length; /**< The length of this name. */ |
---|
96 | const char name[10]; /**< The symbol name. */ |
---|
97 | } rtems_rtl_unresolv_symbol; |
---|
98 | |
---|
99 | /** |
---|
100 | * Unresolved externals symbols require the relocation records to be held |
---|
101 | * and references. |
---|
102 | */ |
---|
103 | typedef struct rtems_rtl_unresolv_reloc |
---|
104 | { |
---|
105 | rtems_rtl_obj* obj; /**< The relocation's object file. */ |
---|
106 | uint16_t flags; /**< Format specific flags. */ |
---|
107 | uint16_t name; /**< The symbol's name. */ |
---|
108 | uint16_t sect; /**< The target section. */ |
---|
109 | rtems_rtl_word rel[3]; /**< Relocation record. */ |
---|
110 | } rtems_rtl_unresolv_reloc; |
---|
111 | |
---|
112 | /** |
---|
113 | * Unresolved externals records. |
---|
114 | */ |
---|
115 | typedef struct rtems_rtl_unresolv_rec |
---|
116 | { |
---|
117 | rtems_rtl_unresolved_rtype type; |
---|
118 | union |
---|
119 | { |
---|
120 | rtems_rtl_unresolv_symbol name; /**< The symnbol, or */ |
---|
121 | rtems_rtl_unresolv_reloc reloc; /**< the relocation record. */ |
---|
122 | } rec; |
---|
123 | } rtems_rtl_unresolv_rec; |
---|
124 | |
---|
125 | /** |
---|
126 | * Unresolved blocks. |
---|
127 | */ |
---|
128 | typedef struct rtems_rtl_unresolv_block |
---|
129 | { |
---|
130 | rtems_chain_node link; /**< Blocks are chained. */ |
---|
131 | uint32_t recs; /**< The number of records in the block. */ |
---|
132 | rtems_rtl_unresolv_rec rec; /**< The records. More follow. */ |
---|
133 | } rtems_rtl_unresolv_block; |
---|
134 | |
---|
135 | /** |
---|
136 | * Unresolved table holds the names and relocations. |
---|
137 | */ |
---|
138 | typedef struct rtems_rtl_unresolved |
---|
139 | { |
---|
140 | uint32_t marker; /**< Block marker. */ |
---|
141 | size_t block_recs; /**< The records per blocks allocated. */ |
---|
142 | rtems_chain_control blocks; /**< List of blocks. */ |
---|
143 | } rtems_rtl_unresolved; |
---|
144 | |
---|
145 | /** |
---|
146 | * The iterator function used to iterate over the unresolved table. |
---|
147 | * |
---|
148 | * @param rec The current iterator. |
---|
149 | * @param data The user data. |
---|
150 | * @retval true The iterator has finished. |
---|
151 | * @retval false The iterator has not finished. Keep iterating. |
---|
152 | */ |
---|
153 | typedef bool rtems_rtl_unresolved_iterator (rtems_rtl_unresolv_rec* rec, |
---|
154 | void* data); |
---|
155 | |
---|
156 | /** |
---|
157 | * Open an unresolved relocation table. |
---|
158 | * |
---|
159 | * @param unresolv The unresolved table to open. |
---|
160 | * @param block_records The number of records per block allocated. |
---|
161 | * @retval true The table is open. |
---|
162 | * @retval false The unresolved relocation table could not created. The RTL |
---|
163 | * error has the error. |
---|
164 | */ |
---|
165 | bool rtems_rtl_unresolved_table_open (rtems_rtl_unresolved* unresolved, |
---|
166 | size_t block_records); |
---|
167 | |
---|
168 | /** |
---|
169 | * Close the table and erase the blocks. |
---|
170 | * |
---|
171 | * @param unreolved Close the unresolved table. |
---|
172 | */ |
---|
173 | void rtems_rtl_unresolved_table_close (rtems_rtl_unresolved* unresolved); |
---|
174 | |
---|
175 | /** |
---|
176 | * Iterate over the table of unresolved entries. |
---|
177 | */ |
---|
178 | bool rtems_rtl_unresolved_iterate (rtems_rtl_unresolved_iterator iterator, |
---|
179 | void* data); |
---|
180 | |
---|
181 | /** |
---|
182 | * Add a relocation to the list of unresolved relocations. |
---|
183 | * |
---|
184 | * @param unresolved The unresolved symbol table. |
---|
185 | * @param obj The object table the symbols are for. |
---|
186 | * @param flags Format specific flags. |
---|
187 | * @param name The symbol name the relocation references. |
---|
188 | * @param sect The target section number the relocation references. |
---|
189 | * @param rel The format specific relocation data. |
---|
190 | * @retval true The relocation has been added. |
---|
191 | * @retval false The relocation could not be added. |
---|
192 | */ |
---|
193 | bool rtems_rtl_unresolved_add (rtems_rtl_obj* obj, |
---|
194 | const uint16_t flags, |
---|
195 | const char* name, |
---|
196 | const uint16_t sect, |
---|
197 | const rtems_rtl_word* rel); |
---|
198 | |
---|
199 | /** |
---|
200 | * Resolve the unresolved symbols. |
---|
201 | */ |
---|
202 | void rtems_rtl_unresolved_resolve (void); |
---|
203 | |
---|
204 | /** |
---|
205 | * Remove a relocation from the list of unresolved relocations. |
---|
206 | * |
---|
207 | * @param unresolved The unresolved symbol table. |
---|
208 | * @param obj The object table the symbols are for. |
---|
209 | * @param esyms The exported symbol table. |
---|
210 | * @param size The size of the table in bytes. |
---|
211 | */ |
---|
212 | bool rtems_rtl_unresolved_remove (rtems_rtl_obj* obj, |
---|
213 | const char* name, |
---|
214 | const uint16_t sect, |
---|
215 | const rtems_rtl_word* rel); |
---|
216 | |
---|
217 | /** |
---|
218 | * Set all symbols to be archive searchable. This is done when the available |
---|
219 | * archives have been refreshed and there are new archives to search for. |
---|
220 | */ |
---|
221 | void rtems_rtl_unresolved_set_archive_search (void); |
---|
222 | |
---|
223 | /** |
---|
224 | * Dump the RTL unresolved data. |
---|
225 | */ |
---|
226 | void rtems_rtl_unresolved_dump (void); |
---|
227 | |
---|
228 | #ifdef __cplusplus |
---|
229 | } |
---|
230 | #endif /* __cplusplus */ |
---|
231 | |
---|
232 | #endif |
---|