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