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