1 // symtab.h -- the gold symbol table -*- C++ -*-
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
31 #include "parameters.h"
32 #include "stringpool.h"
43 template<int size, bool big_endian>
46 template<int size, bool big_endian>
55 // The base class of an entry in the symbol table. The symbol table
56 // can have a lot of entries, so we don't want this class to big.
57 // Size dependent fields can be found in the template class
58 // Sized_symbol. Targets may support their own derived classes.
63 // Because we want the class to be small, we don't use any virtual
64 // functions. But because symbols can be defined in different
65 // places, we need to classify them. This enum is the different
66 // sources of symbols we support.
69 // Symbol defined in a relocatable or dynamic input file--this is
70 // the most common case.
72 // Symbol defined in an Output_data, a special section created by
75 // Symbol defined in an Output_segment, with no associated
78 // Symbol value is constant.
82 // When the source is IN_OUTPUT_SEGMENT, we need to describe what
84 enum Segment_offset_base
86 // From the start of the segment.
88 // From the end of the segment.
90 // From the filesz of the segment--i.e., after the loaded bytes
91 // but before the bytes which are allocated but zeroed.
95 // Return the symbol name.
98 { return this->name_; }
100 // Return the symbol version. This will return NULL for an
101 // unversioned symbol.
104 { return this->version_; }
106 // Return the symbol source.
109 { return this->source_; }
111 // Return the object with which this symbol is associated.
115 gold_assert(this->source_ == FROM_OBJECT);
116 return this->u_.from_object.object;
119 // Return the index of the section in the input relocatable or
120 // dynamic object file.
124 gold_assert(this->source_ == FROM_OBJECT);
125 return this->u_.from_object.shndx;
128 // Return the output data section with which this symbol is
129 // associated, if the symbol was specially defined with respect to
130 // an output data section.
134 gold_assert(this->source_ == IN_OUTPUT_DATA);
135 return this->u_.in_output_data.output_data;
138 // If this symbol was defined with respect to an output data
139 // section, return whether the value is an offset from end.
141 offset_is_from_end() const
143 gold_assert(this->source_ == IN_OUTPUT_DATA);
144 return this->u_.in_output_data.offset_is_from_end;
147 // Return the output segment with which this symbol is associated,
148 // if the symbol was specially defined with respect to an output
151 output_segment() const
153 gold_assert(this->source_ == IN_OUTPUT_SEGMENT);
154 return this->u_.in_output_segment.output_segment;
157 // If this symbol was defined with respect to an output segment,
158 // return the offset base.
162 gold_assert(this->source_ == IN_OUTPUT_SEGMENT);
163 return this->u_.in_output_segment.offset_base;
166 // Return the symbol binding.
169 { return this->binding_; }
171 // Return the symbol type.
174 { return this->type_; }
176 // Return the symbol visibility.
179 { return this->visibility_; }
181 // Return the non-visibility part of the st_other field.
184 { return this->nonvis_; }
186 // Return whether this symbol is a forwarder. This will never be
187 // true of a symbol found in the hash table, but may be true of
188 // symbol pointers attached to object files.
191 { return this->is_forwarder_; }
193 // Mark this symbol as a forwarder.
196 { this->is_forwarder_ = true; }
198 // Return whether this symbol has an alias in the weak aliases table
202 { return this->has_alias_; }
204 // Mark this symbol as having an alias.
207 { this->has_alias_ = true; }
209 // Return whether this symbol needs an entry in the dynamic symbol
212 needs_dynsym_entry() const
214 return (this->needs_dynsym_entry_
215 || (this->in_reg() && this->in_dyn()));
218 // Mark this symbol as needing an entry in the dynamic symbol table.
220 set_needs_dynsym_entry()
221 { this->needs_dynsym_entry_ = true; }
223 // Return whether this symbol should be added to the dynamic symbol
226 should_add_dynsym_entry() const;
228 // Return whether this symbol has been seen in a regular object.
231 { return this->in_reg_; }
233 // Mark this symbol as having been seen in a regular object.
236 { this->in_reg_ = true; }
238 // Return whether this symbol has been seen in a dynamic object.
241 { return this->in_dyn_; }
243 // Mark this symbol as having been seen in a dynamic object.
246 { this->in_dyn_ = true; }
248 // Return the index of this symbol in the output file symbol table.
249 // A value of -1U means that this symbol is not going into the
250 // output file. This starts out as zero, and is set to a non-zero
251 // value by Symbol_table::finalize. It is an error to ask for the
252 // symbol table index before it has been set.
256 gold_assert(this->symtab_index_ != 0);
257 return this->symtab_index_;
260 // Set the index of the symbol in the output file symbol table.
262 set_symtab_index(unsigned int index)
264 gold_assert(index != 0);
265 this->symtab_index_ = index;
268 // Return whether this symbol already has an index in the output
269 // file symbol table.
271 has_symtab_index() const
272 { return this->symtab_index_ != 0; }
274 // Return the index of this symbol in the dynamic symbol table. A
275 // value of -1U means that this symbol is not going into the dynamic
276 // symbol table. This starts out as zero, and is set to a non-zero
277 // during Layout::finalize. It is an error to ask for the dynamic
278 // symbol table index before it has been set.
282 gold_assert(this->dynsym_index_ != 0);
283 return this->dynsym_index_;
286 // Set the index of the symbol in the dynamic symbol table.
288 set_dynsym_index(unsigned int index)
290 gold_assert(index != 0);
291 this->dynsym_index_ = index;
294 // Return whether this symbol already has an index in the dynamic
297 has_dynsym_index() const
298 { return this->dynsym_index_ != 0; }
300 // Return whether this symbol has an entry in the GOT section.
302 has_got_offset() const
303 { return this->has_got_offset_; }
305 // Return the offset into the GOT section of this symbol.
309 gold_assert(this->has_got_offset());
310 return this->got_offset_;
313 // Set the GOT offset of this symbol.
315 set_got_offset(unsigned int got_offset)
317 this->has_got_offset_ = true;
318 this->got_offset_ = got_offset;
321 // Return whether this symbol has an entry in the PLT section.
323 has_plt_offset() const
324 { return this->has_plt_offset_; }
326 // Return the offset into the PLT section of this symbol.
330 gold_assert(this->has_plt_offset());
331 return this->plt_offset_;
334 // Set the PLT offset of this symbol.
336 set_plt_offset(unsigned int plt_offset)
338 this->has_plt_offset_ = true;
339 this->plt_offset_ = plt_offset;
342 // Return whether this dynamic symbol needs a special value in the
343 // dynamic symbol table.
345 needs_dynsym_value() const
346 { return this->needs_dynsym_value_; }
348 // Set that this dynamic symbol needs a special value in the dynamic
351 set_needs_dynsym_value()
353 gold_assert(this->object()->is_dynamic());
354 this->needs_dynsym_value_ = true;
357 // Return true if the final value of this symbol is known at link
360 final_value_is_known() const;
362 // Return whether this is a defined symbol (not undefined or
367 return (this->source_ != FROM_OBJECT
368 || (this->shndx() != elfcpp::SHN_UNDEF
369 && this->shndx() != elfcpp::SHN_COMMON));
372 // Return true if this symbol is from a dynamic object.
374 is_from_dynobj() const
376 return this->source_ == FROM_OBJECT && this->object()->is_dynamic();
379 // Return whether this is an undefined symbol.
383 return this->source_ == FROM_OBJECT && this->shndx() == elfcpp::SHN_UNDEF;
386 // Return whether this is a common symbol.
390 return (this->source_ == FROM_OBJECT
391 && (this->shndx() == elfcpp::SHN_COMMON
392 || this->type_ == elfcpp::STT_COMMON));
395 // Return whether this symbol can be seen outside this object.
397 is_externally_visible() const
399 return (this->visibility_ == elfcpp::STV_DEFAULT
400 || this->visibility_ == elfcpp::STV_PROTECTED);
403 // Return true if this symbol can be preempted by a definition in
404 // another link unit.
406 is_preemptible() const
408 return (this->visibility_ != elfcpp::STV_INTERNAL
409 && this->visibility_ != elfcpp::STV_HIDDEN
410 && this->visibility_ != elfcpp::STV_PROTECTED);
413 // Return whether there should be a warning for references to this
417 { return this->has_warning_; }
419 // Mark this symbol as having a warning.
422 { this->has_warning_ = true; }
425 // Instances of this class should always be created at a specific
428 { memset(this, 0, sizeof *this); }
430 // Initialize the general fields.
432 init_fields(const char* name, const char* version,
433 elfcpp::STT type, elfcpp::STB binding,
434 elfcpp::STV visibility, unsigned char nonvis);
436 // Initialize fields from an ELF symbol in OBJECT.
437 template<int size, bool big_endian>
439 init_base(const char *name, const char* version, Object* object,
440 const elfcpp::Sym<size, big_endian>&);
442 // Initialize fields for an Output_data.
444 init_base(const char* name, Output_data*, elfcpp::STT, elfcpp::STB,
445 elfcpp::STV, unsigned char nonvis, bool offset_is_from_end);
447 // Initialize fields for an Output_segment.
449 init_base(const char* name, Output_segment* os, elfcpp::STT type,
450 elfcpp::STB binding, elfcpp::STV visibility,
451 unsigned char nonvis, Segment_offset_base offset_base);
453 // Initialize fields for a constant.
455 init_base(const char* name, elfcpp::STT type, elfcpp::STB binding,
456 elfcpp::STV visibility, unsigned char nonvis);
458 // Override existing symbol.
459 template<int size, bool big_endian>
461 override_base(const elfcpp::Sym<size, big_endian>&, Object* object,
462 const char* version);
464 // Override existing symbol with a special symbol.
466 override_base_with_special(const Symbol* from);
469 Symbol(const Symbol&);
470 Symbol& operator=(const Symbol&);
472 // Symbol name (expected to point into a Stringpool).
474 // Symbol version (expected to point into a Stringpool). This may
476 const char* version_;
480 // This struct is used if SOURCE_ == FROM_OBJECT.
483 // Object in which symbol is defined, or in which it was first
486 // Section number in object_ in which symbol is defined.
490 // This struct is used if SOURCE_ == IN_OUTPUT_DATA.
493 // Output_data in which symbol is defined. Before
494 // Layout::finalize the symbol's value is an offset within the
496 Output_data* output_data;
497 // True if the offset is from the end, false if the offset is
498 // from the beginning.
499 bool offset_is_from_end;
502 // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
505 // Output_segment in which the symbol is defined. Before
506 // Layout::finalize the symbol's value is an offset.
507 Output_segment* output_segment;
508 // The base to use for the offset before Layout::finalize.
509 Segment_offset_base offset_base;
513 // The index of this symbol in the output file. If the symbol is
514 // not going into the output file, this value is -1U. This field
515 // starts as always holding zero. It is set to a non-zero value by
516 // Symbol_table::finalize.
517 unsigned int symtab_index_;
519 // The index of this symbol in the dynamic symbol table. If the
520 // symbol is not going into the dynamic symbol table, this value is
521 // -1U. This field starts as always holding zero. It is set to a
522 // non-zero value during Layout::finalize.
523 unsigned int dynsym_index_;
525 // If this symbol has an entry in the GOT section (has_got_offset_
526 // is true), this is the offset from the start of the GOT section.
527 unsigned int got_offset_;
529 // If this symbol has an entry in the PLT section (has_plt_offset_
530 // is true), then this is the offset from the start of the PLT
532 unsigned int plt_offset_;
535 elfcpp::STT type_ : 4;
537 elfcpp::STB binding_ : 4;
538 // Symbol visibility.
539 elfcpp::STV visibility_ : 2;
540 // Rest of symbol st_other field.
541 unsigned int nonvis_ : 6;
542 // The type of symbol.
544 // True if this symbol always requires special target-specific
546 bool is_target_special_ : 1;
547 // True if this is the default version of the symbol.
549 // True if this symbol really forwards to another symbol. This is
550 // used when we discover after the fact that two different entries
551 // in the hash table really refer to the same symbol. This will
552 // never be set for a symbol found in the hash table, but may be set
553 // for a symbol found in the list of symbols attached to an Object.
554 // It forwards to the symbol found in the forwarders_ map of
556 bool is_forwarder_ : 1;
557 // True if the symbol has an alias in the weak_aliases table in
560 // True if this symbol needs to be in the dynamic symbol table.
561 bool needs_dynsym_entry_ : 1;
562 // True if we've seen this symbol in a regular object.
564 // True if we've seen this symbol in a dynamic object.
566 // True if the symbol has an entry in the GOT section.
567 bool has_got_offset_ : 1;
568 // True if the symbol has an entry in the PLT section.
569 bool has_plt_offset_ : 1;
570 // True if this is a dynamic symbol which needs a special value in
571 // the dynamic symbol table.
572 bool needs_dynsym_value_ : 1;
573 // True if there is a warning for this symbol.
574 bool has_warning_ : 1;
577 // The parts of a symbol which are size specific. Using a template
578 // derived class like this helps us use less space on a 32-bit system.
581 class Sized_symbol : public Symbol
584 typedef typename elfcpp::Elf_types<size>::Elf_Addr Value_type;
585 typedef typename elfcpp::Elf_types<size>::Elf_WXword Size_type;
590 // Initialize fields from an ELF symbol in OBJECT.
591 template<bool big_endian>
593 init(const char *name, const char* version, Object* object,
594 const elfcpp::Sym<size, big_endian>&);
596 // Initialize fields for an Output_data.
598 init(const char* name, Output_data*, Value_type value, Size_type symsize,
599 elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
600 bool offset_is_from_end);
602 // Initialize fields for an Output_segment.
604 init(const char* name, Output_segment*, Value_type value, Size_type symsize,
605 elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
606 Segment_offset_base offset_base);
608 // Initialize fields for a constant.
610 init(const char* name, Value_type value, Size_type symsize,
611 elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
613 // Override existing symbol.
614 template<bool big_endian>
616 override(const elfcpp::Sym<size, big_endian>&, Object* object,
617 const char* version);
619 // Override existing symbol with a special symbol.
621 override_with_special(const Sized_symbol<size>*);
623 // Return the symbol's value.
626 { return this->value_; }
628 // Return the symbol's size (we can't call this 'size' because that
629 // is a template parameter).
632 { return this->symsize_; }
634 // Set the symbol size. This is used when resolving common symbols.
636 set_symsize(Size_type symsize)
637 { this->symsize_ = symsize; }
639 // Set the symbol value. This is called when we store the final
640 // values of the symbols into the symbol table.
642 set_value(Value_type value)
643 { this->value_ = value; }
646 Sized_symbol(const Sized_symbol&);
647 Sized_symbol& operator=(const Sized_symbol&);
649 // Symbol value. Before Layout::finalize this is the offset in the
650 // input section. This is set to the final value during
657 // A struct describing a symbol defined by the linker, where the value
658 // of the symbol is defined based on an output section. This is used
659 // for symbols defined by the linker, like "_init_array_start".
661 struct Define_symbol_in_section
665 // The name of the output section with which this symbol should be
666 // associated. If there is no output section with that name, the
667 // symbol will be defined as zero.
668 const char* output_section;
669 // The offset of the symbol within the output section. This is an
670 // offset from the start of the output section, unless start_at_end
671 // is true, in which case this is an offset from the end of the
674 // The size of the symbol.
678 // The symbol binding.
680 // The symbol visibility.
681 elfcpp::STV visibility;
682 // The rest of the st_other field.
683 unsigned char nonvis;
684 // If true, the value field is an offset from the end of the output
686 bool offset_is_from_end;
687 // If true, this symbol is defined only if we see a reference to it.
691 // A struct describing a symbol defined by the linker, where the value
692 // of the symbol is defined based on a segment. This is used for
693 // symbols defined by the linker, like "_end". We describe the
694 // segment with which the symbol should be associated by its
695 // characteristics. If no segment meets these characteristics, the
696 // symbol will be defined as zero. If there is more than one segment
697 // which meets these characteristics, we will use the first one.
699 struct Define_symbol_in_segment
703 // The segment type where the symbol should be defined, typically
705 elfcpp::PT segment_type;
706 // Bitmask of segment flags which must be set.
707 elfcpp::PF segment_flags_set;
708 // Bitmask of segment flags which must be clear.
709 elfcpp::PF segment_flags_clear;
710 // The offset of the symbol within the segment. The offset is
711 // calculated from the position set by offset_base.
713 // The size of the symbol.
717 // The symbol binding.
719 // The symbol visibility.
720 elfcpp::STV visibility;
721 // The rest of the st_other field.
722 unsigned char nonvis;
723 // The base from which we compute the offset.
724 Symbol::Segment_offset_base offset_base;
725 // If true, this symbol is defined only if we see a reference to it.
729 // This class manages warnings. Warnings are a GNU extension. When
730 // we see a section named .gnu.warning.SYM in an object file, and if
731 // we wind using the definition of SYM from that object file, then we
732 // will issue a warning for any relocation against SYM from a
733 // different object file. The text of the warning is the contents of
734 // the section. This is not precisely the definition used by the old
735 // GNU linker; the old GNU linker treated an occurrence of
736 // .gnu.warning.SYM as defining a warning symbol. A warning symbol
737 // would trigger a warning on any reference. However, it was
738 // inconsistent in that a warning in a dynamic object only triggered
739 // if there was no definition in a regular object. This linker is
740 // different in that we only issue a warning if we use the symbol
741 // definition from the same object file as the warning section.
750 // Add a warning for symbol NAME in section SHNDX in object OBJ.
752 add_warning(Symbol_table* symtab, const char* name, Object* obj,
755 // For each symbol for which we should give a warning, make a note
758 note_warnings(Symbol_table* symtab);
760 // Issue a warning for a reference to SYM at RELINFO's location.
761 template<int size, bool big_endian>
763 issue_warning(const Symbol* sym, const Relocate_info<size, big_endian>*,
764 size_t relnum, off_t reloffset) const;
767 Warnings(const Warnings&);
768 Warnings& operator=(const Warnings&);
770 // What we need to know to get the warning text.
771 struct Warning_location
773 // The object the warning is in.
775 // The index of the warning section.
777 // The warning text if we have already loaded it.
781 : object(NULL), shndx(0), text()
785 set(Object* o, unsigned int s)
792 set_text(const char* t, off_t l)
793 { this->text.assign(t, l); }
796 // A mapping from warning symbol names (canonicalized in
797 // Symbol_table's namepool_ field) to
798 typedef Unordered_map<const char*, Warning_location> Warning_table;
800 Warning_table warnings_;
803 // The main linker symbol table.
812 // Add COUNT external symbols from the relocatable object RELOBJ to
813 // the symbol table. SYMS is the symbols, SYM_NAMES is their names,
814 // SYM_NAME_SIZE is the size of SYM_NAMES. This sets SYMPOINTERS to
815 // point to the symbols in the symbol table.
816 template<int size, bool big_endian>
818 add_from_relobj(Sized_relobj<size, big_endian>* relobj,
819 const unsigned char* syms, size_t count,
820 const char* sym_names, size_t sym_name_size,
821 Symbol** sympointers);
823 // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
824 // symbol table. SYMS is the symbols. SYM_NAMES is their names.
825 // SYM_NAME_SIZE is the size of SYM_NAMES. The other parameters are
826 // symbol version data.
827 template<int size, bool big_endian>
829 add_from_dynobj(Sized_dynobj<size, big_endian>* dynobj,
830 const unsigned char* syms, size_t count,
831 const char* sym_names, size_t sym_name_size,
832 const unsigned char* versym, size_t versym_size,
833 const std::vector<const char*>*);
835 // Define a special symbol based on an Output_data. It is a
836 // multiple definition error if this symbol is already defined.
838 define_in_output_data(const Target*, const char* name, const char* version,
839 Output_data*, uint64_t value, uint64_t symsize,
840 elfcpp::STT type, elfcpp::STB binding,
841 elfcpp::STV visibility, unsigned char nonvis,
842 bool offset_is_from_end, bool only_if_ref);
844 // Define a special symbol based on an Output_segment. It is a
845 // multiple definition error if this symbol is already defined.
847 define_in_output_segment(const Target*, const char* name,
848 const char* version, Output_segment*,
849 uint64_t value, uint64_t symsize,
850 elfcpp::STT type, elfcpp::STB binding,
851 elfcpp::STV visibility, unsigned char nonvis,
852 Symbol::Segment_offset_base, bool only_if_ref);
854 // Define a special symbol with a constant value. It is a multiple
855 // definition error if this symbol is already defined.
857 define_as_constant(const Target*, const char* name, const char* version,
858 uint64_t value, uint64_t symsize, elfcpp::STT type,
859 elfcpp::STB binding, elfcpp::STV visibility,
860 unsigned char nonvis, bool only_if_ref);
862 // Define a set of symbols in output sections.
864 define_symbols(const Layout*, const Target*, int count,
865 const Define_symbol_in_section*);
867 // Define a set of symbols in output segments.
869 define_symbols(const Layout*, const Target*, int count,
870 const Define_symbol_in_segment*);
874 lookup(const char*, const char* version = NULL) const;
876 // Return the real symbol associated with the forwarder symbol FROM.
878 resolve_forwards(const Symbol* from) const;
880 // Return the sized version of a symbol in this table.
883 get_sized_symbol(Symbol* ACCEPT_SIZE) const;
886 const Sized_symbol<size>*
887 get_sized_symbol(const Symbol* ACCEPT_SIZE) const;
889 // Return the count of undefined symbols seen.
891 saw_undefined() const
892 { return this->saw_undefined_; }
894 // Allocate the common symbols
896 allocate_commons(const General_options&, Layout*);
898 // Add a warning for symbol NAME in section SHNDX in object OBJ.
900 add_warning(const char* name, Object* obj, unsigned int shndx)
901 { this->warnings_.add_warning(this, name, obj, shndx); }
903 // Canonicalize a symbol name for use in the hash table.
905 canonicalize_name(const char* name)
906 { return this->namepool_.add(name, true, NULL); }
908 // Possibly issue a warning for a reference to SYM at LOCATION which
910 template<int size, bool big_endian>
912 issue_warning(const Symbol* sym,
913 const Relocate_info<size, big_endian>* relinfo,
914 size_t relnum, off_t reloffset) const
915 { this->warnings_.issue_warning(sym, relinfo, relnum, reloffset); }
917 // Set the dynamic symbol indexes. INDEX is the index of the first
918 // global dynamic symbol. Pointers to the symbols are stored into
919 // the vector. The names are stored into the Stringpool. This
920 // returns an updated dynamic symbol index.
922 set_dynsym_indexes(const General_options*, const Target*, unsigned int index,
923 std::vector<Symbol*>*, Stringpool*, Versions*);
925 // Finalize the symbol table after we have set the final addresses
926 // of all the input sections. This sets the final symbol indexes,
927 // values and adds the names to *POOL. INDEX is the index of the
928 // first global symbol. OFF is the file offset of the global symbol
929 // table, DYNOFF is the offset of the globals in the dynamic symbol
930 // table, DYN_GLOBAL_INDEX is the index of the first global dynamic
931 // symbol, and DYNCOUNT is the number of global dynamic symbols.
932 // This records the parameters, and returns the new file offset.
934 finalize(unsigned int index, off_t off, off_t dynoff,
935 size_t dyn_global_index, size_t dyncount, Stringpool* pool);
937 // Write out the global symbols.
939 write_globals(const Target*, const Stringpool*, const Stringpool*,
942 // Write out a section symbol. Return the updated offset.
944 write_section_symbol(const Output_section*, Output_file*, off_t) const;
947 Symbol_table(const Symbol_table&);
948 Symbol_table& operator=(const Symbol_table&);
950 // Make FROM a forwarder symbol to TO.
952 make_forwarder(Symbol* from, Symbol* to);
955 template<int size, bool big_endian>
957 add_from_object(Object*, const char *name, Stringpool::Key name_key,
958 const char *version, Stringpool::Key version_key,
959 bool def, const elfcpp::Sym<size, big_endian>& sym);
962 template<int size, bool big_endian>
964 resolve(Sized_symbol<size>* to,
965 const elfcpp::Sym<size, big_endian>& sym,
966 Object*, const char* version);
968 template<int size, bool big_endian>
970 resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
971 const char* version ACCEPT_SIZE_ENDIAN);
973 // Whether we should override a symbol, based on flags in
976 should_override(const Symbol*, unsigned int, Object*, bool*);
978 // Override a symbol.
979 template<int size, bool big_endian>
981 override(Sized_symbol<size>* tosym,
982 const elfcpp::Sym<size, big_endian>& fromsym,
983 Object* object, const char* version);
985 // Whether we should override a symbol with a special symbol which
986 // is automatically defined by the linker.
988 should_override_with_special(const Symbol*);
990 // Override a symbol with a special symbol.
993 override_with_special(Sized_symbol<size>* tosym,
994 const Sized_symbol<size>* fromsym);
996 // Record all weak alias sets for a dynamic object.
999 record_weak_aliases(std::vector<Sized_symbol<size>*>*);
1001 // Define a special symbol.
1002 template<int size, bool big_endian>
1004 define_special_symbol(const Target* target, const char** pname,
1005 const char** pversion, bool only_if_ref,
1006 Sized_symbol<size>** poldsym ACCEPT_SIZE_ENDIAN);
1008 // Define a symbol in an Output_data, sized version.
1011 do_define_in_output_data(const Target*, const char* name,
1012 const char* version, Output_data*,
1013 typename elfcpp::Elf_types<size>::Elf_Addr value,
1014 typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1015 elfcpp::STT type, elfcpp::STB binding,
1016 elfcpp::STV visibility, unsigned char nonvis,
1017 bool offset_is_from_end, bool only_if_ref);
1019 // Define a symbol in an Output_segment, sized version.
1022 do_define_in_output_segment(
1023 const Target*, const char* name, const char* version, Output_segment* os,
1024 typename elfcpp::Elf_types<size>::Elf_Addr value,
1025 typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1026 elfcpp::STT type, elfcpp::STB binding,
1027 elfcpp::STV visibility, unsigned char nonvis,
1028 Symbol::Segment_offset_base offset_base, bool only_if_ref);
1030 // Define a symbol as a constant, sized version.
1033 do_define_as_constant(
1034 const Target*, const char* name, const char* version,
1035 typename elfcpp::Elf_types<size>::Elf_Addr value,
1036 typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1037 elfcpp::STT type, elfcpp::STB binding,
1038 elfcpp::STV visibility, unsigned char nonvis,
1041 // Allocate the common symbols, sized version.
1044 do_allocate_commons(const General_options&, Layout*);
1046 // Finalize symbols specialized for size.
1049 sized_finalize(unsigned int, off_t, Stringpool*);
1051 // Write globals specialized for size and endianness.
1052 template<int size, bool big_endian>
1054 sized_write_globals(const Target*, const Stringpool*, const Stringpool*,
1055 Output_file*) const;
1057 // Write out a symbol to P.
1058 template<int size, bool big_endian>
1060 sized_write_symbol(Sized_symbol<size>*,
1061 typename elfcpp::Elf_types<size>::Elf_Addr value,
1063 const Stringpool*, unsigned char* p
1064 ACCEPT_SIZE_ENDIAN) const;
1066 // Write out a section symbol, specialized for size and endianness.
1067 template<int size, bool big_endian>
1069 sized_write_section_symbol(const Output_section*, Output_file*, off_t) const;
1071 // The type of the symbol hash table.
1073 typedef std::pair<Stringpool::Key, Stringpool::Key> Symbol_table_key;
1075 struct Symbol_table_hash
1078 operator()(const Symbol_table_key&) const;
1081 struct Symbol_table_eq
1084 operator()(const Symbol_table_key&, const Symbol_table_key&) const;
1087 typedef Unordered_map<Symbol_table_key, Symbol*, Symbol_table_hash,
1088 Symbol_table_eq> Symbol_table_type;
1090 // The type of the list of common symbols.
1092 typedef std::vector<Symbol*> Commons_type;
1094 // We increment this every time we see a new undefined symbol, for
1095 // use in archive groups.
1098 // The index of the first global symbol in the output file.
1099 unsigned int first_global_index_;
1101 // The file offset within the output symtab section where we should
1105 // The number of global symbols we want to write out.
1106 size_t output_count_;
1108 // The file offset of the global dynamic symbols, or 0 if none.
1109 off_t dynamic_offset_;
1111 // The index of the first global dynamic symbol.
1112 unsigned int first_dynamic_global_index_;
1114 // The number of global dynamic symbols, or 0 if none.
1115 off_t dynamic_count_;
1117 // The symbol hash table.
1118 Symbol_table_type table_;
1120 // A pool of symbol names. This is used for all global symbols.
1121 // Entries in the hash table point into this pool.
1122 Stringpool namepool_;
1124 // Forwarding symbols.
1125 Unordered_map<const Symbol*, Symbol*> forwarders_;
1127 // Weak aliases. A symbol in this list points to the next alias.
1128 // The aliases point to each other in a circular list.
1129 Unordered_map<Symbol*, Symbol*> weak_aliases_;
1131 // We don't expect there to be very many common symbols, so we keep
1132 // a list of them. When we find a common symbol we add it to this
1133 // list. It is possible that by the time we process the list the
1134 // symbol is no longer a common symbol. It may also have become a
1136 Commons_type commons_;
1138 // Manage symbol warnings.
1142 // We inline get_sized_symbol for efficiency.
1146 Symbol_table::get_sized_symbol(Symbol* sym ACCEPT_SIZE) const
1148 gold_assert(size == parameters->get_size());
1149 return static_cast<Sized_symbol<size>*>(sym);
1153 const Sized_symbol<size>*
1154 Symbol_table::get_sized_symbol(const Symbol* sym ACCEPT_SIZE) const
1156 gold_assert(size == parameters->get_size());
1157 return static_cast<const Sized_symbol<size>*>(sym);
1160 } // End namespace gold.
1162 #endif // !defined(GOLD_SYMTAB_H)