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