1 // symtab.cc -- the gold symbol table
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
33 #include "workqueue.h"
41 // Initialize fields in Symbol. This initializes everything except u_
45 Symbol::init_fields(const char* name
, const char* version
,
46 elfcpp::STT type
, elfcpp::STB binding
,
47 elfcpp::STV visibility
, unsigned char nonvis
)
50 this->version_
= version
;
51 this->symtab_index_
= 0;
52 this->dynsym_index_
= 0;
53 this->got_offset_
= 0;
54 this->plt_offset_
= 0;
56 this->binding_
= binding
;
57 this->visibility_
= visibility
;
58 this->nonvis_
= nonvis
;
59 this->is_target_special_
= false;
60 this->is_def_
= false;
61 this->is_forwarder_
= false;
62 this->has_alias_
= false;
63 this->needs_dynsym_entry_
= false;
64 this->in_reg_
= false;
65 this->in_dyn_
= false;
66 this->has_got_offset_
= false;
67 this->has_plt_offset_
= false;
68 this->has_warning_
= false;
71 // Initialize the fields in the base class Symbol for SYM in OBJECT.
73 template<int size
, bool big_endian
>
75 Symbol::init_base(const char* name
, const char* version
, Object
* object
,
76 const elfcpp::Sym
<size
, big_endian
>& sym
)
78 this->init_fields(name
, version
, sym
.get_st_type(), sym
.get_st_bind(),
79 sym
.get_st_visibility(), sym
.get_st_nonvis());
80 this->u_
.from_object
.object
= object
;
81 // FIXME: Handle SHN_XINDEX.
82 this->u_
.from_object
.shndx
= sym
.get_st_shndx();
83 this->source_
= FROM_OBJECT
;
84 this->in_reg_
= !object
->is_dynamic();
85 this->in_dyn_
= object
->is_dynamic();
88 // Initialize the fields in the base class Symbol for a symbol defined
92 Symbol::init_base(const char* name
, Output_data
* od
, elfcpp::STT type
,
93 elfcpp::STB binding
, elfcpp::STV visibility
,
94 unsigned char nonvis
, bool offset_is_from_end
)
96 this->init_fields(name
, NULL
, type
, binding
, visibility
, nonvis
);
97 this->u_
.in_output_data
.output_data
= od
;
98 this->u_
.in_output_data
.offset_is_from_end
= offset_is_from_end
;
99 this->source_
= IN_OUTPUT_DATA
;
100 this->in_reg_
= true;
103 // Initialize the fields in the base class Symbol for a symbol defined
104 // in an Output_segment.
107 Symbol::init_base(const char* name
, Output_segment
* os
, elfcpp::STT type
,
108 elfcpp::STB binding
, elfcpp::STV visibility
,
109 unsigned char nonvis
, Segment_offset_base offset_base
)
111 this->init_fields(name
, NULL
, type
, binding
, visibility
, nonvis
);
112 this->u_
.in_output_segment
.output_segment
= os
;
113 this->u_
.in_output_segment
.offset_base
= offset_base
;
114 this->source_
= IN_OUTPUT_SEGMENT
;
115 this->in_reg_
= true;
118 // Initialize the fields in the base class Symbol for a symbol defined
122 Symbol::init_base(const char* name
, elfcpp::STT type
,
123 elfcpp::STB binding
, elfcpp::STV visibility
,
124 unsigned char nonvis
)
126 this->init_fields(name
, NULL
, type
, binding
, visibility
, nonvis
);
127 this->source_
= CONSTANT
;
128 this->in_reg_
= true;
131 // Initialize the fields in Sized_symbol for SYM in OBJECT.
134 template<bool big_endian
>
136 Sized_symbol
<size
>::init(const char* name
, const char* version
, Object
* object
,
137 const elfcpp::Sym
<size
, big_endian
>& sym
)
139 this->init_base(name
, version
, object
, sym
);
140 this->value_
= sym
.get_st_value();
141 this->symsize_
= sym
.get_st_size();
144 // Initialize the fields in Sized_symbol for a symbol defined in an
149 Sized_symbol
<size
>::init(const char* name
, Output_data
* od
,
150 Value_type value
, Size_type symsize
,
151 elfcpp::STT type
, elfcpp::STB binding
,
152 elfcpp::STV visibility
, unsigned char nonvis
,
153 bool offset_is_from_end
)
155 this->init_base(name
, od
, type
, binding
, visibility
, nonvis
,
157 this->value_
= value
;
158 this->symsize_
= symsize
;
161 // Initialize the fields in Sized_symbol for a symbol defined in an
166 Sized_symbol
<size
>::init(const char* name
, Output_segment
* os
,
167 Value_type value
, Size_type symsize
,
168 elfcpp::STT type
, elfcpp::STB binding
,
169 elfcpp::STV visibility
, unsigned char nonvis
,
170 Segment_offset_base offset_base
)
172 this->init_base(name
, os
, type
, binding
, visibility
, nonvis
, offset_base
);
173 this->value_
= value
;
174 this->symsize_
= symsize
;
177 // Initialize the fields in Sized_symbol for a symbol defined as a
182 Sized_symbol
<size
>::init(const char* name
, Value_type value
, Size_type symsize
,
183 elfcpp::STT type
, elfcpp::STB binding
,
184 elfcpp::STV visibility
, unsigned char nonvis
)
186 this->init_base(name
, type
, binding
, visibility
, nonvis
);
187 this->value_
= value
;
188 this->symsize_
= symsize
;
191 // Return true if the final value of this symbol is known at link
195 Symbol::final_value_is_known() const
197 // If we are not generating an executable, then no final values are
198 // known, since they will change at runtime.
199 if (!parameters
->output_is_executable())
202 // If the symbol is not from an object file, then it is defined, and
204 if (this->source_
!= FROM_OBJECT
)
207 // If the symbol is from a dynamic object, then the final value is
209 if (this->object()->is_dynamic())
212 // If the symbol is not undefined (it is defined or common), then
213 // the final value is known.
214 if (!this->is_undefined())
217 // If the symbol is undefined, then whether the final value is known
218 // depends on whether we are doing a static link. If we are doing a
219 // dynamic link, then the final value could be filled in at runtime.
220 // This could reasonably be the case for a weak undefined symbol.
221 return parameters
->doing_static_link();
224 // Class Symbol_table.
226 Symbol_table::Symbol_table()
227 : saw_undefined_(0), offset_(0), table_(), namepool_(),
228 forwarders_(), commons_(), warnings_()
232 Symbol_table::~Symbol_table()
236 // The hash function. The key is always canonicalized, so we use a
237 // simple combination of the pointers.
240 Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key
& key
) const
242 return key
.first
^ key
.second
;
245 // The symbol table key equality function. This is only called with
246 // canonicalized name and version strings, so we can use pointer
250 Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key
& k1
,
251 const Symbol_table_key
& k2
) const
253 return k1
.first
== k2
.first
&& k1
.second
== k2
.second
;
256 // Make TO a symbol which forwards to FROM.
259 Symbol_table::make_forwarder(Symbol
* from
, Symbol
* to
)
261 gold_assert(from
!= to
);
262 gold_assert(!from
->is_forwarder() && !to
->is_forwarder());
263 this->forwarders_
[from
] = to
;
264 from
->set_forwarder();
267 // Resolve the forwards from FROM, returning the real symbol.
270 Symbol_table::resolve_forwards(const Symbol
* from
) const
272 gold_assert(from
->is_forwarder());
273 Unordered_map
<const Symbol
*, Symbol
*>::const_iterator p
=
274 this->forwarders_
.find(from
);
275 gold_assert(p
!= this->forwarders_
.end());
279 // Look up a symbol by name.
282 Symbol_table::lookup(const char* name
, const char* version
) const
284 Stringpool::Key name_key
;
285 name
= this->namepool_
.find(name
, &name_key
);
289 Stringpool::Key version_key
= 0;
292 version
= this->namepool_
.find(version
, &version_key
);
297 Symbol_table_key
key(name_key
, version_key
);
298 Symbol_table::Symbol_table_type::const_iterator p
= this->table_
.find(key
);
299 if (p
== this->table_
.end())
304 // Resolve a Symbol with another Symbol. This is only used in the
305 // unusual case where there are references to both an unversioned
306 // symbol and a symbol with a version, and we then discover that that
307 // version is the default version. Because this is unusual, we do
308 // this the slow way, by converting back to an ELF symbol.
310 template<int size
, bool big_endian
>
312 Symbol_table::resolve(Sized_symbol
<size
>* to
, const Sized_symbol
<size
>* from
,
313 const char* version ACCEPT_SIZE_ENDIAN
)
315 unsigned char buf
[elfcpp::Elf_sizes
<size
>::sym_size
];
316 elfcpp::Sym_write
<size
, big_endian
> esym(buf
);
317 // We don't bother to set the st_name field.
318 esym
.put_st_value(from
->value());
319 esym
.put_st_size(from
->symsize());
320 esym
.put_st_info(from
->binding(), from
->type());
321 esym
.put_st_other(from
->visibility(), from
->nonvis());
322 esym
.put_st_shndx(from
->shndx());
323 this->resolve(to
, esym
.sym(), from
->object(), version
);
330 // Add one symbol from OBJECT to the symbol table. NAME is symbol
331 // name and VERSION is the version; both are canonicalized. DEF is
332 // whether this is the default version.
334 // If DEF is true, then this is the definition of a default version of
335 // a symbol. That means that any lookup of NAME/NULL and any lookup
336 // of NAME/VERSION should always return the same symbol. This is
337 // obvious for references, but in particular we want to do this for
338 // definitions: overriding NAME/NULL should also override
339 // NAME/VERSION. If we don't do that, it would be very hard to
340 // override functions in a shared library which uses versioning.
342 // We implement this by simply making both entries in the hash table
343 // point to the same Symbol structure. That is easy enough if this is
344 // the first time we see NAME/NULL or NAME/VERSION, but it is possible
345 // that we have seen both already, in which case they will both have
346 // independent entries in the symbol table. We can't simply change
347 // the symbol table entry, because we have pointers to the entries
348 // attached to the object files. So we mark the entry attached to the
349 // object file as a forwarder, and record it in the forwarders_ map.
350 // Note that entries in the hash table will never be marked as
353 template<int size
, bool big_endian
>
355 Symbol_table::add_from_object(Object
* object
,
357 Stringpool::Key name_key
,
359 Stringpool::Key version_key
,
361 const elfcpp::Sym
<size
, big_endian
>& sym
)
363 Symbol
* const snull
= NULL
;
364 std::pair
<typename
Symbol_table_type::iterator
, bool> ins
=
365 this->table_
.insert(std::make_pair(std::make_pair(name_key
, version_key
),
368 std::pair
<typename
Symbol_table_type::iterator
, bool> insdef
=
369 std::make_pair(this->table_
.end(), false);
372 const Stringpool::Key vnull_key
= 0;
373 insdef
= this->table_
.insert(std::make_pair(std::make_pair(name_key
,
378 // ins.first: an iterator, which is a pointer to a pair.
379 // ins.first->first: the key (a pair of name and version).
380 // ins.first->second: the value (Symbol*).
381 // ins.second: true if new entry was inserted, false if not.
383 Sized_symbol
<size
>* ret
;
388 // We already have an entry for NAME/VERSION.
389 ret
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (ins
.first
->second
391 gold_assert(ret
!= NULL
);
393 was_undefined
= ret
->is_undefined();
394 was_common
= ret
->is_common();
396 this->resolve(ret
, sym
, object
, version
);
402 // This is the first time we have seen NAME/NULL. Make
403 // NAME/NULL point to NAME/VERSION.
404 insdef
.first
->second
= ret
;
406 else if (insdef
.first
->second
!= ret
)
408 // This is the unfortunate case where we already have
409 // entries for both NAME/VERSION and NAME/NULL.
410 const Sized_symbol
<size
>* sym2
;
411 sym2
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (
414 Symbol_table::resolve
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
415 ret
, sym2
, version
SELECT_SIZE_ENDIAN(size
, big_endian
));
416 this->make_forwarder(insdef
.first
->second
, ret
);
417 insdef
.first
->second
= ret
;
423 // This is the first time we have seen NAME/VERSION.
424 gold_assert(ins
.first
->second
== NULL
);
426 was_undefined
= false;
429 if (def
&& !insdef
.second
)
431 // We already have an entry for NAME/NULL. If we override
432 // it, then change it to NAME/VERSION.
433 ret
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (
436 this->resolve(ret
, sym
, object
, version
);
437 ins
.first
->second
= ret
;
441 Sized_target
<size
, big_endian
>* target
=
442 object
->sized_target
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
443 SELECT_SIZE_ENDIAN_ONLY(size
, big_endian
));
444 if (!target
->has_make_symbol())
445 ret
= new Sized_symbol
<size
>();
448 ret
= target
->make_symbol();
451 // This means that we don't want a symbol table
454 this->table_
.erase(ins
.first
);
457 this->table_
.erase(insdef
.first
);
458 // Inserting insdef invalidated ins.
459 this->table_
.erase(std::make_pair(name_key
,
466 ret
->init(name
, version
, object
, sym
);
468 ins
.first
->second
= ret
;
471 // This is the first time we have seen NAME/NULL. Point
472 // it at the new entry for NAME/VERSION.
473 gold_assert(insdef
.second
);
474 insdef
.first
->second
= ret
;
479 // Record every time we see a new undefined symbol, to speed up
481 if (!was_undefined
&& ret
->is_undefined())
482 ++this->saw_undefined_
;
484 // Keep track of common symbols, to speed up common symbol
486 if (!was_common
&& ret
->is_common())
487 this->commons_
.push_back(ret
);
492 // Add all the symbols in a relocatable object to the hash table.
494 template<int size
, bool big_endian
>
496 Symbol_table::add_from_relobj(
497 Sized_relobj
<size
, big_endian
>* relobj
,
498 const unsigned char* syms
,
500 const char* sym_names
,
501 size_t sym_name_size
,
502 Symbol
** sympointers
)
504 gold_assert(size
== relobj
->target()->get_size());
505 gold_assert(size
== parameters
->get_size());
507 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
509 const unsigned char* p
= syms
;
510 for (size_t i
= 0; i
< count
; ++i
, p
+= sym_size
)
512 elfcpp::Sym
<size
, big_endian
> sym(p
);
513 elfcpp::Sym
<size
, big_endian
>* psym
= &sym
;
515 unsigned int st_name
= psym
->get_st_name();
516 if (st_name
>= sym_name_size
)
518 relobj
->error(_("bad global symbol name offset %u at %zu"),
523 const char* name
= sym_names
+ st_name
;
525 // A symbol defined in a section which we are not including must
526 // be treated as an undefined symbol.
527 unsigned char symbuf
[sym_size
];
528 elfcpp::Sym
<size
, big_endian
> sym2(symbuf
);
529 unsigned int st_shndx
= psym
->get_st_shndx();
530 if (st_shndx
!= elfcpp::SHN_UNDEF
531 && st_shndx
< elfcpp::SHN_LORESERVE
532 && !relobj
->is_section_included(st_shndx
))
534 memcpy(symbuf
, p
, sym_size
);
535 elfcpp::Sym_write
<size
, big_endian
> sw(symbuf
);
536 sw
.put_st_shndx(elfcpp::SHN_UNDEF
);
540 // In an object file, an '@' in the name separates the symbol
541 // name from the version name. If there are two '@' characters,
542 // this is the default version.
543 const char* ver
= strchr(name
, '@');
545 Sized_symbol
<size
>* res
;
548 Stringpool::Key name_key
;
549 name
= this->namepool_
.add(name
, true, &name_key
);
550 res
= this->add_from_object(relobj
, name
, name_key
, NULL
, 0,
555 Stringpool::Key name_key
;
556 name
= this->namepool_
.add_prefix(name
, ver
- name
, &name_key
);
566 Stringpool::Key ver_key
;
567 ver
= this->namepool_
.add(ver
, true, &ver_key
);
569 res
= this->add_from_object(relobj
, name
, name_key
, ver
, ver_key
,
573 *sympointers
++ = res
;
577 // Add all the symbols in a dynamic object to the hash table.
579 template<int size
, bool big_endian
>
581 Symbol_table::add_from_dynobj(
582 Sized_dynobj
<size
, big_endian
>* dynobj
,
583 const unsigned char* syms
,
585 const char* sym_names
,
586 size_t sym_name_size
,
587 const unsigned char* versym
,
589 const std::vector
<const char*>* version_map
)
591 gold_assert(size
== dynobj
->target()->get_size());
592 gold_assert(size
== parameters
->get_size());
594 if (versym
!= NULL
&& versym_size
/ 2 < count
)
596 dynobj
->error(_("too few symbol versions"));
600 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
602 // We keep a list of all STT_OBJECT symbols, so that we can resolve
603 // weak aliases. This is necessary because if the dynamic object
604 // provides the same variable under two names, one of which is a
605 // weak definition, and the regular object refers to the weak
606 // definition, we have to put both the weak definition and the
607 // strong definition into the dynamic symbol table. Given a weak
608 // definition, the only way that we can find the corresponding
609 // strong definition, if any, is to search the symbol table.
610 std::vector
<Sized_symbol
<size
>*> object_symbols
;
612 const unsigned char* p
= syms
;
613 const unsigned char* vs
= versym
;
614 for (size_t i
= 0; i
< count
; ++i
, p
+= sym_size
, vs
+= 2)
616 elfcpp::Sym
<size
, big_endian
> sym(p
);
618 // Ignore symbols with local binding.
619 if (sym
.get_st_bind() == elfcpp::STB_LOCAL
)
622 unsigned int st_name
= sym
.get_st_name();
623 if (st_name
>= sym_name_size
)
625 dynobj
->error(_("bad symbol name offset %u at %zu"),
630 const char* name
= sym_names
+ st_name
;
632 Sized_symbol
<size
>* res
;
636 Stringpool::Key name_key
;
637 name
= this->namepool_
.add(name
, true, &name_key
);
638 res
= this->add_from_object(dynobj
, name
, name_key
, NULL
, 0,
643 // Read the version information.
645 unsigned int v
= elfcpp::Swap
<16, big_endian
>::readval(vs
);
647 bool hidden
= (v
& elfcpp::VERSYM_HIDDEN
) != 0;
648 v
&= elfcpp::VERSYM_VERSION
;
650 // The Sun documentation says that V can be VER_NDX_LOCAL,
651 // or VER_NDX_GLOBAL, or a version index. The meaning of
652 // VER_NDX_LOCAL is defined as "Symbol has local scope."
653 // The old GNU linker will happily generate VER_NDX_LOCAL
654 // for an undefined symbol. I don't know what the Sun
655 // linker will generate.
657 if (v
== static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL
)
658 && sym
.get_st_shndx() != elfcpp::SHN_UNDEF
)
660 // This symbol should not be visible outside the object.
664 // At this point we are definitely going to add this symbol.
665 Stringpool::Key name_key
;
666 name
= this->namepool_
.add(name
, true, &name_key
);
668 if (v
== static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL
)
669 || v
== static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL
))
671 // This symbol does not have a version.
672 res
= this->add_from_object(dynobj
, name
, name_key
, NULL
, 0,
677 if (v
>= version_map
->size())
679 dynobj
->error(_("versym for symbol %zu out of range: %u"),
684 const char* version
= (*version_map
)[v
];
687 dynobj
->error(_("versym for symbol %zu has no name: %u"),
692 Stringpool::Key version_key
;
693 version
= this->namepool_
.add(version
, true, &version_key
);
695 // If this is an absolute symbol, and the version name
696 // and symbol name are the same, then this is the
697 // version definition symbol. These symbols exist to
698 // support using -u to pull in particular versions. We
699 // do not want to record a version for them.
700 if (sym
.get_st_shndx() == elfcpp::SHN_ABS
701 && name_key
== version_key
)
702 res
= this->add_from_object(dynobj
, name
, name_key
, NULL
, 0,
706 const bool def
= (!hidden
707 && (sym
.get_st_shndx()
708 != elfcpp::SHN_UNDEF
));
709 res
= this->add_from_object(dynobj
, name
, name_key
, version
,
710 version_key
, def
, sym
);
715 if (sym
.get_st_shndx() != elfcpp::SHN_UNDEF
716 && sym
.get_st_type() == elfcpp::STT_OBJECT
)
717 object_symbols
.push_back(res
);
720 this->record_weak_aliases(&object_symbols
);
723 // This is used to sort weak aliases. We sort them first by section
724 // index, then by offset, then by weak ahead of strong.
727 class Weak_alias_sorter
730 bool operator()(const Sized_symbol
<size
>*, const Sized_symbol
<size
>*) const;
735 Weak_alias_sorter
<size
>::operator()(const Sized_symbol
<size
>* s1
,
736 const Sized_symbol
<size
>* s2
) const
738 if (s1
->shndx() != s2
->shndx())
739 return s1
->shndx() < s2
->shndx();
740 if (s1
->value() != s2
->value())
741 return s1
->value() < s2
->value();
742 if (s1
->binding() != s2
->binding())
744 if (s1
->binding() == elfcpp::STB_WEAK
)
746 if (s2
->binding() == elfcpp::STB_WEAK
)
749 return std::string(s1
->name()) < std::string(s2
->name());
752 // SYMBOLS is a list of object symbols from a dynamic object. Look
753 // for any weak aliases, and record them so that if we add the weak
754 // alias to the dynamic symbol table, we also add the corresponding
759 Symbol_table::record_weak_aliases(std::vector
<Sized_symbol
<size
>*>* symbols
)
761 // Sort the vector by section index, then by offset, then by weak
763 std::sort(symbols
->begin(), symbols
->end(), Weak_alias_sorter
<size
>());
765 // Walk through the vector. For each weak definition, record
767 for (typename
std::vector
<Sized_symbol
<size
>*>::const_iterator p
=
772 if ((*p
)->binding() != elfcpp::STB_WEAK
)
775 // Build a circular list of weak aliases. Each symbol points to
776 // the next one in the circular list.
778 Sized_symbol
<size
>* from_sym
= *p
;
779 typename
std::vector
<Sized_symbol
<size
>*>::const_iterator q
;
780 for (q
= p
+ 1; q
!= symbols
->end(); ++q
)
782 if ((*q
)->shndx() != from_sym
->shndx()
783 || (*q
)->value() != from_sym
->value())
786 this->weak_aliases_
[from_sym
] = *q
;
787 from_sym
->set_has_alias();
793 this->weak_aliases_
[from_sym
] = *p
;
794 from_sym
->set_has_alias();
801 // Create and return a specially defined symbol. If ONLY_IF_REF is
802 // true, then only create the symbol if there is a reference to it.
803 // If this does not return NULL, it sets *POLDSYM to the existing
804 // symbol if there is one. This canonicalizes *PNAME and *PVERSION.
806 template<int size
, bool big_endian
>
808 Symbol_table::define_special_symbol(const Target
* target
, const char** pname
,
809 const char** pversion
, bool only_if_ref
,
810 Sized_symbol
<size
>** poldsym
814 Sized_symbol
<size
>* sym
;
815 bool add_to_table
= false;
816 typename
Symbol_table_type::iterator add_loc
= this->table_
.end();
820 oldsym
= this->lookup(*pname
, *pversion
);
821 if (oldsym
== NULL
|| !oldsym
->is_undefined())
824 *pname
= oldsym
->name();
825 *pversion
= oldsym
->version();
829 // Canonicalize NAME and VERSION.
830 Stringpool::Key name_key
;
831 *pname
= this->namepool_
.add(*pname
, true, &name_key
);
833 Stringpool::Key version_key
= 0;
834 if (*pversion
!= NULL
)
835 *pversion
= this->namepool_
.add(*pversion
, true, &version_key
);
837 Symbol
* const snull
= NULL
;
838 std::pair
<typename
Symbol_table_type::iterator
, bool> ins
=
839 this->table_
.insert(std::make_pair(std::make_pair(name_key
,
845 // We already have a symbol table entry for NAME/VERSION.
846 oldsym
= ins
.first
->second
;
847 gold_assert(oldsym
!= NULL
);
851 // We haven't seen this symbol before.
852 gold_assert(ins
.first
->second
== NULL
);
859 if (!target
->has_make_symbol())
860 sym
= new Sized_symbol
<size
>();
863 gold_assert(target
->get_size() == size
);
864 gold_assert(target
->is_big_endian() ? big_endian
: !big_endian
);
865 typedef Sized_target
<size
, big_endian
> My_target
;
866 const My_target
* sized_target
=
867 static_cast<const My_target
*>(target
);
868 sym
= sized_target
->make_symbol();
874 add_loc
->second
= sym
;
876 gold_assert(oldsym
!= NULL
);
878 *poldsym
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (oldsym
884 // Define a symbol based on an Output_data.
887 Symbol_table::define_in_output_data(const Target
* target
, const char* name
,
888 const char* version
, Output_data
* od
,
889 uint64_t value
, uint64_t symsize
,
890 elfcpp::STT type
, elfcpp::STB binding
,
891 elfcpp::STV visibility
,
892 unsigned char nonvis
,
893 bool offset_is_from_end
,
896 if (parameters
->get_size() == 32)
898 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
899 return this->do_define_in_output_data
<32>(target
, name
, version
, od
,
900 value
, symsize
, type
, binding
,
908 else if (parameters
->get_size() == 64)
910 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
911 return this->do_define_in_output_data
<64>(target
, name
, version
, od
,
912 value
, symsize
, type
, binding
,
924 // Define a symbol in an Output_data, sized version.
928 Symbol_table::do_define_in_output_data(
929 const Target
* target
,
933 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
934 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
,
937 elfcpp::STV visibility
,
938 unsigned char nonvis
,
939 bool offset_is_from_end
,
942 Sized_symbol
<size
>* sym
;
943 Sized_symbol
<size
>* oldsym
;
945 if (parameters
->is_big_endian())
947 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
948 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, true) (
949 target
, &name
, &version
, only_if_ref
, &oldsym
950 SELECT_SIZE_ENDIAN(size
, true));
957 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
958 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, false) (
959 target
, &name
, &version
, only_if_ref
, &oldsym
960 SELECT_SIZE_ENDIAN(size
, false));
969 gold_assert(version
== NULL
|| oldsym
!= NULL
);
970 sym
->init(name
, od
, value
, symsize
, type
, binding
, visibility
, nonvis
,
974 && Symbol_table::should_override_with_special(oldsym
))
975 this->override_with_special(oldsym
, sym
);
980 // Define a symbol based on an Output_segment.
983 Symbol_table::define_in_output_segment(const Target
* target
, const char* name
,
984 const char* version
, Output_segment
* os
,
985 uint64_t value
, uint64_t symsize
,
986 elfcpp::STT type
, elfcpp::STB binding
,
987 elfcpp::STV visibility
,
988 unsigned char nonvis
,
989 Symbol::Segment_offset_base offset_base
,
992 if (parameters
->get_size() == 32)
994 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
995 return this->do_define_in_output_segment
<32>(target
, name
, version
, os
,
996 value
, symsize
, type
,
997 binding
, visibility
, nonvis
,
998 offset_base
, only_if_ref
);
1003 else if (parameters
->get_size() == 64)
1005 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1006 return this->do_define_in_output_segment
<64>(target
, name
, version
, os
,
1007 value
, symsize
, type
,
1008 binding
, visibility
, nonvis
,
1009 offset_base
, only_if_ref
);
1018 // Define a symbol in an Output_segment, sized version.
1022 Symbol_table::do_define_in_output_segment(
1023 const Target
* target
,
1025 const char* version
,
1027 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1028 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
,
1030 elfcpp::STB binding
,
1031 elfcpp::STV visibility
,
1032 unsigned char nonvis
,
1033 Symbol::Segment_offset_base offset_base
,
1036 Sized_symbol
<size
>* sym
;
1037 Sized_symbol
<size
>* oldsym
;
1039 if (parameters
->is_big_endian())
1041 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1042 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, true) (
1043 target
, &name
, &version
, only_if_ref
, &oldsym
1044 SELECT_SIZE_ENDIAN(size
, true));
1051 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1052 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, false) (
1053 target
, &name
, &version
, only_if_ref
, &oldsym
1054 SELECT_SIZE_ENDIAN(size
, false));
1063 gold_assert(version
== NULL
|| oldsym
!= NULL
);
1064 sym
->init(name
, os
, value
, symsize
, type
, binding
, visibility
, nonvis
,
1068 && Symbol_table::should_override_with_special(oldsym
))
1069 this->override_with_special(oldsym
, sym
);
1074 // Define a special symbol with a constant value. It is a multiple
1075 // definition error if this symbol is already defined.
1078 Symbol_table::define_as_constant(const Target
* target
, const char* name
,
1079 const char* version
, uint64_t value
,
1080 uint64_t symsize
, elfcpp::STT type
,
1081 elfcpp::STB binding
, elfcpp::STV visibility
,
1082 unsigned char nonvis
, bool only_if_ref
)
1084 if (parameters
->get_size() == 32)
1086 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1087 return this->do_define_as_constant
<32>(target
, name
, version
, value
,
1088 symsize
, type
, binding
,
1089 visibility
, nonvis
, only_if_ref
);
1094 else if (parameters
->get_size() == 64)
1096 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1097 return this->do_define_as_constant
<64>(target
, name
, version
, value
,
1098 symsize
, type
, binding
,
1099 visibility
, nonvis
, only_if_ref
);
1108 // Define a symbol as a constant, sized version.
1112 Symbol_table::do_define_as_constant(
1113 const Target
* target
,
1115 const char* version
,
1116 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1117 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
,
1119 elfcpp::STB binding
,
1120 elfcpp::STV visibility
,
1121 unsigned char nonvis
,
1124 Sized_symbol
<size
>* sym
;
1125 Sized_symbol
<size
>* oldsym
;
1127 if (parameters
->is_big_endian())
1129 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1130 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, true) (
1131 target
, &name
, &version
, only_if_ref
, &oldsym
1132 SELECT_SIZE_ENDIAN(size
, true));
1139 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1140 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, false) (
1141 target
, &name
, &version
, only_if_ref
, &oldsym
1142 SELECT_SIZE_ENDIAN(size
, false));
1151 gold_assert(version
== NULL
|| oldsym
!= NULL
);
1152 sym
->init(name
, value
, symsize
, type
, binding
, visibility
, nonvis
);
1155 && Symbol_table::should_override_with_special(oldsym
))
1156 this->override_with_special(oldsym
, sym
);
1161 // Define a set of symbols in output sections.
1164 Symbol_table::define_symbols(const Layout
* layout
, const Target
* target
,
1165 int count
, const Define_symbol_in_section
* p
)
1167 for (int i
= 0; i
< count
; ++i
, ++p
)
1169 Output_section
* os
= layout
->find_output_section(p
->output_section
);
1171 this->define_in_output_data(target
, p
->name
, NULL
, os
, p
->value
,
1172 p
->size
, p
->type
, p
->binding
,
1173 p
->visibility
, p
->nonvis
,
1174 p
->offset_is_from_end
, p
->only_if_ref
);
1176 this->define_as_constant(target
, p
->name
, NULL
, 0, p
->size
, p
->type
,
1177 p
->binding
, p
->visibility
, p
->nonvis
,
1182 // Define a set of symbols in output segments.
1185 Symbol_table::define_symbols(const Layout
* layout
, const Target
* target
,
1186 int count
, const Define_symbol_in_segment
* p
)
1188 for (int i
= 0; i
< count
; ++i
, ++p
)
1190 Output_segment
* os
= layout
->find_output_segment(p
->segment_type
,
1191 p
->segment_flags_set
,
1192 p
->segment_flags_clear
);
1194 this->define_in_output_segment(target
, p
->name
, NULL
, os
, p
->value
,
1195 p
->size
, p
->type
, p
->binding
,
1196 p
->visibility
, p
->nonvis
,
1197 p
->offset_base
, p
->only_if_ref
);
1199 this->define_as_constant(target
, p
->name
, NULL
, 0, p
->size
, p
->type
,
1200 p
->binding
, p
->visibility
, p
->nonvis
,
1205 // Set the dynamic symbol indexes. INDEX is the index of the first
1206 // global dynamic symbol. Pointers to the symbols are stored into the
1207 // vector SYMS. The names are added to DYNPOOL. This returns an
1208 // updated dynamic symbol index.
1211 Symbol_table::set_dynsym_indexes(const General_options
* options
,
1212 const Target
* target
,
1214 std::vector
<Symbol
*>* syms
,
1215 Stringpool
* dynpool
,
1218 for (Symbol_table_type::iterator p
= this->table_
.begin();
1219 p
!= this->table_
.end();
1222 Symbol
* sym
= p
->second
;
1224 // Note that SYM may already have a dynamic symbol index, since
1225 // some symbols appear more than once in the symbol table, with
1226 // and without a version.
1228 if (!sym
->needs_dynsym_entry()
1229 && (!options
->export_dynamic()
1231 || !sym
->is_externally_visible()))
1232 sym
->set_dynsym_index(-1U);
1233 else if (!sym
->has_dynsym_index())
1235 sym
->set_dynsym_index(index
);
1237 syms
->push_back(sym
);
1238 dynpool
->add(sym
->name(), false, NULL
);
1240 // Record any version information.
1241 if (sym
->version() != NULL
)
1242 versions
->record_version(options
, dynpool
, sym
);
1246 // Finish up the versions. In some cases this may add new dynamic
1248 index
= versions
->finalize(target
, this, index
, syms
);
1253 // Set the final values for all the symbols. The index of the first
1254 // global symbol in the output file is INDEX. Record the file offset
1255 // OFF. Add their names to POOL. Return the new file offset.
1258 Symbol_table::finalize(unsigned int index
, off_t off
, off_t dynoff
,
1259 size_t dyn_global_index
, size_t dyncount
,
1264 gold_assert(index
!= 0);
1265 this->first_global_index_
= index
;
1267 this->dynamic_offset_
= dynoff
;
1268 this->first_dynamic_global_index_
= dyn_global_index
;
1269 this->dynamic_count_
= dyncount
;
1271 if (parameters
->get_size() == 32)
1273 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
1274 ret
= this->sized_finalize
<32>(index
, off
, pool
);
1279 else if (parameters
->get_size() == 64)
1281 #if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
1282 ret
= this->sized_finalize
<64>(index
, off
, pool
);
1290 // Now that we have the final symbol table, we can reliably note
1291 // which symbols should get warnings.
1292 this->warnings_
.note_warnings(this);
1297 // Set the final value for all the symbols. This is called after
1298 // Layout::finalize, so all the output sections have their final
1303 Symbol_table::sized_finalize(unsigned index
, off_t off
, Stringpool
* pool
)
1305 off
= align_address(off
, size
>> 3);
1306 this->offset_
= off
;
1308 size_t orig_index
= index
;
1310 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1311 for (Symbol_table_type::iterator p
= this->table_
.begin();
1312 p
!= this->table_
.end();
1315 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(p
->second
);
1317 // FIXME: Here we need to decide which symbols should go into
1318 // the output file, based on --strip.
1320 // The default version of a symbol may appear twice in the
1321 // symbol table. We only need to finalize it once.
1322 if (sym
->has_symtab_index())
1327 gold_assert(!sym
->has_symtab_index());
1328 sym
->set_symtab_index(-1U);
1329 gold_assert(sym
->dynsym_index() == -1U);
1333 typename Sized_symbol
<size
>::Value_type value
;
1335 switch (sym
->source())
1337 case Symbol::FROM_OBJECT
:
1339 unsigned int shndx
= sym
->shndx();
1341 // FIXME: We need some target specific support here.
1342 if (shndx
>= elfcpp::SHN_LORESERVE
1343 && shndx
!= elfcpp::SHN_ABS
)
1345 gold_error(_("%s: unsupported symbol section 0x%x"),
1346 sym
->name(), shndx
);
1347 shndx
= elfcpp::SHN_UNDEF
;
1350 Object
* symobj
= sym
->object();
1351 if (symobj
->is_dynamic())
1354 shndx
= elfcpp::SHN_UNDEF
;
1356 else if (shndx
== elfcpp::SHN_UNDEF
)
1358 else if (shndx
== elfcpp::SHN_ABS
)
1359 value
= sym
->value();
1362 Relobj
* relobj
= static_cast<Relobj
*>(symobj
);
1364 Output_section
* os
= relobj
->output_section(shndx
, &secoff
);
1368 sym
->set_symtab_index(-1U);
1369 gold_assert(sym
->dynsym_index() == -1U);
1373 value
= sym
->value() + os
->address() + secoff
;
1378 case Symbol::IN_OUTPUT_DATA
:
1380 Output_data
* od
= sym
->output_data();
1381 value
= sym
->value() + od
->address();
1382 if (sym
->offset_is_from_end())
1383 value
+= od
->data_size();
1387 case Symbol::IN_OUTPUT_SEGMENT
:
1389 Output_segment
* os
= sym
->output_segment();
1390 value
= sym
->value() + os
->vaddr();
1391 switch (sym
->offset_base())
1393 case Symbol::SEGMENT_START
:
1395 case Symbol::SEGMENT_END
:
1396 value
+= os
->memsz();
1398 case Symbol::SEGMENT_BSS
:
1399 value
+= os
->filesz();
1407 case Symbol::CONSTANT
:
1408 value
= sym
->value();
1415 sym
->set_value(value
);
1417 if (parameters
->strip_all())
1418 sym
->set_symtab_index(-1U);
1421 sym
->set_symtab_index(index
);
1422 pool
->add(sym
->name(), false, NULL
);
1428 this->output_count_
= index
- orig_index
;
1433 // Write out the global symbols.
1436 Symbol_table::write_globals(const Target
* target
, const Stringpool
* sympool
,
1437 const Stringpool
* dynpool
, Output_file
* of
) const
1439 if (parameters
->get_size() == 32)
1441 if (parameters
->is_big_endian())
1443 #ifdef HAVE_TARGET_32_BIG
1444 this->sized_write_globals
<32, true>(target
, sympool
, dynpool
, of
);
1451 #ifdef HAVE_TARGET_32_LITTLE
1452 this->sized_write_globals
<32, false>(target
, sympool
, dynpool
, of
);
1458 else if (parameters
->get_size() == 64)
1460 if (parameters
->is_big_endian())
1462 #ifdef HAVE_TARGET_64_BIG
1463 this->sized_write_globals
<64, true>(target
, sympool
, dynpool
, of
);
1470 #ifdef HAVE_TARGET_64_LITTLE
1471 this->sized_write_globals
<64, false>(target
, sympool
, dynpool
, of
);
1481 // Write out the global symbols.
1483 template<int size
, bool big_endian
>
1485 Symbol_table::sized_write_globals(const Target
* target
,
1486 const Stringpool
* sympool
,
1487 const Stringpool
* dynpool
,
1488 Output_file
* of
) const
1490 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1491 unsigned int index
= this->first_global_index_
;
1492 const off_t oview_size
= this->output_count_
* sym_size
;
1493 unsigned char* const psyms
= of
->get_output_view(this->offset_
, oview_size
);
1495 unsigned int dynamic_count
= this->dynamic_count_
;
1496 off_t dynamic_size
= dynamic_count
* sym_size
;
1497 unsigned int first_dynamic_global_index
= this->first_dynamic_global_index_
;
1498 unsigned char* dynamic_view
;
1499 if (this->dynamic_offset_
== 0)
1500 dynamic_view
= NULL
;
1502 dynamic_view
= of
->get_output_view(this->dynamic_offset_
, dynamic_size
);
1504 unsigned char* ps
= psyms
;
1505 for (Symbol_table_type::const_iterator p
= this->table_
.begin();
1506 p
!= this->table_
.end();
1509 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(p
->second
);
1511 unsigned int sym_index
= sym
->symtab_index();
1512 unsigned int dynsym_index
;
1513 if (dynamic_view
== NULL
)
1516 dynsym_index
= sym
->dynsym_index();
1518 if (sym_index
== -1U && dynsym_index
== -1U)
1520 // This symbol is not included in the output file.
1524 if (sym_index
== index
)
1526 else if (sym_index
!= -1U)
1528 // We have already seen this symbol, because it has a
1530 gold_assert(sym_index
< index
);
1531 if (dynsym_index
== -1U)
1537 typename
elfcpp::Elf_types
<32>::Elf_Addr value
= sym
->value();
1538 switch (sym
->source())
1540 case Symbol::FROM_OBJECT
:
1542 unsigned int in_shndx
= sym
->shndx();
1544 // FIXME: We need some target specific support here.
1545 if (in_shndx
>= elfcpp::SHN_LORESERVE
1546 && in_shndx
!= elfcpp::SHN_ABS
)
1548 gold_error(_("%s: unsupported symbol section 0x%x"),
1549 sym
->name(), in_shndx
);
1554 Object
* symobj
= sym
->object();
1555 if (symobj
->is_dynamic())
1557 if (sym
->needs_dynsym_value())
1558 value
= target
->dynsym_value(sym
);
1559 shndx
= elfcpp::SHN_UNDEF
;
1561 else if (in_shndx
== elfcpp::SHN_UNDEF
1562 || in_shndx
== elfcpp::SHN_ABS
)
1566 Relobj
* relobj
= static_cast<Relobj
*>(symobj
);
1568 Output_section
* os
= relobj
->output_section(in_shndx
,
1570 gold_assert(os
!= NULL
);
1571 shndx
= os
->out_shndx();
1577 case Symbol::IN_OUTPUT_DATA
:
1578 shndx
= sym
->output_data()->out_shndx();
1581 case Symbol::IN_OUTPUT_SEGMENT
:
1582 shndx
= elfcpp::SHN_ABS
;
1585 case Symbol::CONSTANT
:
1586 shndx
= elfcpp::SHN_ABS
;
1593 if (sym_index
!= -1U)
1595 this->sized_write_symbol
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
1596 sym
, sym
->value(), shndx
, sympool
, ps
1597 SELECT_SIZE_ENDIAN(size
, big_endian
));
1601 if (dynsym_index
!= -1U)
1603 dynsym_index
-= first_dynamic_global_index
;
1604 gold_assert(dynsym_index
< dynamic_count
);
1605 unsigned char* pd
= dynamic_view
+ (dynsym_index
* sym_size
);
1606 this->sized_write_symbol
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
1607 sym
, value
, shndx
, dynpool
, pd
1608 SELECT_SIZE_ENDIAN(size
, big_endian
));
1612 gold_assert(ps
- psyms
== oview_size
);
1614 of
->write_output_view(this->offset_
, oview_size
, psyms
);
1615 if (dynamic_view
!= NULL
)
1616 of
->write_output_view(this->dynamic_offset_
, dynamic_size
, dynamic_view
);
1619 // Write out the symbol SYM, in section SHNDX, to P. POOL is the
1620 // strtab holding the name.
1622 template<int size
, bool big_endian
>
1624 Symbol_table::sized_write_symbol(
1625 Sized_symbol
<size
>* sym
,
1626 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1628 const Stringpool
* pool
,
1630 ACCEPT_SIZE_ENDIAN
) const
1632 elfcpp::Sym_write
<size
, big_endian
> osym(p
);
1633 osym
.put_st_name(pool
->get_offset(sym
->name()));
1634 osym
.put_st_value(value
);
1635 osym
.put_st_size(sym
->symsize());
1636 osym
.put_st_info(elfcpp::elf_st_info(sym
->binding(), sym
->type()));
1637 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(), sym
->nonvis()));
1638 osym
.put_st_shndx(shndx
);
1641 // Write out a section symbol. Return the update offset.
1644 Symbol_table::write_section_symbol(const Output_section
*os
,
1648 if (parameters
->get_size() == 32)
1650 if (parameters
->is_big_endian())
1652 #ifdef HAVE_TARGET_32_BIG
1653 this->sized_write_section_symbol
<32, true>(os
, of
, offset
);
1660 #ifdef HAVE_TARGET_32_LITTLE
1661 this->sized_write_section_symbol
<32, false>(os
, of
, offset
);
1667 else if (parameters
->get_size() == 64)
1669 if (parameters
->is_big_endian())
1671 #ifdef HAVE_TARGET_64_BIG
1672 this->sized_write_section_symbol
<64, true>(os
, of
, offset
);
1679 #ifdef HAVE_TARGET_64_LITTLE
1680 this->sized_write_section_symbol
<64, false>(os
, of
, offset
);
1690 // Write out a section symbol, specialized for size and endianness.
1692 template<int size
, bool big_endian
>
1694 Symbol_table::sized_write_section_symbol(const Output_section
* os
,
1698 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1700 unsigned char* pov
= of
->get_output_view(offset
, sym_size
);
1702 elfcpp::Sym_write
<size
, big_endian
> osym(pov
);
1703 osym
.put_st_name(0);
1704 osym
.put_st_value(os
->address());
1705 osym
.put_st_size(0);
1706 osym
.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL
,
1707 elfcpp::STT_SECTION
));
1708 osym
.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT
, 0));
1709 osym
.put_st_shndx(os
->out_shndx());
1711 of
->write_output_view(offset
, sym_size
, pov
);
1714 // Warnings functions.
1716 // Add a new warning.
1719 Warnings::add_warning(Symbol_table
* symtab
, const char* name
, Object
* obj
,
1722 name
= symtab
->canonicalize_name(name
);
1723 this->warnings_
[name
].set(obj
, shndx
);
1726 // Look through the warnings and mark the symbols for which we should
1727 // warn. This is called during Layout::finalize when we know the
1728 // sources for all the symbols.
1731 Warnings::note_warnings(Symbol_table
* symtab
)
1733 for (Warning_table::iterator p
= this->warnings_
.begin();
1734 p
!= this->warnings_
.end();
1737 Symbol
* sym
= symtab
->lookup(p
->first
, NULL
);
1739 && sym
->source() == Symbol::FROM_OBJECT
1740 && sym
->object() == p
->second
.object
)
1742 sym
->set_has_warning();
1744 // Read the section contents to get the warning text. It
1745 // would be nicer if we only did this if we have to actually
1746 // issue a warning. Unfortunately, warnings are issued as
1747 // we relocate sections. That means that we can not lock
1748 // the object then, as we might try to issue the same
1749 // warning multiple times simultaneously.
1751 Task_locker_obj
<Object
> tl(*p
->second
.object
);
1752 const unsigned char* c
;
1754 c
= p
->second
.object
->section_contents(p
->second
.shndx
, &len
,
1756 p
->second
.set_text(reinterpret_cast<const char*>(c
), len
);
1762 // Issue a warning. This is called when we see a relocation against a
1763 // symbol for which has a warning.
1765 template<int size
, bool big_endian
>
1767 Warnings::issue_warning(const Symbol
* sym
,
1768 const Relocate_info
<size
, big_endian
>* relinfo
,
1769 size_t relnum
, off_t reloffset
) const
1771 gold_assert(sym
->has_warning());
1772 Warning_table::const_iterator p
= this->warnings_
.find(sym
->name());
1773 gold_assert(p
!= this->warnings_
.end());
1774 gold_warning_at_location(relinfo
, relnum
, reloffset
,
1775 "%s", p
->second
.text
.c_str());
1778 // Instantiate the templates we need. We could use the configure
1779 // script to restrict this to only the ones needed for implemented
1782 #ifdef HAVE_TARGET_32_LITTLE
1785 Symbol_table::add_from_relobj
<32, false>(
1786 Sized_relobj
<32, false>* relobj
,
1787 const unsigned char* syms
,
1789 const char* sym_names
,
1790 size_t sym_name_size
,
1791 Symbol
** sympointers
);
1794 #ifdef HAVE_TARGET_32_BIG
1797 Symbol_table::add_from_relobj
<32, true>(
1798 Sized_relobj
<32, true>* relobj
,
1799 const unsigned char* syms
,
1801 const char* sym_names
,
1802 size_t sym_name_size
,
1803 Symbol
** sympointers
);
1806 #ifdef HAVE_TARGET_64_LITTLE
1809 Symbol_table::add_from_relobj
<64, false>(
1810 Sized_relobj
<64, false>* relobj
,
1811 const unsigned char* syms
,
1813 const char* sym_names
,
1814 size_t sym_name_size
,
1815 Symbol
** sympointers
);
1818 #ifdef HAVE_TARGET_64_BIG
1821 Symbol_table::add_from_relobj
<64, true>(
1822 Sized_relobj
<64, true>* relobj
,
1823 const unsigned char* syms
,
1825 const char* sym_names
,
1826 size_t sym_name_size
,
1827 Symbol
** sympointers
);
1830 #ifdef HAVE_TARGET_32_LITTLE
1833 Symbol_table::add_from_dynobj
<32, false>(
1834 Sized_dynobj
<32, false>* dynobj
,
1835 const unsigned char* syms
,
1837 const char* sym_names
,
1838 size_t sym_name_size
,
1839 const unsigned char* versym
,
1841 const std::vector
<const char*>* version_map
);
1844 #ifdef HAVE_TARGET_32_BIG
1847 Symbol_table::add_from_dynobj
<32, true>(
1848 Sized_dynobj
<32, true>* dynobj
,
1849 const unsigned char* syms
,
1851 const char* sym_names
,
1852 size_t sym_name_size
,
1853 const unsigned char* versym
,
1855 const std::vector
<const char*>* version_map
);
1858 #ifdef HAVE_TARGET_64_LITTLE
1861 Symbol_table::add_from_dynobj
<64, false>(
1862 Sized_dynobj
<64, false>* dynobj
,
1863 const unsigned char* syms
,
1865 const char* sym_names
,
1866 size_t sym_name_size
,
1867 const unsigned char* versym
,
1869 const std::vector
<const char*>* version_map
);
1872 #ifdef HAVE_TARGET_64_BIG
1875 Symbol_table::add_from_dynobj
<64, true>(
1876 Sized_dynobj
<64, true>* dynobj
,
1877 const unsigned char* syms
,
1879 const char* sym_names
,
1880 size_t sym_name_size
,
1881 const unsigned char* versym
,
1883 const std::vector
<const char*>* version_map
);
1886 #ifdef HAVE_TARGET_32_LITTLE
1889 Warnings::issue_warning
<32, false>(const Symbol
* sym
,
1890 const Relocate_info
<32, false>* relinfo
,
1891 size_t relnum
, off_t reloffset
) const;
1894 #ifdef HAVE_TARGET_32_BIG
1897 Warnings::issue_warning
<32, true>(const Symbol
* sym
,
1898 const Relocate_info
<32, true>* relinfo
,
1899 size_t relnum
, off_t reloffset
) const;
1902 #ifdef HAVE_TARGET_64_LITTLE
1905 Warnings::issue_warning
<64, false>(const Symbol
* sym
,
1906 const Relocate_info
<64, false>* relinfo
,
1907 size_t relnum
, off_t reloffset
) const;
1910 #ifdef HAVE_TARGET_64_BIG
1913 Warnings::issue_warning
<64, true>(const Symbol
* sym
,
1914 const Relocate_info
<64, true>* relinfo
,
1915 size_t relnum
, off_t reloffset
) const;
1919 } // End namespace gold.