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 needs an entry in the dynamic symbol
201 needs_dynsym_entry() const
203 return (this->needs_dynsym_entry_
204 || (this->in_reg() && this->in_dyn()));
207 // Mark this symbol as needing an entry in the dynamic symbol table.
209 set_needs_dynsym_entry()
210 { this->needs_dynsym_entry_
= true; }
212 // Return whether this symbol has been seen in a regular object.
215 { return this->in_reg_
; }
217 // Mark this symbol as having been seen in a regular object.
220 { this->in_reg_
= true; }
222 // Return whether this symbol has been seen in a dynamic object.
225 { return this->in_dyn_
; }
227 // Mark this symbol as having been seen in a dynamic object.
230 { this->in_dyn_
= true; }
232 // Return the index of this symbol in the output file symbol table.
233 // A value of -1U means that this symbol is not going into the
234 // output file. This starts out as zero, and is set to a non-zero
235 // value by Symbol_table::finalize. It is an error to ask for the
236 // symbol table index before it has been set.
240 gold_assert(this->symtab_index_
!= 0);
241 return this->symtab_index_
;
244 // Set the index of the symbol in the output file symbol table.
246 set_symtab_index(unsigned int index
)
248 gold_assert(index
!= 0);
249 this->symtab_index_
= index
;
252 // Return whether this symbol already has an index in the output
253 // file symbol table.
255 has_symtab_index() const
256 { return this->symtab_index_
!= 0; }
258 // Return the index of this symbol in the dynamic symbol table. A
259 // value of -1U means that this symbol is not going into the dynamic
260 // symbol table. This starts out as zero, and is set to a non-zero
261 // during Layout::finalize. It is an error to ask for the dynamic
262 // symbol table index before it has been set.
266 gold_assert(this->dynsym_index_
!= 0);
267 return this->dynsym_index_
;
270 // Set the index of the symbol in the dynamic symbol table.
272 set_dynsym_index(unsigned int index
)
274 gold_assert(index
!= 0);
275 this->dynsym_index_
= index
;
278 // Return whether this symbol already has an index in the dynamic
281 has_dynsym_index() const
282 { return this->dynsym_index_
!= 0; }
284 // Return whether this symbol has an entry in the GOT section.
286 has_got_offset() const
287 { return this->has_got_offset_
; }
289 // Return the offset into the GOT section of this symbol.
293 gold_assert(this->has_got_offset());
294 return this->got_offset_
;
297 // Set the GOT offset of this symbol.
299 set_got_offset(unsigned int got_offset
)
301 this->has_got_offset_
= true;
302 this->got_offset_
= got_offset
;
305 // Return whether this symbol has an entry in the PLT section.
307 has_plt_offset() const
308 { return this->has_plt_offset_
; }
310 // Return the offset into the PLT section of this symbol.
314 gold_assert(this->has_plt_offset());
315 return this->plt_offset_
;
318 // Set the PLT offset of this symbol.
320 set_plt_offset(unsigned int plt_offset
)
322 this->has_plt_offset_
= true;
323 this->plt_offset_
= plt_offset
;
326 // Return whether this dynamic symbol needs a special value in the
327 // dynamic symbol table.
329 needs_dynsym_value() const
330 { return this->needs_dynsym_value_
; }
332 // Set that this dynamic symbol needs a special value in the dynamic
335 set_needs_dynsym_value()
337 gold_assert(this->object()->is_dynamic());
338 this->needs_dynsym_value_
= true;
341 // Return true if the final value of this symbol is known at link
344 final_value_is_known() const
346 if (parameters
->output_is_shared())
348 return this->source_
!= FROM_OBJECT
|| !this->object()->is_dynamic();
351 // Return whether this is a defined symbol (not undefined or
356 return (this->source_
!= FROM_OBJECT
357 || (this->shndx() != elfcpp::SHN_UNDEF
358 && this->shndx() != elfcpp::SHN_COMMON
));
361 // Return true if this symbol is from a dynamic object.
363 is_from_dynobj() const
365 return this->source_
== FROM_OBJECT
&& this->object()->is_dynamic();
368 // Return whether this is an undefined symbol.
372 return this->source_
== FROM_OBJECT
&& this->shndx() == elfcpp::SHN_UNDEF
;
375 // Return whether this is a common symbol.
379 return (this->source_
== FROM_OBJECT
380 && (this->shndx() == elfcpp::SHN_COMMON
381 || this->type_
== elfcpp::STT_COMMON
));
384 // Return whether this symbol can be seen outside this object.
386 is_externally_visible() const
388 return (this->visibility_
== elfcpp::STV_DEFAULT
389 || this->visibility_
== elfcpp::STV_PROTECTED
);
392 // Return whether there should be a warning for references to this
396 { return this->has_warning_
; }
398 // Mark this symbol as having a warning.
401 { this->has_warning_
= true; }
404 // Instances of this class should always be created at a specific
407 { memset(this, 0, sizeof *this); }
409 // Initialize the general fields.
411 init_fields(const char* name
, const char* version
,
412 elfcpp::STT type
, elfcpp::STB binding
,
413 elfcpp::STV visibility
, unsigned char nonvis
);
415 // Initialize fields from an ELF symbol in OBJECT.
416 template<int size
, bool big_endian
>
418 init_base(const char *name
, const char* version
, Object
* object
,
419 const elfcpp::Sym
<size
, big_endian
>&);
421 // Initialize fields for an Output_data.
423 init_base(const char* name
, Output_data
*, elfcpp::STT
, elfcpp::STB
,
424 elfcpp::STV
, unsigned char nonvis
, bool offset_is_from_end
);
426 // Initialize fields for an Output_segment.
428 init_base(const char* name
, Output_segment
* os
, elfcpp::STT type
,
429 elfcpp::STB binding
, elfcpp::STV visibility
,
430 unsigned char nonvis
, Segment_offset_base offset_base
);
432 // Initialize fields for a constant.
434 init_base(const char* name
, elfcpp::STT type
, elfcpp::STB binding
,
435 elfcpp::STV visibility
, unsigned char nonvis
);
437 // Override existing symbol.
438 template<int size
, bool big_endian
>
440 override_base(const elfcpp::Sym
<size
, big_endian
>&, Object
* object
,
441 const char* version
);
443 // Override existing symbol with a special symbol.
445 override_base_with_special(const Symbol
* from
);
448 Symbol(const Symbol
&);
449 Symbol
& operator=(const Symbol
&);
451 // Symbol name (expected to point into a Stringpool).
453 // Symbol version (expected to point into a Stringpool). This may
455 const char* version_
;
459 // This struct is used if SOURCE_ == FROM_OBJECT.
462 // Object in which symbol is defined, or in which it was first
465 // Section number in object_ in which symbol is defined.
469 // This struct is used if SOURCE_ == IN_OUTPUT_DATA.
472 // Output_data in which symbol is defined. Before
473 // Layout::finalize the symbol's value is an offset within the
475 Output_data
* output_data
;
476 // True if the offset is from the end, false if the offset is
477 // from the beginning.
478 bool offset_is_from_end
;
481 // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
484 // Output_segment in which the symbol is defined. Before
485 // Layout::finalize the symbol's value is an offset.
486 Output_segment
* output_segment
;
487 // The base to use for the offset before Layout::finalize.
488 Segment_offset_base offset_base
;
492 // The index of this symbol in the output file. If the symbol is
493 // not going into the output file, this value is -1U. This field
494 // starts as always holding zero. It is set to a non-zero value by
495 // Symbol_table::finalize.
496 unsigned int symtab_index_
;
498 // The index of this symbol in the dynamic symbol table. If the
499 // symbol is not going into the dynamic symbol table, this value is
500 // -1U. This field starts as always holding zero. It is set to a
501 // non-zero value during Layout::finalize.
502 unsigned int dynsym_index_
;
504 // If this symbol has an entry in the GOT section (has_got_offset_
505 // is true), this is the offset from the start of the GOT section.
506 unsigned int got_offset_
;
508 // If this symbol has an entry in the PLT section (has_plt_offset_
509 // is true), then this is the offset from the start of the PLT
511 unsigned int plt_offset_
;
514 elfcpp::STT type_
: 4;
516 elfcpp::STB binding_
: 4;
517 // Symbol visibility.
518 elfcpp::STV visibility_
: 2;
519 // Rest of symbol st_other field.
520 unsigned int nonvis_
: 6;
521 // The type of symbol.
523 // True if this symbol always requires special target-specific
525 bool is_target_special_
: 1;
526 // True if this is the default version of the symbol.
528 // True if this symbol really forwards to another symbol. This is
529 // used when we discover after the fact that two different entries
530 // in the hash table really refer to the same symbol. This will
531 // never be set for a symbol found in the hash table, but may be set
532 // for a symbol found in the list of symbols attached to an Object.
533 // It forwards to the symbol found in the forwarders_ map of
535 bool is_forwarder_
: 1;
536 // True if this symbol needs to be in the dynamic symbol table.
537 bool needs_dynsym_entry_
: 1;
538 // True if we've seen this symbol in a regular object.
540 // True if we've seen this symbol in a dynamic object.
542 // True if the symbol has an entry in the GOT section.
543 bool has_got_offset_
: 1;
544 // True if the symbol has an entry in the PLT section.
545 bool has_plt_offset_
: 1;
546 // True if this is a dynamic symbol which needs a special value in
547 // the dynamic symbol table.
548 bool needs_dynsym_value_
: 1;
549 // True if there is a warning for this symbol.
550 bool has_warning_
: 1;
553 // The parts of a symbol which are size specific. Using a template
554 // derived class like this helps us use less space on a 32-bit system.
557 class Sized_symbol
: public Symbol
560 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Value_type
;
561 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Size_type
;
566 // Initialize fields from an ELF symbol in OBJECT.
567 template<bool big_endian
>
569 init(const char *name
, const char* version
, Object
* object
,
570 const elfcpp::Sym
<size
, big_endian
>&);
572 // Initialize fields for an Output_data.
574 init(const char* name
, Output_data
*, Value_type value
, Size_type symsize
,
575 elfcpp::STT
, elfcpp::STB
, elfcpp::STV
, unsigned char nonvis
,
576 bool offset_is_from_end
);
578 // Initialize fields for an Output_segment.
580 init(const char* name
, Output_segment
*, Value_type value
, Size_type symsize
,
581 elfcpp::STT
, elfcpp::STB
, elfcpp::STV
, unsigned char nonvis
,
582 Segment_offset_base offset_base
);
584 // Initialize fields for a constant.
586 init(const char* name
, Value_type value
, Size_type symsize
,
587 elfcpp::STT
, elfcpp::STB
, elfcpp::STV
, unsigned char nonvis
);
589 // Override existing symbol.
590 template<bool big_endian
>
592 override(const elfcpp::Sym
<size
, big_endian
>&, Object
* object
,
593 const char* version
);
595 // Override existing symbol with a special symbol.
597 override_with_special(const Sized_symbol
<size
>*);
599 // Return the symbol's value.
602 { return this->value_
; }
604 // Return the symbol's size (we can't call this 'size' because that
605 // is a template parameter).
608 { return this->symsize_
; }
610 // Set the symbol size. This is used when resolving common symbols.
612 set_symsize(Size_type symsize
)
613 { this->symsize_
= symsize
; }
615 // Set the symbol value. This is called when we store the final
616 // values of the symbols into the symbol table.
618 set_value(Value_type value
)
619 { this->value_
= value
; }
622 Sized_symbol(const Sized_symbol
&);
623 Sized_symbol
& operator=(const Sized_symbol
&);
625 // Symbol value. Before Layout::finalize this is the offset in the
626 // input section. This is set to the final value during
633 // A struct describing a symbol defined by the linker, where the value
634 // of the symbol is defined based on an output section. This is used
635 // for symbols defined by the linker, like "_init_array_start".
637 struct Define_symbol_in_section
641 // The name of the output section with which this symbol should be
642 // associated. If there is no output section with that name, the
643 // symbol will be defined as zero.
644 const char* output_section
;
645 // The offset of the symbol within the output section. This is an
646 // offset from the start of the output section, unless start_at_end
647 // is true, in which case this is an offset from the end of the
650 // The size of the symbol.
654 // The symbol binding.
656 // The symbol visibility.
657 elfcpp::STV visibility
;
658 // The rest of the st_other field.
659 unsigned char nonvis
;
660 // If true, the value field is an offset from the end of the output
662 bool offset_is_from_end
;
663 // If true, this symbol is defined only if we see a reference to it.
667 // A struct describing a symbol defined by the linker, where the value
668 // of the symbol is defined based on a segment. This is used for
669 // symbols defined by the linker, like "_end". We describe the
670 // segment with which the symbol should be associated by its
671 // characteristics. If no segment meets these characteristics, the
672 // symbol will be defined as zero. If there is more than one segment
673 // which meets these characteristics, we will use the first one.
675 struct Define_symbol_in_segment
679 // The segment type where the symbol should be defined, typically
681 elfcpp::PT segment_type
;
682 // Bitmask of segment flags which must be set.
683 elfcpp::PF segment_flags_set
;
684 // Bitmask of segment flags which must be clear.
685 elfcpp::PF segment_flags_clear
;
686 // The offset of the symbol within the segment. The offset is
687 // calculated from the position set by offset_base.
689 // The size of the symbol.
693 // The symbol binding.
695 // The symbol visibility.
696 elfcpp::STV visibility
;
697 // The rest of the st_other field.
698 unsigned char nonvis
;
699 // The base from which we compute the offset.
700 Symbol::Segment_offset_base offset_base
;
701 // If true, this symbol is defined only if we see a reference to it.
705 // This class manages warnings. Warnings are a GNU extension. When
706 // we see a section named .gnu.warning.SYM in an object file, and if
707 // we wind using the definition of SYM from that object file, then we
708 // will issue a warning for any relocation against SYM from a
709 // different object file. The text of the warning is the contents of
710 // the section. This is not precisely the definition used by the old
711 // GNU linker; the old GNU linker treated an occurrence of
712 // .gnu.warning.SYM as defining a warning symbol. A warning symbol
713 // would trigger a warning on any reference. However, it was
714 // inconsistent in that a warning in a dynamic object only triggered
715 // if there was no definition in a regular object. This linker is
716 // different in that we only issue a warning if we use the symbol
717 // definition from the same object file as the warning section.
726 // Add a warning for symbol NAME in section SHNDX in object OBJ.
728 add_warning(Symbol_table
* symtab
, const char* name
, Object
* obj
,
731 // For each symbol for which we should give a warning, make a note
734 note_warnings(Symbol_table
* symtab
);
736 // Issue a warning for a reference to SYM at LOCATION.
738 issue_warning(const Symbol
* sym
, const std::string
& location
) const;
741 Warnings(const Warnings
&);
742 Warnings
& operator=(const Warnings
&);
744 // What we need to know to get the warning text.
745 struct Warning_location
747 // The object the warning is in.
749 // The index of the warning section.
751 // The warning text if we have already loaded it.
755 : object(NULL
), shndx(0), text()
759 set(Object
* o
, unsigned int s
)
766 set_text(const char* t
, off_t l
)
767 { this->text
.assign(t
, l
); }
770 // A mapping from warning symbol names (canonicalized in
771 // Symbol_table's namepool_ field) to
772 typedef Unordered_map
<const char*, Warning_location
> Warning_table
;
774 Warning_table warnings_
;
777 // The main linker symbol table.
786 // Add COUNT external symbols from the relocatable object RELOBJ to
787 // the symbol table. SYMS is the symbols, SYM_NAMES is their names,
788 // SYM_NAME_SIZE is the size of SYM_NAMES. This sets SYMPOINTERS to
789 // point to the symbols in the symbol table.
790 template<int size
, bool big_endian
>
792 add_from_relobj(Sized_relobj
<size
, big_endian
>* relobj
,
793 const unsigned char* syms
, size_t count
,
794 const char* sym_names
, size_t sym_name_size
,
795 Symbol
** sympointers
);
797 // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
798 // symbol table. SYMS is the symbols. SYM_NAMES is their names.
799 // SYM_NAME_SIZE is the size of SYM_NAMES. The other parameters are
800 // symbol version data.
801 template<int size
, bool big_endian
>
803 add_from_dynobj(Sized_dynobj
<size
, big_endian
>* dynobj
,
804 const unsigned char* syms
, size_t count
,
805 const char* sym_names
, size_t sym_name_size
,
806 const unsigned char* versym
, size_t versym_size
,
807 const std::vector
<const char*>*);
809 // Define a special symbol based on an Output_data. It is a
810 // multiple definition error if this symbol is already defined.
812 define_in_output_data(const Target
*, const char* name
, const char* version
,
813 Output_data
*, uint64_t value
, uint64_t symsize
,
814 elfcpp::STT type
, elfcpp::STB binding
,
815 elfcpp::STV visibility
, unsigned char nonvis
,
816 bool offset_is_from_end
, bool only_if_ref
);
818 // Define a special symbol based on an Output_segment. It is a
819 // multiple definition error if this symbol is already defined.
821 define_in_output_segment(const Target
*, const char* name
,
822 const char* version
, Output_segment
*,
823 uint64_t value
, uint64_t symsize
,
824 elfcpp::STT type
, elfcpp::STB binding
,
825 elfcpp::STV visibility
, unsigned char nonvis
,
826 Symbol::Segment_offset_base
, bool only_if_ref
);
828 // Define a special symbol with a constant value. It is a multiple
829 // definition error if this symbol is already defined.
831 define_as_constant(const Target
*, const char* name
, const char* version
,
832 uint64_t value
, uint64_t symsize
, elfcpp::STT type
,
833 elfcpp::STB binding
, elfcpp::STV visibility
,
834 unsigned char nonvis
, bool only_if_ref
);
836 // Define a set of symbols in output sections.
838 define_symbols(const Layout
*, const Target
*, int count
,
839 const Define_symbol_in_section
*);
841 // Define a set of symbols in output segments.
843 define_symbols(const Layout
*, const Target
*, int count
,
844 const Define_symbol_in_segment
*);
848 lookup(const char*, const char* version
= NULL
) const;
850 // Return the real symbol associated with the forwarder symbol FROM.
852 resolve_forwards(const Symbol
* from
) const;
854 // Return the bitsize (32 or 64) of the symbols in the table.
857 { return this->size_
; }
859 // Return the sized version of a symbol in this table.
862 get_sized_symbol(Symbol
* ACCEPT_SIZE
) const;
865 const Sized_symbol
<size
>*
866 get_sized_symbol(const Symbol
* ACCEPT_SIZE
) const;
868 // Return the count of undefined symbols seen.
870 saw_undefined() const
871 { return this->saw_undefined_
; }
873 // Allocate the common symbols
875 allocate_commons(const General_options
&, Layout
*);
877 // Add a warning for symbol NAME in section SHNDX in object OBJ.
879 add_warning(const char* name
, Object
* obj
, unsigned int shndx
)
880 { this->warnings_
.add_warning(this, name
, obj
, shndx
); }
882 // Canonicalize a symbol name for use in the hash table.
884 canonicalize_name(const char* name
)
885 { return this->namepool_
.add(name
, NULL
); }
887 // Possibly issue a warning for a reference to SYM at LOCATION which
890 issue_warning(const Symbol
* sym
, const std::string
& location
) const
891 { this->warnings_
.issue_warning(sym
, location
); }
893 // Set the dynamic symbol indexes. INDEX is the index of the first
894 // global dynamic symbol. Pointers to the symbols are stored into
895 // the vector. The names are stored into the Stringpool. This
896 // returns an updated dynamic symbol index.
898 set_dynsym_indexes(const General_options
*, const Target
*, unsigned int index
,
899 std::vector
<Symbol
*>*, Stringpool
*, Versions
*);
901 // Finalize the symbol table after we have set the final addresses
902 // of all the input sections. This sets the final symbol indexes,
903 // values and adds the names to *POOL. INDEX is the index of the
904 // first global symbol. OFF is the file offset of the global symbol
905 // table, DYNOFF is the offset of the globals in the dynamic symbol
906 // table, DYN_GLOBAL_INDEX is the index of the first global dynamic
907 // symbol, and DYNCOUNT is the number of global dynamic symbols.
908 // This records the parameters, and returns the new file offset.
910 finalize(unsigned int index
, off_t off
, off_t dynoff
,
911 size_t dyn_global_index
, size_t dyncount
, Stringpool
* pool
);
913 // Write out the global symbols.
915 write_globals(const Target
*, const Stringpool
*, const Stringpool
*,
918 // Write out a section symbol. Return the updated offset.
920 write_section_symbol(const Target
*, const Output_section
*, Output_file
*,
924 Symbol_table(const Symbol_table
&);
925 Symbol_table
& operator=(const Symbol_table
&);
927 // Set the size (32 or 64) of the symbols in the table.
930 { this->size_
= size
; }
932 // Make FROM a forwarder symbol to TO.
934 make_forwarder(Symbol
* from
, Symbol
* to
);
937 template<int size
, bool big_endian
>
939 add_from_object(Object
*, const char *name
, Stringpool::Key name_key
,
940 const char *version
, Stringpool::Key version_key
,
941 bool def
, const elfcpp::Sym
<size
, big_endian
>& sym
);
944 template<int size
, bool big_endian
>
946 resolve(Sized_symbol
<size
>* to
,
947 const elfcpp::Sym
<size
, big_endian
>& sym
,
948 Object
*, const char* version
);
950 template<int size
, bool big_endian
>
952 resolve(Sized_symbol
<size
>* to
, const Sized_symbol
<size
>* from
,
953 const char* version ACCEPT_SIZE_ENDIAN
);
955 // Whether we should override a symbol, based on flags in
958 should_override(const Symbol
*, unsigned int, bool*);
960 // Whether we should override a symbol with a special symbol which
961 // is automatically defined by the linker.
963 should_override_with_special(const Symbol
*);
965 // Define a special symbol.
966 template<int size
, bool big_endian
>
968 define_special_symbol(const Target
* target
, const char** pname
,
969 const char** pversion
, bool only_if_ref
,
970 Sized_symbol
<size
>** poldsym ACCEPT_SIZE_ENDIAN
);
972 // Define a symbol in an Output_data, sized version.
975 do_define_in_output_data(const Target
*, const char* name
,
976 const char* version
, Output_data
*,
977 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
978 typename
elfcpp::Elf_types
<size
>::Elf_WXword ssize
,
979 elfcpp::STT type
, elfcpp::STB binding
,
980 elfcpp::STV visibility
, unsigned char nonvis
,
981 bool offset_is_from_end
, bool only_if_ref
);
983 // Define a symbol in an Output_segment, sized version.
986 do_define_in_output_segment(
987 const Target
*, const char* name
, const char* version
, Output_segment
* os
,
988 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
989 typename
elfcpp::Elf_types
<size
>::Elf_WXword ssize
,
990 elfcpp::STT type
, elfcpp::STB binding
,
991 elfcpp::STV visibility
, unsigned char nonvis
,
992 Symbol::Segment_offset_base offset_base
, bool only_if_ref
);
994 // Define a symbol as a constant, sized version.
997 do_define_as_constant(
998 const Target
*, const char* name
, const char* version
,
999 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1000 typename
elfcpp::Elf_types
<size
>::Elf_WXword ssize
,
1001 elfcpp::STT type
, elfcpp::STB binding
,
1002 elfcpp::STV visibility
, unsigned char nonvis
,
1005 // Allocate the common symbols, sized version.
1008 do_allocate_commons(const General_options
&, Layout
*);
1010 // Finalize symbols specialized for size.
1013 sized_finalize(unsigned int, off_t
, Stringpool
*);
1015 // Write globals specialized for size and endianness.
1016 template<int size
, bool big_endian
>
1018 sized_write_globals(const Target
*, const Stringpool
*, const Stringpool
*,
1019 Output_file
*) const;
1021 // Write out a symbol to P.
1022 template<int size
, bool big_endian
>
1024 sized_write_symbol(Sized_symbol
<size
>*,
1025 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1027 const Stringpool
*, unsigned char* p
1028 ACCEPT_SIZE_ENDIAN
) const;
1030 // Write out a section symbol, specialized for size and endianness.
1031 template<int size
, bool big_endian
>
1033 sized_write_section_symbol(const Output_section
*, Output_file
*, off_t
) const;
1035 // The type of the symbol hash table.
1037 typedef std::pair
<Stringpool::Key
, Stringpool::Key
> Symbol_table_key
;
1039 struct Symbol_table_hash
1042 operator()(const Symbol_table_key
&) const;
1045 struct Symbol_table_eq
1048 operator()(const Symbol_table_key
&, const Symbol_table_key
&) const;
1051 typedef Unordered_map
<Symbol_table_key
, Symbol
*, Symbol_table_hash
,
1052 Symbol_table_eq
> Symbol_table_type
;
1054 // The type of the list of common symbols.
1056 typedef std::vector
<Symbol
*> Commons_type
;
1058 // The size of the symbols in the symbol table (32 or 64).
1061 // We increment this every time we see a new undefined symbol, for
1062 // use in archive groups.
1065 // The index of the first global symbol in the output file.
1066 unsigned int first_global_index_
;
1068 // The file offset within the output symtab section where we should
1072 // The number of global symbols we want to write out.
1073 size_t output_count_
;
1075 // The file offset of the global dynamic symbols, or 0 if none.
1076 off_t dynamic_offset_
;
1078 // The index of the first global dynamic symbol.
1079 unsigned int first_dynamic_global_index_
;
1081 // The number of global dynamic symbols, or 0 if none.
1082 off_t dynamic_count_
;
1084 // The symbol hash table.
1085 Symbol_table_type table_
;
1087 // A pool of symbol names. This is used for all global symbols.
1088 // Entries in the hash table point into this pool.
1089 Stringpool namepool_
;
1091 // Forwarding symbols.
1092 Unordered_map
<const Symbol
*, Symbol
*> forwarders_
;
1094 // We don't expect there to be very many common symbols, so we keep
1095 // a list of them. When we find a common symbol we add it to this
1096 // list. It is possible that by the time we process the list the
1097 // symbol is no longer a common symbol. It may also have become a
1099 Commons_type commons_
;
1101 // Manage symbol warnings.
1105 // We inline get_sized_symbol for efficiency.
1109 Symbol_table::get_sized_symbol(Symbol
* sym ACCEPT_SIZE
) const
1111 gold_assert(size
== this->get_size());
1112 return static_cast<Sized_symbol
<size
>*>(sym
);
1116 const Sized_symbol
<size
>*
1117 Symbol_table::get_sized_symbol(const Symbol
* sym ACCEPT_SIZE
) const
1119 gold_assert(size
== this->get_size());
1120 return static_cast<const Sized_symbol
<size
>*>(sym
);
1123 } // End namespace gold.
1125 #endif // !defined(GOLD_SYMTAB_H)