Update the machine code decode algorithm using hash table.
[binutils.git] / gold / symtab.h
1 // symtab.h -- the gold symbol table   -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
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.
12
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.
17
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.
22
23 // Symbol_table
24 //   The symbol table.
25
26 #include <string>
27 #include <utility>
28 #include <vector>
29
30 #include "elfcpp.h"
31 #include "parameters.h"
32 #include "stringpool.h"
33 #include "object.h"
34
35 #ifndef GOLD_SYMTAB_H
36 #define GOLD_SYMTAB_H
37
38 namespace gold
39 {
40
41 class Object;
42 class Relobj;
43 template<int size, bool big_endian>
44 class Sized_relobj;
45 class Dynobj;
46 template<int size, bool big_endian>
47 class Sized_dynobj;
48 class Versions;
49 class Version_script_info;
50 class Input_objects;
51 class Output_data;
52 class Output_section;
53 class Output_segment;
54 class Output_file;
55 class Output_symtab_xindex;
56
57 // The base class of an entry in the symbol table.  The symbol table
58 // can have a lot of entries, so we don't want this class to big.
59 // Size dependent fields can be found in the template class
60 // Sized_symbol.  Targets may support their own derived classes.
61
62 class Symbol
63 {
64  public:
65   // Because we want the class to be small, we don't use any virtual
66   // functions.  But because symbols can be defined in different
67   // places, we need to classify them.  This enum is the different
68   // sources of symbols we support.
69   enum Source
70   {
71     // Symbol defined in a relocatable or dynamic input file--this is
72     // the most common case.
73     FROM_OBJECT,
74     // Symbol defined in an Output_data, a special section created by
75     // the target.
76     IN_OUTPUT_DATA,
77     // Symbol defined in an Output_segment, with no associated
78     // section.
79     IN_OUTPUT_SEGMENT,
80     // Symbol value is constant.
81     CONSTANT
82   };
83
84   // When the source is IN_OUTPUT_SEGMENT, we need to describe what
85   // the offset means.
86   enum Segment_offset_base
87   {
88     // From the start of the segment.
89     SEGMENT_START,
90     // From the end of the segment.
91     SEGMENT_END,
92     // From the filesz of the segment--i.e., after the loaded bytes
93     // but before the bytes which are allocated but zeroed.
94     SEGMENT_BSS
95   };
96
97   // Return the symbol name.
98   const char*
99   name() const
100   { return this->name_; }
101
102   // Return the (ANSI) demangled version of the name, if
103   // parameters.demangle() is true.  Otherwise, return the name.  This
104   // is intended to be used only for logging errors, so it's not
105   // super-efficient.
106   std::string
107   demangled_name() const;
108
109   // Return the symbol version.  This will return NULL for an
110   // unversioned symbol.
111   const char*
112   version() const
113   { return this->version_; }
114
115   // Return whether this version is the default for this symbol name
116   // (eg, "foo@@V2" is a default version; "foo@V1" is not).  Only
117   // meaningful for versioned symbols.
118   bool
119   is_default() const
120   {
121     gold_assert(this->version_ != NULL);
122     return this->is_def_;
123   }
124
125   // Set that this version is the default for this symbol name.
126   void
127   set_is_default()
128   { this->is_def_ = true; }
129
130   // Return the symbol source.
131   Source
132   source() const
133   { return this->source_; }
134
135   // Return the object with which this symbol is associated.
136   Object*
137   object() const
138   {
139     gold_assert(this->source_ == FROM_OBJECT);
140     return this->u_.from_object.object;
141   }
142
143   // Return the index of the section in the input relocatable or
144   // dynamic object file.
145   unsigned int
146   shndx(bool* is_ordinary) const
147   {
148     gold_assert(this->source_ == FROM_OBJECT);
149     *is_ordinary = this->is_ordinary_shndx_;
150     return this->u_.from_object.shndx;
151   }
152
153   // Return the output data section with which this symbol is
154   // associated, if the symbol was specially defined with respect to
155   // an output data section.
156   Output_data*
157   output_data() const
158   {
159     gold_assert(this->source_ == IN_OUTPUT_DATA);
160     return this->u_.in_output_data.output_data;
161   }
162
163   // If this symbol was defined with respect to an output data
164   // section, return whether the value is an offset from end.
165   bool
166   offset_is_from_end() const
167   {
168     gold_assert(this->source_ == IN_OUTPUT_DATA);
169     return this->u_.in_output_data.offset_is_from_end;
170   }
171
172   // Return the output segment with which this symbol is associated,
173   // if the symbol was specially defined with respect to an output
174   // segment.
175   Output_segment*
176   output_segment() const
177   {
178     gold_assert(this->source_ == IN_OUTPUT_SEGMENT);
179     return this->u_.in_output_segment.output_segment;
180   }
181
182   // If this symbol was defined with respect to an output segment,
183   // return the offset base.
184   Segment_offset_base
185   offset_base() const
186   {
187     gold_assert(this->source_ == IN_OUTPUT_SEGMENT);
188     return this->u_.in_output_segment.offset_base;
189   }
190
191   // Return the symbol binding.
192   elfcpp::STB
193   binding() const
194   { return this->binding_; }
195
196   // Return the symbol type.
197   elfcpp::STT
198   type() const
199   { return this->type_; }
200
201   // Return the symbol visibility.
202   elfcpp::STV
203   visibility() const
204   { return this->visibility_; }
205
206   // Return the non-visibility part of the st_other field.
207   unsigned char
208   nonvis() const
209   { return this->nonvis_; }
210
211   // Return whether this symbol is a forwarder.  This will never be
212   // true of a symbol found in the hash table, but may be true of
213   // symbol pointers attached to object files.
214   bool
215   is_forwarder() const
216   { return this->is_forwarder_; }
217
218   // Mark this symbol as a forwarder.
219   void
220   set_forwarder()
221   { this->is_forwarder_ = true; }
222
223   // Return whether this symbol has an alias in the weak aliases table
224   // in Symbol_table.
225   bool
226   has_alias() const
227   { return this->has_alias_; }
228
229   // Mark this symbol as having an alias.
230   void
231   set_has_alias()
232   { this->has_alias_ = true; }
233
234   // Return whether this symbol needs an entry in the dynamic symbol
235   // table.
236   bool
237   needs_dynsym_entry() const
238   {
239     return (this->needs_dynsym_entry_
240             || (this->in_reg() && this->in_dyn()));
241   }
242
243   // Mark this symbol as needing an entry in the dynamic symbol table.
244   void
245   set_needs_dynsym_entry()
246   { this->needs_dynsym_entry_ = true; }
247
248   // Return whether this symbol should be added to the dynamic symbol
249   // table.
250   bool
251   should_add_dynsym_entry() const;
252
253   // Return whether this symbol has been seen in a regular object.
254   bool
255   in_reg() const
256   { return this->in_reg_; }
257
258   // Mark this symbol as having been seen in a regular object.
259   void
260   set_in_reg()
261   { this->in_reg_ = true; }
262
263   // Return whether this symbol has been seen in a dynamic object.
264   bool
265   in_dyn() const
266   { return this->in_dyn_; }
267
268   // Mark this symbol as having been seen in a dynamic object.
269   void
270   set_in_dyn()
271   { this->in_dyn_ = true; }
272
273   // Return the index of this symbol in the output file symbol table.
274   // A value of -1U means that this symbol is not going into the
275   // output file.  This starts out as zero, and is set to a non-zero
276   // value by Symbol_table::finalize.  It is an error to ask for the
277   // symbol table index before it has been set.
278   unsigned int
279   symtab_index() const
280   {
281     gold_assert(this->symtab_index_ != 0);
282     return this->symtab_index_;
283   }
284
285   // Set the index of the symbol in the output file symbol table.
286   void
287   set_symtab_index(unsigned int index)
288   {
289     gold_assert(index != 0);
290     this->symtab_index_ = index;
291   }
292
293   // Return whether this symbol already has an index in the output
294   // file symbol table.
295   bool
296   has_symtab_index() const
297   { return this->symtab_index_ != 0; }
298
299   // Return the index of this symbol in the dynamic symbol table.  A
300   // value of -1U means that this symbol is not going into the dynamic
301   // symbol table.  This starts out as zero, and is set to a non-zero
302   // during Layout::finalize.  It is an error to ask for the dynamic
303   // symbol table index before it has been set.
304   unsigned int
305   dynsym_index() const
306   {
307     gold_assert(this->dynsym_index_ != 0);
308     return this->dynsym_index_;
309   }
310
311   // Set the index of the symbol in the dynamic symbol table.
312   void
313   set_dynsym_index(unsigned int index)
314   {
315     gold_assert(index != 0);
316     this->dynsym_index_ = index;
317   }
318
319   // Return whether this symbol already has an index in the dynamic
320   // symbol table.
321   bool
322   has_dynsym_index() const
323   { return this->dynsym_index_ != 0; }
324
325   // Return whether this symbol has an entry in the GOT section.
326   // For a TLS symbol, this GOT entry will hold its tp-relative offset.
327   bool
328   has_got_offset(unsigned int got_type) const
329   { return this->got_offsets_.get_offset(got_type) != -1U; }
330
331   // Return the offset into the GOT section of this symbol.
332   unsigned int
333   got_offset(unsigned int got_type) const
334   {
335     unsigned int got_offset = this->got_offsets_.get_offset(got_type);
336     gold_assert(got_offset != -1U);
337     return got_offset;
338   }
339
340   // Set the GOT offset of this symbol.
341   void
342   set_got_offset(unsigned int got_type, unsigned int got_offset)
343   { this->got_offsets_.set_offset(got_type, got_offset); }
344
345   // Return whether this symbol has an entry in the PLT section.
346   bool
347   has_plt_offset() const
348   { return this->has_plt_offset_; }
349
350   // Return the offset into the PLT section of this symbol.
351   unsigned int
352   plt_offset() const
353   {
354     gold_assert(this->has_plt_offset());
355     return this->plt_offset_;
356   }
357
358   // Set the PLT offset of this symbol.
359   void
360   set_plt_offset(unsigned int plt_offset)
361   {
362     this->has_plt_offset_ = true;
363     this->plt_offset_ = plt_offset;
364   }
365
366   // Return whether this dynamic symbol needs a special value in the
367   // dynamic symbol table.
368   bool
369   needs_dynsym_value() const
370   { return this->needs_dynsym_value_; }
371
372   // Set that this dynamic symbol needs a special value in the dynamic
373   // symbol table.
374   void
375   set_needs_dynsym_value()
376   {
377     gold_assert(this->object()->is_dynamic());
378     this->needs_dynsym_value_ = true;
379   }
380
381   // Return true if the final value of this symbol is known at link
382   // time.
383   bool
384   final_value_is_known() const;
385
386   // Return whether this is a defined symbol (not undefined or
387   // common).
388   bool
389   is_defined() const
390   {
391     bool is_ordinary;
392     if (this->source_ != FROM_OBJECT)
393       return true;
394     unsigned int shndx = this->shndx(&is_ordinary);
395     return (is_ordinary
396             ? shndx != elfcpp::SHN_UNDEF
397             : shndx != elfcpp::SHN_COMMON);
398   }
399
400   // Return true if this symbol is from a dynamic object.
401   bool
402   is_from_dynobj() const
403   {
404     return this->source_ == FROM_OBJECT && this->object()->is_dynamic();
405   }
406
407   // Return whether this is an undefined symbol.
408   bool
409   is_undefined() const
410   {
411     bool is_ordinary;
412     return (this->source_ == FROM_OBJECT
413             && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
414             && is_ordinary);
415   }
416
417   // Return whether this is a weak undefined symbol.
418   bool
419   is_weak_undefined() const
420   {
421     bool is_ordinary;
422     return (this->source_ == FROM_OBJECT
423             && this->binding() == elfcpp::STB_WEAK
424             && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
425             && is_ordinary);
426   }
427
428   // Return whether this is an absolute symbol.
429   bool
430   is_absolute() const
431   {
432     bool is_ordinary;
433     return (this->source_ == FROM_OBJECT
434             && this->shndx(&is_ordinary) == elfcpp::SHN_ABS
435             && !is_ordinary);
436   }
437
438   // Return whether this is a common symbol.
439   bool
440   is_common() const
441   {
442     bool is_ordinary;
443     return (this->source_ == FROM_OBJECT
444             && ((this->shndx(&is_ordinary) == elfcpp::SHN_COMMON
445                  && !is_ordinary)
446                 || this->type_ == elfcpp::STT_COMMON));
447   }
448
449   // Return whether this symbol can be seen outside this object.
450   bool
451   is_externally_visible() const
452   {
453     return (this->visibility_ == elfcpp::STV_DEFAULT
454             || this->visibility_ == elfcpp::STV_PROTECTED);
455   }
456
457   // Return true if this symbol can be preempted by a definition in
458   // another link unit.
459   bool
460   is_preemptible() const
461   {
462     // It doesn't make sense to ask whether a symbol defined in
463     // another object is preemptible.
464     gold_assert(!this->is_from_dynobj());
465
466     // It doesn't make sense to ask whether an undefined symbol
467     // is preemptible.
468     gold_assert(!this->is_undefined());
469
470     return (this->visibility_ != elfcpp::STV_INTERNAL
471             && this->visibility_ != elfcpp::STV_HIDDEN
472             && this->visibility_ != elfcpp::STV_PROTECTED
473             && !this->is_forced_local_
474             && parameters->options().shared()
475             && !parameters->options().Bsymbolic());
476   }
477
478   // Return true if this symbol is a function that needs a PLT entry.
479   // If the symbol is defined in a dynamic object or if it is subject
480   // to pre-emption, we need to make a PLT entry. If we're doing a
481   // static link, we don't create PLT entries.
482   bool
483   needs_plt_entry() const
484   {
485     return (!parameters->doing_static_link()
486             && this->type() == elfcpp::STT_FUNC
487             && (this->is_from_dynobj()
488                 || this->is_undefined()
489                 || this->is_preemptible()));
490   }
491
492   // When determining whether a reference to a symbol needs a dynamic
493   // relocation, we need to know several things about the reference.
494   // These flags may be or'ed together.
495   enum Reference_flags
496   {
497     // Reference to the symbol's absolute address.
498     ABSOLUTE_REF = 1,
499     // A non-PIC reference.
500     NON_PIC_REF = 2,
501     // A function call.
502     FUNCTION_CALL = 4
503   };
504
505   // Given a direct absolute or pc-relative static relocation against
506   // the global symbol, this function returns whether a dynamic relocation
507   // is needed.
508
509   bool
510   needs_dynamic_reloc(int flags) const
511   {
512     // No dynamic relocations in a static link!
513     if (parameters->doing_static_link())
514       return false;
515
516     // A reference to a weak undefined symbol from an executable should be
517     // statically resolved to 0, and does not need a dynamic relocation.
518     // This matches gnu ld behavior.
519     if (this->is_weak_undefined() && !parameters->options().shared())
520       return false;
521
522     // A reference to an absolute symbol does not need a dynamic relocation.
523     if (this->is_absolute())
524       return false;
525
526     // An absolute reference within a position-independent output file
527     // will need a dynamic relocation.
528     if ((flags & ABSOLUTE_REF)
529         && parameters->options().output_is_position_independent())
530       return true;
531
532     // A function call that can branch to a local PLT entry does not need
533     // a dynamic relocation.  A non-pic pc-relative function call in a
534     // shared library cannot use a PLT entry.
535     if ((flags & FUNCTION_CALL)
536         && this->has_plt_offset()
537         && !((flags & NON_PIC_REF) && parameters->options().shared()))
538       return false;
539
540     // A reference to any PLT entry in a non-position-independent executable
541     // does not need a dynamic relocation.
542     if (!parameters->options().output_is_position_independent()
543         && this->has_plt_offset())
544       return false;
545
546     // A reference to a symbol defined in a dynamic object or to a
547     // symbol that is preemptible will need a dynamic relocation.
548     if (this->is_from_dynobj()
549         || this->is_undefined()
550         || this->is_preemptible())
551       return true;
552
553     // For all other cases, return FALSE.
554     return false;
555   }
556
557   // Given a direct absolute static relocation against
558   // the global symbol, where a dynamic relocation is needed, this
559   // function returns whether a relative dynamic relocation can be used.
560   // The caller must determine separately whether the static relocation
561   // is compatible with a relative relocation.
562
563   bool
564   can_use_relative_reloc(bool is_function_call) const
565   {
566     // A function call that can branch to a local PLT entry can
567     // use a RELATIVE relocation.
568     if (is_function_call && this->has_plt_offset())
569       return true;
570
571     // A reference to a symbol defined in a dynamic object or to a
572     // symbol that is preemptible can not use a RELATIVE relocaiton.
573     if (this->is_from_dynobj()
574         || this->is_undefined()
575         || this->is_preemptible())
576       return false;
577
578     // For all other cases, return TRUE.
579     return true;
580   }
581
582   // Return the output section where this symbol is defined.  Return
583   // NULL if the symbol has an absolute value.
584   Output_section*
585   output_section() const;
586
587   // Set the symbol's output section.  This is used for symbols
588   // defined in scripts.  This should only be called after the symbol
589   // table has been finalized.
590   void
591   set_output_section(Output_section*);
592
593   // Return whether there should be a warning for references to this
594   // symbol.
595   bool
596   has_warning() const
597   { return this->has_warning_; }
598
599   // Mark this symbol as having a warning.
600   void
601   set_has_warning()
602   { this->has_warning_ = true; }
603
604   // Return whether this symbol is defined by a COPY reloc from a
605   // dynamic object.
606   bool
607   is_copied_from_dynobj() const
608   { return this->is_copied_from_dynobj_; }
609
610   // Mark this symbol as defined by a COPY reloc.
611   void
612   set_is_copied_from_dynobj()
613   { this->is_copied_from_dynobj_ = true; }
614
615   // Return whether this symbol is forced to visibility STB_LOCAL
616   // by a "local:" entry in a version script.
617   bool
618   is_forced_local() const
619   { return this->is_forced_local_; }
620
621   // Mark this symbol as forced to STB_LOCAL visibility.
622   void
623   set_is_forced_local()
624   { this->is_forced_local_ = true; }
625
626  protected:
627   // Instances of this class should always be created at a specific
628   // size.
629   Symbol()
630   { memset(this, 0, sizeof *this); }
631
632   // Initialize the general fields.
633   void
634   init_fields(const char* name, const char* version,
635               elfcpp::STT type, elfcpp::STB binding,
636               elfcpp::STV visibility, unsigned char nonvis);
637
638   // Initialize fields from an ELF symbol in OBJECT.  ST_SHNDX is the
639   // section index, IS_ORDINARY is whether it is a normal section
640   // index rather than a special code.
641   template<int size, bool big_endian>
642   void
643   init_base(const char *name, const char* version, Object* object,
644             const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
645             bool is_ordinary);
646
647   // Initialize fields for an Output_data.
648   void
649   init_base(const char* name, Output_data*, elfcpp::STT, elfcpp::STB,
650             elfcpp::STV, unsigned char nonvis, bool offset_is_from_end);
651
652   // Initialize fields for an Output_segment.
653   void
654   init_base(const char* name, Output_segment* os, elfcpp::STT type,
655             elfcpp::STB binding, elfcpp::STV visibility,
656             unsigned char nonvis, Segment_offset_base offset_base);
657
658   // Initialize fields for a constant.
659   void
660   init_base(const char* name, elfcpp::STT type, elfcpp::STB binding,
661             elfcpp::STV visibility, unsigned char nonvis);
662
663   // Override existing symbol.
664   template<int size, bool big_endian>
665   void
666   override_base(const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
667                 bool is_ordinary, Object* object, const char* version);
668
669   // Override existing symbol with a special symbol.
670   void
671   override_base_with_special(const Symbol* from);
672
673   // Allocate a common symbol by giving it a location in the output
674   // file.
675   void
676   allocate_base_common(Output_data*);
677
678  private:
679   Symbol(const Symbol&);
680   Symbol& operator=(const Symbol&);
681
682   // Symbol name (expected to point into a Stringpool).
683   const char* name_;
684   // Symbol version (expected to point into a Stringpool).  This may
685   // be NULL.
686   const char* version_;
687
688   union
689   {
690     // This struct is used if SOURCE_ == FROM_OBJECT.
691     struct
692     {
693       // Object in which symbol is defined, or in which it was first
694       // seen.
695       Object* object;
696       // Section number in object_ in which symbol is defined.
697       unsigned int shndx;
698     } from_object;
699
700     // This struct is used if SOURCE_ == IN_OUTPUT_DATA.
701     struct
702     {
703       // Output_data in which symbol is defined.  Before
704       // Layout::finalize the symbol's value is an offset within the
705       // Output_data.
706       Output_data* output_data;
707       // True if the offset is from the end, false if the offset is
708       // from the beginning.
709       bool offset_is_from_end;
710     } in_output_data;
711
712     // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
713     struct
714     {
715       // Output_segment in which the symbol is defined.  Before
716       // Layout::finalize the symbol's value is an offset.
717       Output_segment* output_segment;
718       // The base to use for the offset before Layout::finalize.
719       Segment_offset_base offset_base;
720     } in_output_segment;
721   } u_;
722
723   // The index of this symbol in the output file.  If the symbol is
724   // not going into the output file, this value is -1U.  This field
725   // starts as always holding zero.  It is set to a non-zero value by
726   // Symbol_table::finalize.
727   unsigned int symtab_index_;
728
729   // The index of this symbol in the dynamic symbol table.  If the
730   // symbol is not going into the dynamic symbol table, this value is
731   // -1U.  This field starts as always holding zero.  It is set to a
732   // non-zero value during Layout::finalize.
733   unsigned int dynsym_index_;
734
735   // If this symbol has an entry in the GOT section (has_got_offset_
736   // is true), this holds the offset from the start of the GOT section.
737   // A symbol may have more than one GOT offset (e.g., when mixing
738   // modules compiled with two different TLS models), but will usually
739   // have at most one.
740   Got_offset_list got_offsets_;
741
742   // If this symbol has an entry in the PLT section (has_plt_offset_
743   // is true), then this is the offset from the start of the PLT
744   // section.
745   unsigned int plt_offset_;
746
747   // Symbol type (bits 0 to 3).
748   elfcpp::STT type_ : 4;
749   // Symbol binding (bits 4 to 7).
750   elfcpp::STB binding_ : 4;
751   // Symbol visibility (bits 8 to 9).
752   elfcpp::STV visibility_ : 2;
753   // Rest of symbol st_other field (bits 10 to 15).
754   unsigned int nonvis_ : 6;
755   // The type of symbol (bits 16 to 18).
756   Source source_ : 3;
757   // True if this symbol always requires special target-specific
758   // handling (bit 19).
759   bool is_target_special_ : 1;
760   // True if this is the default version of the symbol (bit 20).
761   bool is_def_ : 1;
762   // True if this symbol really forwards to another symbol.  This is
763   // used when we discover after the fact that two different entries
764   // in the hash table really refer to the same symbol.  This will
765   // never be set for a symbol found in the hash table, but may be set
766   // for a symbol found in the list of symbols attached to an Object.
767   // It forwards to the symbol found in the forwarders_ map of
768   // Symbol_table (bit 21).
769   bool is_forwarder_ : 1;
770   // True if the symbol has an alias in the weak_aliases table in
771   // Symbol_table (bit 22).
772   bool has_alias_ : 1;
773   // True if this symbol needs to be in the dynamic symbol table (bit
774   // 23).
775   bool needs_dynsym_entry_ : 1;
776   // True if we've seen this symbol in a regular object (bit 24).
777   bool in_reg_ : 1;
778   // True if we've seen this symbol in a dynamic object (bit 25).
779   bool in_dyn_ : 1;
780   // True if the symbol has an entry in the PLT section (bit 26).
781   bool has_plt_offset_ : 1;
782   // True if this is a dynamic symbol which needs a special value in
783   // the dynamic symbol table (bit 27).
784   bool needs_dynsym_value_ : 1;
785   // True if there is a warning for this symbol (bit 28).
786   bool has_warning_ : 1;
787   // True if we are using a COPY reloc for this symbol, so that the
788   // real definition lives in a dynamic object (bit 29).
789   bool is_copied_from_dynobj_ : 1;
790   // True if this symbol was forced to local visibility by a version
791   // script (bit 30).
792   bool is_forced_local_ : 1;
793   // True if the field u_.from_object.shndx is an ordinary section
794   // index, not one of the special codes from SHN_LORESERVE to
795   // SHN_HIRESERVE.
796   bool is_ordinary_shndx_ : 1;
797 };
798
799 // The parts of a symbol which are size specific.  Using a template
800 // derived class like this helps us use less space on a 32-bit system.
801
802 template<int size>
803 class Sized_symbol : public Symbol
804 {
805  public:
806   typedef typename elfcpp::Elf_types<size>::Elf_Addr Value_type;
807   typedef typename elfcpp::Elf_types<size>::Elf_WXword Size_type;
808
809   Sized_symbol()
810   { }
811
812   // Initialize fields from an ELF symbol in OBJECT.  ST_SHNDX is the
813   // section index, IS_ORDINARY is whether it is a normal section
814   // index rather than a special code.
815   template<bool big_endian>
816   void
817   init(const char *name, const char* version, Object* object,
818        const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
819        bool is_ordinary);
820
821   // Initialize fields for an Output_data.
822   void
823   init(const char* name, Output_data*, Value_type value, Size_type symsize,
824        elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
825        bool offset_is_from_end);
826
827   // Initialize fields for an Output_segment.
828   void
829   init(const char* name, Output_segment*, Value_type value, Size_type symsize,
830        elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
831        Segment_offset_base offset_base);
832
833   // Initialize fields for a constant.
834   void
835   init(const char* name, Value_type value, Size_type symsize,
836        elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
837
838   // Override existing symbol.
839   template<bool big_endian>
840   void
841   override(const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
842            bool is_ordinary, Object* object, const char* version);
843
844   // Override existing symbol with a special symbol.
845   void
846   override_with_special(const Sized_symbol<size>*);
847
848   // Return the symbol's value.
849   Value_type
850   value() const
851   { return this->value_; }
852
853   // Return the symbol's size (we can't call this 'size' because that
854   // is a template parameter).
855   Size_type
856   symsize() const
857   { return this->symsize_; }
858
859   // Set the symbol size.  This is used when resolving common symbols.
860   void
861   set_symsize(Size_type symsize)
862   { this->symsize_ = symsize; }
863
864   // Set the symbol value.  This is called when we store the final
865   // values of the symbols into the symbol table.
866   void
867   set_value(Value_type value)
868   { this->value_ = value; }
869
870   // Allocate a common symbol by giving it a location in the output
871   // file.
872   void
873   allocate_common(Output_data*, Value_type value);
874
875  private:
876   Sized_symbol(const Sized_symbol&);
877   Sized_symbol& operator=(const Sized_symbol&);
878
879   // Symbol value.  Before Layout::finalize this is the offset in the
880   // input section.  This is set to the final value during
881   // Layout::finalize.
882   Value_type value_;
883   // Symbol size.
884   Size_type symsize_;
885 };
886
887 // A struct describing a symbol defined by the linker, where the value
888 // of the symbol is defined based on an output section.  This is used
889 // for symbols defined by the linker, like "_init_array_start".
890
891 struct Define_symbol_in_section
892 {
893   // The symbol name.
894   const char* name;
895   // The name of the output section with which this symbol should be
896   // associated.  If there is no output section with that name, the
897   // symbol will be defined as zero.
898   const char* output_section;
899   // The offset of the symbol within the output section.  This is an
900   // offset from the start of the output section, unless start_at_end
901   // is true, in which case this is an offset from the end of the
902   // output section.
903   uint64_t value;
904   // The size of the symbol.
905   uint64_t size;
906   // The symbol type.
907   elfcpp::STT type;
908   // The symbol binding.
909   elfcpp::STB binding;
910   // The symbol visibility.
911   elfcpp::STV visibility;
912   // The rest of the st_other field.
913   unsigned char nonvis;
914   // If true, the value field is an offset from the end of the output
915   // section.
916   bool offset_is_from_end;
917   // If true, this symbol is defined only if we see a reference to it.
918   bool only_if_ref;
919 };
920
921 // A struct describing a symbol defined by the linker, where the value
922 // of the symbol is defined based on a segment.  This is used for
923 // symbols defined by the linker, like "_end".  We describe the
924 // segment with which the symbol should be associated by its
925 // characteristics.  If no segment meets these characteristics, the
926 // symbol will be defined as zero.  If there is more than one segment
927 // which meets these characteristics, we will use the first one.
928
929 struct Define_symbol_in_segment
930 {
931   // The symbol name.
932   const char* name;
933   // The segment type where the symbol should be defined, typically
934   // PT_LOAD.
935   elfcpp::PT segment_type;
936   // Bitmask of segment flags which must be set.
937   elfcpp::PF segment_flags_set;
938   // Bitmask of segment flags which must be clear.
939   elfcpp::PF segment_flags_clear;
940   // The offset of the symbol within the segment.  The offset is
941   // calculated from the position set by offset_base.
942   uint64_t value;
943   // The size of the symbol.
944   uint64_t size;
945   // The symbol type.
946   elfcpp::STT type;
947   // The symbol binding.
948   elfcpp::STB binding;
949   // The symbol visibility.
950   elfcpp::STV visibility;
951   // The rest of the st_other field.
952   unsigned char nonvis;
953   // The base from which we compute the offset.
954   Symbol::Segment_offset_base offset_base;
955   // If true, this symbol is defined only if we see a reference to it.
956   bool only_if_ref;
957 };
958
959 // This class manages warnings.  Warnings are a GNU extension.  When
960 // we see a section named .gnu.warning.SYM in an object file, and if
961 // we wind using the definition of SYM from that object file, then we
962 // will issue a warning for any relocation against SYM from a
963 // different object file.  The text of the warning is the contents of
964 // the section.  This is not precisely the definition used by the old
965 // GNU linker; the old GNU linker treated an occurrence of
966 // .gnu.warning.SYM as defining a warning symbol.  A warning symbol
967 // would trigger a warning on any reference.  However, it was
968 // inconsistent in that a warning in a dynamic object only triggered
969 // if there was no definition in a regular object.  This linker is
970 // different in that we only issue a warning if we use the symbol
971 // definition from the same object file as the warning section.
972
973 class Warnings
974 {
975  public:
976   Warnings()
977     : warnings_()
978   { }
979
980   // Add a warning for symbol NAME in object OBJ.  WARNING is the text
981   // of the warning.
982   void
983   add_warning(Symbol_table* symtab, const char* name, Object* obj,
984               const std::string& warning);
985
986   // For each symbol for which we should give a warning, make a note
987   // on the symbol.
988   void
989   note_warnings(Symbol_table* symtab);
990
991   // Issue a warning for a reference to SYM at RELINFO's location.
992   template<int size, bool big_endian>
993   void
994   issue_warning(const Symbol* sym, const Relocate_info<size, big_endian>*,
995                 size_t relnum, off_t reloffset) const;
996
997  private:
998   Warnings(const Warnings&);
999   Warnings& operator=(const Warnings&);
1000
1001   // What we need to know to get the warning text.
1002   struct Warning_location
1003   {
1004     // The object the warning is in.
1005     Object* object;
1006     // The warning text.
1007     std::string text;
1008
1009     Warning_location()
1010       : object(NULL), text()
1011     { }
1012
1013     void
1014     set(Object* o, const std::string& t)
1015     {
1016       this->object = o;
1017       this->text = t;
1018     }
1019   };
1020
1021   // A mapping from warning symbol names (canonicalized in
1022   // Symbol_table's namepool_ field) to warning information.
1023   typedef Unordered_map<const char*, Warning_location> Warning_table;
1024
1025   Warning_table warnings_;
1026 };
1027
1028 // The main linker symbol table.
1029
1030 class Symbol_table
1031 {
1032  public:
1033   // COUNT is an estimate of how many symbosl will be inserted in the
1034   // symbol table.  It's ok to put 0 if you don't know; a correct
1035   // guess will just save some CPU by reducing hashtable resizes.
1036   Symbol_table(unsigned int count, const Version_script_info& version_script);
1037
1038   ~Symbol_table();
1039
1040   // Add COUNT external symbols from the relocatable object RELOBJ to
1041   // the symbol table.  SYMS is the symbols, SYMNDX_OFFSET is the
1042   // offset in the symbol table of the first symbol, SYM_NAMES is
1043   // their names, SYM_NAME_SIZE is the size of SYM_NAMES.  This sets
1044   // SYMPOINTERS to point to the symbols in the symbol table.
1045   template<int size, bool big_endian>
1046   void
1047   add_from_relobj(Sized_relobj<size, big_endian>* relobj,
1048                   const unsigned char* syms, size_t count,
1049                   size_t symndx_offset, const char* sym_names,
1050                   size_t sym_name_size,
1051                   typename Sized_relobj<size, big_endian>::Symbols*);
1052
1053   // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
1054   // symbol table.  SYMS is the symbols.  SYM_NAMES is their names.
1055   // SYM_NAME_SIZE is the size of SYM_NAMES.  The other parameters are
1056   // symbol version data.
1057   template<int size, bool big_endian>
1058   void
1059   add_from_dynobj(Sized_dynobj<size, big_endian>* dynobj,
1060                   const unsigned char* syms, size_t count,
1061                   const char* sym_names, size_t sym_name_size,
1062                   const unsigned char* versym, size_t versym_size,
1063                   const std::vector<const char*>*);
1064
1065   // Define a special symbol based on an Output_data.  It is a
1066   // multiple definition error if this symbol is already defined.
1067   Symbol*
1068   define_in_output_data(const char* name, const char* version,
1069                         Output_data*, uint64_t value, uint64_t symsize,
1070                         elfcpp::STT type, elfcpp::STB binding,
1071                         elfcpp::STV visibility, unsigned char nonvis,
1072                         bool offset_is_from_end, bool only_if_ref);
1073
1074   // Define a special symbol based on an Output_segment.  It is a
1075   // multiple definition error if this symbol is already defined.
1076   Symbol*
1077   define_in_output_segment(const char* name, const char* version,
1078                            Output_segment*, uint64_t value, uint64_t symsize,
1079                            elfcpp::STT type, elfcpp::STB binding,
1080                            elfcpp::STV visibility, unsigned char nonvis,
1081                            Symbol::Segment_offset_base, bool only_if_ref);
1082
1083   // Define a special symbol with a constant value.  It is a multiple
1084   // definition error if this symbol is already defined.
1085   Symbol*
1086   define_as_constant(const char* name, const char* version,
1087                      uint64_t value, uint64_t symsize, elfcpp::STT type,
1088                      elfcpp::STB binding, elfcpp::STV visibility,
1089                      unsigned char nonvis, bool only_if_ref,
1090                      bool force_override);
1091
1092   // Define a set of symbols in output sections.  If ONLY_IF_REF is
1093   // true, only define them if they are referenced.
1094   void
1095   define_symbols(const Layout*, int count, const Define_symbol_in_section*,
1096                  bool only_if_ref);
1097
1098   // Define a set of symbols in output segments.  If ONLY_IF_REF is
1099   // true, only defined them if they are referenced.
1100   void
1101   define_symbols(const Layout*, int count, const Define_symbol_in_segment*,
1102                  bool only_if_ref);
1103
1104   // Define SYM using a COPY reloc.  POSD is the Output_data where the
1105   // symbol should be defined--typically a .dyn.bss section.  VALUE is
1106   // the offset within POSD.
1107   template<int size>
1108   void
1109   define_with_copy_reloc(Sized_symbol<size>* sym, Output_data* posd,
1110                          typename elfcpp::Elf_types<size>::Elf_Addr);
1111
1112   // Look up a symbol.
1113   Symbol*
1114   lookup(const char*, const char* version = NULL) const;
1115
1116   // Return the real symbol associated with the forwarder symbol FROM.
1117   Symbol*
1118   resolve_forwards(const Symbol* from) const;
1119
1120   // Return the sized version of a symbol in this table.
1121   template<int size>
1122   Sized_symbol<size>*
1123   get_sized_symbol(Symbol*) const;
1124
1125   template<int size>
1126   const Sized_symbol<size>*
1127   get_sized_symbol(const Symbol*) const;
1128
1129   // Return the count of undefined symbols seen.
1130   int
1131   saw_undefined() const
1132   { return this->saw_undefined_; }
1133
1134   // Allocate the common symbols
1135   void
1136   allocate_commons(Layout*);
1137
1138   // Add a warning for symbol NAME in object OBJ.  WARNING is the text
1139   // of the warning.
1140   void
1141   add_warning(const char* name, Object* obj, const std::string& warning)
1142   { this->warnings_.add_warning(this, name, obj, warning); }
1143
1144   // Canonicalize a symbol name for use in the hash table.
1145   const char*
1146   canonicalize_name(const char* name)
1147   { return this->namepool_.add(name, true, NULL); }
1148
1149   // Possibly issue a warning for a reference to SYM at LOCATION which
1150   // is in OBJ.
1151   template<int size, bool big_endian>
1152   void
1153   issue_warning(const Symbol* sym,
1154                 const Relocate_info<size, big_endian>* relinfo,
1155                 size_t relnum, off_t reloffset) const
1156   { this->warnings_.issue_warning(sym, relinfo, relnum, reloffset); }
1157
1158   // Check candidate_odr_violations_ to find symbols with the same name
1159   // but apparently different definitions (different source-file/line-no).
1160   void
1161   detect_odr_violations(const Task*, const char* output_file_name) const;
1162
1163   // SYM is defined using a COPY reloc.  Return the dynamic object
1164   // where the original definition was found.
1165   Dynobj*
1166   get_copy_source(const Symbol* sym) const;
1167
1168   // Set the dynamic symbol indexes.  INDEX is the index of the first
1169   // global dynamic symbol.  Pointers to the symbols are stored into
1170   // the vector.  The names are stored into the Stringpool.  This
1171   // returns an updated dynamic symbol index.
1172   unsigned int
1173   set_dynsym_indexes(unsigned int index, std::vector<Symbol*>*,
1174                      Stringpool*, Versions*);
1175
1176   // Finalize the symbol table after we have set the final addresses
1177   // of all the input sections.  This sets the final symbol indexes,
1178   // values and adds the names to *POOL.  *PLOCAL_SYMCOUNT is the
1179   // index of the first global symbol.  OFF is the file offset of the
1180   // global symbol table, DYNOFF is the offset of the globals in the
1181   // dynamic symbol table, DYN_GLOBAL_INDEX is the index of the first
1182   // global dynamic symbol, and DYNCOUNT is the number of global
1183   // dynamic symbols.  This records the parameters, and returns the
1184   // new file offset.  It updates *PLOCAL_SYMCOUNT if it created any
1185   // local symbols.
1186   off_t
1187   finalize(off_t off, off_t dynoff, size_t dyn_global_index, size_t dyncount,
1188            Stringpool* pool, unsigned int *plocal_symcount);
1189
1190   // Write out the global symbols.
1191   void
1192   write_globals(const Input_objects*, const Stringpool*, const Stringpool*,
1193                 Output_symtab_xindex*, Output_symtab_xindex*,
1194                 Output_file*) const;
1195
1196   // Write out a section symbol.  Return the updated offset.
1197   void
1198   write_section_symbol(const Output_section*, Output_symtab_xindex*,
1199                        Output_file*, off_t) const;
1200
1201   // Dump statistical information to stderr.
1202   void
1203   print_stats() const;
1204
1205   // Return the version script information.
1206   const Version_script_info&
1207   version_script() const
1208   { return version_script_; }
1209
1210  private:
1211   Symbol_table(const Symbol_table&);
1212   Symbol_table& operator=(const Symbol_table&);
1213
1214   // The type of the list of common symbols.
1215   typedef std::vector<Symbol*> Commons_type;
1216
1217   // Make FROM a forwarder symbol to TO.
1218   void
1219   make_forwarder(Symbol* from, Symbol* to);
1220
1221   // Add a symbol.
1222   template<int size, bool big_endian>
1223   Sized_symbol<size>*
1224   add_from_object(Object*, const char *name, Stringpool::Key name_key,
1225                   const char *version, Stringpool::Key version_key,
1226                   bool def, const elfcpp::Sym<size, big_endian>& sym,
1227                   unsigned int st_shndx, bool is_ordinary,
1228                   unsigned int orig_st_shndx);
1229
1230   // Resolve symbols.
1231   template<int size, bool big_endian>
1232   void
1233   resolve(Sized_symbol<size>* to,
1234           const elfcpp::Sym<size, big_endian>& sym,
1235           unsigned int st_shndx, bool is_ordinary,
1236           unsigned int orig_st_shndx,
1237           Object*, const char* version);
1238
1239   template<int size, bool big_endian>
1240   void
1241   resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
1242           const char* version);
1243
1244   // Record that a symbol is forced to be local by a version script.
1245   void
1246   force_local(Symbol*);
1247
1248   // Adjust NAME and *NAME_KEY for wrapping.
1249   const char*
1250   wrap_symbol(Object* object, const char*, Stringpool::Key* name_key);
1251
1252   // Whether we should override a symbol, based on flags in
1253   // resolve.cc.
1254   static bool
1255   should_override(const Symbol*, unsigned int, Object*, bool*);
1256
1257   // Override a symbol.
1258   template<int size, bool big_endian>
1259   void
1260   override(Sized_symbol<size>* tosym,
1261            const elfcpp::Sym<size, big_endian>& fromsym,
1262            unsigned int st_shndx, bool is_ordinary,
1263            Object* object, const char* version);
1264
1265   // Whether we should override a symbol with a special symbol which
1266   // is automatically defined by the linker.
1267   static bool
1268   should_override_with_special(const Symbol*);
1269
1270   // Override a symbol with a special symbol.
1271   template<int size>
1272   void
1273   override_with_special(Sized_symbol<size>* tosym,
1274                         const Sized_symbol<size>* fromsym);
1275
1276   // Record all weak alias sets for a dynamic object.
1277   template<int size>
1278   void
1279   record_weak_aliases(std::vector<Sized_symbol<size>*>*);
1280
1281   // Define a special symbol.
1282   template<int size, bool big_endian>
1283   Sized_symbol<size>*
1284   define_special_symbol(const char** pname, const char** pversion,
1285                         bool only_if_ref, Sized_symbol<size>** poldsym);
1286
1287   // Define a symbol in an Output_data, sized version.
1288   template<int size>
1289   Sized_symbol<size>*
1290   do_define_in_output_data(const char* name, const char* version, Output_data*,
1291                            typename elfcpp::Elf_types<size>::Elf_Addr value,
1292                            typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1293                            elfcpp::STT type, elfcpp::STB binding,
1294                            elfcpp::STV visibility, unsigned char nonvis,
1295                            bool offset_is_from_end, bool only_if_ref);
1296
1297   // Define a symbol in an Output_segment, sized version.
1298   template<int size>
1299   Sized_symbol<size>*
1300   do_define_in_output_segment(
1301     const char* name, const char* version, Output_segment* os,
1302     typename elfcpp::Elf_types<size>::Elf_Addr value,
1303     typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1304     elfcpp::STT type, elfcpp::STB binding,
1305     elfcpp::STV visibility, unsigned char nonvis,
1306     Symbol::Segment_offset_base offset_base, bool only_if_ref);
1307
1308   // Define a symbol as a constant, sized version.
1309   template<int size>
1310   Sized_symbol<size>*
1311   do_define_as_constant(
1312     const char* name, const char* version,
1313     typename elfcpp::Elf_types<size>::Elf_Addr value,
1314     typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1315     elfcpp::STT type, elfcpp::STB binding,
1316     elfcpp::STV visibility, unsigned char nonvis,
1317     bool only_if_ref, bool force_override);
1318
1319   // Allocate the common symbols, sized version.
1320   template<int size>
1321   void
1322   do_allocate_commons(Layout*);
1323
1324   // Allocate the common symbols from one list.
1325   template<int size>
1326   void
1327   do_allocate_commons_list(Layout*, bool is_tls, Commons_type*);
1328
1329   // Implement detect_odr_violations.
1330   template<int size, bool big_endian>
1331   void
1332   sized_detect_odr_violations() const;
1333
1334   // Finalize symbols specialized for size.
1335   template<int size>
1336   off_t
1337   sized_finalize(off_t, Stringpool*, unsigned int*);
1338
1339   // Finalize a symbol.  Return whether it should be added to the
1340   // symbol table.
1341   template<int size>
1342   bool
1343   sized_finalize_symbol(Symbol*);
1344
1345   // Add a symbol the final symtab by setting its index.
1346   template<int size>
1347   void
1348   add_to_final_symtab(Symbol*, Stringpool*, unsigned int* pindex, off_t* poff);
1349
1350   // Write globals specialized for size and endianness.
1351   template<int size, bool big_endian>
1352   void
1353   sized_write_globals(const Input_objects*, const Stringpool*,
1354                       const Stringpool*, Output_symtab_xindex*,
1355                       Output_symtab_xindex*, Output_file*) const;
1356
1357   // Write out a symbol to P.
1358   template<int size, bool big_endian>
1359   void
1360   sized_write_symbol(Sized_symbol<size>*,
1361                      typename elfcpp::Elf_types<size>::Elf_Addr value,
1362                      unsigned int shndx,
1363                      const Stringpool*, unsigned char* p) const;
1364
1365   // Possibly warn about an undefined symbol from a dynamic object.
1366   void
1367   warn_about_undefined_dynobj_symbol(const Input_objects*, Symbol*) const;
1368
1369   // Write out a section symbol, specialized for size and endianness.
1370   template<int size, bool big_endian>
1371   void
1372   sized_write_section_symbol(const Output_section*, Output_symtab_xindex*,
1373                              Output_file*, off_t) const;
1374
1375   // The type of the symbol hash table.
1376
1377   typedef std::pair<Stringpool::Key, Stringpool::Key> Symbol_table_key;
1378
1379   struct Symbol_table_hash
1380   {
1381     size_t
1382     operator()(const Symbol_table_key&) const;
1383   };
1384
1385   struct Symbol_table_eq
1386   {
1387     bool
1388     operator()(const Symbol_table_key&, const Symbol_table_key&) const;
1389   };
1390
1391   typedef Unordered_map<Symbol_table_key, Symbol*, Symbol_table_hash,
1392                         Symbol_table_eq> Symbol_table_type;
1393
1394   // The type of the list of symbols which have been forced local.
1395   typedef std::vector<Symbol*> Forced_locals;
1396
1397   // A map from symbols with COPY relocs to the dynamic objects where
1398   // they are defined.
1399   typedef Unordered_map<const Symbol*, Dynobj*> Copied_symbol_dynobjs;
1400
1401   // A map from symbol name (as a pointer into the namepool) to all
1402   // the locations the symbols is (weakly) defined (and certain other
1403   // conditions are met).  This map will be used later to detect
1404   // possible One Definition Rule (ODR) violations.
1405   struct Symbol_location
1406   {
1407     Object* object;         // Object where the symbol is defined.
1408     unsigned int shndx;     // Section-in-object where the symbol is defined.
1409     off_t offset;           // Offset-in-section where the symbol is defined.
1410     bool operator==(const Symbol_location& that) const
1411     {
1412       return (this->object == that.object
1413               && this->shndx == that.shndx
1414               && this->offset == that.offset);
1415     }
1416   };
1417
1418   struct Symbol_location_hash
1419   {
1420     size_t operator()(const Symbol_location& loc) const
1421     { return reinterpret_cast<uintptr_t>(loc.object) ^ loc.offset ^ loc.shndx; }
1422   };
1423
1424   typedef Unordered_map<const char*,
1425                         Unordered_set<Symbol_location, Symbol_location_hash> >
1426   Odr_map;
1427
1428   // We increment this every time we see a new undefined symbol, for
1429   // use in archive groups.
1430   int saw_undefined_;
1431   // The index of the first global symbol in the output file.
1432   unsigned int first_global_index_;
1433   // The file offset within the output symtab section where we should
1434   // write the table.
1435   off_t offset_;
1436   // The number of global symbols we want to write out.
1437   unsigned int output_count_;
1438   // The file offset of the global dynamic symbols, or 0 if none.
1439   off_t dynamic_offset_;
1440   // The index of the first global dynamic symbol.
1441   unsigned int first_dynamic_global_index_;
1442   // The number of global dynamic symbols, or 0 if none.
1443   unsigned int dynamic_count_;
1444   // The symbol hash table.
1445   Symbol_table_type table_;
1446   // A pool of symbol names.  This is used for all global symbols.
1447   // Entries in the hash table point into this pool.
1448   Stringpool namepool_;
1449   // Forwarding symbols.
1450   Unordered_map<const Symbol*, Symbol*> forwarders_;
1451   // Weak aliases.  A symbol in this list points to the next alias.
1452   // The aliases point to each other in a circular list.
1453   Unordered_map<Symbol*, Symbol*> weak_aliases_;
1454   // We don't expect there to be very many common symbols, so we keep
1455   // a list of them.  When we find a common symbol we add it to this
1456   // list.  It is possible that by the time we process the list the
1457   // symbol is no longer a common symbol.  It may also have become a
1458   // forwarder.
1459   Commons_type commons_;
1460   // This is like the commons_ field, except that it holds TLS common
1461   // symbols.
1462   Commons_type tls_commons_;
1463   // A list of symbols which have been forced to be local.  We don't
1464   // expect there to be very many of them, so we keep a list of them
1465   // rather than walking the whole table to find them.
1466   Forced_locals forced_locals_;
1467   // Manage symbol warnings.
1468   Warnings warnings_;
1469   // Manage potential One Definition Rule (ODR) violations.
1470   Odr_map candidate_odr_violations_;
1471
1472   // When we emit a COPY reloc for a symbol, we define it in an
1473   // Output_data.  When it's time to emit version information for it,
1474   // we need to know the dynamic object in which we found the original
1475   // definition.  This maps symbols with COPY relocs to the dynamic
1476   // object where they were defined.
1477   Copied_symbol_dynobjs copied_symbol_dynobjs_;
1478   // Information parsed from the version script, if any.
1479   const Version_script_info& version_script_;
1480 };
1481
1482 // We inline get_sized_symbol for efficiency.
1483
1484 template<int size>
1485 Sized_symbol<size>*
1486 Symbol_table::get_sized_symbol(Symbol* sym) const
1487 {
1488   gold_assert(size == parameters->target().get_size());
1489   return static_cast<Sized_symbol<size>*>(sym);
1490 }
1491
1492 template<int size>
1493 const Sized_symbol<size>*
1494 Symbol_table::get_sized_symbol(const Symbol* sym) const
1495 {
1496   gold_assert(size == parameters->target().get_size());
1497   return static_cast<const Sized_symbol<size>*>(sym);
1498 }
1499
1500 } // End namespace gold.
1501
1502 #endif // !defined(GOLD_SYMTAB_H)
This page took 0.105545 seconds and 4 git commands to generate.