Don't pass around the target in order to define symbols; get it from
[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     return (this->visibility_ != elfcpp::STV_INTERNAL
466             && this->visibility_ != elfcpp::STV_HIDDEN
467             && this->visibility_ != elfcpp::STV_PROTECTED
468             && !this->is_forced_local_
469             && parameters->output_is_shared()
470             && !parameters->symbolic());
471   }
472
473   // Return true if this symbol is a function that needs a PLT entry.
474   // If the symbol is defined in a dynamic object or if it is subject
475   // to pre-emption, we need to make a PLT entry.
476   bool
477   needs_plt_entry() const
478   {
479     return (this->type() == elfcpp::STT_FUNC
480             && (this->is_from_dynobj() || this->is_preemptible()));
481   }
482
483   // When determining whether a reference to a symbol needs a dynamic
484   // relocation, we need to know several things about the reference.
485   // These flags may be or'ed together.
486   enum Reference_flags
487   {
488     // Reference to the symbol's absolute address.
489     ABSOLUTE_REF = 1,
490     // A non-PIC reference.
491     NON_PIC_REF = 2,
492     // A function call.
493     FUNCTION_CALL = 4
494   };
495
496   // Given a direct absolute or pc-relative static relocation against
497   // the global symbol, this function returns whether a dynamic relocation
498   // is needed.
499
500   bool
501   needs_dynamic_reloc(int flags) const
502   {
503     // An absolute reference within a position-independent output file
504     // will need a dynamic relocation.
505     if ((flags & ABSOLUTE_REF)
506         && parameters->output_is_position_independent())
507       return true;
508
509     // A function call that can branch to a local PLT entry does not need
510     // a dynamic relocation.  A non-pic pc-relative function call in a
511     // shared library cannot use a PLT entry.
512     if ((flags & FUNCTION_CALL)
513         && this->has_plt_offset()
514         && !((flags & NON_PIC_REF) && parameters->output_is_shared()))
515       return false;
516
517     // A reference to any PLT entry in a non-position-independent executable
518     // does not need a dynamic relocation.
519     if (!parameters->output_is_position_independent()
520         && this->has_plt_offset())
521       return false;
522
523     // A reference to a symbol defined in a dynamic object or to a
524     // symbol that is preemptible will need a dynamic relocation.
525     if (this->is_from_dynobj() || this->is_preemptible())
526       return true;
527
528     // For all other cases, return FALSE.
529     return false;
530   }
531
532   // Given a direct absolute static relocation against
533   // the global symbol, where a dynamic relocation is needed, this
534   // function returns whether a relative dynamic relocation can be used.
535   // The caller must determine separately whether the static relocation
536   // is compatible with a relative relocation.
537
538   bool
539   can_use_relative_reloc(bool is_function_call) const
540   {
541     // A function call that can branch to a local PLT entry can
542     // use a RELATIVE relocation.
543     if (is_function_call && this->has_plt_offset())
544       return true;
545
546     // A reference to a symbol defined in a dynamic object or to a
547     // symbol that is preemptible can not use a RELATIVE relocaiton.
548     if (this->is_from_dynobj() || this->is_preemptible())
549       return false;
550
551     // For all other cases, return TRUE.
552     return true;
553   }
554
555   // Return whether there should be a warning for references to this
556   // symbol.
557   bool
558   has_warning() const
559   { return this->has_warning_; }
560
561   // Mark this symbol as having a warning.
562   void
563   set_has_warning()
564   { this->has_warning_ = true; }
565
566   // Return whether this symbol is defined by a COPY reloc from a
567   // dynamic object.
568   bool
569   is_copied_from_dynobj() const
570   { return this->is_copied_from_dynobj_; }
571
572   // Mark this symbol as defined by a COPY reloc.
573   void
574   set_is_copied_from_dynobj()
575   { this->is_copied_from_dynobj_ = true; }
576
577   // Return whether this symbol is forced to visibility STB_LOCAL
578   // by a "local:" entry in a version script.
579   bool
580   is_forced_local() const
581   { return this->is_forced_local_; }
582
583   // Mark this symbol as forced to STB_LOCAL visibility.
584   void
585   set_is_forced_local()
586   { this->is_forced_local_ = true; }
587
588  protected:
589   // Instances of this class should always be created at a specific
590   // size.
591   Symbol()
592   { memset(this, 0, sizeof *this); }
593
594   // Initialize the general fields.
595   void
596   init_fields(const char* name, const char* version,
597               elfcpp::STT type, elfcpp::STB binding,
598               elfcpp::STV visibility, unsigned char nonvis);
599
600   // Initialize fields from an ELF symbol in OBJECT.
601   template<int size, bool big_endian>
602   void
603   init_base(const char *name, const char* version, Object* object,
604             const elfcpp::Sym<size, big_endian>&);
605
606   // Initialize fields for an Output_data.
607   void
608   init_base(const char* name, Output_data*, elfcpp::STT, elfcpp::STB,
609             elfcpp::STV, unsigned char nonvis, bool offset_is_from_end);
610
611   // Initialize fields for an Output_segment.
612   void
613   init_base(const char* name, Output_segment* os, elfcpp::STT type,
614             elfcpp::STB binding, elfcpp::STV visibility,
615             unsigned char nonvis, Segment_offset_base offset_base);
616
617   // Initialize fields for a constant.
618   void
619   init_base(const char* name, elfcpp::STT type, elfcpp::STB binding,
620             elfcpp::STV visibility, unsigned char nonvis);
621
622   // Override existing symbol.
623   template<int size, bool big_endian>
624   void
625   override_base(const elfcpp::Sym<size, big_endian>&, Object* object,
626                 const char* version);
627
628   // Override existing symbol with a special symbol.
629   void
630   override_base_with_special(const Symbol* from);
631
632   // Allocate a common symbol by giving it a location in the output
633   // file.
634   void
635   allocate_base_common(Output_data*);
636
637  private:
638   Symbol(const Symbol&);
639   Symbol& operator=(const Symbol&);
640
641   // Symbol name (expected to point into a Stringpool).
642   const char* name_;
643   // Symbol version (expected to point into a Stringpool).  This may
644   // be NULL.
645   const char* version_;
646
647   union
648   {
649     // This struct is used if SOURCE_ == FROM_OBJECT.
650     struct
651     {
652       // Object in which symbol is defined, or in which it was first
653       // seen.
654       Object* object;
655       // Section number in object_ in which symbol is defined.
656       unsigned int shndx;
657     } from_object;
658
659     // This struct is used if SOURCE_ == IN_OUTPUT_DATA.
660     struct
661     {
662       // Output_data in which symbol is defined.  Before
663       // Layout::finalize the symbol's value is an offset within the
664       // Output_data.
665       Output_data* output_data;
666       // True if the offset is from the end, false if the offset is
667       // from the beginning.
668       bool offset_is_from_end;
669     } in_output_data;
670
671     // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
672     struct
673     {
674       // Output_segment in which the symbol is defined.  Before
675       // Layout::finalize the symbol's value is an offset.
676       Output_segment* output_segment;
677       // The base to use for the offset before Layout::finalize.
678       Segment_offset_base offset_base;
679     } in_output_segment;
680   } u_;
681
682   // The index of this symbol in the output file.  If the symbol is
683   // not going into the output file, this value is -1U.  This field
684   // starts as always holding zero.  It is set to a non-zero value by
685   // Symbol_table::finalize.
686   unsigned int symtab_index_;
687
688   // The index of this symbol in the dynamic symbol table.  If the
689   // symbol is not going into the dynamic symbol table, this value is
690   // -1U.  This field starts as always holding zero.  It is set to a
691   // non-zero value during Layout::finalize.
692   unsigned int dynsym_index_;
693
694   // If this symbol has an entry in the GOT section (has_got_offset_
695   // is true), this is the offset from the start of the GOT section.
696   // For a TLS symbol, if has_tls_tpoff_got_offset_ is true, this
697   // serves as the GOT offset for the GOT entry that holds its
698   // TP-relative offset.
699   unsigned int got_offset_;
700
701   // If this is a TLS symbol and has an entry in the GOT section
702   // for a module index or a pair of entries (module index,
703   // dtv-relative offset), these are the offsets from the start
704   // of the GOT section.
705   unsigned int tls_mod_got_offset_;
706   unsigned int tls_pair_got_offset_;
707
708   // If this symbol has an entry in the PLT section (has_plt_offset_
709   // is true), then this is the offset from the start of the PLT
710   // section.
711   unsigned int plt_offset_;
712
713   // Symbol type.
714   elfcpp::STT type_ : 4;
715   // Symbol binding.
716   elfcpp::STB binding_ : 4;
717   // Symbol visibility.
718   elfcpp::STV visibility_ : 2;
719   // Rest of symbol st_other field.
720   unsigned int nonvis_ : 6;
721   // The type of symbol.
722   Source source_ : 3;
723   // True if this symbol always requires special target-specific
724   // handling.
725   bool is_target_special_ : 1;
726   // True if this is the default version of the symbol.
727   bool is_def_ : 1;
728   // True if this symbol really forwards to another symbol.  This is
729   // used when we discover after the fact that two different entries
730   // in the hash table really refer to the same symbol.  This will
731   // never be set for a symbol found in the hash table, but may be set
732   // for a symbol found in the list of symbols attached to an Object.
733   // It forwards to the symbol found in the forwarders_ map of
734   // Symbol_table.
735   bool is_forwarder_ : 1;
736   // True if the symbol has an alias in the weak_aliases table in
737   // Symbol_table.
738   bool has_alias_ : 1;
739   // True if this symbol needs to be in the dynamic symbol table.
740   bool needs_dynsym_entry_ : 1;
741   // True if we've seen this symbol in a regular object.
742   bool in_reg_ : 1;
743   // True if we've seen this symbol in a dynamic object.
744   bool in_dyn_ : 1;
745   // True if the symbol has an entry in the GOT section.
746   // For a TLS symbol, this GOT entry will hold its tp-relative offset.
747   bool has_got_offset_ : 1;
748   // True if the symbol has an entry in the GOT section for its
749   // module index.
750   bool has_tls_mod_got_offset_ : 1;
751   // True if the symbol has a pair of entries in the GOT section for its
752   // module index and dtv-relative offset.
753   bool has_tls_pair_got_offset_ : 1;
754   // True if the symbol has an entry in the PLT section.
755   bool has_plt_offset_ : 1;
756   // True if this is a dynamic symbol which needs a special value in
757   // the dynamic symbol table.
758   bool needs_dynsym_value_ : 1;
759   // True if there is a warning for this symbol.
760   bool has_warning_ : 1;
761   // True if we are using a COPY reloc for this symbol, so that the
762   // real definition lives in a dynamic object.
763   bool is_copied_from_dynobj_ : 1;
764   // True if this symbol was forced to local visibility by a version
765   // script.
766   bool is_forced_local_ : 1;
767 };
768
769 // The parts of a symbol which are size specific.  Using a template
770 // derived class like this helps us use less space on a 32-bit system.
771
772 template<int size>
773 class Sized_symbol : public Symbol
774 {
775  public:
776   typedef typename elfcpp::Elf_types<size>::Elf_Addr Value_type;
777   typedef typename elfcpp::Elf_types<size>::Elf_WXword Size_type;
778
779   Sized_symbol()
780   { }
781
782   // Initialize fields from an ELF symbol in OBJECT.
783   template<bool big_endian>
784   void
785   init(const char *name, const char* version, Object* object,
786        const elfcpp::Sym<size, big_endian>&);
787
788   // Initialize fields for an Output_data.
789   void
790   init(const char* name, Output_data*, Value_type value, Size_type symsize,
791        elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
792        bool offset_is_from_end);
793
794   // Initialize fields for an Output_segment.
795   void
796   init(const char* name, Output_segment*, Value_type value, Size_type symsize,
797        elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
798        Segment_offset_base offset_base);
799
800   // Initialize fields for a constant.
801   void
802   init(const char* name, Value_type value, Size_type symsize,
803        elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
804
805   // Override existing symbol.
806   template<bool big_endian>
807   void
808   override(const elfcpp::Sym<size, big_endian>&, Object* object,
809            const char* version);
810
811   // Override existing symbol with a special symbol.
812   void
813   override_with_special(const Sized_symbol<size>*);
814
815   // Return the symbol's value.
816   Value_type
817   value() const
818   { return this->value_; }
819
820   // Return the symbol's size (we can't call this 'size' because that
821   // is a template parameter).
822   Size_type
823   symsize() const
824   { return this->symsize_; }
825
826   // Set the symbol size.  This is used when resolving common symbols.
827   void
828   set_symsize(Size_type symsize)
829   { this->symsize_ = symsize; }
830
831   // Set the symbol value.  This is called when we store the final
832   // values of the symbols into the symbol table.
833   void
834   set_value(Value_type value)
835   { this->value_ = value; }
836
837   // Allocate a common symbol by giving it a location in the output
838   // file.
839   void
840   allocate_common(Output_data*, Value_type value);
841
842  private:
843   Sized_symbol(const Sized_symbol&);
844   Sized_symbol& operator=(const Sized_symbol&);
845
846   // Symbol value.  Before Layout::finalize this is the offset in the
847   // input section.  This is set to the final value during
848   // Layout::finalize.
849   Value_type value_;
850   // Symbol size.
851   Size_type symsize_;
852 };
853
854 // A struct describing a symbol defined by the linker, where the value
855 // of the symbol is defined based on an output section.  This is used
856 // for symbols defined by the linker, like "_init_array_start".
857
858 struct Define_symbol_in_section
859 {
860   // The symbol name.
861   const char* name;
862   // The name of the output section with which this symbol should be
863   // associated.  If there is no output section with that name, the
864   // symbol will be defined as zero.
865   const char* output_section;
866   // The offset of the symbol within the output section.  This is an
867   // offset from the start of the output section, unless start_at_end
868   // is true, in which case this is an offset from the end of the
869   // output section.
870   uint64_t value;
871   // The size of the symbol.
872   uint64_t size;
873   // The symbol type.
874   elfcpp::STT type;
875   // The symbol binding.
876   elfcpp::STB binding;
877   // The symbol visibility.
878   elfcpp::STV visibility;
879   // The rest of the st_other field.
880   unsigned char nonvis;
881   // If true, the value field is an offset from the end of the output
882   // section.
883   bool offset_is_from_end;
884   // If true, this symbol is defined only if we see a reference to it.
885   bool only_if_ref;
886 };
887
888 // A struct describing a symbol defined by the linker, where the value
889 // of the symbol is defined based on a segment.  This is used for
890 // symbols defined by the linker, like "_end".  We describe the
891 // segment with which the symbol should be associated by its
892 // characteristics.  If no segment meets these characteristics, the
893 // symbol will be defined as zero.  If there is more than one segment
894 // which meets these characteristics, we will use the first one.
895
896 struct Define_symbol_in_segment
897 {
898   // The symbol name.
899   const char* name;
900   // The segment type where the symbol should be defined, typically
901   // PT_LOAD.
902   elfcpp::PT segment_type;
903   // Bitmask of segment flags which must be set.
904   elfcpp::PF segment_flags_set;
905   // Bitmask of segment flags which must be clear.
906   elfcpp::PF segment_flags_clear;
907   // The offset of the symbol within the segment.  The offset is
908   // calculated from the position set by offset_base.
909   uint64_t value;
910   // The size of the symbol.
911   uint64_t size;
912   // The symbol type.
913   elfcpp::STT type;
914   // The symbol binding.
915   elfcpp::STB binding;
916   // The symbol visibility.
917   elfcpp::STV visibility;
918   // The rest of the st_other field.
919   unsigned char nonvis;
920   // The base from which we compute the offset.
921   Symbol::Segment_offset_base offset_base;
922   // If true, this symbol is defined only if we see a reference to it.
923   bool only_if_ref;
924 };
925
926 // This class manages warnings.  Warnings are a GNU extension.  When
927 // we see a section named .gnu.warning.SYM in an object file, and if
928 // we wind using the definition of SYM from that object file, then we
929 // will issue a warning for any relocation against SYM from a
930 // different object file.  The text of the warning is the contents of
931 // the section.  This is not precisely the definition used by the old
932 // GNU linker; the old GNU linker treated an occurrence of
933 // .gnu.warning.SYM as defining a warning symbol.  A warning symbol
934 // would trigger a warning on any reference.  However, it was
935 // inconsistent in that a warning in a dynamic object only triggered
936 // if there was no definition in a regular object.  This linker is
937 // different in that we only issue a warning if we use the symbol
938 // definition from the same object file as the warning section.
939
940 class Warnings
941 {
942  public:
943   Warnings()
944     : warnings_()
945   { }
946
947   // Add a warning for symbol NAME in object OBJ.  WARNING is the text
948   // of the warning.
949   void
950   add_warning(Symbol_table* symtab, const char* name, Object* obj,
951               const std::string& warning);
952
953   // For each symbol for which we should give a warning, make a note
954   // on the symbol.
955   void
956   note_warnings(Symbol_table* symtab);
957
958   // Issue a warning for a reference to SYM at RELINFO's location.
959   template<int size, bool big_endian>
960   void
961   issue_warning(const Symbol* sym, const Relocate_info<size, big_endian>*,
962                 size_t relnum, off_t reloffset) const;
963
964  private:
965   Warnings(const Warnings&);
966   Warnings& operator=(const Warnings&);
967
968   // What we need to know to get the warning text.
969   struct Warning_location
970   {
971     // The object the warning is in.
972     Object* object;
973     // The warning text.
974     std::string text;
975
976     Warning_location()
977       : object(NULL), text()
978     { }
979
980     void
981     set(Object* o, const std::string& t)
982     {
983       this->object = o;
984       this->text = t;
985     }
986   };
987
988   // A mapping from warning symbol names (canonicalized in
989   // Symbol_table's namepool_ field) to warning information.
990   typedef Unordered_map<const char*, Warning_location> Warning_table;
991
992   Warning_table warnings_;
993 };
994
995 // The main linker symbol table.
996
997 class Symbol_table
998 {
999  public:
1000   // COUNT is an estimate of how many symbosl will be inserted in the
1001   // symbol table.  It's ok to put 0 if you don't know; a correct
1002   // guess will just save some CPU by reducing hashtable resizes.
1003   Symbol_table(unsigned int count, const Version_script_info& version_script);
1004
1005   ~Symbol_table();
1006
1007   // Add COUNT external symbols from the relocatable object RELOBJ to
1008   // the symbol table.  SYMS is the symbols, SYM_NAMES is their names,
1009   // SYM_NAME_SIZE is the size of SYM_NAMES.  This sets SYMPOINTERS to
1010   // point to the symbols in the symbol table.
1011   template<int size, bool big_endian>
1012   void
1013   add_from_relobj(Sized_relobj<size, big_endian>* relobj,
1014                   const unsigned char* syms, size_t count,
1015                   const char* sym_names, size_t sym_name_size,
1016                   typename Sized_relobj<size, big_endian>::Symbols*);
1017
1018   // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
1019   // symbol table.  SYMS is the symbols.  SYM_NAMES is their names.
1020   // SYM_NAME_SIZE is the size of SYM_NAMES.  The other parameters are
1021   // symbol version data.
1022   template<int size, bool big_endian>
1023   void
1024   add_from_dynobj(Sized_dynobj<size, big_endian>* dynobj,
1025                   const unsigned char* syms, size_t count,
1026                   const char* sym_names, size_t sym_name_size,
1027                   const unsigned char* versym, size_t versym_size,
1028                   const std::vector<const char*>*);
1029
1030   // Define a special symbol based on an Output_data.  It is a
1031   // multiple definition error if this symbol is already defined.
1032   Symbol*
1033   define_in_output_data(const char* name, const char* version,
1034                         Output_data*, uint64_t value, uint64_t symsize,
1035                         elfcpp::STT type, elfcpp::STB binding,
1036                         elfcpp::STV visibility, unsigned char nonvis,
1037                         bool offset_is_from_end, bool only_if_ref);
1038
1039   // Define a special symbol based on an Output_segment.  It is a
1040   // multiple definition error if this symbol is already defined.
1041   Symbol*
1042   define_in_output_segment(const char* name, const char* version,
1043                            Output_segment*, uint64_t value, uint64_t symsize,
1044                            elfcpp::STT type, elfcpp::STB binding,
1045                            elfcpp::STV visibility, unsigned char nonvis,
1046                            Symbol::Segment_offset_base, bool only_if_ref);
1047
1048   // Define a special symbol with a constant value.  It is a multiple
1049   // definition error if this symbol is already defined.
1050   Symbol*
1051   define_as_constant(const char* name, const char* version,
1052                      uint64_t value, uint64_t symsize, elfcpp::STT type,
1053                      elfcpp::STB binding, elfcpp::STV visibility,
1054                      unsigned char nonvis, bool only_if_ref);
1055
1056   // Define a set of symbols in output sections.
1057   void
1058   define_symbols(const Layout*, int count, const Define_symbol_in_section*);
1059
1060   // Define a set of symbols in output segments.
1061   void
1062   define_symbols(const Layout*, int count, const Define_symbol_in_segment*);
1063
1064   // Define SYM using a COPY reloc.  POSD is the Output_data where the
1065   // symbol should be defined--typically a .dyn.bss section.  VALUE is
1066   // the offset within POSD.
1067   template<int size>
1068   void
1069   define_with_copy_reloc(Sized_symbol<size>* sym, Output_data* posd,
1070                          typename elfcpp::Elf_types<size>::Elf_Addr);
1071
1072   // Look up a symbol.
1073   Symbol*
1074   lookup(const char*, const char* version = NULL) const;
1075
1076   // Return the real symbol associated with the forwarder symbol FROM.
1077   Symbol*
1078   resolve_forwards(const Symbol* from) const;
1079
1080   // Return the sized version of a symbol in this table.
1081   template<int size>
1082   Sized_symbol<size>*
1083   get_sized_symbol(Symbol* ACCEPT_SIZE) const;
1084
1085   template<int size>
1086   const Sized_symbol<size>*
1087   get_sized_symbol(const Symbol* ACCEPT_SIZE) const;
1088
1089   // Return the count of undefined symbols seen.
1090   int
1091   saw_undefined() const
1092   { return this->saw_undefined_; }
1093
1094   // Allocate the common symbols
1095   void
1096   allocate_commons(const General_options&, Layout*);
1097
1098   // Add a warning for symbol NAME in object OBJ.  WARNING is the text
1099   // of the warning.
1100   void
1101   add_warning(const char* name, Object* obj, const std::string& warning)
1102   { this->warnings_.add_warning(this, name, obj, warning); }
1103
1104   // Canonicalize a symbol name for use in the hash table.
1105   const char*
1106   canonicalize_name(const char* name)
1107   { return this->namepool_.add(name, true, NULL); }
1108
1109   // Possibly issue a warning for a reference to SYM at LOCATION which
1110   // is in OBJ.
1111   template<int size, bool big_endian>
1112   void
1113   issue_warning(const Symbol* sym,
1114                 const Relocate_info<size, big_endian>* relinfo,
1115                 size_t relnum, off_t reloffset) const
1116   { this->warnings_.issue_warning(sym, relinfo, relnum, reloffset); }
1117
1118   // Check candidate_odr_violations_ to find symbols with the same name
1119   // but apparently different definitions (different source-file/line-no).
1120   void
1121   detect_odr_violations(const Task*, const char* output_file_name) const;
1122
1123   // SYM is defined using a COPY reloc.  Return the dynamic object
1124   // where the original definition was found.
1125   Dynobj*
1126   get_copy_source(const Symbol* sym) const;
1127
1128   // Set the dynamic symbol indexes.  INDEX is the index of the first
1129   // global dynamic symbol.  Pointers to the symbols are stored into
1130   // the vector.  The names are stored into the Stringpool.  This
1131   // returns an updated dynamic symbol index.
1132   unsigned int
1133   set_dynsym_indexes(unsigned int index, std::vector<Symbol*>*,
1134                      Stringpool*, Versions*);
1135
1136   // Finalize the symbol table after we have set the final addresses
1137   // of all the input sections.  This sets the final symbol indexes,
1138   // values and adds the names to *POOL.  *PLOCAL_SYMCOUNT is the
1139   // index of the first global symbol.  OFF is the file offset of the
1140   // global symbol table, DYNOFF is the offset of the globals in the
1141   // dynamic symbol table, DYN_GLOBAL_INDEX is the index of the first
1142   // global dynamic symbol, and DYNCOUNT is the number of global
1143   // dynamic symbols.  This records the parameters, and returns the
1144   // new file offset.  It updates *PLOCAL_SYMCOUNT if it created any
1145   // local symbols.
1146   off_t
1147   finalize(off_t off, off_t dynoff, size_t dyn_global_index, size_t dyncount,
1148            Stringpool* pool, unsigned int *plocal_symcount);
1149
1150   // Write out the global symbols.
1151   void
1152   write_globals(const Input_objects*, const Stringpool*, const Stringpool*,
1153                 Output_file*) const;
1154
1155   // Write out a section symbol.  Return the updated offset.
1156   void
1157   write_section_symbol(const Output_section*, Output_file*, off_t) const;
1158
1159   // Dump statistical information to stderr.
1160   void
1161   print_stats() const;
1162
1163   // Return the version script information.
1164   const Version_script_info&
1165   version_script() const
1166   { return version_script_; }
1167
1168  private:
1169   Symbol_table(const Symbol_table&);
1170   Symbol_table& operator=(const Symbol_table&);
1171
1172   // Make FROM a forwarder symbol to TO.
1173   void
1174   make_forwarder(Symbol* from, Symbol* to);
1175
1176   // Add a symbol.
1177   template<int size, bool big_endian>
1178   Sized_symbol<size>*
1179   add_from_object(Object*, const char *name, Stringpool::Key name_key,
1180                   const char *version, Stringpool::Key version_key,
1181                   bool def, const elfcpp::Sym<size, big_endian>& sym,
1182                   const elfcpp::Sym<size, big_endian>& orig_sym);
1183
1184   // Resolve symbols.
1185   template<int size, bool big_endian>
1186   void
1187   resolve(Sized_symbol<size>* to,
1188           const elfcpp::Sym<size, big_endian>& sym,
1189           const elfcpp::Sym<size, big_endian>& orig_sym,
1190           Object*, const char* version);
1191
1192   template<int size, bool big_endian>
1193   void
1194   resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
1195           const char* version ACCEPT_SIZE_ENDIAN);
1196
1197   // Record that a symbol is forced to be local by a version script.
1198   void
1199   force_local(Symbol*);
1200
1201   // Whether we should override a symbol, based on flags in
1202   // resolve.cc.
1203   static bool
1204   should_override(const Symbol*, unsigned int, Object*, bool*);
1205
1206   // Override a symbol.
1207   template<int size, bool big_endian>
1208   void
1209   override(Sized_symbol<size>* tosym,
1210            const elfcpp::Sym<size, big_endian>& fromsym,
1211            Object* object, const char* version);
1212
1213   // Whether we should override a symbol with a special symbol which
1214   // is automatically defined by the linker.
1215   static bool
1216   should_override_with_special(const Symbol*);
1217
1218   // Override a symbol with a special symbol.
1219   template<int size>
1220   void
1221   override_with_special(Sized_symbol<size>* tosym,
1222                         const Sized_symbol<size>* fromsym);
1223
1224   // Record all weak alias sets for a dynamic object.
1225   template<int size>
1226   void
1227   record_weak_aliases(std::vector<Sized_symbol<size>*>*);
1228
1229   // Define a special symbol.
1230   template<int size, bool big_endian>
1231   Sized_symbol<size>*
1232   define_special_symbol(const char** pname, const char** pversion,
1233                         bool only_if_ref, Sized_symbol<size>** poldsym
1234                         ACCEPT_SIZE_ENDIAN);
1235
1236   // Define a symbol in an Output_data, sized version.
1237   template<int size>
1238   Sized_symbol<size>*
1239   do_define_in_output_data(const char* name, const char* version, Output_data*,
1240                            typename elfcpp::Elf_types<size>::Elf_Addr value,
1241                            typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1242                            elfcpp::STT type, elfcpp::STB binding,
1243                            elfcpp::STV visibility, unsigned char nonvis,
1244                            bool offset_is_from_end, bool only_if_ref);
1245
1246   // Define a symbol in an Output_segment, sized version.
1247   template<int size>
1248   Sized_symbol<size>*
1249   do_define_in_output_segment(
1250     const char* name, const char* version, Output_segment* os,
1251     typename elfcpp::Elf_types<size>::Elf_Addr value,
1252     typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1253     elfcpp::STT type, elfcpp::STB binding,
1254     elfcpp::STV visibility, unsigned char nonvis,
1255     Symbol::Segment_offset_base offset_base, bool only_if_ref);
1256
1257   // Define a symbol as a constant, sized version.
1258   template<int size>
1259   Sized_symbol<size>*
1260   do_define_as_constant(
1261     const char* name, const char* version,
1262     typename elfcpp::Elf_types<size>::Elf_Addr value,
1263     typename elfcpp::Elf_types<size>::Elf_WXword ssize,
1264     elfcpp::STT type, elfcpp::STB binding,
1265     elfcpp::STV visibility, unsigned char nonvis,
1266     bool only_if_ref);
1267
1268   // Allocate the common symbols, sized version.
1269   template<int size>
1270   void
1271   do_allocate_commons(const General_options&, Layout*);
1272
1273   // Implement detect_odr_violations.
1274   template<int size, bool big_endian>
1275   void
1276   sized_detect_odr_violations() const;
1277
1278   // Finalize symbols specialized for size.
1279   template<int size>
1280   off_t
1281   sized_finalize(off_t, Stringpool*, unsigned int*);
1282
1283   // Finalize a symbol.  Return whether it should be added to the
1284   // symbol table.
1285   template<int size>
1286   bool
1287   sized_finalize_symbol(Symbol*);
1288
1289   // Add a symbol the final symtab by setting its index.
1290   template<int size>
1291   void
1292   add_to_final_symtab(Symbol*, Stringpool*, unsigned int* pindex, off_t* poff);
1293
1294   // Write globals specialized for size and endianness.
1295   template<int size, bool big_endian>
1296   void
1297   sized_write_globals(const Input_objects*, const Stringpool*,
1298                       const Stringpool*, Output_file*) const;
1299
1300   // Write out a symbol to P.
1301   template<int size, bool big_endian>
1302   void
1303   sized_write_symbol(Sized_symbol<size>*,
1304                      typename elfcpp::Elf_types<size>::Elf_Addr value,
1305                      unsigned int shndx,
1306                      const Stringpool*, unsigned char* p
1307                      ACCEPT_SIZE_ENDIAN) const;
1308
1309   // Possibly warn about an undefined symbol from a dynamic object.
1310   void
1311   warn_about_undefined_dynobj_symbol(const Input_objects*, Symbol*) const;
1312
1313   // Write out a section symbol, specialized for size and endianness.
1314   template<int size, bool big_endian>
1315   void
1316   sized_write_section_symbol(const Output_section*, Output_file*, off_t) const;
1317
1318   // The type of the symbol hash table.
1319
1320   typedef std::pair<Stringpool::Key, Stringpool::Key> Symbol_table_key;
1321
1322   struct Symbol_table_hash
1323   {
1324     size_t
1325     operator()(const Symbol_table_key&) const;
1326   };
1327
1328   struct Symbol_table_eq
1329   {
1330     bool
1331     operator()(const Symbol_table_key&, const Symbol_table_key&) const;
1332   };
1333
1334   typedef Unordered_map<Symbol_table_key, Symbol*, Symbol_table_hash,
1335                         Symbol_table_eq> Symbol_table_type;
1336
1337   // The type of the list of common symbols.
1338   typedef std::vector<Symbol*> Commons_type;
1339
1340   // The type of the list of symbols which have been forced local.
1341   typedef std::vector<Symbol*> Forced_locals;
1342
1343   // A map from symbols with COPY relocs to the dynamic objects where
1344   // they are defined.
1345   typedef Unordered_map<const Symbol*, Dynobj*> Copied_symbol_dynobjs;
1346
1347   // A map from symbol name (as a pointer into the namepool) to all
1348   // the locations the symbols is (weakly) defined (and certain other
1349   // conditions are met).  This map will be used later to detect
1350   // possible One Definition Rule (ODR) violations.
1351   struct Symbol_location
1352   {
1353     Object* object;         // Object where the symbol is defined.
1354     unsigned int shndx;     // Section-in-object where the symbol is defined.
1355     off_t offset;           // Offset-in-section where the symbol is defined.
1356     bool operator==(const Symbol_location& that) const
1357     {
1358       return (this->object == that.object
1359               && this->shndx == that.shndx
1360               && this->offset == that.offset);
1361     }
1362   };
1363
1364   struct Symbol_location_hash
1365   {
1366     size_t operator()(const Symbol_location& loc) const
1367     { return reinterpret_cast<uintptr_t>(loc.object) ^ loc.offset ^ loc.shndx; }
1368   };
1369
1370   typedef Unordered_map<const char*,
1371                         Unordered_set<Symbol_location, Symbol_location_hash> >
1372   Odr_map;
1373
1374   // We increment this every time we see a new undefined symbol, for
1375   // use in archive groups.
1376   int saw_undefined_;
1377   // The index of the first global symbol in the output file.
1378   unsigned int first_global_index_;
1379   // The file offset within the output symtab section where we should
1380   // write the table.
1381   off_t offset_;
1382   // The number of global symbols we want to write out.
1383   unsigned int output_count_;
1384   // The file offset of the global dynamic symbols, or 0 if none.
1385   off_t dynamic_offset_;
1386   // The index of the first global dynamic symbol.
1387   unsigned int first_dynamic_global_index_;
1388   // The number of global dynamic symbols, or 0 if none.
1389   unsigned int dynamic_count_;
1390   // The symbol hash table.
1391   Symbol_table_type table_;
1392   // A pool of symbol names.  This is used for all global symbols.
1393   // Entries in the hash table point into this pool.
1394   Stringpool namepool_;
1395   // Forwarding symbols.
1396   Unordered_map<const Symbol*, Symbol*> forwarders_;
1397   // Weak aliases.  A symbol in this list points to the next alias.
1398   // The aliases point to each other in a circular list.
1399   Unordered_map<Symbol*, Symbol*> weak_aliases_;
1400   // We don't expect there to be very many common symbols, so we keep
1401   // a list of them.  When we find a common symbol we add it to this
1402   // list.  It is possible that by the time we process the list the
1403   // symbol is no longer a common symbol.  It may also have become a
1404   // forwarder.
1405   Commons_type commons_;
1406   // A list of symbols which have been forced to be local.  We don't
1407   // expect there to be very many of them, so we keep a list of them
1408   // rather than walking the whole table to find them.
1409   Forced_locals forced_locals_;
1410   // Manage symbol warnings.
1411   Warnings warnings_;
1412   // Manage potential One Definition Rule (ODR) violations.
1413   Odr_map candidate_odr_violations_;
1414
1415   // When we emit a COPY reloc for a symbol, we define it in an
1416   // Output_data.  When it's time to emit version information for it,
1417   // we need to know the dynamic object in which we found the original
1418   // definition.  This maps symbols with COPY relocs to the dynamic
1419   // object where they were defined.
1420   Copied_symbol_dynobjs copied_symbol_dynobjs_;
1421   // Information parsed from the version script, if any.
1422   const Version_script_info& version_script_;
1423 };
1424
1425 // We inline get_sized_symbol for efficiency.
1426
1427 template<int size>
1428 Sized_symbol<size>*
1429 Symbol_table::get_sized_symbol(Symbol* sym ACCEPT_SIZE) const
1430 {
1431   gold_assert(size == parameters->get_size());
1432   return static_cast<Sized_symbol<size>*>(sym);
1433 }
1434
1435 template<int size>
1436 const Sized_symbol<size>*
1437 Symbol_table::get_sized_symbol(const Symbol* sym ACCEPT_SIZE) const
1438 {
1439   gold_assert(size == parameters->get_size());
1440   return static_cast<const Sized_symbol<size>*>(sym);
1441 }
1442
1443 } // End namespace gold.
1444
1445 #endif // !defined(GOLD_SYMTAB_H)