Use special value when we refer a function symbol in some way other
[binutils.git] / gold / symtab.cc
blob8cd55cdaf6ff2cc7323b78954169bbdcf75eaf56
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.
23 #include "gold.h"
25 #include <stdint.h>
26 #include <string>
27 #include <utility>
29 #include "object.h"
30 #include "dynobj.h"
31 #include "output.h"
32 #include "target.h"
33 #include "workqueue.h"
34 #include "symtab.h"
36 namespace gold
39 // Class Symbol.
41 // Initialize fields in Symbol. This initializes everything except u_
42 // and source_.
44 void
45 Symbol::init_fields(const char* name, const char* version,
46 elfcpp::STT type, elfcpp::STB binding,
47 elfcpp::STV visibility, unsigned char nonvis)
49 this->name_ = name;
50 this->version_ = version;
51 this->symtab_index_ = 0;
52 this->dynsym_index_ = 0;
53 this->got_offset_ = 0;
54 this->plt_offset_ = 0;
55 this->type_ = type;
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->needs_dynsym_entry_ = false;
63 this->in_reg_ = false;
64 this->in_dyn_ = false;
65 this->has_got_offset_ = false;
66 this->has_plt_offset_ = false;
67 this->has_warning_ = false;
70 // Initialize the fields in the base class Symbol for SYM in OBJECT.
72 template<int size, bool big_endian>
73 void
74 Symbol::init_base(const char* name, const char* version, Object* object,
75 const elfcpp::Sym<size, big_endian>& sym)
77 this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
78 sym.get_st_visibility(), sym.get_st_nonvis());
79 this->u_.from_object.object = object;
80 // FIXME: Handle SHN_XINDEX.
81 this->u_.from_object.shndx = sym.get_st_shndx();
82 this->source_ = FROM_OBJECT;
83 this->in_reg_ = !object->is_dynamic();
84 this->in_dyn_ = object->is_dynamic();
87 // Initialize the fields in the base class Symbol for a symbol defined
88 // in an Output_data.
90 void
91 Symbol::init_base(const char* name, Output_data* od, elfcpp::STT type,
92 elfcpp::STB binding, elfcpp::STV visibility,
93 unsigned char nonvis, bool offset_is_from_end)
95 this->init_fields(name, NULL, type, binding, visibility, nonvis);
96 this->u_.in_output_data.output_data = od;
97 this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
98 this->source_ = IN_OUTPUT_DATA;
99 this->in_reg_ = true;
102 // Initialize the fields in the base class Symbol for a symbol defined
103 // in an Output_segment.
105 void
106 Symbol::init_base(const char* name, Output_segment* os, elfcpp::STT type,
107 elfcpp::STB binding, elfcpp::STV visibility,
108 unsigned char nonvis, Segment_offset_base offset_base)
110 this->init_fields(name, NULL, type, binding, visibility, nonvis);
111 this->u_.in_output_segment.output_segment = os;
112 this->u_.in_output_segment.offset_base = offset_base;
113 this->source_ = IN_OUTPUT_SEGMENT;
114 this->in_reg_ = true;
117 // Initialize the fields in the base class Symbol for a symbol defined
118 // as a constant.
120 void
121 Symbol::init_base(const char* name, elfcpp::STT type,
122 elfcpp::STB binding, elfcpp::STV visibility,
123 unsigned char nonvis)
125 this->init_fields(name, NULL, type, binding, visibility, nonvis);
126 this->source_ = CONSTANT;
127 this->in_reg_ = true;
130 // Initialize the fields in Sized_symbol for SYM in OBJECT.
132 template<int size>
133 template<bool big_endian>
134 void
135 Sized_symbol<size>::init(const char* name, const char* version, Object* object,
136 const elfcpp::Sym<size, big_endian>& sym)
138 this->init_base(name, version, object, sym);
139 this->value_ = sym.get_st_value();
140 this->symsize_ = sym.get_st_size();
143 // Initialize the fields in Sized_symbol for a symbol defined in an
144 // Output_data.
146 template<int size>
147 void
148 Sized_symbol<size>::init(const char* name, Output_data* od,
149 Value_type value, Size_type symsize,
150 elfcpp::STT type, elfcpp::STB binding,
151 elfcpp::STV visibility, unsigned char nonvis,
152 bool offset_is_from_end)
154 this->init_base(name, od, type, binding, visibility, nonvis,
155 offset_is_from_end);
156 this->value_ = value;
157 this->symsize_ = symsize;
160 // Initialize the fields in Sized_symbol for a symbol defined in an
161 // Output_segment.
163 template<int size>
164 void
165 Sized_symbol<size>::init(const char* name, Output_segment* os,
166 Value_type value, Size_type symsize,
167 elfcpp::STT type, elfcpp::STB binding,
168 elfcpp::STV visibility, unsigned char nonvis,
169 Segment_offset_base offset_base)
171 this->init_base(name, os, type, binding, visibility, nonvis, offset_base);
172 this->value_ = value;
173 this->symsize_ = symsize;
176 // Initialize the fields in Sized_symbol for a symbol defined as a
177 // constant.
179 template<int size>
180 void
181 Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
182 elfcpp::STT type, elfcpp::STB binding,
183 elfcpp::STV visibility, unsigned char nonvis)
185 this->init_base(name, type, binding, visibility, nonvis);
186 this->value_ = value;
187 this->symsize_ = symsize;
190 // Class Symbol_table.
192 Symbol_table::Symbol_table()
193 : size_(0), saw_undefined_(0), offset_(0), table_(), namepool_(),
194 forwarders_(), commons_(), warnings_()
198 Symbol_table::~Symbol_table()
202 // The hash function. The key is always canonicalized, so we use a
203 // simple combination of the pointers.
205 size_t
206 Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key& key) const
208 return key.first ^ key.second;
211 // The symbol table key equality function. This is only called with
212 // canonicalized name and version strings, so we can use pointer
213 // comparison.
215 bool
216 Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
217 const Symbol_table_key& k2) const
219 return k1.first == k2.first && k1.second == k2.second;
222 // Make TO a symbol which forwards to FROM.
224 void
225 Symbol_table::make_forwarder(Symbol* from, Symbol* to)
227 gold_assert(from != to);
228 gold_assert(!from->is_forwarder() && !to->is_forwarder());
229 this->forwarders_[from] = to;
230 from->set_forwarder();
233 // Resolve the forwards from FROM, returning the real symbol.
235 Symbol*
236 Symbol_table::resolve_forwards(const Symbol* from) const
238 gold_assert(from->is_forwarder());
239 Unordered_map<const Symbol*, Symbol*>::const_iterator p =
240 this->forwarders_.find(from);
241 gold_assert(p != this->forwarders_.end());
242 return p->second;
245 // Look up a symbol by name.
247 Symbol*
248 Symbol_table::lookup(const char* name, const char* version) const
250 Stringpool::Key name_key;
251 name = this->namepool_.find(name, &name_key);
252 if (name == NULL)
253 return NULL;
255 Stringpool::Key version_key = 0;
256 if (version != NULL)
258 version = this->namepool_.find(version, &version_key);
259 if (version == NULL)
260 return NULL;
263 Symbol_table_key key(name_key, version_key);
264 Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
265 if (p == this->table_.end())
266 return NULL;
267 return p->second;
270 // Resolve a Symbol with another Symbol. This is only used in the
271 // unusual case where there are references to both an unversioned
272 // symbol and a symbol with a version, and we then discover that that
273 // version is the default version. Because this is unusual, we do
274 // this the slow way, by converting back to an ELF symbol.
276 template<int size, bool big_endian>
277 void
278 Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
279 const char* version ACCEPT_SIZE_ENDIAN)
281 unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
282 elfcpp::Sym_write<size, big_endian> esym(buf);
283 // We don't bother to set the st_name field.
284 esym.put_st_value(from->value());
285 esym.put_st_size(from->symsize());
286 esym.put_st_info(from->binding(), from->type());
287 esym.put_st_other(from->visibility(), from->nonvis());
288 esym.put_st_shndx(from->shndx());
289 Symbol_table::resolve(to, esym.sym(), from->object(), version);
290 if (from->in_reg())
291 to->set_in_reg();
292 if (from->in_dyn())
293 to->set_in_dyn();
296 // Add one symbol from OBJECT to the symbol table. NAME is symbol
297 // name and VERSION is the version; both are canonicalized. DEF is
298 // whether this is the default version.
300 // If DEF is true, then this is the definition of a default version of
301 // a symbol. That means that any lookup of NAME/NULL and any lookup
302 // of NAME/VERSION should always return the same symbol. This is
303 // obvious for references, but in particular we want to do this for
304 // definitions: overriding NAME/NULL should also override
305 // NAME/VERSION. If we don't do that, it would be very hard to
306 // override functions in a shared library which uses versioning.
308 // We implement this by simply making both entries in the hash table
309 // point to the same Symbol structure. That is easy enough if this is
310 // the first time we see NAME/NULL or NAME/VERSION, but it is possible
311 // that we have seen both already, in which case they will both have
312 // independent entries in the symbol table. We can't simply change
313 // the symbol table entry, because we have pointers to the entries
314 // attached to the object files. So we mark the entry attached to the
315 // object file as a forwarder, and record it in the forwarders_ map.
316 // Note that entries in the hash table will never be marked as
317 // forwarders.
319 template<int size, bool big_endian>
320 Symbol*
321 Symbol_table::add_from_object(Object* object,
322 const char *name,
323 Stringpool::Key name_key,
324 const char *version,
325 Stringpool::Key version_key,
326 bool def,
327 const elfcpp::Sym<size, big_endian>& sym)
329 Symbol* const snull = NULL;
330 std::pair<typename Symbol_table_type::iterator, bool> ins =
331 this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
332 snull));
334 std::pair<typename Symbol_table_type::iterator, bool> insdef =
335 std::make_pair(this->table_.end(), false);
336 if (def)
338 const Stringpool::Key vnull_key = 0;
339 insdef = this->table_.insert(std::make_pair(std::make_pair(name_key,
340 vnull_key),
341 snull));
344 // ins.first: an iterator, which is a pointer to a pair.
345 // ins.first->first: the key (a pair of name and version).
346 // ins.first->second: the value (Symbol*).
347 // ins.second: true if new entry was inserted, false if not.
349 Sized_symbol<size>* ret;
350 bool was_undefined;
351 bool was_common;
352 if (!ins.second)
354 // We already have an entry for NAME/VERSION.
355 ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (ins.first->second
356 SELECT_SIZE(size));
357 gold_assert(ret != NULL);
359 was_undefined = ret->is_undefined();
360 was_common = ret->is_common();
362 Symbol_table::resolve(ret, sym, object, version);
364 if (def)
366 if (insdef.second)
368 // This is the first time we have seen NAME/NULL. Make
369 // NAME/NULL point to NAME/VERSION.
370 insdef.first->second = ret;
372 else if (insdef.first->second != ret)
374 // This is the unfortunate case where we already have
375 // entries for both NAME/VERSION and NAME/NULL.
376 const Sized_symbol<size>* sym2;
377 sym2 = this->get_sized_symbol SELECT_SIZE_NAME(size) (
378 insdef.first->second
379 SELECT_SIZE(size));
380 Symbol_table::resolve SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
381 ret, sym2, version SELECT_SIZE_ENDIAN(size, big_endian));
382 this->make_forwarder(insdef.first->second, ret);
383 insdef.first->second = ret;
387 else
389 // This is the first time we have seen NAME/VERSION.
390 gold_assert(ins.first->second == NULL);
392 was_undefined = false;
393 was_common = false;
395 if (def && !insdef.second)
397 // We already have an entry for NAME/NULL. If we override
398 // it, then change it to NAME/VERSION.
399 ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (
400 insdef.first->second
401 SELECT_SIZE(size));
402 Symbol_table::resolve(ret, sym, object, version);
403 ins.first->second = ret;
405 else
407 Sized_target<size, big_endian>* target =
408 object->sized_target SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
409 SELECT_SIZE_ENDIAN_ONLY(size, big_endian));
410 if (!target->has_make_symbol())
411 ret = new Sized_symbol<size>();
412 else
414 ret = target->make_symbol();
415 if (ret == NULL)
417 // This means that we don't want a symbol table
418 // entry after all.
419 if (!def)
420 this->table_.erase(ins.first);
421 else
423 this->table_.erase(insdef.first);
424 // Inserting insdef invalidated ins.
425 this->table_.erase(std::make_pair(name_key,
426 version_key));
428 return NULL;
432 ret->init(name, version, object, sym);
434 ins.first->second = ret;
435 if (def)
437 // This is the first time we have seen NAME/NULL. Point
438 // it at the new entry for NAME/VERSION.
439 gold_assert(insdef.second);
440 insdef.first->second = ret;
445 // Record every time we see a new undefined symbol, to speed up
446 // archive groups.
447 if (!was_undefined && ret->is_undefined())
448 ++this->saw_undefined_;
450 // Keep track of common symbols, to speed up common symbol
451 // allocation.
452 if (!was_common && ret->is_common())
453 this->commons_.push_back(ret);
455 return ret;
458 // Add all the symbols in a relocatable object to the hash table.
460 template<int size, bool big_endian>
461 void
462 Symbol_table::add_from_relobj(
463 Sized_relobj<size, big_endian>* relobj,
464 const unsigned char* syms,
465 size_t count,
466 const char* sym_names,
467 size_t sym_name_size,
468 Symbol** sympointers)
470 // We take the size from the first object we see.
471 if (this->get_size() == 0)
472 this->set_size(size);
474 if (size != this->get_size() || size != relobj->target()->get_size())
476 fprintf(stderr, _("%s: %s: mixing 32-bit and 64-bit ELF objects\n"),
477 program_name, relobj->name().c_str());
478 gold_exit(false);
481 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
483 const unsigned char* p = syms;
484 for (size_t i = 0; i < count; ++i, p += sym_size)
486 elfcpp::Sym<size, big_endian> sym(p);
487 elfcpp::Sym<size, big_endian>* psym = &sym;
489 unsigned int st_name = psym->get_st_name();
490 if (st_name >= sym_name_size)
492 fprintf(stderr,
493 _("%s: %s: bad global symbol name offset %u at %lu\n"),
494 program_name, relobj->name().c_str(), st_name,
495 static_cast<unsigned long>(i));
496 gold_exit(false);
499 const char* name = sym_names + st_name;
501 // A symbol defined in a section which we are not including must
502 // be treated as an undefined symbol.
503 unsigned char symbuf[sym_size];
504 elfcpp::Sym<size, big_endian> sym2(symbuf);
505 unsigned int st_shndx = psym->get_st_shndx();
506 if (st_shndx != elfcpp::SHN_UNDEF
507 && st_shndx < elfcpp::SHN_LORESERVE
508 && !relobj->is_section_included(st_shndx))
510 memcpy(symbuf, p, sym_size);
511 elfcpp::Sym_write<size, big_endian> sw(symbuf);
512 sw.put_st_shndx(elfcpp::SHN_UNDEF);
513 psym = &sym2;
516 // In an object file, an '@' in the name separates the symbol
517 // name from the version name. If there are two '@' characters,
518 // this is the default version.
519 const char* ver = strchr(name, '@');
521 Symbol* res;
522 if (ver == NULL)
524 Stringpool::Key name_key;
525 name = this->namepool_.add(name, &name_key);
526 res = this->add_from_object(relobj, name, name_key, NULL, 0,
527 false, *psym);
529 else
531 Stringpool::Key name_key;
532 name = this->namepool_.add(name, ver - name, &name_key);
534 bool def = false;
535 ++ver;
536 if (*ver == '@')
538 def = true;
539 ++ver;
542 Stringpool::Key ver_key;
543 ver = this->namepool_.add(ver, &ver_key);
545 res = this->add_from_object(relobj, name, name_key, ver, ver_key,
546 def, *psym);
549 *sympointers++ = res;
553 // Add all the symbols in a dynamic object to the hash table.
555 template<int size, bool big_endian>
556 void
557 Symbol_table::add_from_dynobj(
558 Sized_dynobj<size, big_endian>* dynobj,
559 const unsigned char* syms,
560 size_t count,
561 const char* sym_names,
562 size_t sym_name_size,
563 const unsigned char* versym,
564 size_t versym_size,
565 const std::vector<const char*>* version_map)
567 // We take the size from the first object we see.
568 if (this->get_size() == 0)
569 this->set_size(size);
571 if (size != this->get_size() || size != dynobj->target()->get_size())
573 fprintf(stderr, _("%s: %s: mixing 32-bit and 64-bit ELF objects\n"),
574 program_name, dynobj->name().c_str());
575 gold_exit(false);
578 if (versym != NULL && versym_size / 2 < count)
580 fprintf(stderr, _("%s: %s: too few symbol versions\n"),
581 program_name, dynobj->name().c_str());
582 gold_exit(false);
585 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
587 const unsigned char* p = syms;
588 const unsigned char* vs = versym;
589 for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
591 elfcpp::Sym<size, big_endian> sym(p);
593 // Ignore symbols with local binding.
594 if (sym.get_st_bind() == elfcpp::STB_LOCAL)
595 continue;
597 unsigned int st_name = sym.get_st_name();
598 if (st_name >= sym_name_size)
600 fprintf(stderr, _("%s: %s: bad symbol name offset %u at %lu\n"),
601 program_name, dynobj->name().c_str(), st_name,
602 static_cast<unsigned long>(i));
603 gold_exit(false);
606 const char* name = sym_names + st_name;
608 if (versym == NULL)
610 Stringpool::Key name_key;
611 name = this->namepool_.add(name, &name_key);
612 this->add_from_object(dynobj, name, name_key, NULL, 0,
613 false, sym);
614 continue;
617 // Read the version information.
619 unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
621 bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
622 v &= elfcpp::VERSYM_VERSION;
624 // The Sun documentation says that V can be VER_NDX_LOCAL, or
625 // VER_NDX_GLOBAL, or a version index. The meaning of
626 // VER_NDX_LOCAL is defined as "Symbol has local scope." The
627 // old GNU linker will happily generate VER_NDX_LOCAL for an
628 // undefined symbol. I don't know what the Sun linker will
629 // generate.
631 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
632 && sym.get_st_shndx() != elfcpp::SHN_UNDEF)
634 // This symbol should not be visible outside the object.
635 continue;
638 // At this point we are definitely going to add this symbol.
639 Stringpool::Key name_key;
640 name = this->namepool_.add(name, &name_key);
642 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
643 || v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
645 // This symbol does not have a version.
646 this->add_from_object(dynobj, name, name_key, NULL, 0, false, sym);
647 continue;
650 if (v >= version_map->size())
652 fprintf(stderr,
653 _("%s: %s: versym for symbol %zu out of range: %u\n"),
654 program_name, dynobj->name().c_str(), i, v);
655 gold_exit(false);
658 const char* version = (*version_map)[v];
659 if (version == NULL)
661 fprintf(stderr, _("%s: %s: versym for symbol %zu has no name: %u\n"),
662 program_name, dynobj->name().c_str(), i, v);
663 gold_exit(false);
666 Stringpool::Key version_key;
667 version = this->namepool_.add(version, &version_key);
669 // If this is an absolute symbol, and the version name and
670 // symbol name are the same, then this is the version definition
671 // symbol. These symbols exist to support using -u to pull in
672 // particular versions. We do not want to record a version for
673 // them.
674 if (sym.get_st_shndx() == elfcpp::SHN_ABS && name_key == version_key)
676 this->add_from_object(dynobj, name, name_key, NULL, 0, false, sym);
677 continue;
680 const bool def = !hidden && sym.get_st_shndx() != elfcpp::SHN_UNDEF;
682 this->add_from_object(dynobj, name, name_key, version, version_key,
683 def, sym);
687 // Create and return a specially defined symbol. If ONLY_IF_REF is
688 // true, then only create the symbol if there is a reference to it.
689 // If this does not return NULL, it sets *POLDSYM to the existing
690 // symbol if there is one. This canonicalizes *PNAME and *PVERSION.
692 template<int size, bool big_endian>
693 Sized_symbol<size>*
694 Symbol_table::define_special_symbol(const Target* target, const char** pname,
695 const char** pversion, bool only_if_ref,
696 Sized_symbol<size>** poldsym
697 ACCEPT_SIZE_ENDIAN)
699 gold_assert(this->size_ == size);
701 Symbol* oldsym;
702 Sized_symbol<size>* sym;
703 bool add_to_table = false;
704 typename Symbol_table_type::iterator add_loc = this->table_.end();
706 if (only_if_ref)
708 oldsym = this->lookup(*pname, *pversion);
709 if (oldsym == NULL || !oldsym->is_undefined())
710 return NULL;
712 *pname = oldsym->name();
713 *pversion = oldsym->version();
715 else
717 // Canonicalize NAME and VERSION.
718 Stringpool::Key name_key;
719 *pname = this->namepool_.add(*pname, &name_key);
721 Stringpool::Key version_key = 0;
722 if (*pversion != NULL)
723 *pversion = this->namepool_.add(*pversion, &version_key);
725 Symbol* const snull = NULL;
726 std::pair<typename Symbol_table_type::iterator, bool> ins =
727 this->table_.insert(std::make_pair(std::make_pair(name_key,
728 version_key),
729 snull));
731 if (!ins.second)
733 // We already have a symbol table entry for NAME/VERSION.
734 oldsym = ins.first->second;
735 gold_assert(oldsym != NULL);
737 else
739 // We haven't seen this symbol before.
740 gold_assert(ins.first->second == NULL);
741 add_to_table = true;
742 add_loc = ins.first;
743 oldsym = NULL;
747 if (!target->has_make_symbol())
748 sym = new Sized_symbol<size>();
749 else
751 gold_assert(target->get_size() == size);
752 gold_assert(target->is_big_endian() ? big_endian : !big_endian);
753 typedef Sized_target<size, big_endian> My_target;
754 const My_target* sized_target =
755 static_cast<const My_target*>(target);
756 sym = sized_target->make_symbol();
757 if (sym == NULL)
758 return NULL;
761 if (add_to_table)
762 add_loc->second = sym;
763 else
764 gold_assert(oldsym != NULL);
766 *poldsym = this->get_sized_symbol SELECT_SIZE_NAME(size) (oldsym
767 SELECT_SIZE(size));
769 return sym;
772 // Define a symbol based on an Output_data.
774 Symbol*
775 Symbol_table::define_in_output_data(const Target* target, const char* name,
776 const char* version, Output_data* od,
777 uint64_t value, uint64_t symsize,
778 elfcpp::STT type, elfcpp::STB binding,
779 elfcpp::STV visibility,
780 unsigned char nonvis,
781 bool offset_is_from_end,
782 bool only_if_ref)
784 gold_assert(target->get_size() == this->size_);
785 if (this->size_ == 32)
787 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
788 return this->do_define_in_output_data<32>(target, name, version, od,
789 value, symsize, type, binding,
790 visibility, nonvis,
791 offset_is_from_end,
792 only_if_ref);
793 #else
794 gold_unreachable();
795 #endif
797 else if (this->size_ == 64)
799 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
800 return this->do_define_in_output_data<64>(target, name, version, od,
801 value, symsize, type, binding,
802 visibility, nonvis,
803 offset_is_from_end,
804 only_if_ref);
805 #else
806 gold_unreachable();
807 #endif
809 else
810 gold_unreachable();
813 // Define a symbol in an Output_data, sized version.
815 template<int size>
816 Sized_symbol<size>*
817 Symbol_table::do_define_in_output_data(
818 const Target* target,
819 const char* name,
820 const char* version,
821 Output_data* od,
822 typename elfcpp::Elf_types<size>::Elf_Addr value,
823 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
824 elfcpp::STT type,
825 elfcpp::STB binding,
826 elfcpp::STV visibility,
827 unsigned char nonvis,
828 bool offset_is_from_end,
829 bool only_if_ref)
831 Sized_symbol<size>* sym;
832 Sized_symbol<size>* oldsym;
834 if (target->is_big_endian())
836 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
837 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
838 target, &name, &version, only_if_ref, &oldsym
839 SELECT_SIZE_ENDIAN(size, true));
840 #else
841 gold_unreachable();
842 #endif
844 else
846 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
847 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
848 target, &name, &version, only_if_ref, &oldsym
849 SELECT_SIZE_ENDIAN(size, false));
850 #else
851 gold_unreachable();
852 #endif
855 if (sym == NULL)
856 return NULL;
858 gold_assert(version == NULL || oldsym != NULL);
859 sym->init(name, od, value, symsize, type, binding, visibility, nonvis,
860 offset_is_from_end);
862 if (oldsym != NULL
863 && Symbol_table::should_override_with_special(oldsym))
864 oldsym->override_with_special(sym);
866 return sym;
869 // Define a symbol based on an Output_segment.
871 Symbol*
872 Symbol_table::define_in_output_segment(const Target* target, const char* name,
873 const char* version, Output_segment* os,
874 uint64_t value, uint64_t symsize,
875 elfcpp::STT type, elfcpp::STB binding,
876 elfcpp::STV visibility,
877 unsigned char nonvis,
878 Symbol::Segment_offset_base offset_base,
879 bool only_if_ref)
881 gold_assert(target->get_size() == this->size_);
882 if (this->size_ == 32)
884 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
885 return this->do_define_in_output_segment<32>(target, name, version, os,
886 value, symsize, type,
887 binding, visibility, nonvis,
888 offset_base, only_if_ref);
889 #else
890 gold_unreachable();
891 #endif
893 else if (this->size_ == 64)
895 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
896 return this->do_define_in_output_segment<64>(target, name, version, os,
897 value, symsize, type,
898 binding, visibility, nonvis,
899 offset_base, only_if_ref);
900 #else
901 gold_unreachable();
902 #endif
904 else
905 gold_unreachable();
908 // Define a symbol in an Output_segment, sized version.
910 template<int size>
911 Sized_symbol<size>*
912 Symbol_table::do_define_in_output_segment(
913 const Target* target,
914 const char* name,
915 const char* version,
916 Output_segment* os,
917 typename elfcpp::Elf_types<size>::Elf_Addr value,
918 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
919 elfcpp::STT type,
920 elfcpp::STB binding,
921 elfcpp::STV visibility,
922 unsigned char nonvis,
923 Symbol::Segment_offset_base offset_base,
924 bool only_if_ref)
926 Sized_symbol<size>* sym;
927 Sized_symbol<size>* oldsym;
929 if (target->is_big_endian())
930 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
931 target, &name, &version, only_if_ref, &oldsym
932 SELECT_SIZE_ENDIAN(size, true));
933 else
934 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
935 target, &name, &version, only_if_ref, &oldsym
936 SELECT_SIZE_ENDIAN(size, false));
938 if (sym == NULL)
939 return NULL;
941 gold_assert(version == NULL || oldsym != NULL);
942 sym->init(name, os, value, symsize, type, binding, visibility, nonvis,
943 offset_base);
945 if (oldsym != NULL
946 && Symbol_table::should_override_with_special(oldsym))
947 oldsym->override_with_special(sym);
949 return sym;
952 // Define a special symbol with a constant value. It is a multiple
953 // definition error if this symbol is already defined.
955 Symbol*
956 Symbol_table::define_as_constant(const Target* target, const char* name,
957 const char* version, uint64_t value,
958 uint64_t symsize, elfcpp::STT type,
959 elfcpp::STB binding, elfcpp::STV visibility,
960 unsigned char nonvis, bool only_if_ref)
962 gold_assert(target->get_size() == this->size_);
963 if (this->size_ == 32)
965 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
966 return this->do_define_as_constant<32>(target, name, version, value,
967 symsize, type, binding,
968 visibility, nonvis, only_if_ref);
969 #else
970 gold_unreachable();
971 #endif
973 else if (this->size_ == 64)
975 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
976 return this->do_define_as_constant<64>(target, name, version, value,
977 symsize, type, binding,
978 visibility, nonvis, only_if_ref);
979 #else
980 gold_unreachable();
981 #endif
983 else
984 gold_unreachable();
987 // Define a symbol as a constant, sized version.
989 template<int size>
990 Sized_symbol<size>*
991 Symbol_table::do_define_as_constant(
992 const Target* target,
993 const char* name,
994 const char* version,
995 typename elfcpp::Elf_types<size>::Elf_Addr value,
996 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
997 elfcpp::STT type,
998 elfcpp::STB binding,
999 elfcpp::STV visibility,
1000 unsigned char nonvis,
1001 bool only_if_ref)
1003 Sized_symbol<size>* sym;
1004 Sized_symbol<size>* oldsym;
1006 if (target->is_big_endian())
1007 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1008 target, &name, &version, only_if_ref, &oldsym
1009 SELECT_SIZE_ENDIAN(size, true));
1010 else
1011 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1012 target, &name, &version, only_if_ref, &oldsym
1013 SELECT_SIZE_ENDIAN(size, false));
1015 if (sym == NULL)
1016 return NULL;
1018 gold_assert(version == NULL || oldsym != NULL);
1019 sym->init(name, value, symsize, type, binding, visibility, nonvis);
1021 if (oldsym != NULL
1022 && Symbol_table::should_override_with_special(oldsym))
1023 oldsym->override_with_special(sym);
1025 return sym;
1028 // Define a set of symbols in output sections.
1030 void
1031 Symbol_table::define_symbols(const Layout* layout, const Target* target,
1032 int count, const Define_symbol_in_section* p)
1034 for (int i = 0; i < count; ++i, ++p)
1036 Output_section* os = layout->find_output_section(p->output_section);
1037 if (os != NULL)
1038 this->define_in_output_data(target, p->name, NULL, os, p->value,
1039 p->size, p->type, p->binding,
1040 p->visibility, p->nonvis,
1041 p->offset_is_from_end, p->only_if_ref);
1042 else
1043 this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
1044 p->binding, p->visibility, p->nonvis,
1045 p->only_if_ref);
1049 // Define a set of symbols in output segments.
1051 void
1052 Symbol_table::define_symbols(const Layout* layout, const Target* target,
1053 int count, const Define_symbol_in_segment* p)
1055 for (int i = 0; i < count; ++i, ++p)
1057 Output_segment* os = layout->find_output_segment(p->segment_type,
1058 p->segment_flags_set,
1059 p->segment_flags_clear);
1060 if (os != NULL)
1061 this->define_in_output_segment(target, p->name, NULL, os, p->value,
1062 p->size, p->type, p->binding,
1063 p->visibility, p->nonvis,
1064 p->offset_base, p->only_if_ref);
1065 else
1066 this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
1067 p->binding, p->visibility, p->nonvis,
1068 p->only_if_ref);
1072 // Set the dynamic symbol indexes. INDEX is the index of the first
1073 // global dynamic symbol. Pointers to the symbols are stored into the
1074 // vector SYMS. The names are added to DYNPOOL. This returns an
1075 // updated dynamic symbol index.
1077 unsigned int
1078 Symbol_table::set_dynsym_indexes(const General_options* options,
1079 const Target* target,
1080 unsigned int index,
1081 std::vector<Symbol*>* syms,
1082 Stringpool* dynpool,
1083 Versions* versions)
1085 for (Symbol_table_type::iterator p = this->table_.begin();
1086 p != this->table_.end();
1087 ++p)
1089 Symbol* sym = p->second;
1091 // Note that SYM may already have a dynamic symbol index, since
1092 // some symbols appear more than once in the symbol table, with
1093 // and without a version.
1095 if (!sym->needs_dynsym_entry()
1096 && (!options->export_dynamic()
1097 || !sym->in_reg()
1098 || !sym->is_externally_visible()))
1099 sym->set_dynsym_index(-1U);
1100 else if (!sym->has_dynsym_index())
1102 sym->set_dynsym_index(index);
1103 ++index;
1104 syms->push_back(sym);
1105 dynpool->add(sym->name(), NULL);
1107 // Record any version information.
1108 if (sym->version() != NULL)
1109 versions->record_version(options, dynpool, sym);
1113 // Finish up the versions. In some cases this may add new dynamic
1114 // symbols.
1115 index = versions->finalize(target, this, index, syms);
1117 return index;
1120 // Set the final values for all the symbols. The index of the first
1121 // global symbol in the output file is INDEX. Record the file offset
1122 // OFF. Add their names to POOL. Return the new file offset.
1124 off_t
1125 Symbol_table::finalize(unsigned int index, off_t off, off_t dynoff,
1126 size_t dyn_global_index, size_t dyncount,
1127 Stringpool* pool)
1129 off_t ret;
1131 gold_assert(index != 0);
1132 this->first_global_index_ = index;
1134 this->dynamic_offset_ = dynoff;
1135 this->first_dynamic_global_index_ = dyn_global_index;
1136 this->dynamic_count_ = dyncount;
1138 if (this->size_ == 32)
1139 ret = this->sized_finalize<32>(index, off, pool);
1140 else if (this->size_ == 64)
1141 ret = this->sized_finalize<64>(index, off, pool);
1142 else
1143 gold_unreachable();
1145 // Now that we have the final symbol table, we can reliably note
1146 // which symbols should get warnings.
1147 this->warnings_.note_warnings(this);
1149 return ret;
1152 // Set the final value for all the symbols. This is called after
1153 // Layout::finalize, so all the output sections have their final
1154 // address.
1156 template<int size>
1157 off_t
1158 Symbol_table::sized_finalize(unsigned index, off_t off, Stringpool* pool)
1160 off = align_address(off, size >> 3);
1161 this->offset_ = off;
1163 size_t orig_index = index;
1165 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1166 for (Symbol_table_type::iterator p = this->table_.begin();
1167 p != this->table_.end();
1168 ++p)
1170 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1172 // FIXME: Here we need to decide which symbols should go into
1173 // the output file, based on --strip.
1175 // The default version of a symbol may appear twice in the
1176 // symbol table. We only need to finalize it once.
1177 if (sym->has_symtab_index())
1178 continue;
1180 if (!sym->in_reg())
1182 gold_assert(!sym->has_symtab_index());
1183 sym->set_symtab_index(-1U);
1184 gold_assert(sym->dynsym_index() == -1U);
1185 continue;
1188 typename Sized_symbol<size>::Value_type value;
1190 switch (sym->source())
1192 case Symbol::FROM_OBJECT:
1194 unsigned int shndx = sym->shndx();
1196 // FIXME: We need some target specific support here.
1197 if (shndx >= elfcpp::SHN_LORESERVE
1198 && shndx != elfcpp::SHN_ABS)
1200 fprintf(stderr, _("%s: %s: unsupported symbol section 0x%x\n"),
1201 program_name, sym->name(), shndx);
1202 gold_exit(false);
1205 Object* symobj = sym->object();
1206 if (symobj->is_dynamic())
1208 value = 0;
1209 shndx = elfcpp::SHN_UNDEF;
1211 else if (shndx == elfcpp::SHN_UNDEF)
1212 value = 0;
1213 else if (shndx == elfcpp::SHN_ABS)
1214 value = sym->value();
1215 else
1217 Relobj* relobj = static_cast<Relobj*>(symobj);
1218 off_t secoff;
1219 Output_section* os = relobj->output_section(shndx, &secoff);
1221 if (os == NULL)
1223 sym->set_symtab_index(-1U);
1224 gold_assert(sym->dynsym_index() == -1U);
1225 continue;
1228 value = sym->value() + os->address() + secoff;
1231 break;
1233 case Symbol::IN_OUTPUT_DATA:
1235 Output_data* od = sym->output_data();
1236 value = sym->value() + od->address();
1237 if (sym->offset_is_from_end())
1238 value += od->data_size();
1240 break;
1242 case Symbol::IN_OUTPUT_SEGMENT:
1244 Output_segment* os = sym->output_segment();
1245 value = sym->value() + os->vaddr();
1246 switch (sym->offset_base())
1248 case Symbol::SEGMENT_START:
1249 break;
1250 case Symbol::SEGMENT_END:
1251 value += os->memsz();
1252 break;
1253 case Symbol::SEGMENT_BSS:
1254 value += os->filesz();
1255 break;
1256 default:
1257 gold_unreachable();
1260 break;
1262 case Symbol::CONSTANT:
1263 value = sym->value();
1264 break;
1266 default:
1267 gold_unreachable();
1270 sym->set_value(value);
1271 sym->set_symtab_index(index);
1272 pool->add(sym->name(), NULL);
1273 ++index;
1274 off += sym_size;
1277 this->output_count_ = index - orig_index;
1279 return off;
1282 // Write out the global symbols.
1284 void
1285 Symbol_table::write_globals(const Target* target, const Stringpool* sympool,
1286 const Stringpool* dynpool, Output_file* of) const
1288 if (this->size_ == 32)
1290 if (target->is_big_endian())
1291 this->sized_write_globals<32, true>(target, sympool, dynpool, of);
1292 else
1293 this->sized_write_globals<32, false>(target, sympool, dynpool, of);
1295 else if (this->size_ == 64)
1297 if (target->is_big_endian())
1298 this->sized_write_globals<64, true>(target, sympool, dynpool, of);
1299 else
1300 this->sized_write_globals<64, false>(target, sympool, dynpool, of);
1302 else
1303 gold_unreachable();
1306 // Write out the global symbols.
1308 template<int size, bool big_endian>
1309 void
1310 Symbol_table::sized_write_globals(const Target* target,
1311 const Stringpool* sympool,
1312 const Stringpool* dynpool,
1313 Output_file* of) const
1315 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1316 unsigned int index = this->first_global_index_;
1317 const off_t oview_size = this->output_count_ * sym_size;
1318 unsigned char* const psyms = of->get_output_view(this->offset_, oview_size);
1320 unsigned int dynamic_count = this->dynamic_count_;
1321 off_t dynamic_size = dynamic_count * sym_size;
1322 unsigned int first_dynamic_global_index = this->first_dynamic_global_index_;
1323 unsigned char* dynamic_view;
1324 if (this->dynamic_offset_ == 0)
1325 dynamic_view = NULL;
1326 else
1327 dynamic_view = of->get_output_view(this->dynamic_offset_, dynamic_size);
1329 unsigned char* ps = psyms;
1330 for (Symbol_table_type::const_iterator p = this->table_.begin();
1331 p != this->table_.end();
1332 ++p)
1334 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1336 unsigned int sym_index = sym->symtab_index();
1337 unsigned int dynsym_index;
1338 if (dynamic_view == NULL)
1339 dynsym_index = -1U;
1340 else
1341 dynsym_index = sym->dynsym_index();
1343 if (sym_index == -1U && dynsym_index == -1U)
1345 // This symbol is not included in the output file.
1346 continue;
1349 if (sym_index == index)
1350 ++index;
1351 else if (sym_index != -1U)
1353 // We have already seen this symbol, because it has a
1354 // default version.
1355 gold_assert(sym_index < index);
1356 if (dynsym_index == -1U)
1357 continue;
1358 sym_index = -1U;
1361 unsigned int shndx;
1362 typename elfcpp::Elf_types<32>::Elf_Addr value = sym->value();
1363 switch (sym->source())
1365 case Symbol::FROM_OBJECT:
1367 unsigned int in_shndx = sym->shndx();
1369 // FIXME: We need some target specific support here.
1370 if (in_shndx >= elfcpp::SHN_LORESERVE
1371 && in_shndx != elfcpp::SHN_ABS)
1373 fprintf(stderr, _("%s: %s: unsupported symbol section 0x%x\n"),
1374 program_name, sym->name(), in_shndx);
1375 gold_exit(false);
1378 Object* symobj = sym->object();
1379 if (symobj->is_dynamic())
1381 if (sym->needs_dynsym_value())
1382 value = target->dynsym_value(sym);
1383 shndx = elfcpp::SHN_UNDEF;
1385 else if (in_shndx == elfcpp::SHN_UNDEF
1386 || in_shndx == elfcpp::SHN_ABS)
1387 shndx = in_shndx;
1388 else
1390 Relobj* relobj = static_cast<Relobj*>(symobj);
1391 off_t secoff;
1392 Output_section* os = relobj->output_section(in_shndx, &secoff);
1393 gold_assert(os != NULL);
1394 shndx = os->out_shndx();
1397 break;
1399 case Symbol::IN_OUTPUT_DATA:
1400 shndx = sym->output_data()->out_shndx();
1401 break;
1403 case Symbol::IN_OUTPUT_SEGMENT:
1404 shndx = elfcpp::SHN_ABS;
1405 break;
1407 case Symbol::CONSTANT:
1408 shndx = elfcpp::SHN_ABS;
1409 break;
1411 default:
1412 gold_unreachable();
1415 if (sym_index != -1U)
1417 this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
1418 sym, sym->value(), shndx, sympool, ps
1419 SELECT_SIZE_ENDIAN(size, big_endian));
1420 ps += sym_size;
1423 if (dynsym_index != -1U)
1425 dynsym_index -= first_dynamic_global_index;
1426 gold_assert(dynsym_index < dynamic_count);
1427 unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
1428 this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
1429 sym, value, shndx, dynpool, pd
1430 SELECT_SIZE_ENDIAN(size, big_endian));
1434 gold_assert(ps - psyms == oview_size);
1436 of->write_output_view(this->offset_, oview_size, psyms);
1437 if (dynamic_view != NULL)
1438 of->write_output_view(this->dynamic_offset_, dynamic_size, dynamic_view);
1441 // Write out the symbol SYM, in section SHNDX, to P. POOL is the
1442 // strtab holding the name.
1444 template<int size, bool big_endian>
1445 void
1446 Symbol_table::sized_write_symbol(
1447 Sized_symbol<size>* sym,
1448 typename elfcpp::Elf_types<size>::Elf_Addr value,
1449 unsigned int shndx,
1450 const Stringpool* pool,
1451 unsigned char* p
1452 ACCEPT_SIZE_ENDIAN) const
1454 elfcpp::Sym_write<size, big_endian> osym(p);
1455 osym.put_st_name(pool->get_offset(sym->name()));
1456 osym.put_st_value(value);
1457 osym.put_st_size(sym->symsize());
1458 osym.put_st_info(elfcpp::elf_st_info(sym->binding(), sym->type()));
1459 osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
1460 osym.put_st_shndx(shndx);
1463 // Write out a section symbol. Return the update offset.
1465 void
1466 Symbol_table::write_section_symbol(const Target* target,
1467 const Output_section *os,
1468 Output_file* of,
1469 off_t offset) const
1471 if (this->size_ == 32)
1473 if (target->is_big_endian())
1474 this->sized_write_section_symbol<32, true>(os, of, offset);
1475 else
1476 this->sized_write_section_symbol<32, false>(os, of, offset);
1478 else if (this->size_ == 64)
1480 if (target->is_big_endian())
1481 this->sized_write_section_symbol<64, true>(os, of, offset);
1482 else
1483 this->sized_write_section_symbol<64, false>(os, of, offset);
1485 else
1486 gold_unreachable();
1489 // Write out a section symbol, specialized for size and endianness.
1491 template<int size, bool big_endian>
1492 void
1493 Symbol_table::sized_write_section_symbol(const Output_section* os,
1494 Output_file* of,
1495 off_t offset) const
1497 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1499 unsigned char* pov = of->get_output_view(offset, sym_size);
1501 elfcpp::Sym_write<size, big_endian> osym(pov);
1502 osym.put_st_name(0);
1503 osym.put_st_value(os->address());
1504 osym.put_st_size(0);
1505 osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
1506 elfcpp::STT_SECTION));
1507 osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
1508 osym.put_st_shndx(os->out_shndx());
1510 of->write_output_view(offset, sym_size, pov);
1513 // Warnings functions.
1515 // Add a new warning.
1517 void
1518 Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
1519 unsigned int shndx)
1521 name = symtab->canonicalize_name(name);
1522 this->warnings_[name].set(obj, shndx);
1525 // Look through the warnings and mark the symbols for which we should
1526 // warn. This is called during Layout::finalize when we know the
1527 // sources for all the symbols.
1529 void
1530 Warnings::note_warnings(Symbol_table* symtab)
1532 for (Warning_table::iterator p = this->warnings_.begin();
1533 p != this->warnings_.end();
1534 ++p)
1536 Symbol* sym = symtab->lookup(p->first, NULL);
1537 if (sym != NULL
1538 && sym->source() == Symbol::FROM_OBJECT
1539 && sym->object() == p->second.object)
1541 sym->set_has_warning();
1543 // Read the section contents to get the warning text. It
1544 // would be nicer if we only did this if we have to actually
1545 // issue a warning. Unfortunately, warnings are issued as
1546 // we relocate sections. That means that we can not lock
1547 // the object then, as we might try to issue the same
1548 // warning multiple times simultaneously.
1550 Task_locker_obj<Object> tl(*p->second.object);
1551 const unsigned char* c;
1552 off_t len;
1553 c = p->second.object->section_contents(p->second.shndx, &len);
1554 p->second.set_text(reinterpret_cast<const char*>(c), len);
1560 // Issue a warning. This is called when we see a relocation against a
1561 // symbol for which has a warning.
1563 void
1564 Warnings::issue_warning(const Symbol* sym, const std::string& location) const
1566 gold_assert(sym->has_warning());
1567 Warning_table::const_iterator p = this->warnings_.find(sym->name());
1568 gold_assert(p != this->warnings_.end());
1569 fprintf(stderr, _("%s: %s: warning: %s\n"), program_name, location.c_str(),
1570 p->second.text.c_str());
1573 // Instantiate the templates we need. We could use the configure
1574 // script to restrict this to only the ones needed for implemented
1575 // targets.
1577 #ifdef HAVE_TARGET_32_LITTLE
1578 template
1579 void
1580 Symbol_table::add_from_relobj<32, false>(
1581 Sized_relobj<32, false>* relobj,
1582 const unsigned char* syms,
1583 size_t count,
1584 const char* sym_names,
1585 size_t sym_name_size,
1586 Symbol** sympointers);
1587 #endif
1589 #ifdef HAVE_TARGET_32_BIG
1590 template
1591 void
1592 Symbol_table::add_from_relobj<32, true>(
1593 Sized_relobj<32, true>* relobj,
1594 const unsigned char* syms,
1595 size_t count,
1596 const char* sym_names,
1597 size_t sym_name_size,
1598 Symbol** sympointers);
1599 #endif
1601 #ifdef HAVE_TARGET_64_LITTLE
1602 template
1603 void
1604 Symbol_table::add_from_relobj<64, false>(
1605 Sized_relobj<64, false>* relobj,
1606 const unsigned char* syms,
1607 size_t count,
1608 const char* sym_names,
1609 size_t sym_name_size,
1610 Symbol** sympointers);
1611 #endif
1613 #ifdef HAVE_TARGET_64_BIG
1614 template
1615 void
1616 Symbol_table::add_from_relobj<64, true>(
1617 Sized_relobj<64, true>* relobj,
1618 const unsigned char* syms,
1619 size_t count,
1620 const char* sym_names,
1621 size_t sym_name_size,
1622 Symbol** sympointers);
1623 #endif
1625 #ifdef HAVE_TARGET_32_LITTLE
1626 template
1627 void
1628 Symbol_table::add_from_dynobj<32, false>(
1629 Sized_dynobj<32, false>* dynobj,
1630 const unsigned char* syms,
1631 size_t count,
1632 const char* sym_names,
1633 size_t sym_name_size,
1634 const unsigned char* versym,
1635 size_t versym_size,
1636 const std::vector<const char*>* version_map);
1637 #endif
1639 #ifdef HAVE_TARGET_32_BIG
1640 template
1641 void
1642 Symbol_table::add_from_dynobj<32, true>(
1643 Sized_dynobj<32, true>* dynobj,
1644 const unsigned char* syms,
1645 size_t count,
1646 const char* sym_names,
1647 size_t sym_name_size,
1648 const unsigned char* versym,
1649 size_t versym_size,
1650 const std::vector<const char*>* version_map);
1651 #endif
1653 #ifdef HAVE_TARGET_64_LITTLE
1654 template
1655 void
1656 Symbol_table::add_from_dynobj<64, false>(
1657 Sized_dynobj<64, false>* dynobj,
1658 const unsigned char* syms,
1659 size_t count,
1660 const char* sym_names,
1661 size_t sym_name_size,
1662 const unsigned char* versym,
1663 size_t versym_size,
1664 const std::vector<const char*>* version_map);
1665 #endif
1667 #ifdef HAVE_TARGET_64_BIG
1668 template
1669 void
1670 Symbol_table::add_from_dynobj<64, true>(
1671 Sized_dynobj<64, true>* dynobj,
1672 const unsigned char* syms,
1673 size_t count,
1674 const char* sym_names,
1675 size_t sym_name_size,
1676 const unsigned char* versym,
1677 size_t versym_size,
1678 const std::vector<const char*>* version_map);
1679 #endif
1681 } // End namespace gold.