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