source: rtems/cpukit/include/rtems/rtl/rtl-unresolved.h @ b36c5209

5
Last change on this file since b36c5209 was b36c5209, checked in by Chris Johns <chrisj@…>, on 05/03/19 at 00:15:20

libdl: Do not access the ELF file while the allocator is locked.

  • Load symbols before allocation.
  • Parse reloc records and place any reloc recs in a cache to use while the allocator is locked.
  • Relocate symbols after section allocation.
  • Split section loading into allocation/locating and loading.
  • Update all arch back-ends with a new reloc interface to control tramp handling.
  • Add -a and -t to the object list shell command.

Closes #3741

  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 2012, 2019 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 <rtems/chain.h>
57#include "rtl-obj-fwd.h"
58
59#ifdef __cplusplus
60extern "C" {
61#endif /* __cplusplus */
62
63/**
64 * Hack to work around machine size. This needs to be cleaned up
65 * to better support 64bit targets.
66 */
67typedef uint32_t rtems_rtl_word;
68
69/**
70 * The types of records in the blocks.
71 */
72typedef enum rtems_rtl_unresolved_rtype
73{
74  rtems_rtl_unresolved_empty = 0,  /**< The records is empty. Must always be 0 */
75  rtems_rtl_unresolved_symbol = 1, /**< The record is a symbol. */
76  rtems_rtl_unresolved_reloc = 2,  /**< The record is a relocation record. */
77  rtems_rtl_trampoline_reloc = 3   /**< The record is a trampoline relocation record. */
78} rtems_rtl_unresolved_rtype;
79
80/**
81 * Unresolved external symbol flags.
82 */
83#define RTEMS_RTL_UNRESOLV_SYM_SEARCH_ARCHIVE (1 << 0) /**< Search the archive. */
84#define RTEMS_RTL_UNRESOLV_SYM_HAS_ERROR      (1 << 1) /**< The symbol load
85                                                        *   has an error. */
86
87/**
88 * Unresolved externals symbols. The symbols are reference counted and separate
89 * from the relocation records because a number of records could reference the
90 * same symbol.
91 *
92 * The name is extended in the allocator of the record in the unresolved data
93 * block. The 10 is a minimum that is added to by joining more than one record.
94 */
95typedef struct rtems_rtl_unresolv_symbol
96{
97  uint16_t   refs;     /**< The number of references to this name. */
98  uint16_t   flags;    /**< Flags to manage the symbol. */
99  uint16_t   length;   /**< The length of this name. */
100  const char name[];   /**< The symbol name. */
101} rtems_rtl_unresolv_symbol;
102
103/**
104 * Unresolved externals symbols require the relocation records to be held
105 * and referenced.
106 */
107typedef struct rtems_rtl_unresolv_reloc
108{
109  rtems_rtl_obj* obj;     /**< The relocation's object file. */
110  uint16_t       flags;   /**< Format specific flags. */
111  uint16_t       name;    /**< The symbol's name. */
112  uint16_t       sect;    /**< The target section. */
113  rtems_rtl_word rel[3];  /**< Relocation record. */
114} rtems_rtl_unresolv_reloc;
115
116/**
117 * Trampolines require the relocation records to be held
118 */
119typedef struct rtems_rtl_tramp_reloc
120{
121  rtems_rtl_obj* obj;      /**< The relocation's object file. */
122  uint16_t       flags;    /**< Format specific flags. */
123  uint16_t       sect;     /**< The target section. */
124  rtems_rtl_word symvalue; /**< The symbol's value. */
125  rtems_rtl_word rel[3];   /**< Relocation record. */
126} rtems_rtl_tramp_reloc;
127
128/**
129 * Unresolved externals records.
130 */
131typedef struct rtems_rtl_unresolv_rec
132{
133  rtems_rtl_unresolved_rtype type;
134  union
135  {
136    rtems_rtl_unresolv_symbol name;   /**< The symbol, or */
137    rtems_rtl_unresolv_reloc  reloc;  /**< The relocation record. */
138    rtems_rtl_tramp_reloc     tramp;  /**< The trampoline relocation record. */
139  } rec;
140} rtems_rtl_unresolv_rec;
141
142/**
143 * Unresolved blocks.
144 */
145typedef struct rtems_rtl_unresolv_block
146{
147  rtems_chain_node       link;  /**< Blocks are chained. */
148  uint32_t               recs;  /**< The number of records in the block. */
149  rtems_rtl_unresolv_rec rec[]; /**< The records. More follow. */
150} rtems_rtl_unresolv_block;
151
152/**
153 * Unresolved table holds the names and relocations.
154 */
155typedef struct rtems_rtl_unresolved
156{
157  uint32_t            marker;     /**< Block marker. */
158  size_t              block_recs; /**< The records per blocks allocated. */
159  rtems_chain_control blocks;     /**< List of blocks. */
160} rtems_rtl_unresolved;
161
162/**
163 * The iterator function used to iterate over the unresolved table.
164 *
165 * @param rec The current iterator.
166 * @param data The user data.
167 * @retval true The iterator has finished.
168 * @retval false The iterator has not finished. Keep iterating.
169 */
170typedef bool rtems_rtl_unresolved_iterator (rtems_rtl_unresolv_rec* rec,
171                                            void*                   data);
172
173/**
174 * Open an unresolved relocation table.
175 *
176 * @param unresolv The unresolved table to open.
177 * @param block_records The number of records per block allocated.
178 * @retval true The table is open.
179 * @retval false The unresolved relocation table could not created. The RTL
180 *               error has the error.
181 */
182bool rtems_rtl_unresolved_table_open (rtems_rtl_unresolved* unresolved,
183                                      size_t                block_records);
184
185/**
186 * Close the table and erase the blocks.
187 *
188 * @param unreolved Close the unresolved table.
189 */
190void rtems_rtl_unresolved_table_close (rtems_rtl_unresolved* unresolved);
191
192/**
193 * Iterate over the table of unresolved entries.
194 */
195bool rtems_rtl_unresolved_iterate (rtems_rtl_unresolved_iterator iterator,
196                                   void*                         data);
197
198/**
199 * Add a relocation to the list of unresolved relocations.
200 *
201 * @param unresolved The unresolved symbol table.
202 * @param obj The object table the symbols are for.
203 * @param flags Format specific flags.
204 * @param name The symbol name the relocation references.
205 * @param sect The target section number the relocation references.
206 * @param rel The format specific relocation data.
207 * @retval true The relocation has been added.
208 * @retval false The relocation could not be added.
209 */
210bool rtems_rtl_unresolved_add (rtems_rtl_obj*        obj,
211                               const uint16_t        flags,
212                               const char*           name,
213                               const uint16_t        sect,
214                               const rtems_rtl_word* rel);
215
216/**
217 * Resolve the unresolved symbols.
218 */
219void rtems_rtl_unresolved_resolve (void);
220
221/**
222 * Remove a relocation from the list of unresolved relocations.
223 *
224 * @param unresolved The unresolved symbol table.
225 * @param obj The object table the symbols are for.
226 * @param esyms The exported symbol table.
227 * @param size The size of the table in bytes.
228 */
229bool rtems_rtl_unresolved_remove (rtems_rtl_obj*        obj,
230                                  const char*           name,
231                                  const uint16_t        sect,
232                                  const rtems_rtl_word* rel);
233
234/**
235 * Set all symbols to be archive searchable. This is done when the available
236 * archives have been refreshed and there are new archives to search for.
237 */
238void rtems_rtl_unresolved_set_archive_search (void);
239
240/**
241 * Dump the RTL unresolved data.
242 */
243void rtems_rtl_unresolved_dump (void);
244
245#ifdef __cplusplus
246}
247#endif /* __cplusplus */
248
249#endif
Note: See TracBrowser for help on using the repository browser.