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