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