1 // symtab.h -- the gold symbol table -*- C++ -*-
11 #include "stringpool.h"
21 template<int size
, bool big_endian
>
24 // The base class of an entry in the symbol table. The symbol table
25 // can have a lot of entries, so we don't want this class to big.
26 // Size dependent fields can be found in the template class
27 // Sized_symbol. Targets may support their own derived classes.
32 // Return the symbol name.
35 { return this->name_
; }
37 // Return the symbol version. This will return NULL for an
38 // unversioned symbol.
41 { return this->version_
; }
43 // Return the object with which this symbol is associated.
46 { return this->object_
; }
48 // Return the symbol binding.
51 { return this->binding_
; }
53 // Return the symbol type.
56 { return this->type_
; }
58 // Return the symbol visibility.
61 { return this->visibility_
; }
63 // Return the non-visibility part of the st_other field.
66 { return this->other_
; }
68 // Return the section index.
71 { return this->shnum_
; }
73 // Return whether this symbol is a forwarder. This will never be
74 // true of a symbol found in the hash table, but may be true of
75 // symbol pointers attached to object files.
78 { return this->is_forwarder_
; }
80 // Mark this symbol as a forwarder.
83 { this->is_forwarder_
= true; }
85 // Return whether this symbol was seen in a dynamic object.
88 { return this->in_dyn_
; }
90 // Mark this symbol as seen in a dynamic object.
93 { this->in_dyn_
= true; }
96 // Instances of this class should always be created at a specific
101 // Initialize fields from an ELF symbol in OBJECT.
102 template<int size
, bool big_endian
>
104 init_base(const char *name
, const char* version
, Object
* object
,
105 const elfcpp::Sym
<size
, big_endian
>&);
107 // Override existing symbol.
108 template<int size
, bool big_endian
>
110 override_base(const elfcpp::Sym
<size
, big_endian
>&, Object
* object
);
113 Symbol(const Symbol
&);
114 Symbol
& operator=(const Symbol
&);
116 // Symbol name (expected to point into a Stringpool).
118 // Symbol version (expected to point into a Stringpool). This may
120 const char* version_
;
121 // Object in which symbol is defined, or in which it was first seen.
123 // Section number in object_ in which symbol is defined.
126 elfcpp::STT type_
: 4;
128 elfcpp::STB binding_
: 4;
129 // Symbol visibility.
130 elfcpp::STV visibility_
: 2;
131 // Rest of symbol st_other field.
132 unsigned int other_
: 6;
133 // True if this symbol always requires special target-specific
135 bool is_special_
: 1;
136 // True if this is the default version of the symbol.
138 // True if this symbol really forwards to another symbol. This is
139 // used when we discover after the fact that two different entries
140 // in the hash table really refer to the same symbol. This will
141 // never be set for a symbol found in the hash table, but may be set
142 // for a symbol found in the list of symbols attached to an Object.
143 // It forwards to the symbol found in the forwarders_ map of
145 bool is_forwarder_
: 1;
146 // True if we've seen this symbol in a dynamic object.
150 // The parts of a symbol which are size specific. Using a template
151 // derived class like this helps us use less space on a 32-bit system.
154 class Sized_symbol
: public Symbol
157 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Value_type
;
158 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Size_type
;
163 // Initialize fields from an ELF symbol in OBJECT.
164 template<bool big_endian
>
166 init(const char *name
, const char* version
, Object
* object
,
167 const elfcpp::Sym
<size
, big_endian
>&);
169 // Override existing symbol.
170 template<bool big_endian
>
172 override(const elfcpp::Sym
<size
, big_endian
>&, Object
* object
);
174 // Return the symbol's value.
177 { return this->value_
; }
179 // Return the symbol's size (we can't call this 'size' because that
180 // is a template parameter).
183 { return this->size_
; }
186 Sized_symbol(const Sized_symbol
&);
187 Sized_symbol
& operator=(const Sized_symbol
&);
195 // The main linker symbol table.
204 // Add COUNT external symbols from OBJECT to the symbol table. SYMS
205 // is the symbols, SYM_NAMES is their names, SYM_NAME_SIZE is the
206 // size of SYM_NAMES. This sets SYMPOINTERS to point to the symbols
207 // in the symbol table.
208 template<int size
, bool big_endian
>
210 add_from_object(Sized_object
<size
, big_endian
>* object
,
211 const elfcpp::Sym
<size
, big_endian
>* syms
,
212 size_t count
, const char* sym_names
, size_t sym_name_size
,
213 Symbol
** sympointers
);
215 // Return the real symbol associated with the forwarder symbol FROM.
217 resolve_forwards(Symbol
* from
) const;
219 // Return the size of the symbols in the table.
222 { return this->size_
; }
224 // Return the sized version of a symbol in this table.
227 get_sized_symbol(Symbol
*) const;
230 const Sized_symbol
<size
>*
231 get_sized_symbol(const Symbol
*) const;
233 // Record the names of the local symbols for an object.
234 template<int size
, bool big_endian
>
236 add_local_symbol_names(Sized_object
<size
, big_endian
>* object
,
237 const elfcpp::Sym
<size
, big_endian
>* syms
,
238 size_t count
, const char* sym_names
,
239 size_t sym_name_size
);
242 Symbol_table(const Symbol_table
&);
243 Symbol_table
& operator=(const Symbol_table
&);
245 // Set the size of the symbols in the table.
248 { this->size_
= size
; }
250 // Make FROM a forwarder symbol to TO.
252 make_forwarder(Symbol
* from
, Symbol
* to
);
255 template<int size
, bool big_endian
>
257 add_from_object(Sized_object
<size
, big_endian
>*, const char *name
,
258 const char *version
, bool def
,
259 const elfcpp::Sym
<size
, big_endian
>& sym
);
262 template<int size
, bool big_endian
>
264 resolve(Sized_symbol
<size
>* to
,
265 const elfcpp::Sym
<size
, big_endian
>& sym
,
268 template<int size
, bool big_endian
>
270 resolve(Sized_symbol
<size
>* to
, const Sized_symbol
<size
>* from
);
272 // The type of the symbol hash table.
274 typedef std::pair
<const char*, const char*> Symbol_table_key
;
276 struct Symbol_table_hash
279 operator()(const Symbol_table_key
&) const;
282 struct Symbol_table_eq
285 operator()(const Symbol_table_key
&, const Symbol_table_key
&) const;
288 typedef Unordered_map
<Symbol_table_key
, Symbol
*, Symbol_table_hash
,
289 Symbol_table_eq
> Symbol_table_type
;
291 // The size of the symbols in the symbol table (32 or 64).
294 // The symbol hash table.
295 Symbol_table_type table_
;
297 // A pool of symbol names. This is used for all global symbols.
298 // Entries in the hash table point into this pool.
299 Stringpool namepool_
;
301 // A pool of symbol names to go into the output file. This is used
302 // for all symbols, global and local, but only the names of symbols
303 // which will definitely be output are added to this pool.
304 Stringpool output_pool_
;
306 // Forwarding symbols.
307 Unordered_map
<Symbol
*, Symbol
*> forwarders_
;
310 // We inline get_sized_symbol for efficiency.
314 Symbol_table::get_sized_symbol(Symbol
* sym
) const
316 assert(size
== this->get_size());
317 return static_cast<Sized_symbol
<size
>*>(sym
);
321 const Sized_symbol
<size
>*
322 Symbol_table::get_sized_symbol(const Symbol
* sym
) const
324 assert(size
== this->get_size());
325 return static_cast<const Sized_symbol
<size
>*>(sym
);
328 } // End namespace gold.
330 #endif // !defined(GOLD_SYMTAB_H)