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