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_
; }
185 // Set the symbol value. This is called when we store the final
186 // values of the symbols into the symbol table.
188 set_value(Value_type value
)
189 { this->value_
= value
; }
192 Sized_symbol(const Sized_symbol
&);
193 Sized_symbol
& operator=(const Sized_symbol
&);
201 // The main linker symbol table.
210 // Add COUNT external symbols from OBJECT to the symbol table. SYMS
211 // is the symbols, SYM_NAMES is their names, SYM_NAME_SIZE is the
212 // size of SYM_NAMES. This sets SYMPOINTERS to point to the symbols
213 // in the symbol table.
214 template<int size
, bool big_endian
>
216 add_from_object(Sized_object
<size
, big_endian
>* object
,
217 const elfcpp::Sym
<size
, big_endian
>* syms
,
218 size_t count
, const char* sym_names
, size_t sym_name_size
,
219 Symbol
** sympointers
);
221 // Return the real symbol associated with the forwarder symbol FROM.
223 resolve_forwards(Symbol
* from
) const;
225 // Return the size of the symbols in the table.
228 { return this->size_
; }
230 // Return the sized version of a symbol in this table.
233 get_sized_symbol(Symbol
*) const;
236 const Sized_symbol
<size
>*
237 get_sized_symbol(const Symbol
*) const;
239 // Finalize the symbol table after we have set the final addresses
240 // of all the input sections. This sets the final symbol values and
241 // adds the names to *POOL. It records the file offset OFF, and
242 // returns the new file offset.
244 finalize(off_t
, Stringpool
*);
247 Symbol_table(const Symbol_table
&);
248 Symbol_table
& operator=(const Symbol_table
&);
250 // Set the size of the symbols in the table.
253 { this->size_
= size
; }
255 // Make FROM a forwarder symbol to TO.
257 make_forwarder(Symbol
* from
, Symbol
* to
);
260 template<int size
, bool big_endian
>
262 add_from_object(Sized_object
<size
, big_endian
>*, const char *name
,
263 const char *version
, bool def
,
264 const elfcpp::Sym
<size
, big_endian
>& sym
);
267 template<int size
, bool big_endian
>
269 resolve(Sized_symbol
<size
>* to
,
270 const elfcpp::Sym
<size
, big_endian
>& sym
,
273 #ifdef HAVE_MEMBER_TEMPLATE_SPECIFICATIONS
274 template<int size
, bool big_endian
>
276 resolve(Sized_symbol
<size
>* to
, const Sized_symbol
<size
>* from
);
280 resolve(Sized_symbol
<size
>* to
, const Sized_symbol
<size
>* from
,
284 // Finalize symbols specialized for size.
287 sized_finalize(off_t
, Stringpool
*);
289 // The type of the symbol hash table.
291 typedef std::pair
<const char*, const char*> Symbol_table_key
;
293 struct Symbol_table_hash
296 operator()(const Symbol_table_key
&) const;
299 struct Symbol_table_eq
302 operator()(const Symbol_table_key
&, const Symbol_table_key
&) const;
305 typedef Unordered_map
<Symbol_table_key
, Symbol
*, Symbol_table_hash
,
306 Symbol_table_eq
> Symbol_table_type
;
308 // The size of the symbols in the symbol table (32 or 64).
311 // The file offset within the output symtab section where we should
315 // The symbol hash table.
316 Symbol_table_type table_
;
318 // A pool of symbol names. This is used for all global symbols.
319 // Entries in the hash table point into this pool.
320 Stringpool namepool_
;
322 // Forwarding symbols.
323 Unordered_map
<Symbol
*, Symbol
*> forwarders_
;
326 // We inline get_sized_symbol for efficiency.
330 Symbol_table::get_sized_symbol(Symbol
* sym
) const
332 assert(size
== this->get_size());
333 return static_cast<Sized_symbol
<size
>*>(sym
);
337 const Sized_symbol
<size
>*
338 Symbol_table::get_sized_symbol(const Symbol
* sym
) const
340 assert(size
== this->get_size());
341 return static_cast<const Sized_symbol
<size
>*>(sym
);
344 } // End namespace gold.
346 #endif // !defined(GOLD_SYMTAB_H)
This page took 0.037826 seconds and 4 git commands to generate.