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