source: rtems/cpukit/include/rtems/rtl/rtl-sym.h @ 327e45da

5
Last change on this file since 327e45da was 327e45da, checked in by Chris Johns <chrisj@…>, on 05/14/19 at 00:34:32

libdl: Sort object file symbols and use a binary search to find

  • Replace the linear object file symbol search with a binary search.
  • Sort the object file symbols after loading.

Closes #3748

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 2012-2014, 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 Symbol Table.
14 */
15
16#if !defined (_RTEMS_RTL_SYM_H_)
17#define _RTEMS_RTL_SYM_H_
18
19#include <rtems.h>
20#include "rtl-obj-fwd.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26/**
27 * An object file symbol.
28 */
29typedef struct rtems_rtl_obj_sym
30{
31  rtems_chain_node node;    /**< The node's link in the chain. */
32  const char*      name;    /**< The symbol's name. */
33  void*            value;   /**< The value of the symbol. */
34  uint32_t         data;    /**< Format specific data. */
35} rtems_rtl_obj_sym;
36
37/**
38 * Table of symbols stored in a hash table.
39 */
40typedef struct rtems_rtl_symbols
41{
42  rtems_chain_control* buckets;
43  size_t               nbuckets;
44} rtems_rtl_symbols;
45
46/**
47 * Open a symbol table with the specified number of buckets.
48 *
49 * @param symbols The symbol table to open.
50 * @param buckets The number of buckets in the hash table.
51 * @retval true The symbol is open.
52 * @retval false The symbol table could not created. The RTL
53 *               error has the error.
54 */
55bool rtems_rtl_symbol_table_open (rtems_rtl_symbols* symbols,
56                                  size_t             buckets);
57
58/**
59 * Close the table and erase the hash table.
60 *
61 * @param symbols Close the symbol table.
62 */
63void rtems_rtl_symbol_table_close (rtems_rtl_symbols* symbols);
64
65/**
66 * Add a table of exported symbols to the symbol table.
67 *
68 * The export table is a series of symbol records and each record has two
69 * fields:
70 *
71 *  1. label
72 *  2. address
73 *
74 * The 'label' is an ASCIIZ string of variable length. The address is of size
75 * of an unsigned long for the target running the link editor. The byte order
76 * is defined by the machine type because the table should be built by the
77 * target compiler.
78 *
79 * The table is terminated with a nul string followed by the bytes 0xDE, 0xAD,
80 * 0xBE, and 0xEF. This avoids alignments issues.
81 *
82 * @param obj The object table the symbols are for.
83 * @param esyms The exported symbol table.
84 * @param size The size of the table in bytes.
85 */
86bool rtems_rtl_symbol_global_add (rtems_rtl_obj*       obj,
87                                  const unsigned char* esyms,
88                                  unsigned int         size);
89
90/**
91 * Find a symbol given the symbol label in the global symbol table.
92 *
93 * @param name The name as an ASCIIZ string.
94 * @retval NULL No symbol found.
95 * @return rtems_rtl_obj_sym* Reference to the symbol.
96 */
97rtems_rtl_obj_sym* rtems_rtl_symbol_global_find (const char* name);
98
99/**
100 * Sort an object file's local and global symbol table. This needs to
101 * be done before calling @ref rtems_rtl_symbol_obj_find as it
102 * performs a binary search on the tables.
103 *
104 * @param obj The object file to sort.
105 */
106void rtems_rtl_symbol_obj_sort (rtems_rtl_obj* obj);
107
108/**
109 * Find a symbol given the symbol label in the local object file.
110 *
111 * @param obj The object file to search.
112 * @param name The name as an ASCIIZ string.
113 * @retval NULL No symbol found.
114 * @return rtems_rtl_obj_sym* Reference to the symbol.
115 */
116rtems_rtl_obj_sym* rtems_rtl_symbol_obj_find (rtems_rtl_obj* obj,
117                                              const char*    name);
118
119/**
120 * Add the object file's symbols to the global table.
121 *
122 * @param obj The object file the symbols are to be added.
123 */
124void rtems_rtl_symbol_obj_add (rtems_rtl_obj* obj);
125
126/**
127 * Erase the object file's local symbols.
128 *
129 * @param obj The object file the local symbols are to be erased from.
130 */
131void rtems_rtl_symbol_obj_erase_local (rtems_rtl_obj* obj);
132
133/**
134 * Erase the object file's symbols.
135 *
136 * @param obj The object file the symbols are to be erased from.
137 */
138void rtems_rtl_symbol_obj_erase (rtems_rtl_obj* obj);
139
140#ifdef __cplusplus
141}
142#endif /* __cplusplus */
143
144#endif
Note: See TracBrowser for help on using the repository browser.