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 this symbol should be added to the dynamic symbol
195 Symbol::should_add_dynsym_entry() const
197 // If the symbol is used by a dynamic relocation, we need to add it.
198 if (this->needs_dynsym_entry())
201 // If exporting all symbols or building a shared library,
202 // and the symbol is defined in a regular object and is
203 // externally visible, we need to add it.
204 if ((parameters
->export_dynamic() || parameters
->output_is_shared())
205 && !this->is_from_dynobj()
206 && this->is_externally_visible())
212 // Return true if the final value of this symbol is known at link
216 Symbol::final_value_is_known() const
218 // If we are not generating an executable, then no final values are
219 // known, since they will change at runtime.
220 if (!parameters
->output_is_executable())
223 // If the symbol is not from an object file, then it is defined, and
225 if (this->source_
!= FROM_OBJECT
)
228 // If the symbol is from a dynamic object, then the final value is
230 if (this->object()->is_dynamic())
233 // If the symbol is not undefined (it is defined or common), then
234 // the final value is known.
235 if (!this->is_undefined())
238 // If the symbol is undefined, then whether the final value is known
239 // depends on whether we are doing a static link. If we are doing a
240 // dynamic link, then the final value could be filled in at runtime.
241 // This could reasonably be the case for a weak undefined symbol.
242 return parameters
->doing_static_link();
245 // Class Symbol_table.
247 Symbol_table::Symbol_table()
248 : saw_undefined_(0), offset_(0), table_(), namepool_(),
249 forwarders_(), commons_(), warnings_()
253 Symbol_table::~Symbol_table()
257 // The hash function. The key is always canonicalized, so we use a
258 // simple combination of the pointers.
261 Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key
& key
) const
263 return key
.first
^ key
.second
;
266 // The symbol table key equality function. This is only called with
267 // canonicalized name and version strings, so we can use pointer
271 Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key
& k1
,
272 const Symbol_table_key
& k2
) const
274 return k1
.first
== k2
.first
&& k1
.second
== k2
.second
;
277 // Make TO a symbol which forwards to FROM.
280 Symbol_table::make_forwarder(Symbol
* from
, Symbol
* to
)
282 gold_assert(from
!= to
);
283 gold_assert(!from
->is_forwarder() && !to
->is_forwarder());
284 this->forwarders_
[from
] = to
;
285 from
->set_forwarder();
288 // Resolve the forwards from FROM, returning the real symbol.
291 Symbol_table::resolve_forwards(const Symbol
* from
) const
293 gold_assert(from
->is_forwarder());
294 Unordered_map
<const Symbol
*, Symbol
*>::const_iterator p
=
295 this->forwarders_
.find(from
);
296 gold_assert(p
!= this->forwarders_
.end());
300 // Look up a symbol by name.
303 Symbol_table::lookup(const char* name
, const char* version
) const
305 Stringpool::Key name_key
;
306 name
= this->namepool_
.find(name
, &name_key
);
310 Stringpool::Key version_key
= 0;
313 version
= this->namepool_
.find(version
, &version_key
);
318 Symbol_table_key
key(name_key
, version_key
);
319 Symbol_table::Symbol_table_type::const_iterator p
= this->table_
.find(key
);
320 if (p
== this->table_
.end())
325 // Resolve a Symbol with another Symbol. This is only used in the
326 // unusual case where there are references to both an unversioned
327 // symbol and a symbol with a version, and we then discover that that
328 // version is the default version. Because this is unusual, we do
329 // this the slow way, by converting back to an ELF symbol.
331 template<int size
, bool big_endian
>
333 Symbol_table::resolve(Sized_symbol
<size
>* to
, const Sized_symbol
<size
>* from
,
334 const char* version ACCEPT_SIZE_ENDIAN
)
336 unsigned char buf
[elfcpp::Elf_sizes
<size
>::sym_size
];
337 elfcpp::Sym_write
<size
, big_endian
> esym(buf
);
338 // We don't bother to set the st_name field.
339 esym
.put_st_value(from
->value());
340 esym
.put_st_size(from
->symsize());
341 esym
.put_st_info(from
->binding(), from
->type());
342 esym
.put_st_other(from
->visibility(), from
->nonvis());
343 esym
.put_st_shndx(from
->shndx());
344 this->resolve(to
, esym
.sym(), from
->object(), version
);
351 // Add one symbol from OBJECT to the symbol table. NAME is symbol
352 // name and VERSION is the version; both are canonicalized. DEF is
353 // whether this is the default version.
355 // If DEF is true, then this is the definition of a default version of
356 // a symbol. That means that any lookup of NAME/NULL and any lookup
357 // of NAME/VERSION should always return the same symbol. This is
358 // obvious for references, but in particular we want to do this for
359 // definitions: overriding NAME/NULL should also override
360 // NAME/VERSION. If we don't do that, it would be very hard to
361 // override functions in a shared library which uses versioning.
363 // We implement this by simply making both entries in the hash table
364 // point to the same Symbol structure. That is easy enough if this is
365 // the first time we see NAME/NULL or NAME/VERSION, but it is possible
366 // that we have seen both already, in which case they will both have
367 // independent entries in the symbol table. We can't simply change
368 // the symbol table entry, because we have pointers to the entries
369 // attached to the object files. So we mark the entry attached to the
370 // object file as a forwarder, and record it in the forwarders_ map.
371 // Note that entries in the hash table will never be marked as
374 template<int size
, bool big_endian
>
376 Symbol_table::add_from_object(Object
* object
,
378 Stringpool::Key name_key
,
380 Stringpool::Key version_key
,
382 const elfcpp::Sym
<size
, big_endian
>& sym
)
384 Symbol
* const snull
= NULL
;
385 std::pair
<typename
Symbol_table_type::iterator
, bool> ins
=
386 this->table_
.insert(std::make_pair(std::make_pair(name_key
, version_key
),
389 std::pair
<typename
Symbol_table_type::iterator
, bool> insdef
=
390 std::make_pair(this->table_
.end(), false);
393 const Stringpool::Key vnull_key
= 0;
394 insdef
= this->table_
.insert(std::make_pair(std::make_pair(name_key
,
399 // ins.first: an iterator, which is a pointer to a pair.
400 // ins.first->first: the key (a pair of name and version).
401 // ins.first->second: the value (Symbol*).
402 // ins.second: true if new entry was inserted, false if not.
404 Sized_symbol
<size
>* ret
;
409 // We already have an entry for NAME/VERSION.
410 ret
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (ins
.first
->second
412 gold_assert(ret
!= NULL
);
414 was_undefined
= ret
->is_undefined();
415 was_common
= ret
->is_common();
417 this->resolve(ret
, sym
, object
, version
);
423 // This is the first time we have seen NAME/NULL. Make
424 // NAME/NULL point to NAME/VERSION.
425 insdef
.first
->second
= ret
;
427 else if (insdef
.first
->second
!= ret
)
429 // This is the unfortunate case where we already have
430 // entries for both NAME/VERSION and NAME/NULL.
431 const Sized_symbol
<size
>* sym2
;
432 sym2
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (
435 Symbol_table::resolve
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
436 ret
, sym2
, version
SELECT_SIZE_ENDIAN(size
, big_endian
));
437 this->make_forwarder(insdef
.first
->second
, ret
);
438 insdef
.first
->second
= ret
;
444 // This is the first time we have seen NAME/VERSION.
445 gold_assert(ins
.first
->second
== NULL
);
447 was_undefined
= false;
450 if (def
&& !insdef
.second
)
452 // We already have an entry for NAME/NULL. If we override
453 // it, then change it to NAME/VERSION.
454 ret
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (
457 this->resolve(ret
, sym
, object
, version
);
458 ins
.first
->second
= ret
;
462 Sized_target
<size
, big_endian
>* target
=
463 object
->sized_target
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
464 SELECT_SIZE_ENDIAN_ONLY(size
, big_endian
));
465 if (!target
->has_make_symbol())
466 ret
= new Sized_symbol
<size
>();
469 ret
= target
->make_symbol();
472 // This means that we don't want a symbol table
475 this->table_
.erase(ins
.first
);
478 this->table_
.erase(insdef
.first
);
479 // Inserting insdef invalidated ins.
480 this->table_
.erase(std::make_pair(name_key
,
487 ret
->init(name
, version
, object
, sym
);
489 ins
.first
->second
= ret
;
492 // This is the first time we have seen NAME/NULL. Point
493 // it at the new entry for NAME/VERSION.
494 gold_assert(insdef
.second
);
495 insdef
.first
->second
= ret
;
500 // Record every time we see a new undefined symbol, to speed up
502 if (!was_undefined
&& ret
->is_undefined())
503 ++this->saw_undefined_
;
505 // Keep track of common symbols, to speed up common symbol
507 if (!was_common
&& ret
->is_common())
508 this->commons_
.push_back(ret
);
513 // Add all the symbols in a relocatable object to the hash table.
515 template<int size
, bool big_endian
>
517 Symbol_table::add_from_relobj(
518 Sized_relobj
<size
, big_endian
>* relobj
,
519 const unsigned char* syms
,
521 const char* sym_names
,
522 size_t sym_name_size
,
523 Symbol
** sympointers
)
525 gold_assert(size
== relobj
->target()->get_size());
526 gold_assert(size
== parameters
->get_size());
528 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
530 const unsigned char* p
= syms
;
531 for (size_t i
= 0; i
< count
; ++i
, p
+= sym_size
)
533 elfcpp::Sym
<size
, big_endian
> sym(p
);
534 elfcpp::Sym
<size
, big_endian
>* psym
= &sym
;
536 unsigned int st_name
= psym
->get_st_name();
537 if (st_name
>= sym_name_size
)
539 relobj
->error(_("bad global symbol name offset %u at %zu"),
544 const char* name
= sym_names
+ st_name
;
546 // A symbol defined in a section which we are not including must
547 // be treated as an undefined symbol.
548 unsigned char symbuf
[sym_size
];
549 elfcpp::Sym
<size
, big_endian
> sym2(symbuf
);
550 unsigned int st_shndx
= psym
->get_st_shndx();
551 if (st_shndx
!= elfcpp::SHN_UNDEF
552 && st_shndx
< elfcpp::SHN_LORESERVE
553 && !relobj
->is_section_included(st_shndx
))
555 memcpy(symbuf
, p
, sym_size
);
556 elfcpp::Sym_write
<size
, big_endian
> sw(symbuf
);
557 sw
.put_st_shndx(elfcpp::SHN_UNDEF
);
561 // In an object file, an '@' in the name separates the symbol
562 // name from the version name. If there are two '@' characters,
563 // this is the default version.
564 const char* ver
= strchr(name
, '@');
566 Sized_symbol
<size
>* res
;
569 Stringpool::Key name_key
;
570 name
= this->namepool_
.add(name
, true, &name_key
);
571 res
= this->add_from_object(relobj
, name
, name_key
, NULL
, 0,
576 Stringpool::Key name_key
;
577 name
= this->namepool_
.add_prefix(name
, ver
- name
, &name_key
);
587 Stringpool::Key ver_key
;
588 ver
= this->namepool_
.add(ver
, true, &ver_key
);
590 res
= this->add_from_object(relobj
, name
, name_key
, ver
, ver_key
,
594 *sympointers
++ = res
;
598 // Add all the symbols in a dynamic object to the hash table.
600 template<int size
, bool big_endian
>
602 Symbol_table::add_from_dynobj(
603 Sized_dynobj
<size
, big_endian
>* dynobj
,
604 const unsigned char* syms
,
606 const char* sym_names
,
607 size_t sym_name_size
,
608 const unsigned char* versym
,
610 const std::vector
<const char*>* version_map
)
612 gold_assert(size
== dynobj
->target()->get_size());
613 gold_assert(size
== parameters
->get_size());
615 if (versym
!= NULL
&& versym_size
/ 2 < count
)
617 dynobj
->error(_("too few symbol versions"));
621 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
623 // We keep a list of all STT_OBJECT symbols, so that we can resolve
624 // weak aliases. This is necessary because if the dynamic object
625 // provides the same variable under two names, one of which is a
626 // weak definition, and the regular object refers to the weak
627 // definition, we have to put both the weak definition and the
628 // strong definition into the dynamic symbol table. Given a weak
629 // definition, the only way that we can find the corresponding
630 // strong definition, if any, is to search the symbol table.
631 std::vector
<Sized_symbol
<size
>*> object_symbols
;
633 const unsigned char* p
= syms
;
634 const unsigned char* vs
= versym
;
635 for (size_t i
= 0; i
< count
; ++i
, p
+= sym_size
, vs
+= 2)
637 elfcpp::Sym
<size
, big_endian
> sym(p
);
639 // Ignore symbols with local binding.
640 if (sym
.get_st_bind() == elfcpp::STB_LOCAL
)
643 unsigned int st_name
= sym
.get_st_name();
644 if (st_name
>= sym_name_size
)
646 dynobj
->error(_("bad symbol name offset %u at %zu"),
651 const char* name
= sym_names
+ st_name
;
653 Sized_symbol
<size
>* res
;
657 Stringpool::Key name_key
;
658 name
= this->namepool_
.add(name
, true, &name_key
);
659 res
= this->add_from_object(dynobj
, name
, name_key
, NULL
, 0,
664 // Read the version information.
666 unsigned int v
= elfcpp::Swap
<16, big_endian
>::readval(vs
);
668 bool hidden
= (v
& elfcpp::VERSYM_HIDDEN
) != 0;
669 v
&= elfcpp::VERSYM_VERSION
;
671 // The Sun documentation says that V can be VER_NDX_LOCAL,
672 // or VER_NDX_GLOBAL, or a version index. The meaning of
673 // VER_NDX_LOCAL is defined as "Symbol has local scope."
674 // The old GNU linker will happily generate VER_NDX_LOCAL
675 // for an undefined symbol. I don't know what the Sun
676 // linker will generate.
678 if (v
== static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL
)
679 && sym
.get_st_shndx() != elfcpp::SHN_UNDEF
)
681 // This symbol should not be visible outside the object.
685 // At this point we are definitely going to add this symbol.
686 Stringpool::Key name_key
;
687 name
= this->namepool_
.add(name
, true, &name_key
);
689 if (v
== static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL
)
690 || v
== static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL
))
692 // This symbol does not have a version.
693 res
= this->add_from_object(dynobj
, name
, name_key
, NULL
, 0,
698 if (v
>= version_map
->size())
700 dynobj
->error(_("versym for symbol %zu out of range: %u"),
705 const char* version
= (*version_map
)[v
];
708 dynobj
->error(_("versym for symbol %zu has no name: %u"),
713 Stringpool::Key version_key
;
714 version
= this->namepool_
.add(version
, true, &version_key
);
716 // If this is an absolute symbol, and the version name
717 // and symbol name are the same, then this is the
718 // version definition symbol. These symbols exist to
719 // support using -u to pull in particular versions. We
720 // do not want to record a version for them.
721 if (sym
.get_st_shndx() == elfcpp::SHN_ABS
722 && name_key
== version_key
)
723 res
= this->add_from_object(dynobj
, name
, name_key
, NULL
, 0,
727 const bool def
= (!hidden
728 && (sym
.get_st_shndx()
729 != elfcpp::SHN_UNDEF
));
730 res
= this->add_from_object(dynobj
, name
, name_key
, version
,
731 version_key
, def
, sym
);
736 if (sym
.get_st_shndx() != elfcpp::SHN_UNDEF
737 && sym
.get_st_type() == elfcpp::STT_OBJECT
)
738 object_symbols
.push_back(res
);
741 this->record_weak_aliases(&object_symbols
);
744 // This is used to sort weak aliases. We sort them first by section
745 // index, then by offset, then by weak ahead of strong.
748 class Weak_alias_sorter
751 bool operator()(const Sized_symbol
<size
>*, const Sized_symbol
<size
>*) const;
756 Weak_alias_sorter
<size
>::operator()(const Sized_symbol
<size
>* s1
,
757 const Sized_symbol
<size
>* s2
) const
759 if (s1
->shndx() != s2
->shndx())
760 return s1
->shndx() < s2
->shndx();
761 if (s1
->value() != s2
->value())
762 return s1
->value() < s2
->value();
763 if (s1
->binding() != s2
->binding())
765 if (s1
->binding() == elfcpp::STB_WEAK
)
767 if (s2
->binding() == elfcpp::STB_WEAK
)
770 return std::string(s1
->name()) < std::string(s2
->name());
773 // SYMBOLS is a list of object symbols from a dynamic object. Look
774 // for any weak aliases, and record them so that if we add the weak
775 // alias to the dynamic symbol table, we also add the corresponding
780 Symbol_table::record_weak_aliases(std::vector
<Sized_symbol
<size
>*>* symbols
)
782 // Sort the vector by section index, then by offset, then by weak
784 std::sort(symbols
->begin(), symbols
->end(), Weak_alias_sorter
<size
>());
786 // Walk through the vector. For each weak definition, record
788 for (typename
std::vector
<Sized_symbol
<size
>*>::const_iterator p
=
793 if ((*p
)->binding() != elfcpp::STB_WEAK
)
796 // Build a circular list of weak aliases. Each symbol points to
797 // the next one in the circular list.
799 Sized_symbol
<size
>* from_sym
= *p
;
800 typename
std::vector
<Sized_symbol
<size
>*>::const_iterator q
;
801 for (q
= p
+ 1; q
!= symbols
->end(); ++q
)
803 if ((*q
)->shndx() != from_sym
->shndx()
804 || (*q
)->value() != from_sym
->value())
807 this->weak_aliases_
[from_sym
] = *q
;
808 from_sym
->set_has_alias();
814 this->weak_aliases_
[from_sym
] = *p
;
815 from_sym
->set_has_alias();
822 // Create and return a specially defined symbol. If ONLY_IF_REF is
823 // true, then only create the symbol if there is a reference to it.
824 // If this does not return NULL, it sets *POLDSYM to the existing
825 // symbol if there is one. This canonicalizes *PNAME and *PVERSION.
827 template<int size
, bool big_endian
>
829 Symbol_table::define_special_symbol(const Target
* target
, const char** pname
,
830 const char** pversion
, bool only_if_ref
,
831 Sized_symbol
<size
>** poldsym
835 Sized_symbol
<size
>* sym
;
836 bool add_to_table
= false;
837 typename
Symbol_table_type::iterator add_loc
= this->table_
.end();
841 oldsym
= this->lookup(*pname
, *pversion
);
842 if (oldsym
== NULL
|| !oldsym
->is_undefined())
845 *pname
= oldsym
->name();
846 *pversion
= oldsym
->version();
850 // Canonicalize NAME and VERSION.
851 Stringpool::Key name_key
;
852 *pname
= this->namepool_
.add(*pname
, true, &name_key
);
854 Stringpool::Key version_key
= 0;
855 if (*pversion
!= NULL
)
856 *pversion
= this->namepool_
.add(*pversion
, true, &version_key
);
858 Symbol
* const snull
= NULL
;
859 std::pair
<typename
Symbol_table_type::iterator
, bool> ins
=
860 this->table_
.insert(std::make_pair(std::make_pair(name_key
,
866 // We already have a symbol table entry for NAME/VERSION.
867 oldsym
= ins
.first
->second
;
868 gold_assert(oldsym
!= NULL
);
872 // We haven't seen this symbol before.
873 gold_assert(ins
.first
->second
== NULL
);
880 if (!target
->has_make_symbol())
881 sym
= new Sized_symbol
<size
>();
884 gold_assert(target
->get_size() == size
);
885 gold_assert(target
->is_big_endian() ? big_endian
: !big_endian
);
886 typedef Sized_target
<size
, big_endian
> My_target
;
887 const My_target
* sized_target
=
888 static_cast<const My_target
*>(target
);
889 sym
= sized_target
->make_symbol();
895 add_loc
->second
= sym
;
897 gold_assert(oldsym
!= NULL
);
899 *poldsym
= this->get_sized_symbol
SELECT_SIZE_NAME(size
) (oldsym
905 // Define a symbol based on an Output_data.
908 Symbol_table::define_in_output_data(const Target
* target
, const char* name
,
909 const char* version
, Output_data
* od
,
910 uint64_t value
, uint64_t symsize
,
911 elfcpp::STT type
, elfcpp::STB binding
,
912 elfcpp::STV visibility
,
913 unsigned char nonvis
,
914 bool offset_is_from_end
,
917 if (parameters
->get_size() == 32)
919 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
920 return this->do_define_in_output_data
<32>(target
, name
, version
, od
,
921 value
, symsize
, type
, binding
,
929 else if (parameters
->get_size() == 64)
931 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
932 return this->do_define_in_output_data
<64>(target
, name
, version
, od
,
933 value
, symsize
, type
, binding
,
945 // Define a symbol in an Output_data, sized version.
949 Symbol_table::do_define_in_output_data(
950 const Target
* target
,
954 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
955 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
,
958 elfcpp::STV visibility
,
959 unsigned char nonvis
,
960 bool offset_is_from_end
,
963 Sized_symbol
<size
>* sym
;
964 Sized_symbol
<size
>* oldsym
;
966 if (parameters
->is_big_endian())
968 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
969 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, true) (
970 target
, &name
, &version
, only_if_ref
, &oldsym
971 SELECT_SIZE_ENDIAN(size
, true));
978 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
979 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, false) (
980 target
, &name
, &version
, only_if_ref
, &oldsym
981 SELECT_SIZE_ENDIAN(size
, false));
990 gold_assert(version
== NULL
|| oldsym
!= NULL
);
991 sym
->init(name
, od
, value
, symsize
, type
, binding
, visibility
, nonvis
,
995 && Symbol_table::should_override_with_special(oldsym
))
996 this->override_with_special(oldsym
, sym
);
1001 // Define a symbol based on an Output_segment.
1004 Symbol_table::define_in_output_segment(const Target
* target
, const char* name
,
1005 const char* version
, Output_segment
* os
,
1006 uint64_t value
, uint64_t symsize
,
1007 elfcpp::STT type
, elfcpp::STB binding
,
1008 elfcpp::STV visibility
,
1009 unsigned char nonvis
,
1010 Symbol::Segment_offset_base offset_base
,
1013 if (parameters
->get_size() == 32)
1015 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1016 return this->do_define_in_output_segment
<32>(target
, name
, version
, os
,
1017 value
, symsize
, type
,
1018 binding
, visibility
, nonvis
,
1019 offset_base
, only_if_ref
);
1024 else if (parameters
->get_size() == 64)
1026 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1027 return this->do_define_in_output_segment
<64>(target
, name
, version
, os
,
1028 value
, symsize
, type
,
1029 binding
, visibility
, nonvis
,
1030 offset_base
, only_if_ref
);
1039 // Define a symbol in an Output_segment, sized version.
1043 Symbol_table::do_define_in_output_segment(
1044 const Target
* target
,
1046 const char* version
,
1048 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1049 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
,
1051 elfcpp::STB binding
,
1052 elfcpp::STV visibility
,
1053 unsigned char nonvis
,
1054 Symbol::Segment_offset_base offset_base
,
1057 Sized_symbol
<size
>* sym
;
1058 Sized_symbol
<size
>* oldsym
;
1060 if (parameters
->is_big_endian())
1062 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1063 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, true) (
1064 target
, &name
, &version
, only_if_ref
, &oldsym
1065 SELECT_SIZE_ENDIAN(size
, true));
1072 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1073 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, false) (
1074 target
, &name
, &version
, only_if_ref
, &oldsym
1075 SELECT_SIZE_ENDIAN(size
, false));
1084 gold_assert(version
== NULL
|| oldsym
!= NULL
);
1085 sym
->init(name
, os
, value
, symsize
, type
, binding
, visibility
, nonvis
,
1089 && Symbol_table::should_override_with_special(oldsym
))
1090 this->override_with_special(oldsym
, sym
);
1095 // Define a special symbol with a constant value. It is a multiple
1096 // definition error if this symbol is already defined.
1099 Symbol_table::define_as_constant(const Target
* target
, const char* name
,
1100 const char* version
, uint64_t value
,
1101 uint64_t symsize
, elfcpp::STT type
,
1102 elfcpp::STB binding
, elfcpp::STV visibility
,
1103 unsigned char nonvis
, bool only_if_ref
)
1105 if (parameters
->get_size() == 32)
1107 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1108 return this->do_define_as_constant
<32>(target
, name
, version
, value
,
1109 symsize
, type
, binding
,
1110 visibility
, nonvis
, only_if_ref
);
1115 else if (parameters
->get_size() == 64)
1117 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1118 return this->do_define_as_constant
<64>(target
, name
, version
, value
,
1119 symsize
, type
, binding
,
1120 visibility
, nonvis
, only_if_ref
);
1129 // Define a symbol as a constant, sized version.
1133 Symbol_table::do_define_as_constant(
1134 const Target
* target
,
1136 const char* version
,
1137 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1138 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
,
1140 elfcpp::STB binding
,
1141 elfcpp::STV visibility
,
1142 unsigned char nonvis
,
1145 Sized_symbol
<size
>* sym
;
1146 Sized_symbol
<size
>* oldsym
;
1148 if (parameters
->is_big_endian())
1150 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1151 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, true) (
1152 target
, &name
, &version
, only_if_ref
, &oldsym
1153 SELECT_SIZE_ENDIAN(size
, true));
1160 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1161 sym
= this->define_special_symbol
SELECT_SIZE_ENDIAN_NAME(size
, false) (
1162 target
, &name
, &version
, only_if_ref
, &oldsym
1163 SELECT_SIZE_ENDIAN(size
, false));
1172 gold_assert(version
== NULL
|| oldsym
!= NULL
);
1173 sym
->init(name
, value
, symsize
, type
, binding
, visibility
, nonvis
);
1176 && Symbol_table::should_override_with_special(oldsym
))
1177 this->override_with_special(oldsym
, sym
);
1182 // Define a set of symbols in output sections.
1185 Symbol_table::define_symbols(const Layout
* layout
, const Target
* target
,
1186 int count
, const Define_symbol_in_section
* p
)
1188 for (int i
= 0; i
< count
; ++i
, ++p
)
1190 Output_section
* os
= layout
->find_output_section(p
->output_section
);
1192 this->define_in_output_data(target
, p
->name
, NULL
, os
, p
->value
,
1193 p
->size
, p
->type
, p
->binding
,
1194 p
->visibility
, p
->nonvis
,
1195 p
->offset_is_from_end
, p
->only_if_ref
);
1197 this->define_as_constant(target
, p
->name
, NULL
, 0, p
->size
, p
->type
,
1198 p
->binding
, p
->visibility
, p
->nonvis
,
1203 // Define a set of symbols in output segments.
1206 Symbol_table::define_symbols(const Layout
* layout
, const Target
* target
,
1207 int count
, const Define_symbol_in_segment
* p
)
1209 for (int i
= 0; i
< count
; ++i
, ++p
)
1211 Output_segment
* os
= layout
->find_output_segment(p
->segment_type
,
1212 p
->segment_flags_set
,
1213 p
->segment_flags_clear
);
1215 this->define_in_output_segment(target
, p
->name
, NULL
, os
, p
->value
,
1216 p
->size
, p
->type
, p
->binding
,
1217 p
->visibility
, p
->nonvis
,
1218 p
->offset_base
, p
->only_if_ref
);
1220 this->define_as_constant(target
, p
->name
, NULL
, 0, p
->size
, p
->type
,
1221 p
->binding
, p
->visibility
, p
->nonvis
,
1226 // Set the dynamic symbol indexes. INDEX is the index of the first
1227 // global dynamic symbol. Pointers to the symbols are stored into the
1228 // vector SYMS. The names are added to DYNPOOL. This returns an
1229 // updated dynamic symbol index.
1232 Symbol_table::set_dynsym_indexes(const General_options
* options
,
1233 const Target
* target
,
1235 std::vector
<Symbol
*>* syms
,
1236 Stringpool
* dynpool
,
1239 for (Symbol_table_type::iterator p
= this->table_
.begin();
1240 p
!= this->table_
.end();
1243 Symbol
* sym
= p
->second
;
1245 // Note that SYM may already have a dynamic symbol index, since
1246 // some symbols appear more than once in the symbol table, with
1247 // and without a version.
1249 if (!sym
->should_add_dynsym_entry())
1250 sym
->set_dynsym_index(-1U);
1251 else if (!sym
->has_dynsym_index())
1253 sym
->set_dynsym_index(index
);
1255 syms
->push_back(sym
);
1256 dynpool
->add(sym
->name(), false, NULL
);
1258 // Record any version information.
1259 if (sym
->version() != NULL
)
1260 versions
->record_version(options
, dynpool
, sym
);
1264 // Finish up the versions. In some cases this may add new dynamic
1266 index
= versions
->finalize(target
, this, index
, syms
);
1271 // Set the final values for all the symbols. The index of the first
1272 // global symbol in the output file is INDEX. Record the file offset
1273 // OFF. Add their names to POOL. Return the new file offset.
1276 Symbol_table::finalize(unsigned int index
, off_t off
, off_t dynoff
,
1277 size_t dyn_global_index
, size_t dyncount
,
1282 gold_assert(index
!= 0);
1283 this->first_global_index_
= index
;
1285 this->dynamic_offset_
= dynoff
;
1286 this->first_dynamic_global_index_
= dyn_global_index
;
1287 this->dynamic_count_
= dyncount
;
1289 if (parameters
->get_size() == 32)
1291 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
1292 ret
= this->sized_finalize
<32>(index
, off
, pool
);
1297 else if (parameters
->get_size() == 64)
1299 #if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
1300 ret
= this->sized_finalize
<64>(index
, off
, pool
);
1308 // Now that we have the final symbol table, we can reliably note
1309 // which symbols should get warnings.
1310 this->warnings_
.note_warnings(this);
1315 // Set the final value for all the symbols. This is called after
1316 // Layout::finalize, so all the output sections have their final
1321 Symbol_table::sized_finalize(unsigned index
, off_t off
, Stringpool
* pool
)
1323 off
= align_address(off
, size
>> 3);
1324 this->offset_
= off
;
1326 size_t orig_index
= index
;
1328 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1329 for (Symbol_table_type::iterator p
= this->table_
.begin();
1330 p
!= this->table_
.end();
1333 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(p
->second
);
1335 // FIXME: Here we need to decide which symbols should go into
1336 // the output file, based on --strip.
1338 // The default version of a symbol may appear twice in the
1339 // symbol table. We only need to finalize it once.
1340 if (sym
->has_symtab_index())
1345 gold_assert(!sym
->has_symtab_index());
1346 sym
->set_symtab_index(-1U);
1347 gold_assert(sym
->dynsym_index() == -1U);
1351 typename Sized_symbol
<size
>::Value_type value
;
1353 switch (sym
->source())
1355 case Symbol::FROM_OBJECT
:
1357 unsigned int shndx
= sym
->shndx();
1359 // FIXME: We need some target specific support here.
1360 if (shndx
>= elfcpp::SHN_LORESERVE
1361 && shndx
!= elfcpp::SHN_ABS
)
1363 gold_error(_("%s: unsupported symbol section 0x%x"),
1364 sym
->name(), shndx
);
1365 shndx
= elfcpp::SHN_UNDEF
;
1368 Object
* symobj
= sym
->object();
1369 if (symobj
->is_dynamic())
1372 shndx
= elfcpp::SHN_UNDEF
;
1374 else if (shndx
== elfcpp::SHN_UNDEF
)
1376 else if (shndx
== elfcpp::SHN_ABS
)
1377 value
= sym
->value();
1380 Relobj
* relobj
= static_cast<Relobj
*>(symobj
);
1382 Output_section
* os
= relobj
->output_section(shndx
, &secoff
);
1386 sym
->set_symtab_index(-1U);
1387 gold_assert(sym
->dynsym_index() == -1U);
1391 value
= sym
->value() + os
->address() + secoff
;
1396 case Symbol::IN_OUTPUT_DATA
:
1398 Output_data
* od
= sym
->output_data();
1399 value
= sym
->value() + od
->address();
1400 if (sym
->offset_is_from_end())
1401 value
+= od
->data_size();
1405 case Symbol::IN_OUTPUT_SEGMENT
:
1407 Output_segment
* os
= sym
->output_segment();
1408 value
= sym
->value() + os
->vaddr();
1409 switch (sym
->offset_base())
1411 case Symbol::SEGMENT_START
:
1413 case Symbol::SEGMENT_END
:
1414 value
+= os
->memsz();
1416 case Symbol::SEGMENT_BSS
:
1417 value
+= os
->filesz();
1425 case Symbol::CONSTANT
:
1426 value
= sym
->value();
1433 sym
->set_value(value
);
1435 if (parameters
->strip_all())
1436 sym
->set_symtab_index(-1U);
1439 sym
->set_symtab_index(index
);
1440 pool
->add(sym
->name(), false, NULL
);
1446 this->output_count_
= index
- orig_index
;
1451 // Write out the global symbols.
1454 Symbol_table::write_globals(const Target
* target
, const Stringpool
* sympool
,
1455 const Stringpool
* dynpool
, Output_file
* of
) const
1457 if (parameters
->get_size() == 32)
1459 if (parameters
->is_big_endian())
1461 #ifdef HAVE_TARGET_32_BIG
1462 this->sized_write_globals
<32, true>(target
, sympool
, dynpool
, of
);
1469 #ifdef HAVE_TARGET_32_LITTLE
1470 this->sized_write_globals
<32, false>(target
, sympool
, dynpool
, of
);
1476 else if (parameters
->get_size() == 64)
1478 if (parameters
->is_big_endian())
1480 #ifdef HAVE_TARGET_64_BIG
1481 this->sized_write_globals
<64, true>(target
, sympool
, dynpool
, of
);
1488 #ifdef HAVE_TARGET_64_LITTLE
1489 this->sized_write_globals
<64, false>(target
, sympool
, dynpool
, of
);
1499 // Write out the global symbols.
1501 template<int size
, bool big_endian
>
1503 Symbol_table::sized_write_globals(const Target
* target
,
1504 const Stringpool
* sympool
,
1505 const Stringpool
* dynpool
,
1506 Output_file
* of
) const
1508 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1509 unsigned int index
= this->first_global_index_
;
1510 const off_t oview_size
= this->output_count_
* sym_size
;
1511 unsigned char* const psyms
= of
->get_output_view(this->offset_
, oview_size
);
1513 unsigned int dynamic_count
= this->dynamic_count_
;
1514 off_t dynamic_size
= dynamic_count
* sym_size
;
1515 unsigned int first_dynamic_global_index
= this->first_dynamic_global_index_
;
1516 unsigned char* dynamic_view
;
1517 if (this->dynamic_offset_
== 0)
1518 dynamic_view
= NULL
;
1520 dynamic_view
= of
->get_output_view(this->dynamic_offset_
, dynamic_size
);
1522 unsigned char* ps
= psyms
;
1523 for (Symbol_table_type::const_iterator p
= this->table_
.begin();
1524 p
!= this->table_
.end();
1527 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(p
->second
);
1529 unsigned int sym_index
= sym
->symtab_index();
1530 unsigned int dynsym_index
;
1531 if (dynamic_view
== NULL
)
1534 dynsym_index
= sym
->dynsym_index();
1536 if (sym_index
== -1U && dynsym_index
== -1U)
1538 // This symbol is not included in the output file.
1542 if (sym_index
== index
)
1544 else if (sym_index
!= -1U)
1546 // We have already seen this symbol, because it has a
1548 gold_assert(sym_index
< index
);
1549 if (dynsym_index
== -1U)
1555 typename
elfcpp::Elf_types
<32>::Elf_Addr value
= sym
->value();
1556 switch (sym
->source())
1558 case Symbol::FROM_OBJECT
:
1560 unsigned int in_shndx
= sym
->shndx();
1562 // FIXME: We need some target specific support here.
1563 if (in_shndx
>= elfcpp::SHN_LORESERVE
1564 && in_shndx
!= elfcpp::SHN_ABS
)
1566 gold_error(_("%s: unsupported symbol section 0x%x"),
1567 sym
->name(), in_shndx
);
1572 Object
* symobj
= sym
->object();
1573 if (symobj
->is_dynamic())
1575 if (sym
->needs_dynsym_value())
1576 value
= target
->dynsym_value(sym
);
1577 shndx
= elfcpp::SHN_UNDEF
;
1579 else if (in_shndx
== elfcpp::SHN_UNDEF
1580 || in_shndx
== elfcpp::SHN_ABS
)
1584 Relobj
* relobj
= static_cast<Relobj
*>(symobj
);
1586 Output_section
* os
= relobj
->output_section(in_shndx
,
1588 gold_assert(os
!= NULL
);
1589 shndx
= os
->out_shndx();
1595 case Symbol::IN_OUTPUT_DATA
:
1596 shndx
= sym
->output_data()->out_shndx();
1599 case Symbol::IN_OUTPUT_SEGMENT
:
1600 shndx
= elfcpp::SHN_ABS
;
1603 case Symbol::CONSTANT
:
1604 shndx
= elfcpp::SHN_ABS
;
1611 if (sym_index
!= -1U)
1613 this->sized_write_symbol
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
1614 sym
, sym
->value(), shndx
, sympool
, ps
1615 SELECT_SIZE_ENDIAN(size
, big_endian
));
1619 if (dynsym_index
!= -1U)
1621 dynsym_index
-= first_dynamic_global_index
;
1622 gold_assert(dynsym_index
< dynamic_count
);
1623 unsigned char* pd
= dynamic_view
+ (dynsym_index
* sym_size
);
1624 this->sized_write_symbol
SELECT_SIZE_ENDIAN_NAME(size
, big_endian
) (
1625 sym
, value
, shndx
, dynpool
, pd
1626 SELECT_SIZE_ENDIAN(size
, big_endian
));
1630 gold_assert(ps
- psyms
== oview_size
);
1632 of
->write_output_view(this->offset_
, oview_size
, psyms
);
1633 if (dynamic_view
!= NULL
)
1634 of
->write_output_view(this->dynamic_offset_
, dynamic_size
, dynamic_view
);
1637 // Write out the symbol SYM, in section SHNDX, to P. POOL is the
1638 // strtab holding the name.
1640 template<int size
, bool big_endian
>
1642 Symbol_table::sized_write_symbol(
1643 Sized_symbol
<size
>* sym
,
1644 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1646 const Stringpool
* pool
,
1648 ACCEPT_SIZE_ENDIAN
) const
1650 elfcpp::Sym_write
<size
, big_endian
> osym(p
);
1651 osym
.put_st_name(pool
->get_offset(sym
->name()));
1652 osym
.put_st_value(value
);
1653 osym
.put_st_size(sym
->symsize());
1654 osym
.put_st_info(elfcpp::elf_st_info(sym
->binding(), sym
->type()));
1655 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(), sym
->nonvis()));
1656 osym
.put_st_shndx(shndx
);
1659 // Write out a section symbol. Return the update offset.
1662 Symbol_table::write_section_symbol(const Output_section
*os
,
1666 if (parameters
->get_size() == 32)
1668 if (parameters
->is_big_endian())
1670 #ifdef HAVE_TARGET_32_BIG
1671 this->sized_write_section_symbol
<32, true>(os
, of
, offset
);
1678 #ifdef HAVE_TARGET_32_LITTLE
1679 this->sized_write_section_symbol
<32, false>(os
, of
, offset
);
1685 else if (parameters
->get_size() == 64)
1687 if (parameters
->is_big_endian())
1689 #ifdef HAVE_TARGET_64_BIG
1690 this->sized_write_section_symbol
<64, true>(os
, of
, offset
);
1697 #ifdef HAVE_TARGET_64_LITTLE
1698 this->sized_write_section_symbol
<64, false>(os
, of
, offset
);
1708 // Write out a section symbol, specialized for size and endianness.
1710 template<int size
, bool big_endian
>
1712 Symbol_table::sized_write_section_symbol(const Output_section
* os
,
1716 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1718 unsigned char* pov
= of
->get_output_view(offset
, sym_size
);
1720 elfcpp::Sym_write
<size
, big_endian
> osym(pov
);
1721 osym
.put_st_name(0);
1722 osym
.put_st_value(os
->address());
1723 osym
.put_st_size(0);
1724 osym
.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL
,
1725 elfcpp::STT_SECTION
));
1726 osym
.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT
, 0));
1727 osym
.put_st_shndx(os
->out_shndx());
1729 of
->write_output_view(offset
, sym_size
, pov
);
1732 // Warnings functions.
1734 // Add a new warning.
1737 Warnings::add_warning(Symbol_table
* symtab
, const char* name
, Object
* obj
,
1740 name
= symtab
->canonicalize_name(name
);
1741 this->warnings_
[name
].set(obj
, shndx
);
1744 // Look through the warnings and mark the symbols for which we should
1745 // warn. This is called during Layout::finalize when we know the
1746 // sources for all the symbols.
1749 Warnings::note_warnings(Symbol_table
* symtab
)
1751 for (Warning_table::iterator p
= this->warnings_
.begin();
1752 p
!= this->warnings_
.end();
1755 Symbol
* sym
= symtab
->lookup(p
->first
, NULL
);
1757 && sym
->source() == Symbol::FROM_OBJECT
1758 && sym
->object() == p
->second
.object
)
1760 sym
->set_has_warning();
1762 // Read the section contents to get the warning text. It
1763 // would be nicer if we only did this if we have to actually
1764 // issue a warning. Unfortunately, warnings are issued as
1765 // we relocate sections. That means that we can not lock
1766 // the object then, as we might try to issue the same
1767 // warning multiple times simultaneously.
1769 Task_locker_obj
<Object
> tl(*p
->second
.object
);
1770 const unsigned char* c
;
1772 c
= p
->second
.object
->section_contents(p
->second
.shndx
, &len
,
1774 p
->second
.set_text(reinterpret_cast<const char*>(c
), len
);
1780 // Issue a warning. This is called when we see a relocation against a
1781 // symbol for which has a warning.
1783 template<int size
, bool big_endian
>
1785 Warnings::issue_warning(const Symbol
* sym
,
1786 const Relocate_info
<size
, big_endian
>* relinfo
,
1787 size_t relnum
, off_t reloffset
) const
1789 gold_assert(sym
->has_warning());
1790 Warning_table::const_iterator p
= this->warnings_
.find(sym
->name());
1791 gold_assert(p
!= this->warnings_
.end());
1792 gold_warning_at_location(relinfo
, relnum
, reloffset
,
1793 "%s", p
->second
.text
.c_str());
1796 // Instantiate the templates we need. We could use the configure
1797 // script to restrict this to only the ones needed for implemented
1800 #ifdef HAVE_TARGET_32_LITTLE
1803 Symbol_table::add_from_relobj
<32, false>(
1804 Sized_relobj
<32, false>* relobj
,
1805 const unsigned char* syms
,
1807 const char* sym_names
,
1808 size_t sym_name_size
,
1809 Symbol
** sympointers
);
1812 #ifdef HAVE_TARGET_32_BIG
1815 Symbol_table::add_from_relobj
<32, true>(
1816 Sized_relobj
<32, true>* relobj
,
1817 const unsigned char* syms
,
1819 const char* sym_names
,
1820 size_t sym_name_size
,
1821 Symbol
** sympointers
);
1824 #ifdef HAVE_TARGET_64_LITTLE
1827 Symbol_table::add_from_relobj
<64, false>(
1828 Sized_relobj
<64, false>* relobj
,
1829 const unsigned char* syms
,
1831 const char* sym_names
,
1832 size_t sym_name_size
,
1833 Symbol
** sympointers
);
1836 #ifdef HAVE_TARGET_64_BIG
1839 Symbol_table::add_from_relobj
<64, true>(
1840 Sized_relobj
<64, true>* relobj
,
1841 const unsigned char* syms
,
1843 const char* sym_names
,
1844 size_t sym_name_size
,
1845 Symbol
** sympointers
);
1848 #ifdef HAVE_TARGET_32_LITTLE
1851 Symbol_table::add_from_dynobj
<32, false>(
1852 Sized_dynobj
<32, false>* dynobj
,
1853 const unsigned char* syms
,
1855 const char* sym_names
,
1856 size_t sym_name_size
,
1857 const unsigned char* versym
,
1859 const std::vector
<const char*>* version_map
);
1862 #ifdef HAVE_TARGET_32_BIG
1865 Symbol_table::add_from_dynobj
<32, true>(
1866 Sized_dynobj
<32, true>* dynobj
,
1867 const unsigned char* syms
,
1869 const char* sym_names
,
1870 size_t sym_name_size
,
1871 const unsigned char* versym
,
1873 const std::vector
<const char*>* version_map
);
1876 #ifdef HAVE_TARGET_64_LITTLE
1879 Symbol_table::add_from_dynobj
<64, false>(
1880 Sized_dynobj
<64, false>* dynobj
,
1881 const unsigned char* syms
,
1883 const char* sym_names
,
1884 size_t sym_name_size
,
1885 const unsigned char* versym
,
1887 const std::vector
<const char*>* version_map
);
1890 #ifdef HAVE_TARGET_64_BIG
1893 Symbol_table::add_from_dynobj
<64, true>(
1894 Sized_dynobj
<64, true>* dynobj
,
1895 const unsigned char* syms
,
1897 const char* sym_names
,
1898 size_t sym_name_size
,
1899 const unsigned char* versym
,
1901 const std::vector
<const char*>* version_map
);
1904 #ifdef HAVE_TARGET_32_LITTLE
1907 Warnings::issue_warning
<32, false>(const Symbol
* sym
,
1908 const Relocate_info
<32, false>* relinfo
,
1909 size_t relnum
, off_t reloffset
) const;
1912 #ifdef HAVE_TARGET_32_BIG
1915 Warnings::issue_warning
<32, true>(const Symbol
* sym
,
1916 const Relocate_info
<32, true>* relinfo
,
1917 size_t relnum
, off_t reloffset
) const;
1920 #ifdef HAVE_TARGET_64_LITTLE
1923 Warnings::issue_warning
<64, false>(const Symbol
* sym
,
1924 const Relocate_info
<64, false>* relinfo
,
1925 size_t relnum
, off_t reloffset
) const;
1928 #ifdef HAVE_TARGET_64_BIG
1931 Warnings::issue_warning
<64, true>(const Symbol
* sym
,
1932 const Relocate_info
<64, true>* relinfo
,
1933 size_t relnum
, off_t reloffset
) const;
1937 } // End namespace gold.