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