*** empty log message ***
[deliverable/binutils-gdb.git] / gold / symtab.h
CommitLineData
bae7f79e
ILT
1// symtab.h -- the gold symbol table -*- C++ -*-
2
3// Symbol_table
4// The symbol table.
5
bae7f79e
ILT
6#include <string>
7#include <utility>
ead1e424 8#include <vector>
54dc6425 9#include <cassert>
bae7f79e
ILT
10
11#include "elfcpp.h"
14bfc3f5 12#include "stringpool.h"
f6ce93d6 13#include "object.h"
bae7f79e
ILT
14
15#ifndef GOLD_SYMTAB_H
16#define GOLD_SYMTAB_H
17
18namespace gold
19{
20
14bfc3f5 21class Object;
f6ce93d6 22class Relobj;
dbe717ef
ILT
23template<int size, bool big_endian>
24class Sized_relobj;
f6ce93d6 25class Dynobj;
dbe717ef
ILT
26template<int size, bool big_endian>
27class Sized_dynobj;
ead1e424
ILT
28class Output_data;
29class Output_segment;
61ba1cf9
ILT
30class Output_file;
31class Target;
14bfc3f5 32
14bfc3f5
ILT
33// The base class of an entry in the symbol table. The symbol table
34// can have a lot of entries, so we don't want this class to big.
35// Size dependent fields can be found in the template class
36// Sized_symbol. Targets may support their own derived classes.
bae7f79e 37
bae7f79e
ILT
38class Symbol
39{
40 public:
ead1e424
ILT
41 // Because we want the class to be small, we don't use any virtual
42 // functions. But because symbols can be defined in different
43 // places, we need to classify them. This enum is the different
44 // sources of symbols we support.
45 enum Source
46 {
f6ce93d6
ILT
47 // Symbol defined in a relocatable or dynamic input file--this is
48 // the most common case.
ead1e424
ILT
49 FROM_OBJECT,
50 // Symbol defined in an Output_data, a special section created by
51 // the target.
52 IN_OUTPUT_DATA,
53 // Symbol defined in an Output_segment, with no associated
54 // section.
55 IN_OUTPUT_SEGMENT,
56 // Symbol value is constant.
57 CONSTANT
58 };
59
60 // When the source is IN_OUTPUT_SEGMENT, we need to describe what
61 // the offset means.
62 enum Segment_offset_base
63 {
64 // From the start of the segment.
65 SEGMENT_START,
66 // From the end of the segment.
67 SEGMENT_END,
68 // From the filesz of the segment--i.e., after the loaded bytes
69 // but before the bytes which are allocated but zeroed.
70 SEGMENT_BSS
71 };
72
14bfc3f5
ILT
73 // Return the symbol name.
74 const char*
75 name() const
76 { return this->name_; }
77
78 // Return the symbol version. This will return NULL for an
79 // unversioned symbol.
80 const char*
81 version() const
82 { return this->version_; }
83
ead1e424
ILT
84 // Return the symbol source.
85 Source
86 source() const
87 { return this->source_; }
88
14bfc3f5
ILT
89 // Return the object with which this symbol is associated.
90 Object*
91 object() const
ead1e424
ILT
92 {
93 assert(this->source_ == FROM_OBJECT);
94 return this->u_.from_object.object;
95 }
96
f6ce93d6
ILT
97 // Return the index of the section in the input relocatable or
98 // dynamic object file.
ead1e424
ILT
99 unsigned int
100 shnum() const
101 {
102 assert(this->source_ == FROM_OBJECT);
103 return this->u_.from_object.shnum;
104 }
105
106 // Return the output data section with which this symbol is
107 // associated, if the symbol was specially defined with respect to
108 // an output data section.
109 Output_data*
110 output_data() const
111 {
112 assert(this->source_ == IN_OUTPUT_DATA);
113 return this->u_.in_output_data.output_data;
114 }
115
116 // If this symbol was defined with respect to an output data
117 // section, return whether the value is an offset from end.
118 bool
119 offset_is_from_end() const
120 {
121 assert(this->source_ == IN_OUTPUT_DATA);
122 return this->u_.in_output_data.offset_is_from_end;
123 }
124
125 // Return the output segment with which this symbol is associated,
126 // if the symbol was specially defined with respect to an output
127 // segment.
128 Output_segment*
129 output_segment() const
130 {
131 assert(this->source_ == IN_OUTPUT_SEGMENT);
132 return this->u_.in_output_segment.output_segment;
133 }
134
135 // If this symbol was defined with respect to an output segment,
136 // return the offset base.
137 Segment_offset_base
138 offset_base() const
139 {
140 assert(this->source_ == IN_OUTPUT_SEGMENT);
141 return this->u_.in_output_segment.offset_base;
142 }
14bfc3f5
ILT
143
144 // Return the symbol binding.
145 elfcpp::STB
146 binding() const
147 { return this->binding_; }
148
1564db8d
ILT
149 // Return the symbol type.
150 elfcpp::STT
151 type() const
152 { return this->type_; }
153
154 // Return the symbol visibility.
155 elfcpp::STV
156 visibility() const
157 { return this->visibility_; }
158
159 // Return the non-visibility part of the st_other field.
160 unsigned char
ead1e424
ILT
161 nonvis() const
162 { return this->nonvis_; }
14bfc3f5 163
1564db8d
ILT
164 // Return whether this symbol is a forwarder. This will never be
165 // true of a symbol found in the hash table, but may be true of
166 // symbol pointers attached to object files.
167 bool
168 is_forwarder() const
169 { return this->is_forwarder_; }
170
171 // Mark this symbol as a forwarder.
172 void
173 set_forwarder()
174 { this->is_forwarder_ = true; }
175
f6ce93d6 176 // Return whether this symbol was ever seen in a dynamic object.
1564db8d
ILT
177 bool
178 in_dyn() const
179 { return this->in_dyn_; }
180
f6ce93d6 181 // Mark this symbol as having been seen in a dynamic object.
1564db8d
ILT
182 void
183 set_in_dyn()
184 { this->in_dyn_ = true; }
185
ead1e424 186 // Return whether this symbol has an entry in the GOT section.
92e059d8 187 bool
ead1e424
ILT
188 has_got_offset() const
189 { return this->has_got_offset_; }
190
191 // Return the offset into the GOT section of this symbol.
192 unsigned int
193 got_offset() const
194 {
195 assert(this->has_got_offset());
196 return this->got_offset_;
197 }
198
199 // Set the GOT offset of this symbol.
200 void
201 set_got_offset(unsigned int got_offset)
202 {
203 this->has_got_offset_ = true;
204 this->got_offset_ = got_offset;
205 }
206
207 // Return whether this symbol is resolved locally. This is always
208 // true when linking statically. It is true for a symbol defined in
209 // this object when using -Bsymbolic. It is true for a symbol
210 // marked local in a version file. FIXME: This needs to be
211 // completed.
212 bool
213 is_resolved_locally() const
214 { return !this->in_dyn_; }
215
f6ce93d6
ILT
216 // Return whether this is a defined symbol (not undefined or
217 // common).
218 bool
219 is_defined() const
220 {
221 return (this->source_ != FROM_OBJECT
222 || (this->u_.from_object.shnum != elfcpp::SHN_UNDEF
223 && this->u_.from_object.shnum != elfcpp::SHN_COMMON));
224 }
225
ead1e424
ILT
226 // Return whether this is an undefined symbol.
227 bool
228 is_undefined() const
229 {
230 return this->source_ == FROM_OBJECT && this->shnum() == elfcpp::SHN_UNDEF;
231 }
232
233 // Return whether this is a common symbol.
234 bool
235 is_common() const
236 {
f6ce93d6
ILT
237 return (this->source_ == FROM_OBJECT
238 && (this->u_.from_object.shnum == elfcpp::SHN_COMMON
239 || this->type_ == elfcpp::STT_COMMON));
ead1e424 240 }
92e059d8 241
f6ce93d6
ILT
242 // Return whether there should be a warning for references to this
243 // symbol.
244 bool
245 has_warning() const
246 { return this->has_warning_; }
247
248 // Mark this symbol as having a warning.
249 void
250 set_has_warning()
251 { this->has_warning_ = true; }
252
14bfc3f5
ILT
253 protected:
254 // Instances of this class should always be created at a specific
255 // size.
256 Symbol()
f6ce93d6 257 { memset(this, 0, sizeof *this); }
14bfc3f5 258
ead1e424
ILT
259 // Initialize the general fields.
260 void
261 init_fields(const char* name, const char* version,
262 elfcpp::STT type, elfcpp::STB binding,
263 elfcpp::STV visibility, unsigned char nonvis);
264
14bfc3f5
ILT
265 // Initialize fields from an ELF symbol in OBJECT.
266 template<int size, bool big_endian>
267 void
268 init_base(const char *name, const char* version, Object* object,
269 const elfcpp::Sym<size, big_endian>&);
bae7f79e 270
ead1e424
ILT
271 // Initialize fields for an Output_data.
272 void
273 init_base(const char* name, Output_data*, elfcpp::STT, elfcpp::STB,
274 elfcpp::STV, unsigned char nonvis, bool offset_is_from_end);
275
276 // Initialize fields for an Output_segment.
277 void
278 init_base(const char* name, Output_segment* os, elfcpp::STT type,
279 elfcpp::STB binding, elfcpp::STV visibility,
280 unsigned char nonvis, Segment_offset_base offset_base);
281
282 // Initialize fields for a constant.
283 void
284 init_base(const char* name, elfcpp::STT type, elfcpp::STB binding,
285 elfcpp::STV visibility, unsigned char nonvis);
286
1564db8d
ILT
287 // Override existing symbol.
288 template<int size, bool big_endian>
289 void
290 override_base(const elfcpp::Sym<size, big_endian>&, Object* object);
291
bae7f79e 292 private:
14bfc3f5
ILT
293 Symbol(const Symbol&);
294 Symbol& operator=(const Symbol&);
295
296 // Symbol name (expected to point into a Stringpool).
297 const char* name_;
298 // Symbol version (expected to point into a Stringpool). This may
299 // be NULL.
bae7f79e 300 const char* version_;
ead1e424
ILT
301
302 union
303 {
304 // This struct is used if SOURCE_ == FROM_OBJECT.
305 struct
306 {
307 // Object in which symbol is defined, or in which it was first
308 // seen.
309 Object* object;
310 // Section number in object_ in which symbol is defined.
311 unsigned int shnum;
312 } from_object;
313
314 // This struct is used if SOURCE_ == IN_OUTPUT_DATA.
315 struct
316 {
317 // Output_data in which symbol is defined. Before
318 // Layout::finalize the symbol's value is an offset within the
319 // Output_data.
320 Output_data* output_data;
321 // True if the offset is from the end, false if the offset is
322 // from the beginning.
323 bool offset_is_from_end;
324 } in_output_data;
325
326 // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
327 struct
328 {
329 // Output_segment in which the symbol is defined. Before
330 // Layout::finalize the symbol's value is an offset.
331 Output_segment* output_segment;
332 // The base to use for the offset before Layout::finalize.
333 Segment_offset_base offset_base;
334 } in_output_segment;
335 } u_;
336
337 // If this symbol has an entry in the GOT section (has_got_offset_
338 // is true), this is the offset.
339 unsigned int got_offset_;
14bfc3f5 340 // Symbol type.
bae7f79e 341 elfcpp::STT type_ : 4;
14bfc3f5 342 // Symbol binding.
bae7f79e 343 elfcpp::STB binding_ : 4;
14bfc3f5
ILT
344 // Symbol visibility.
345 elfcpp::STV visibility_ : 2;
346 // Rest of symbol st_other field.
ead1e424
ILT
347 unsigned int nonvis_ : 6;
348 // The type of symbol.
f6ce93d6 349 Source source_ : 3;
14bfc3f5
ILT
350 // True if this symbol always requires special target-specific
351 // handling.
ead1e424 352 bool is_target_special_ : 1;
14bfc3f5 353 // True if this is the default version of the symbol.
1564db8d 354 bool is_def_ : 1;
14bfc3f5
ILT
355 // True if this symbol really forwards to another symbol. This is
356 // used when we discover after the fact that two different entries
357 // in the hash table really refer to the same symbol. This will
358 // never be set for a symbol found in the hash table, but may be set
359 // for a symbol found in the list of symbols attached to an Object.
360 // It forwards to the symbol found in the forwarders_ map of
361 // Symbol_table.
1564db8d
ILT
362 bool is_forwarder_ : 1;
363 // True if we've seen this symbol in a dynamic object.
364 bool in_dyn_ : 1;
ead1e424
ILT
365 // True if the symbol has an entry in the GOT section.
366 bool has_got_offset_ : 1;
f6ce93d6
ILT
367 // True if there is a warning for this symbol.
368 bool has_warning_ : 1;
bae7f79e
ILT
369};
370
14bfc3f5
ILT
371// The parts of a symbol which are size specific. Using a template
372// derived class like this helps us use less space on a 32-bit system.
bae7f79e
ILT
373
374template<int size>
14bfc3f5
ILT
375class Sized_symbol : public Symbol
376{
377 public:
1564db8d
ILT
378 typedef typename elfcpp::Elf_types<size>::Elf_Addr Value_type;
379 typedef typename elfcpp::Elf_types<size>::Elf_WXword Size_type;
380
14bfc3f5
ILT
381 Sized_symbol()
382 { }
383
384 // Initialize fields from an ELF symbol in OBJECT.
385 template<bool big_endian>
386 void
387 init(const char *name, const char* version, Object* object,
388 const elfcpp::Sym<size, big_endian>&);
389
ead1e424
ILT
390 // Initialize fields for an Output_data.
391 void
392 init(const char* name, Output_data*, Value_type value, Size_type symsize,
393 elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
394 bool offset_is_from_end);
395
396 // Initialize fields for an Output_segment.
397 void
398 init(const char* name, Output_segment*, Value_type value, Size_type symsize,
399 elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
400 Segment_offset_base offset_base);
401
402 // Initialize fields for a constant.
403 void
404 init(const char* name, Value_type value, Size_type symsize,
405 elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
406
1564db8d
ILT
407 // Override existing symbol.
408 template<bool big_endian>
409 void
410 override(const elfcpp::Sym<size, big_endian>&, Object* object);
411
412 // Return the symbol's value.
413 Value_type
414 value() const
415 { return this->value_; }
416
417 // Return the symbol's size (we can't call this 'size' because that
418 // is a template parameter).
419 Size_type
420 symsize() const
ead1e424
ILT
421 { return this->symsize_; }
422
423 // Set the symbol size. This is used when resolving common symbols.
424 void
425 set_symsize(Size_type symsize)
426 { this->symsize_ = symsize; }
1564db8d 427
75f65a3e
ILT
428 // Set the symbol value. This is called when we store the final
429 // values of the symbols into the symbol table.
430 void
431 set_value(Value_type value)
432 { this->value_ = value; }
433
14bfc3f5
ILT
434 private:
435 Sized_symbol(const Sized_symbol&);
436 Sized_symbol& operator=(const Sized_symbol&);
437
ead1e424
ILT
438 // Symbol value. Before Layout::finalize this is the offset in the
439 // input section. This is set to the final value during
440 // Layout::finalize.
1564db8d 441 Value_type value_;
14bfc3f5 442 // Symbol size.
ead1e424
ILT
443 Size_type symsize_;
444};
445
446// A struct describing a symbol defined by the linker, where the value
447// of the symbol is defined based on an output section. This is used
448// for symbols defined by the linker, like "_init_array_start".
449
450struct Define_symbol_in_section
451{
452 // The symbol name.
453 const char* name;
454 // The name of the output section with which this symbol should be
455 // associated. If there is no output section with that name, the
456 // symbol will be defined as zero.
457 const char* output_section;
458 // The offset of the symbol within the output section. This is an
459 // offset from the start of the output section, unless start_at_end
460 // is true, in which case this is an offset from the end of the
461 // output section.
462 uint64_t value;
463 // The size of the symbol.
464 uint64_t size;
465 // The symbol type.
466 elfcpp::STT type;
467 // The symbol binding.
468 elfcpp::STB binding;
469 // The symbol visibility.
470 elfcpp::STV visibility;
471 // The rest of the st_other field.
472 unsigned char nonvis;
473 // If true, the value field is an offset from the end of the output
474 // section.
475 bool offset_is_from_end;
476 // If true, this symbol is defined only if we see a reference to it.
477 bool only_if_ref;
478};
479
480// A struct describing a symbol defined by the linker, where the value
481// of the symbol is defined based on a segment. This is used for
482// symbols defined by the linker, like "_end". We describe the
483// segment with which the symbol should be associated by its
484// characteristics. If no segment meets these characteristics, the
485// symbol will be defined as zero. If there is more than one segment
486// which meets these characteristics, we will use the first one.
487
488struct Define_symbol_in_segment
489{
490 // The symbol name.
491 const char* name;
492 // The segment type where the symbol should be defined, typically
493 // PT_LOAD.
494 elfcpp::PT segment_type;
495 // Bitmask of segment flags which must be set.
496 elfcpp::PF segment_flags_set;
497 // Bitmask of segment flags which must be clear.
498 elfcpp::PF segment_flags_clear;
499 // The offset of the symbol within the segment. The offset is
500 // calculated from the position set by offset_base.
501 uint64_t value;
502 // The size of the symbol.
503 uint64_t size;
504 // The symbol type.
505 elfcpp::STT type;
506 // The symbol binding.
507 elfcpp::STB binding;
508 // The symbol visibility.
509 elfcpp::STV visibility;
510 // The rest of the st_other field.
511 unsigned char nonvis;
512 // The base from which we compute the offset.
513 Symbol::Segment_offset_base offset_base;
514 // If true, this symbol is defined only if we see a reference to it.
515 bool only_if_ref;
14bfc3f5
ILT
516};
517
f6ce93d6
ILT
518// This class manages warnings. Warnings are a GNU extension. When
519// we see a section named .gnu.warning.SYM in an object file, and if
520// we wind using the definition of SYM from that object file, then we
521// will issue a warning for any relocation against SYM from a
522// different object file. The text of the warning is the contents of
523// the section. This is not precisely the definition used by the old
524// GNU linker; the old GNU linker treated an occurrence of
525// .gnu.warning.SYM as defining a warning symbol. A warning symbol
526// would trigger a warning on any reference. However, it was
527// inconsistent in that a warning in a dynamic object only triggered
528// if there was no definition in a regular object. This linker is
529// different in that we only issue a warning if we use the symbol
530// definition from the same object file as the warning section.
531
532class Warnings
533{
534 public:
535 Warnings()
536 : warnings_()
537 { }
538
539 // Add a warning for symbol NAME in section SHNDX in object OBJ.
540 void
541 add_warning(Symbol_table* symtab, const char* name, Object* obj,
542 unsigned int shndx);
543
544 // For each symbol for which we should give a warning, make a note
545 // on the symbol.
546 void
547 note_warnings(Symbol_table* symtab);
548
549 // Issue a warning for a reference to SYM at LOCATION.
550 void
551 issue_warning(Symbol* sym, const std::string& location) const;
552
553 private:
554 Warnings(const Warnings&);
555 Warnings& operator=(const Warnings&);
556
557 // What we need to know to get the warning text.
558 struct Warning_location
559 {
560 // The object the warning is in.
561 Object* object;
562 // The index of the warning section.
563 unsigned int shndx;
564 // The warning text if we have already loaded it.
565 std::string text;
566
567 Warning_location()
568 : object(NULL), shndx(0), text()
569 { }
570
571 void
572 set(Object* o, unsigned int s)
573 {
574 this->object = o;
575 this->shndx = s;
576 }
577
578 void
579 set_text(const char* t, off_t l)
580 { this->text.assign(t, l); }
581 };
582
583 // A mapping from warning symbol names (canonicalized in
584 // Symbol_table's namepool_ field) to
585 typedef Unordered_map<const char*, Warning_location> Warning_table;
586
587 Warning_table warnings_;
588};
589
14bfc3f5
ILT
590// The main linker symbol table.
591
bae7f79e
ILT
592class Symbol_table
593{
594 public:
595 Symbol_table();
596
1564db8d 597 ~Symbol_table();
bae7f79e 598
dbe717ef 599 // Add COUNT external symbols from the relocatable object RELOBJ to
f6ce93d6
ILT
600 // the symbol table. SYMS is the symbols, SYM_NAMES is their names,
601 // SYM_NAME_SIZE is the size of SYM_NAMES. This sets SYMPOINTERS to
602 // point to the symbols in the symbol table.
14bfc3f5
ILT
603 template<int size, bool big_endian>
604 void
dbe717ef
ILT
605 add_from_relobj(Sized_relobj<size, big_endian>* relobj,
606 const unsigned char* syms, size_t count,
607 const char* sym_names, size_t sym_name_size,
14bfc3f5
ILT
608 Symbol** sympointers);
609
dbe717ef
ILT
610 // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
611 // symbol table. SYMS is the symbols. SYM_NAMES is their names.
612 // SYM_NAME_SIZE is the size of SYM_NAMES. The other parameters are
613 // symbol version data.
614 template<int size, bool big_endian>
615 void
616 add_from_dynobj(Sized_dynobj<size, big_endian>* dynobj,
617 const unsigned char* syms, size_t count,
618 const char* sym_names, size_t sym_name_size,
619 const unsigned char* versym, size_t versym_size,
620 const std::vector<const char*>*);
621
ead1e424
ILT
622 // Define a special symbol.
623 template<int size, bool big_endian>
624 Sized_symbol<size>*
593f47df
ILT
625 define_special_symbol(Target* target, const char* name, bool only_if_ref
626 ACCEPT_SIZE_ENDIAN);
ead1e424
ILT
627
628 // Define a special symbol based on an Output_data. It is a
629 // multiple definition error if this symbol is already defined.
630 void
631 define_in_output_data(Target*, const char* name, Output_data*,
632 uint64_t value, uint64_t symsize,
633 elfcpp::STT type, elfcpp::STB binding,
634 elfcpp::STV visibility, unsigned char nonvis,
635 bool offset_is_from_end, bool only_if_ref);
636
637 // Define a special symbol based on an Output_segment. It is a
638 // multiple definition error if this symbol is already defined.
639 void
640 define_in_output_segment(Target*, const char* name, Output_segment*,
641 uint64_t value, uint64_t symsize,
642 elfcpp::STT type, elfcpp::STB binding,
643 elfcpp::STV visibility, unsigned char nonvis,
644 Symbol::Segment_offset_base, bool only_if_ref);
645
646 // Define a special symbol with a constant value. It is a multiple
647 // definition error if this symbol is already defined.
648 void
649 define_as_constant(Target*, const char* name, uint64_t value,
650 uint64_t symsize, elfcpp::STT type, elfcpp::STB binding,
651 elfcpp::STV visibility, unsigned char nonvis,
652 bool only_if_ref);
653
654 // Define a set of symbols in output sections.
655 void
656 define_symbols(const Layout*, Target*, int count,
657 const Define_symbol_in_section*);
658
659 // Define a set of symbols in output segments.
660 void
661 define_symbols(const Layout*, Target*, int count,
662 const Define_symbol_in_segment*);
663
61ba1cf9
ILT
664 // Look up a symbol.
665 Symbol*
666 lookup(const char*, const char* version = NULL) const;
667
14bfc3f5 668 // Return the real symbol associated with the forwarder symbol FROM.
bae7f79e 669 Symbol*
14bfc3f5 670 resolve_forwards(Symbol* from) const;
bae7f79e 671
14bfc3f5
ILT
672 // Return the size of the symbols in the table.
673 int
674 get_size() const
675 { return this->size_; }
bae7f79e 676
1564db8d
ILT
677 // Return the sized version of a symbol in this table.
678 template<int size>
679 Sized_symbol<size>*
5482377d 680 get_sized_symbol(Symbol* ACCEPT_SIZE) const;
1564db8d
ILT
681
682 template<int size>
683 const Sized_symbol<size>*
5482377d 684 get_sized_symbol(const Symbol* ACCEPT_SIZE) const;
54dc6425 685
ead1e424
ILT
686 // Return the count of undefined symbols seen.
687 int
688 saw_undefined() const
689 { return this->saw_undefined_; }
690
691 // Allocate the common symbols
692 void
693 allocate_commons(const General_options&, Layout*);
694
f6ce93d6
ILT
695 // Add a warning for symbol NAME in section SHNDX in object OBJ.
696 void
697 add_warning(const char* name, Object* obj, unsigned int shndx)
698 { this->warnings_.add_warning(this, name, obj, shndx); }
699
700 // Canonicalize a symbol name for use in the hash table.
701 const char*
702 canonicalize_name(const char* name)
f0641a0b 703 { return this->namepool_.add(name, NULL); }
f6ce93d6
ILT
704
705 // Possibly issue a warning for a reference to SYM at LOCATION which
706 // is in OBJ.
707 void
708 issue_warning(Symbol* sym, const std::string& location) const
709 { this->warnings_.issue_warning(sym, location); }
710
75f65a3e
ILT
711 // Finalize the symbol table after we have set the final addresses
712 // of all the input sections. This sets the final symbol values and
713 // adds the names to *POOL. It records the file offset OFF, and
714 // returns the new file offset.
715 off_t
716 finalize(off_t, Stringpool*);
1564db8d 717
61ba1cf9
ILT
718 // Write out the global symbols.
719 void
720 write_globals(const Target*, const Stringpool*, Output_file*) const;
721
bae7f79e
ILT
722 private:
723 Symbol_table(const Symbol_table&);
724 Symbol_table& operator=(const Symbol_table&);
725
14bfc3f5
ILT
726 // Set the size of the symbols in the table.
727 void
728 set_size(int size)
729 { this->size_ = size; }
730
731 // Make FROM a forwarder symbol to TO.
732 void
733 make_forwarder(Symbol* from, Symbol* to);
734
735 // Add a symbol.
736 template<int size, bool big_endian>
737 Symbol*
f0641a0b
ILT
738 add_from_object(Object*, const char *name, Stringpool::Key name_key,
739 const char *version, Stringpool::Key version_key,
740 bool def, const elfcpp::Sym<size, big_endian>& sym);
14bfc3f5
ILT
741
742 // Resolve symbols.
743 template<int size, bool big_endian>
744 static void
1564db8d
ILT
745 resolve(Sized_symbol<size>* to,
746 const elfcpp::Sym<size, big_endian>& sym,
747 Object*);
14bfc3f5 748
1564db8d 749 template<int size, bool big_endian>
14bfc3f5 750 static void
5482377d
ILT
751 resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from
752 ACCEPT_SIZE_ENDIAN);
14bfc3f5 753
ead1e424
ILT
754 // Define a symbol in an Output_data, sized version.
755 template<int size>
756 void
757 do_define_in_output_data(Target*, const char* name, Output_data*,
758 typename elfcpp::Elf_types<size>::Elf_Addr value,
759 typename elfcpp::Elf_types<size>::Elf_WXword ssize,
760 elfcpp::STT type, elfcpp::STB binding,
761 elfcpp::STV visibility, unsigned char nonvis,
762 bool offset_is_from_end, bool only_if_ref);
763
764 // Define a symbol in an Output_segment, sized version.
765 template<int size>
766 void
767 do_define_in_output_segment(
768 Target*, const char* name, Output_segment* os,
769 typename elfcpp::Elf_types<size>::Elf_Addr value,
770 typename elfcpp::Elf_types<size>::Elf_WXword ssize,
771 elfcpp::STT type, elfcpp::STB binding,
772 elfcpp::STV visibility, unsigned char nonvis,
773 Symbol::Segment_offset_base offset_base, bool only_if_ref);
774
775 // Define a symbol as a constant, sized version.
776 template<int size>
777 void
778 do_define_as_constant(
779 Target*, const char* name,
780 typename elfcpp::Elf_types<size>::Elf_Addr value,
781 typename elfcpp::Elf_types<size>::Elf_WXword ssize,
782 elfcpp::STT type, elfcpp::STB binding,
783 elfcpp::STV visibility, unsigned char nonvis,
784 bool only_if_ref);
785
786 // Allocate the common symbols, sized version.
787 template<int size>
788 void
789 do_allocate_commons(const General_options&, Layout*);
790
75f65a3e
ILT
791 // Finalize symbols specialized for size.
792 template<int size>
793 off_t
794 sized_finalize(off_t, Stringpool*);
795
61ba1cf9
ILT
796 // Write globals specialized for size and endianness.
797 template<int size, bool big_endian>
798 void
799 sized_write_globals(const Target*, const Stringpool*, Output_file*) const;
800
54dc6425
ILT
801 // The type of the symbol hash table.
802
f0641a0b 803 typedef std::pair<Stringpool::Key, Stringpool::Key> Symbol_table_key;
14bfc3f5
ILT
804
805 struct Symbol_table_hash
806 {
807 size_t
808 operator()(const Symbol_table_key&) const;
809 };
810
811 struct Symbol_table_eq
812 {
813 bool
814 operator()(const Symbol_table_key&, const Symbol_table_key&) const;
815 };
816
817 typedef Unordered_map<Symbol_table_key, Symbol*, Symbol_table_hash,
818 Symbol_table_eq> Symbol_table_type;
819
ead1e424
ILT
820 // The type of the list of common symbols.
821
822 typedef std::vector<Symbol*> Commons_type;
823
14bfc3f5
ILT
824 // The size of the symbols in the symbol table (32 or 64).
825 int size_;
826
ead1e424
ILT
827 // We increment this every time we see a new undefined symbol, for
828 // use in archive groups.
829 int saw_undefined_;
830
75f65a3e
ILT
831 // The file offset within the output symtab section where we should
832 // write the table.
833 off_t offset_;
834
61ba1cf9
ILT
835 // The number of global symbols we want to write out.
836 size_t output_count_;
837
54dc6425 838 // The symbol hash table.
14bfc3f5
ILT
839 Symbol_table_type table_;
840
54dc6425
ILT
841 // A pool of symbol names. This is used for all global symbols.
842 // Entries in the hash table point into this pool.
14bfc3f5 843 Stringpool namepool_;
bae7f79e 844
14bfc3f5
ILT
845 // Forwarding symbols.
846 Unordered_map<Symbol*, Symbol*> forwarders_;
ead1e424
ILT
847
848 // We don't expect there to be very many common symbols, so we keep
849 // a list of them. When we find a common symbol we add it to this
850 // list. It is possible that by the time we process the list the
851 // symbol is no longer a common symbol. It may also have become a
852 // forwarder.
853 Commons_type commons_;
f6ce93d6
ILT
854
855 // Manage symbol warnings.
856 Warnings warnings_;
bae7f79e
ILT
857};
858
1564db8d
ILT
859// We inline get_sized_symbol for efficiency.
860
861template<int size>
862Sized_symbol<size>*
5482377d 863Symbol_table::get_sized_symbol(Symbol* sym ACCEPT_SIZE) const
1564db8d
ILT
864{
865 assert(size == this->get_size());
866 return static_cast<Sized_symbol<size>*>(sym);
867}
868
869template<int size>
870const Sized_symbol<size>*
5482377d 871Symbol_table::get_sized_symbol(const Symbol* sym ACCEPT_SIZE) const
1564db8d
ILT
872{
873 assert(size == this->get_size());
874 return static_cast<const Sized_symbol<size>*>(sym);
875}
876
bae7f79e
ILT
877} // End namespace gold.
878
879#endif // !defined(GOLD_SYMTAB_H)
This page took 0.085761 seconds and 4 git commands to generate.