From Andrew Chatham and Craig Silverstein: Add support for version
[binutils-gdb.git] / gold / symtab.cc
1 // symtab.cc -- the gold symbol table
2
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #include "gold.h"
24
25 #include <stdint.h>
26 #include <set>
27 #include <string>
28 #include <utility>
29 #include "demangle.h"
30
31 #include "object.h"
32 #include "dwarf_reader.h"
33 #include "dynobj.h"
34 #include "output.h"
35 #include "target.h"
36 #include "workqueue.h"
37 #include "symtab.h"
38
39 namespace gold
40 {
41
42 // Class Symbol.
43
44 // Initialize fields in Symbol. This initializes everything except u_
45 // and source_.
46
47 void
48 Symbol::init_fields(const char* name, const char* version,
49 elfcpp::STT type, elfcpp::STB binding,
50 elfcpp::STV visibility, unsigned char nonvis)
51 {
52 this->name_ = name;
53 this->version_ = version;
54 this->symtab_index_ = 0;
55 this->dynsym_index_ = 0;
56 this->got_offset_ = 0;
57 this->plt_offset_ = 0;
58 this->type_ = type;
59 this->binding_ = binding;
60 this->visibility_ = visibility;
61 this->nonvis_ = nonvis;
62 this->is_target_special_ = false;
63 this->is_def_ = false;
64 this->is_forwarder_ = false;
65 this->has_alias_ = false;
66 this->needs_dynsym_entry_ = false;
67 this->in_reg_ = false;
68 this->in_dyn_ = false;
69 this->has_got_offset_ = false;
70 this->has_plt_offset_ = false;
71 this->has_warning_ = false;
72 this->is_copied_from_dynobj_ = false;
73 }
74
75 // Return the demangled version of the symbol's name, but only
76 // if the --demangle flag was set.
77
78 static std::string
79 demangle(const char* name)
80 {
81 if (!parameters->demangle())
82 return name;
83
84 // cplus_demangle allocates memory for the result it returns,
85 // and returns NULL if the name is already demangled.
86 char* demangled_name = cplus_demangle(name, DMGL_ANSI | DMGL_PARAMS);
87 if (demangled_name == NULL)
88 return name;
89
90 std::string retval(demangled_name);
91 free(demangled_name);
92 return retval;
93 }
94
95 std::string
96 Symbol::demangled_name() const
97 {
98 return demangle(this->name());
99 }
100
101 // Initialize the fields in the base class Symbol for SYM in OBJECT.
102
103 template<int size, bool big_endian>
104 void
105 Symbol::init_base(const char* name, const char* version, Object* object,
106 const elfcpp::Sym<size, big_endian>& sym)
107 {
108 this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
109 sym.get_st_visibility(), sym.get_st_nonvis());
110 this->u_.from_object.object = object;
111 // FIXME: Handle SHN_XINDEX.
112 this->u_.from_object.shndx = sym.get_st_shndx();
113 this->source_ = FROM_OBJECT;
114 this->in_reg_ = !object->is_dynamic();
115 this->in_dyn_ = object->is_dynamic();
116 }
117
118 // Initialize the fields in the base class Symbol for a symbol defined
119 // in an Output_data.
120
121 void
122 Symbol::init_base(const char* name, Output_data* od, elfcpp::STT type,
123 elfcpp::STB binding, elfcpp::STV visibility,
124 unsigned char nonvis, bool offset_is_from_end)
125 {
126 this->init_fields(name, NULL, type, binding, visibility, nonvis);
127 this->u_.in_output_data.output_data = od;
128 this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
129 this->source_ = IN_OUTPUT_DATA;
130 this->in_reg_ = true;
131 }
132
133 // Initialize the fields in the base class Symbol for a symbol defined
134 // in an Output_segment.
135
136 void
137 Symbol::init_base(const char* name, Output_segment* os, elfcpp::STT type,
138 elfcpp::STB binding, elfcpp::STV visibility,
139 unsigned char nonvis, Segment_offset_base offset_base)
140 {
141 this->init_fields(name, NULL, type, binding, visibility, nonvis);
142 this->u_.in_output_segment.output_segment = os;
143 this->u_.in_output_segment.offset_base = offset_base;
144 this->source_ = IN_OUTPUT_SEGMENT;
145 this->in_reg_ = true;
146 }
147
148 // Initialize the fields in the base class Symbol for a symbol defined
149 // as a constant.
150
151 void
152 Symbol::init_base(const char* name, elfcpp::STT type,
153 elfcpp::STB binding, elfcpp::STV visibility,
154 unsigned char nonvis)
155 {
156 this->init_fields(name, NULL, type, binding, visibility, nonvis);
157 this->source_ = CONSTANT;
158 this->in_reg_ = true;
159 }
160
161 // Allocate a common symbol in the base.
162
163 void
164 Symbol::allocate_base_common(Output_data* od)
165 {
166 gold_assert(this->is_common());
167 this->source_ = IN_OUTPUT_DATA;
168 this->u_.in_output_data.output_data = od;
169 this->u_.in_output_data.offset_is_from_end = false;
170 }
171
172 // Initialize the fields in Sized_symbol for SYM in OBJECT.
173
174 template<int size>
175 template<bool big_endian>
176 void
177 Sized_symbol<size>::init(const char* name, const char* version, Object* object,
178 const elfcpp::Sym<size, big_endian>& sym)
179 {
180 this->init_base(name, version, object, sym);
181 this->value_ = sym.get_st_value();
182 this->symsize_ = sym.get_st_size();
183 }
184
185 // Initialize the fields in Sized_symbol for a symbol defined in an
186 // Output_data.
187
188 template<int size>
189 void
190 Sized_symbol<size>::init(const char* name, Output_data* od,
191 Value_type value, Size_type symsize,
192 elfcpp::STT type, elfcpp::STB binding,
193 elfcpp::STV visibility, unsigned char nonvis,
194 bool offset_is_from_end)
195 {
196 this->init_base(name, od, type, binding, visibility, nonvis,
197 offset_is_from_end);
198 this->value_ = value;
199 this->symsize_ = symsize;
200 }
201
202 // Initialize the fields in Sized_symbol for a symbol defined in an
203 // Output_segment.
204
205 template<int size>
206 void
207 Sized_symbol<size>::init(const char* name, Output_segment* os,
208 Value_type value, Size_type symsize,
209 elfcpp::STT type, elfcpp::STB binding,
210 elfcpp::STV visibility, unsigned char nonvis,
211 Segment_offset_base offset_base)
212 {
213 this->init_base(name, os, type, binding, visibility, nonvis, offset_base);
214 this->value_ = value;
215 this->symsize_ = symsize;
216 }
217
218 // Initialize the fields in Sized_symbol for a symbol defined as a
219 // constant.
220
221 template<int size>
222 void
223 Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
224 elfcpp::STT type, elfcpp::STB binding,
225 elfcpp::STV visibility, unsigned char nonvis)
226 {
227 this->init_base(name, type, binding, visibility, nonvis);
228 this->value_ = value;
229 this->symsize_ = symsize;
230 }
231
232 // Allocate a common symbol.
233
234 template<int size>
235 void
236 Sized_symbol<size>::allocate_common(Output_data* od, Value_type value)
237 {
238 this->allocate_base_common(od);
239 this->value_ = value;
240 }
241
242 // Return true if this symbol should be added to the dynamic symbol
243 // table.
244
245 inline bool
246 Symbol::should_add_dynsym_entry() const
247 {
248 // If the symbol is used by a dynamic relocation, we need to add it.
249 if (this->needs_dynsym_entry())
250 return true;
251
252 // If exporting all symbols or building a shared library,
253 // and the symbol is defined in a regular object and is
254 // externally visible, we need to add it.
255 if ((parameters->export_dynamic() || parameters->output_is_shared())
256 && !this->is_from_dynobj()
257 && this->is_externally_visible())
258 return true;
259
260 return false;
261 }
262
263 // Return true if the final value of this symbol is known at link
264 // time.
265
266 bool
267 Symbol::final_value_is_known() const
268 {
269 // If we are not generating an executable, then no final values are
270 // known, since they will change at runtime.
271 if (!parameters->output_is_executable())
272 return false;
273
274 // If the symbol is not from an object file, then it is defined, and
275 // known.
276 if (this->source_ != FROM_OBJECT)
277 return true;
278
279 // If the symbol is from a dynamic object, then the final value is
280 // not known.
281 if (this->object()->is_dynamic())
282 return false;
283
284 // If the symbol is not undefined (it is defined or common), then
285 // the final value is known.
286 if (!this->is_undefined())
287 return true;
288
289 // If the symbol is undefined, then whether the final value is known
290 // depends on whether we are doing a static link. If we are doing a
291 // dynamic link, then the final value could be filled in at runtime.
292 // This could reasonably be the case for a weak undefined symbol.
293 return parameters->doing_static_link();
294 }
295
296 // Class Symbol_table.
297
298 Symbol_table::Symbol_table(unsigned int count,
299 const Version_script_info& version_script)
300 : saw_undefined_(0), offset_(0), table_(count), namepool_(),
301 forwarders_(), commons_(), warnings_(), version_script_(version_script)
302 {
303 namepool_.reserve(count);
304 }
305
306 Symbol_table::~Symbol_table()
307 {
308 }
309
310 // The hash function. The key values are Stringpool keys.
311
312 inline size_t
313 Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key& key) const
314 {
315 return key.first ^ key.second;
316 }
317
318 // The symbol table key equality function. This is called with
319 // Stringpool keys.
320
321 inline bool
322 Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
323 const Symbol_table_key& k2) const
324 {
325 return k1.first == k2.first && k1.second == k2.second;
326 }
327
328 // Make TO a symbol which forwards to FROM.
329
330 void
331 Symbol_table::make_forwarder(Symbol* from, Symbol* to)
332 {
333 gold_assert(from != to);
334 gold_assert(!from->is_forwarder() && !to->is_forwarder());
335 this->forwarders_[from] = to;
336 from->set_forwarder();
337 }
338
339 // Resolve the forwards from FROM, returning the real symbol.
340
341 Symbol*
342 Symbol_table::resolve_forwards(const Symbol* from) const
343 {
344 gold_assert(from->is_forwarder());
345 Unordered_map<const Symbol*, Symbol*>::const_iterator p =
346 this->forwarders_.find(from);
347 gold_assert(p != this->forwarders_.end());
348 return p->second;
349 }
350
351 // Look up a symbol by name.
352
353 Symbol*
354 Symbol_table::lookup(const char* name, const char* version) const
355 {
356 Stringpool::Key name_key;
357 name = this->namepool_.find(name, &name_key);
358 if (name == NULL)
359 return NULL;
360
361 Stringpool::Key version_key = 0;
362 if (version != NULL)
363 {
364 version = this->namepool_.find(version, &version_key);
365 if (version == NULL)
366 return NULL;
367 }
368
369 Symbol_table_key key(name_key, version_key);
370 Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
371 if (p == this->table_.end())
372 return NULL;
373 return p->second;
374 }
375
376 // Resolve a Symbol with another Symbol. This is only used in the
377 // unusual case where there are references to both an unversioned
378 // symbol and a symbol with a version, and we then discover that that
379 // version is the default version. Because this is unusual, we do
380 // this the slow way, by converting back to an ELF symbol.
381
382 template<int size, bool big_endian>
383 void
384 Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
385 const char* version ACCEPT_SIZE_ENDIAN)
386 {
387 unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
388 elfcpp::Sym_write<size, big_endian> esym(buf);
389 // We don't bother to set the st_name field.
390 esym.put_st_value(from->value());
391 esym.put_st_size(from->symsize());
392 esym.put_st_info(from->binding(), from->type());
393 esym.put_st_other(from->visibility(), from->nonvis());
394 esym.put_st_shndx(from->shndx());
395 this->resolve(to, esym.sym(), esym.sym(), from->object(), version);
396 if (from->in_reg())
397 to->set_in_reg();
398 if (from->in_dyn())
399 to->set_in_dyn();
400 }
401
402 // Add one symbol from OBJECT to the symbol table. NAME is symbol
403 // name and VERSION is the version; both are canonicalized. DEF is
404 // whether this is the default version.
405
406 // If DEF is true, then this is the definition of a default version of
407 // a symbol. That means that any lookup of NAME/NULL and any lookup
408 // of NAME/VERSION should always return the same symbol. This is
409 // obvious for references, but in particular we want to do this for
410 // definitions: overriding NAME/NULL should also override
411 // NAME/VERSION. If we don't do that, it would be very hard to
412 // override functions in a shared library which uses versioning.
413
414 // We implement this by simply making both entries in the hash table
415 // point to the same Symbol structure. That is easy enough if this is
416 // the first time we see NAME/NULL or NAME/VERSION, but it is possible
417 // that we have seen both already, in which case they will both have
418 // independent entries in the symbol table. We can't simply change
419 // the symbol table entry, because we have pointers to the entries
420 // attached to the object files. So we mark the entry attached to the
421 // object file as a forwarder, and record it in the forwarders_ map.
422 // Note that entries in the hash table will never be marked as
423 // forwarders.
424 //
425 // SYM and ORIG_SYM are almost always the same. ORIG_SYM is the
426 // symbol exactly as it existed in the input file. SYM is usually
427 // that as well, but can be modified, for instance if we determine
428 // it's in a to-be-discarded section.
429
430 template<int size, bool big_endian>
431 Sized_symbol<size>*
432 Symbol_table::add_from_object(Object* object,
433 const char *name,
434 Stringpool::Key name_key,
435 const char *version,
436 Stringpool::Key version_key,
437 bool def,
438 const elfcpp::Sym<size, big_endian>& sym,
439 const elfcpp::Sym<size, big_endian>& orig_sym)
440 {
441 Symbol* const snull = NULL;
442 std::pair<typename Symbol_table_type::iterator, bool> ins =
443 this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
444 snull));
445
446 std::pair<typename Symbol_table_type::iterator, bool> insdef =
447 std::make_pair(this->table_.end(), false);
448 if (def)
449 {
450 const Stringpool::Key vnull_key = 0;
451 insdef = this->table_.insert(std::make_pair(std::make_pair(name_key,
452 vnull_key),
453 snull));
454 }
455
456 // ins.first: an iterator, which is a pointer to a pair.
457 // ins.first->first: the key (a pair of name and version).
458 // ins.first->second: the value (Symbol*).
459 // ins.second: true if new entry was inserted, false if not.
460
461 Sized_symbol<size>* ret;
462 bool was_undefined;
463 bool was_common;
464 if (!ins.second)
465 {
466 // We already have an entry for NAME/VERSION.
467 ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (ins.first->second
468 SELECT_SIZE(size));
469 gold_assert(ret != NULL);
470
471 was_undefined = ret->is_undefined();
472 was_common = ret->is_common();
473
474 this->resolve(ret, sym, orig_sym, object, version);
475
476 if (def)
477 {
478 if (insdef.second)
479 {
480 // This is the first time we have seen NAME/NULL. Make
481 // NAME/NULL point to NAME/VERSION.
482 insdef.first->second = ret;
483 }
484 else if (insdef.first->second != ret
485 && insdef.first->second->is_undefined())
486 {
487 // This is the unfortunate case where we already have
488 // entries for both NAME/VERSION and NAME/NULL. Note
489 // that we don't want to combine them if the existing
490 // symbol is going to override the new one. FIXME: We
491 // currently just test is_undefined, but this may not do
492 // the right thing if the existing symbol is from a
493 // shared library and the new one is from a regular
494 // object.
495
496 const Sized_symbol<size>* sym2;
497 sym2 = this->get_sized_symbol SELECT_SIZE_NAME(size) (
498 insdef.first->second
499 SELECT_SIZE(size));
500 Symbol_table::resolve SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
501 ret, sym2, version SELECT_SIZE_ENDIAN(size, big_endian));
502 this->make_forwarder(insdef.first->second, ret);
503 insdef.first->second = ret;
504 }
505 }
506 }
507 else
508 {
509 // This is the first time we have seen NAME/VERSION.
510 gold_assert(ins.first->second == NULL);
511
512 was_undefined = false;
513 was_common = false;
514
515 if (def && !insdef.second)
516 {
517 // We already have an entry for NAME/NULL. If we override
518 // it, then change it to NAME/VERSION.
519 ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (
520 insdef.first->second
521 SELECT_SIZE(size));
522 this->resolve(ret, sym, orig_sym, object, version);
523 ins.first->second = ret;
524 }
525 else
526 {
527 Sized_target<size, big_endian>* target =
528 object->sized_target SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
529 SELECT_SIZE_ENDIAN_ONLY(size, big_endian));
530 if (!target->has_make_symbol())
531 ret = new Sized_symbol<size>();
532 else
533 {
534 ret = target->make_symbol();
535 if (ret == NULL)
536 {
537 // This means that we don't want a symbol table
538 // entry after all.
539 if (!def)
540 this->table_.erase(ins.first);
541 else
542 {
543 this->table_.erase(insdef.first);
544 // Inserting insdef invalidated ins.
545 this->table_.erase(std::make_pair(name_key,
546 version_key));
547 }
548 return NULL;
549 }
550 }
551
552 ret->init(name, version, object, sym);
553
554 ins.first->second = ret;
555 if (def)
556 {
557 // This is the first time we have seen NAME/NULL. Point
558 // it at the new entry for NAME/VERSION.
559 gold_assert(insdef.second);
560 insdef.first->second = ret;
561 }
562 }
563 }
564
565 // Record every time we see a new undefined symbol, to speed up
566 // archive groups.
567 if (!was_undefined && ret->is_undefined())
568 ++this->saw_undefined_;
569
570 // Keep track of common symbols, to speed up common symbol
571 // allocation.
572 if (!was_common && ret->is_common())
573 this->commons_.push_back(ret);
574
575 ret->set_is_default(def);
576 return ret;
577 }
578
579 // Add all the symbols in a relocatable object to the hash table.
580
581 template<int size, bool big_endian>
582 void
583 Symbol_table::add_from_relobj(
584 Sized_relobj<size, big_endian>* relobj,
585 const unsigned char* syms,
586 size_t count,
587 const char* sym_names,
588 size_t sym_name_size,
589 typename Sized_relobj<size, big_endian>::Symbols* sympointers)
590 {
591 gold_assert(size == relobj->target()->get_size());
592 gold_assert(size == parameters->get_size());
593
594 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
595
596 const unsigned char* p = syms;
597 for (size_t i = 0; i < count; ++i, p += sym_size)
598 {
599 elfcpp::Sym<size, big_endian> sym(p);
600 elfcpp::Sym<size, big_endian>* psym = &sym;
601
602 unsigned int st_name = psym->get_st_name();
603 if (st_name >= sym_name_size)
604 {
605 relobj->error(_("bad global symbol name offset %u at %zu"),
606 st_name, i);
607 continue;
608 }
609
610 const char* name = sym_names + st_name;
611
612 // A symbol defined in a section which we are not including must
613 // be treated as an undefined symbol.
614 unsigned char symbuf[sym_size];
615 elfcpp::Sym<size, big_endian> sym2(symbuf);
616 unsigned int st_shndx = psym->get_st_shndx();
617 if (st_shndx != elfcpp::SHN_UNDEF
618 && st_shndx < elfcpp::SHN_LORESERVE
619 && !relobj->is_section_included(st_shndx))
620 {
621 memcpy(symbuf, p, sym_size);
622 elfcpp::Sym_write<size, big_endian> sw(symbuf);
623 sw.put_st_shndx(elfcpp::SHN_UNDEF);
624 psym = &sym2;
625 }
626
627 // In an object file, an '@' in the name separates the symbol
628 // name from the version name. If there are two '@' characters,
629 // this is the default version.
630 const char* ver = strchr(name, '@');
631 int namelen = 0;
632 bool def = false;
633
634 if (ver != NULL)
635 {
636 // The symbol name is of the form foo@VERSION or foo@@VERSION
637 namelen = ver - name;
638 ++ver;
639 if (*ver == '@')
640 {
641 def = true;
642 ++ver;
643 }
644 }
645 else if (!version_script_.empty())
646 {
647 // The symbol name did not have a version, but
648 // the version script may assign a version anyway.
649 namelen = strlen(name);
650 def = true;
651 const std::string& version =
652 version_script_.get_symbol_version(name);
653 if (!version.empty())
654 ver = version.c_str();
655 }
656
657 Sized_symbol<size>* res;
658 if (ver == NULL)
659 {
660 Stringpool::Key name_key;
661 name = this->namepool_.add(name, true, &name_key);
662 res = this->add_from_object(relobj, name, name_key, NULL, 0,
663 false, *psym, sym);
664 }
665 else
666 {
667 Stringpool::Key name_key;
668 name = this->namepool_.add_with_length(name, namelen, true,
669 &name_key);
670 Stringpool::Key ver_key;
671 ver = this->namepool_.add(ver, true, &ver_key);
672
673 res = this->add_from_object(relobj, name, name_key, ver, ver_key,
674 def, *psym, sym);
675 }
676
677 (*sympointers)[i] = res;
678 }
679 }
680
681 // Add all the symbols in a dynamic object to the hash table.
682
683 template<int size, bool big_endian>
684 void
685 Symbol_table::add_from_dynobj(
686 Sized_dynobj<size, big_endian>* dynobj,
687 const unsigned char* syms,
688 size_t count,
689 const char* sym_names,
690 size_t sym_name_size,
691 const unsigned char* versym,
692 size_t versym_size,
693 const std::vector<const char*>* version_map)
694 {
695 gold_assert(size == dynobj->target()->get_size());
696 gold_assert(size == parameters->get_size());
697
698 if (versym != NULL && versym_size / 2 < count)
699 {
700 dynobj->error(_("too few symbol versions"));
701 return;
702 }
703
704 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
705
706 // We keep a list of all STT_OBJECT symbols, so that we can resolve
707 // weak aliases. This is necessary because if the dynamic object
708 // provides the same variable under two names, one of which is a
709 // weak definition, and the regular object refers to the weak
710 // definition, we have to put both the weak definition and the
711 // strong definition into the dynamic symbol table. Given a weak
712 // definition, the only way that we can find the corresponding
713 // strong definition, if any, is to search the symbol table.
714 std::vector<Sized_symbol<size>*> object_symbols;
715
716 const unsigned char* p = syms;
717 const unsigned char* vs = versym;
718 for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
719 {
720 elfcpp::Sym<size, big_endian> sym(p);
721
722 // Ignore symbols with local binding.
723 if (sym.get_st_bind() == elfcpp::STB_LOCAL)
724 continue;
725
726 unsigned int st_name = sym.get_st_name();
727 if (st_name >= sym_name_size)
728 {
729 dynobj->error(_("bad symbol name offset %u at %zu"),
730 st_name, i);
731 continue;
732 }
733
734 const char* name = sym_names + st_name;
735
736 Sized_symbol<size>* res;
737
738 if (versym == NULL)
739 {
740 Stringpool::Key name_key;
741 name = this->namepool_.add(name, true, &name_key);
742 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
743 false, sym, sym);
744 }
745 else
746 {
747 // Read the version information.
748
749 unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
750
751 bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
752 v &= elfcpp::VERSYM_VERSION;
753
754 // The Sun documentation says that V can be VER_NDX_LOCAL,
755 // or VER_NDX_GLOBAL, or a version index. The meaning of
756 // VER_NDX_LOCAL is defined as "Symbol has local scope."
757 // The old GNU linker will happily generate VER_NDX_LOCAL
758 // for an undefined symbol. I don't know what the Sun
759 // linker will generate.
760
761 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
762 && sym.get_st_shndx() != elfcpp::SHN_UNDEF)
763 {
764 // This symbol should not be visible outside the object.
765 continue;
766 }
767
768 // At this point we are definitely going to add this symbol.
769 Stringpool::Key name_key;
770 name = this->namepool_.add(name, true, &name_key);
771
772 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
773 || v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
774 {
775 // This symbol does not have a version.
776 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
777 false, sym, sym);
778 }
779 else
780 {
781 if (v >= version_map->size())
782 {
783 dynobj->error(_("versym for symbol %zu out of range: %u"),
784 i, v);
785 continue;
786 }
787
788 const char* version = (*version_map)[v];
789 if (version == NULL)
790 {
791 dynobj->error(_("versym for symbol %zu has no name: %u"),
792 i, v);
793 continue;
794 }
795
796 Stringpool::Key version_key;
797 version = this->namepool_.add(version, true, &version_key);
798
799 // If this is an absolute symbol, and the version name
800 // and symbol name are the same, then this is the
801 // version definition symbol. These symbols exist to
802 // support using -u to pull in particular versions. We
803 // do not want to record a version for them.
804 if (sym.get_st_shndx() == elfcpp::SHN_ABS
805 && name_key == version_key)
806 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
807 false, sym, sym);
808 else
809 {
810 const bool def = (!hidden
811 && (sym.get_st_shndx()
812 != elfcpp::SHN_UNDEF));
813 res = this->add_from_object(dynobj, name, name_key, version,
814 version_key, def, sym, sym);
815 }
816 }
817 }
818
819 if (sym.get_st_shndx() != elfcpp::SHN_UNDEF
820 && sym.get_st_type() == elfcpp::STT_OBJECT)
821 object_symbols.push_back(res);
822 }
823
824 this->record_weak_aliases(&object_symbols);
825 }
826
827 // This is used to sort weak aliases. We sort them first by section
828 // index, then by offset, then by weak ahead of strong.
829
830 template<int size>
831 class Weak_alias_sorter
832 {
833 public:
834 bool operator()(const Sized_symbol<size>*, const Sized_symbol<size>*) const;
835 };
836
837 template<int size>
838 bool
839 Weak_alias_sorter<size>::operator()(const Sized_symbol<size>* s1,
840 const Sized_symbol<size>* s2) const
841 {
842 if (s1->shndx() != s2->shndx())
843 return s1->shndx() < s2->shndx();
844 if (s1->value() != s2->value())
845 return s1->value() < s2->value();
846 if (s1->binding() != s2->binding())
847 {
848 if (s1->binding() == elfcpp::STB_WEAK)
849 return true;
850 if (s2->binding() == elfcpp::STB_WEAK)
851 return false;
852 }
853 return std::string(s1->name()) < std::string(s2->name());
854 }
855
856 // SYMBOLS is a list of object symbols from a dynamic object. Look
857 // for any weak aliases, and record them so that if we add the weak
858 // alias to the dynamic symbol table, we also add the corresponding
859 // strong symbol.
860
861 template<int size>
862 void
863 Symbol_table::record_weak_aliases(std::vector<Sized_symbol<size>*>* symbols)
864 {
865 // Sort the vector by section index, then by offset, then by weak
866 // ahead of strong.
867 std::sort(symbols->begin(), symbols->end(), Weak_alias_sorter<size>());
868
869 // Walk through the vector. For each weak definition, record
870 // aliases.
871 for (typename std::vector<Sized_symbol<size>*>::const_iterator p =
872 symbols->begin();
873 p != symbols->end();
874 ++p)
875 {
876 if ((*p)->binding() != elfcpp::STB_WEAK)
877 continue;
878
879 // Build a circular list of weak aliases. Each symbol points to
880 // the next one in the circular list.
881
882 Sized_symbol<size>* from_sym = *p;
883 typename std::vector<Sized_symbol<size>*>::const_iterator q;
884 for (q = p + 1; q != symbols->end(); ++q)
885 {
886 if ((*q)->shndx() != from_sym->shndx()
887 || (*q)->value() != from_sym->value())
888 break;
889
890 this->weak_aliases_[from_sym] = *q;
891 from_sym->set_has_alias();
892 from_sym = *q;
893 }
894
895 if (from_sym != *p)
896 {
897 this->weak_aliases_[from_sym] = *p;
898 from_sym->set_has_alias();
899 }
900
901 p = q - 1;
902 }
903 }
904
905 // Create and return a specially defined symbol. If ONLY_IF_REF is
906 // true, then only create the symbol if there is a reference to it.
907 // If this does not return NULL, it sets *POLDSYM to the existing
908 // symbol if there is one. This canonicalizes *PNAME and *PVERSION.
909
910 template<int size, bool big_endian>
911 Sized_symbol<size>*
912 Symbol_table::define_special_symbol(const Target* target, const char** pname,
913 const char** pversion, bool only_if_ref,
914 Sized_symbol<size>** poldsym
915 ACCEPT_SIZE_ENDIAN)
916 {
917 Symbol* oldsym;
918 Sized_symbol<size>* sym;
919 bool add_to_table = false;
920 typename Symbol_table_type::iterator add_loc = this->table_.end();
921
922 if (only_if_ref)
923 {
924 oldsym = this->lookup(*pname, *pversion);
925 if (oldsym == NULL || !oldsym->is_undefined())
926 return NULL;
927
928 *pname = oldsym->name();
929 *pversion = oldsym->version();
930 }
931 else
932 {
933 // Canonicalize NAME and VERSION.
934 Stringpool::Key name_key;
935 *pname = this->namepool_.add(*pname, true, &name_key);
936
937 Stringpool::Key version_key = 0;
938 if (*pversion != NULL)
939 *pversion = this->namepool_.add(*pversion, true, &version_key);
940
941 Symbol* const snull = NULL;
942 std::pair<typename Symbol_table_type::iterator, bool> ins =
943 this->table_.insert(std::make_pair(std::make_pair(name_key,
944 version_key),
945 snull));
946
947 if (!ins.second)
948 {
949 // We already have a symbol table entry for NAME/VERSION.
950 oldsym = ins.first->second;
951 gold_assert(oldsym != NULL);
952 }
953 else
954 {
955 // We haven't seen this symbol before.
956 gold_assert(ins.first->second == NULL);
957 add_to_table = true;
958 add_loc = ins.first;
959 oldsym = NULL;
960 }
961 }
962
963 if (!target->has_make_symbol())
964 sym = new Sized_symbol<size>();
965 else
966 {
967 gold_assert(target->get_size() == size);
968 gold_assert(target->is_big_endian() ? big_endian : !big_endian);
969 typedef Sized_target<size, big_endian> My_target;
970 const My_target* sized_target =
971 static_cast<const My_target*>(target);
972 sym = sized_target->make_symbol();
973 if (sym == NULL)
974 return NULL;
975 }
976
977 if (add_to_table)
978 add_loc->second = sym;
979 else
980 gold_assert(oldsym != NULL);
981
982 *poldsym = this->get_sized_symbol SELECT_SIZE_NAME(size) (oldsym
983 SELECT_SIZE(size));
984
985 return sym;
986 }
987
988 // Define a symbol based on an Output_data.
989
990 Symbol*
991 Symbol_table::define_in_output_data(const Target* target, const char* name,
992 const char* version, Output_data* od,
993 uint64_t value, uint64_t symsize,
994 elfcpp::STT type, elfcpp::STB binding,
995 elfcpp::STV visibility,
996 unsigned char nonvis,
997 bool offset_is_from_end,
998 bool only_if_ref)
999 {
1000 if (parameters->get_size() == 32)
1001 {
1002 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1003 return this->do_define_in_output_data<32>(target, name, version, od,
1004 value, symsize, type, binding,
1005 visibility, nonvis,
1006 offset_is_from_end,
1007 only_if_ref);
1008 #else
1009 gold_unreachable();
1010 #endif
1011 }
1012 else if (parameters->get_size() == 64)
1013 {
1014 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1015 return this->do_define_in_output_data<64>(target, name, version, od,
1016 value, symsize, type, binding,
1017 visibility, nonvis,
1018 offset_is_from_end,
1019 only_if_ref);
1020 #else
1021 gold_unreachable();
1022 #endif
1023 }
1024 else
1025 gold_unreachable();
1026 }
1027
1028 // Define a symbol in an Output_data, sized version.
1029
1030 template<int size>
1031 Sized_symbol<size>*
1032 Symbol_table::do_define_in_output_data(
1033 const Target* target,
1034 const char* name,
1035 const char* version,
1036 Output_data* od,
1037 typename elfcpp::Elf_types<size>::Elf_Addr value,
1038 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1039 elfcpp::STT type,
1040 elfcpp::STB binding,
1041 elfcpp::STV visibility,
1042 unsigned char nonvis,
1043 bool offset_is_from_end,
1044 bool only_if_ref)
1045 {
1046 Sized_symbol<size>* sym;
1047 Sized_symbol<size>* oldsym;
1048
1049 if (parameters->is_big_endian())
1050 {
1051 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1052 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1053 target, &name, &version, only_if_ref, &oldsym
1054 SELECT_SIZE_ENDIAN(size, true));
1055 #else
1056 gold_unreachable();
1057 #endif
1058 }
1059 else
1060 {
1061 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1062 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1063 target, &name, &version, only_if_ref, &oldsym
1064 SELECT_SIZE_ENDIAN(size, false));
1065 #else
1066 gold_unreachable();
1067 #endif
1068 }
1069
1070 if (sym == NULL)
1071 return NULL;
1072
1073 gold_assert(version == NULL || oldsym != NULL);
1074 sym->init(name, od, value, symsize, type, binding, visibility, nonvis,
1075 offset_is_from_end);
1076
1077 if (oldsym == NULL)
1078 return sym;
1079
1080 if (Symbol_table::should_override_with_special(oldsym))
1081 this->override_with_special(oldsym, sym);
1082 delete sym;
1083 return oldsym;
1084 }
1085
1086 // Define a symbol based on an Output_segment.
1087
1088 Symbol*
1089 Symbol_table::define_in_output_segment(const Target* target, const char* name,
1090 const char* version, Output_segment* os,
1091 uint64_t value, uint64_t symsize,
1092 elfcpp::STT type, elfcpp::STB binding,
1093 elfcpp::STV visibility,
1094 unsigned char nonvis,
1095 Symbol::Segment_offset_base offset_base,
1096 bool only_if_ref)
1097 {
1098 if (parameters->get_size() == 32)
1099 {
1100 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1101 return this->do_define_in_output_segment<32>(target, name, version, os,
1102 value, symsize, type,
1103 binding, visibility, nonvis,
1104 offset_base, only_if_ref);
1105 #else
1106 gold_unreachable();
1107 #endif
1108 }
1109 else if (parameters->get_size() == 64)
1110 {
1111 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1112 return this->do_define_in_output_segment<64>(target, name, version, os,
1113 value, symsize, type,
1114 binding, visibility, nonvis,
1115 offset_base, only_if_ref);
1116 #else
1117 gold_unreachable();
1118 #endif
1119 }
1120 else
1121 gold_unreachable();
1122 }
1123
1124 // Define a symbol in an Output_segment, sized version.
1125
1126 template<int size>
1127 Sized_symbol<size>*
1128 Symbol_table::do_define_in_output_segment(
1129 const Target* target,
1130 const char* name,
1131 const char* version,
1132 Output_segment* os,
1133 typename elfcpp::Elf_types<size>::Elf_Addr value,
1134 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1135 elfcpp::STT type,
1136 elfcpp::STB binding,
1137 elfcpp::STV visibility,
1138 unsigned char nonvis,
1139 Symbol::Segment_offset_base offset_base,
1140 bool only_if_ref)
1141 {
1142 Sized_symbol<size>* sym;
1143 Sized_symbol<size>* oldsym;
1144
1145 if (parameters->is_big_endian())
1146 {
1147 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1148 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1149 target, &name, &version, only_if_ref, &oldsym
1150 SELECT_SIZE_ENDIAN(size, true));
1151 #else
1152 gold_unreachable();
1153 #endif
1154 }
1155 else
1156 {
1157 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1158 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1159 target, &name, &version, only_if_ref, &oldsym
1160 SELECT_SIZE_ENDIAN(size, false));
1161 #else
1162 gold_unreachable();
1163 #endif
1164 }
1165
1166 if (sym == NULL)
1167 return NULL;
1168
1169 gold_assert(version == NULL || oldsym != NULL);
1170 sym->init(name, os, value, symsize, type, binding, visibility, nonvis,
1171 offset_base);
1172
1173 if (oldsym == NULL)
1174 return sym;
1175
1176 if (Symbol_table::should_override_with_special(oldsym))
1177 this->override_with_special(oldsym, sym);
1178 delete sym;
1179 return oldsym;
1180 }
1181
1182 // Define a special symbol with a constant value. It is a multiple
1183 // definition error if this symbol is already defined.
1184
1185 Symbol*
1186 Symbol_table::define_as_constant(const Target* target, const char* name,
1187 const char* version, uint64_t value,
1188 uint64_t symsize, elfcpp::STT type,
1189 elfcpp::STB binding, elfcpp::STV visibility,
1190 unsigned char nonvis, bool only_if_ref)
1191 {
1192 if (parameters->get_size() == 32)
1193 {
1194 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1195 return this->do_define_as_constant<32>(target, name, version, value,
1196 symsize, type, binding,
1197 visibility, nonvis, only_if_ref);
1198 #else
1199 gold_unreachable();
1200 #endif
1201 }
1202 else if (parameters->get_size() == 64)
1203 {
1204 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1205 return this->do_define_as_constant<64>(target, name, version, value,
1206 symsize, type, binding,
1207 visibility, nonvis, only_if_ref);
1208 #else
1209 gold_unreachable();
1210 #endif
1211 }
1212 else
1213 gold_unreachable();
1214 }
1215
1216 // Define a symbol as a constant, sized version.
1217
1218 template<int size>
1219 Sized_symbol<size>*
1220 Symbol_table::do_define_as_constant(
1221 const Target* target,
1222 const char* name,
1223 const char* version,
1224 typename elfcpp::Elf_types<size>::Elf_Addr value,
1225 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1226 elfcpp::STT type,
1227 elfcpp::STB binding,
1228 elfcpp::STV visibility,
1229 unsigned char nonvis,
1230 bool only_if_ref)
1231 {
1232 Sized_symbol<size>* sym;
1233 Sized_symbol<size>* oldsym;
1234
1235 if (parameters->is_big_endian())
1236 {
1237 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1238 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1239 target, &name, &version, only_if_ref, &oldsym
1240 SELECT_SIZE_ENDIAN(size, true));
1241 #else
1242 gold_unreachable();
1243 #endif
1244 }
1245 else
1246 {
1247 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1248 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1249 target, &name, &version, only_if_ref, &oldsym
1250 SELECT_SIZE_ENDIAN(size, false));
1251 #else
1252 gold_unreachable();
1253 #endif
1254 }
1255
1256 if (sym == NULL)
1257 return NULL;
1258
1259 gold_assert(version == NULL || version == name || oldsym != NULL);
1260 sym->init(name, value, symsize, type, binding, visibility, nonvis);
1261
1262 if (oldsym == NULL)
1263 return sym;
1264
1265 if (Symbol_table::should_override_with_special(oldsym))
1266 this->override_with_special(oldsym, sym);
1267 delete sym;
1268 return oldsym;
1269 }
1270
1271 // Define a set of symbols in output sections.
1272
1273 void
1274 Symbol_table::define_symbols(const Layout* layout, const Target* target,
1275 int count, const Define_symbol_in_section* p)
1276 {
1277 for (int i = 0; i < count; ++i, ++p)
1278 {
1279 Output_section* os = layout->find_output_section(p->output_section);
1280 if (os != NULL)
1281 this->define_in_output_data(target, p->name, NULL, os, p->value,
1282 p->size, p->type, p->binding,
1283 p->visibility, p->nonvis,
1284 p->offset_is_from_end, p->only_if_ref);
1285 else
1286 this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
1287 p->binding, p->visibility, p->nonvis,
1288 p->only_if_ref);
1289 }
1290 }
1291
1292 // Define a set of symbols in output segments.
1293
1294 void
1295 Symbol_table::define_symbols(const Layout* layout, const Target* target,
1296 int count, const Define_symbol_in_segment* p)
1297 {
1298 for (int i = 0; i < count; ++i, ++p)
1299 {
1300 Output_segment* os = layout->find_output_segment(p->segment_type,
1301 p->segment_flags_set,
1302 p->segment_flags_clear);
1303 if (os != NULL)
1304 this->define_in_output_segment(target, p->name, NULL, os, p->value,
1305 p->size, p->type, p->binding,
1306 p->visibility, p->nonvis,
1307 p->offset_base, p->only_if_ref);
1308 else
1309 this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
1310 p->binding, p->visibility, p->nonvis,
1311 p->only_if_ref);
1312 }
1313 }
1314
1315 // Define CSYM using a COPY reloc. POSD is the Output_data where the
1316 // symbol should be defined--typically a .dyn.bss section. VALUE is
1317 // the offset within POSD.
1318
1319 template<int size>
1320 void
1321 Symbol_table::define_with_copy_reloc(
1322 const Target* target,
1323 Sized_symbol<size>* csym,
1324 Output_data* posd,
1325 typename elfcpp::Elf_types<size>::Elf_Addr value)
1326 {
1327 gold_assert(csym->is_from_dynobj());
1328 gold_assert(!csym->is_copied_from_dynobj());
1329 Object* object = csym->object();
1330 gold_assert(object->is_dynamic());
1331 Dynobj* dynobj = static_cast<Dynobj*>(object);
1332
1333 // Our copied variable has to override any variable in a shared
1334 // library.
1335 elfcpp::STB binding = csym->binding();
1336 if (binding == elfcpp::STB_WEAK)
1337 binding = elfcpp::STB_GLOBAL;
1338
1339 this->define_in_output_data(target, csym->name(), csym->version(),
1340 posd, value, csym->symsize(),
1341 csym->type(), binding,
1342 csym->visibility(), csym->nonvis(),
1343 false, false);
1344
1345 csym->set_is_copied_from_dynobj();
1346 csym->set_needs_dynsym_entry();
1347
1348 this->copied_symbol_dynobjs_[csym] = dynobj;
1349
1350 // We have now defined all aliases, but we have not entered them all
1351 // in the copied_symbol_dynobjs_ map.
1352 if (csym->has_alias())
1353 {
1354 Symbol* sym = csym;
1355 while (true)
1356 {
1357 sym = this->weak_aliases_[sym];
1358 if (sym == csym)
1359 break;
1360 gold_assert(sym->output_data() == posd);
1361
1362 sym->set_is_copied_from_dynobj();
1363 this->copied_symbol_dynobjs_[sym] = dynobj;
1364 }
1365 }
1366 }
1367
1368 // SYM is defined using a COPY reloc. Return the dynamic object where
1369 // the original definition was found.
1370
1371 Dynobj*
1372 Symbol_table::get_copy_source(const Symbol* sym) const
1373 {
1374 gold_assert(sym->is_copied_from_dynobj());
1375 Copied_symbol_dynobjs::const_iterator p =
1376 this->copied_symbol_dynobjs_.find(sym);
1377 gold_assert(p != this->copied_symbol_dynobjs_.end());
1378 return p->second;
1379 }
1380
1381 // Set the dynamic symbol indexes. INDEX is the index of the first
1382 // global dynamic symbol. Pointers to the symbols are stored into the
1383 // vector SYMS. The names are added to DYNPOOL. This returns an
1384 // updated dynamic symbol index.
1385
1386 unsigned int
1387 Symbol_table::set_dynsym_indexes(const Target* target,
1388 unsigned int index,
1389 std::vector<Symbol*>* syms,
1390 Stringpool* dynpool,
1391 Versions* versions)
1392 {
1393 for (Symbol_table_type::iterator p = this->table_.begin();
1394 p != this->table_.end();
1395 ++p)
1396 {
1397 Symbol* sym = p->second;
1398
1399 // Note that SYM may already have a dynamic symbol index, since
1400 // some symbols appear more than once in the symbol table, with
1401 // and without a version.
1402
1403 if (!sym->should_add_dynsym_entry())
1404 sym->set_dynsym_index(-1U);
1405 else if (!sym->has_dynsym_index())
1406 {
1407 sym->set_dynsym_index(index);
1408 ++index;
1409 syms->push_back(sym);
1410 dynpool->add(sym->name(), false, NULL);
1411
1412 // Record any version information.
1413 if (sym->version() != NULL)
1414 versions->record_version(this, dynpool, sym);
1415 }
1416 }
1417
1418 // Finish up the versions. In some cases this may add new dynamic
1419 // symbols.
1420 index = versions->finalize(target, this, index, syms);
1421
1422 return index;
1423 }
1424
1425 // Set the final values for all the symbols. The index of the first
1426 // global symbol in the output file is INDEX. Record the file offset
1427 // OFF. Add their names to POOL. Return the new file offset.
1428
1429 off_t
1430 Symbol_table::finalize(unsigned int index, off_t off, off_t dynoff,
1431 size_t dyn_global_index, size_t dyncount,
1432 Stringpool* pool)
1433 {
1434 off_t ret;
1435
1436 gold_assert(index != 0);
1437 this->first_global_index_ = index;
1438
1439 this->dynamic_offset_ = dynoff;
1440 this->first_dynamic_global_index_ = dyn_global_index;
1441 this->dynamic_count_ = dyncount;
1442
1443 if (parameters->get_size() == 32)
1444 {
1445 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
1446 ret = this->sized_finalize<32>(index, off, pool);
1447 #else
1448 gold_unreachable();
1449 #endif
1450 }
1451 else if (parameters->get_size() == 64)
1452 {
1453 #if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
1454 ret = this->sized_finalize<64>(index, off, pool);
1455 #else
1456 gold_unreachable();
1457 #endif
1458 }
1459 else
1460 gold_unreachable();
1461
1462 // Now that we have the final symbol table, we can reliably note
1463 // which symbols should get warnings.
1464 this->warnings_.note_warnings(this);
1465
1466 return ret;
1467 }
1468
1469 // Set the final value for all the symbols. This is called after
1470 // Layout::finalize, so all the output sections have their final
1471 // address.
1472
1473 template<int size>
1474 off_t
1475 Symbol_table::sized_finalize(unsigned index, off_t off, Stringpool* pool)
1476 {
1477 off = align_address(off, size >> 3);
1478 this->offset_ = off;
1479
1480 size_t orig_index = index;
1481
1482 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1483 for (Symbol_table_type::iterator p = this->table_.begin();
1484 p != this->table_.end();
1485 ++p)
1486 {
1487 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1488
1489 // FIXME: Here we need to decide which symbols should go into
1490 // the output file, based on --strip.
1491
1492 // The default version of a symbol may appear twice in the
1493 // symbol table. We only need to finalize it once.
1494 if (sym->has_symtab_index())
1495 continue;
1496
1497 if (!sym->in_reg())
1498 {
1499 gold_assert(!sym->has_symtab_index());
1500 sym->set_symtab_index(-1U);
1501 gold_assert(sym->dynsym_index() == -1U);
1502 continue;
1503 }
1504
1505 typename Sized_symbol<size>::Value_type value;
1506
1507 switch (sym->source())
1508 {
1509 case Symbol::FROM_OBJECT:
1510 {
1511 unsigned int shndx = sym->shndx();
1512
1513 // FIXME: We need some target specific support here.
1514 if (shndx >= elfcpp::SHN_LORESERVE
1515 && shndx != elfcpp::SHN_ABS)
1516 {
1517 gold_error(_("%s: unsupported symbol section 0x%x"),
1518 sym->demangled_name().c_str(), shndx);
1519 shndx = elfcpp::SHN_UNDEF;
1520 }
1521
1522 Object* symobj = sym->object();
1523 if (symobj->is_dynamic())
1524 {
1525 value = 0;
1526 shndx = elfcpp::SHN_UNDEF;
1527 }
1528 else if (shndx == elfcpp::SHN_UNDEF)
1529 value = 0;
1530 else if (shndx == elfcpp::SHN_ABS)
1531 value = sym->value();
1532 else
1533 {
1534 Relobj* relobj = static_cast<Relobj*>(symobj);
1535 section_offset_type secoff;
1536 Output_section* os = relobj->output_section(shndx, &secoff);
1537
1538 if (os == NULL)
1539 {
1540 sym->set_symtab_index(-1U);
1541 gold_assert(sym->dynsym_index() == -1U);
1542 continue;
1543 }
1544
1545 if (sym->type() == elfcpp::STT_TLS)
1546 value = sym->value() + os->tls_offset() + secoff;
1547 else
1548 value = sym->value() + os->address() + secoff;
1549 }
1550 }
1551 break;
1552
1553 case Symbol::IN_OUTPUT_DATA:
1554 {
1555 Output_data* od = sym->output_data();
1556 value = sym->value() + od->address();
1557 if (sym->offset_is_from_end())
1558 value += od->data_size();
1559 }
1560 break;
1561
1562 case Symbol::IN_OUTPUT_SEGMENT:
1563 {
1564 Output_segment* os = sym->output_segment();
1565 value = sym->value() + os->vaddr();
1566 switch (sym->offset_base())
1567 {
1568 case Symbol::SEGMENT_START:
1569 break;
1570 case Symbol::SEGMENT_END:
1571 value += os->memsz();
1572 break;
1573 case Symbol::SEGMENT_BSS:
1574 value += os->filesz();
1575 break;
1576 default:
1577 gold_unreachable();
1578 }
1579 }
1580 break;
1581
1582 case Symbol::CONSTANT:
1583 value = sym->value();
1584 break;
1585
1586 default:
1587 gold_unreachable();
1588 }
1589
1590 sym->set_value(value);
1591
1592 if (parameters->strip_all())
1593 sym->set_symtab_index(-1U);
1594 else
1595 {
1596 sym->set_symtab_index(index);
1597 pool->add(sym->name(), false, NULL);
1598 ++index;
1599 off += sym_size;
1600 }
1601 }
1602
1603 this->output_count_ = index - orig_index;
1604
1605 return off;
1606 }
1607
1608 // Write out the global symbols.
1609
1610 void
1611 Symbol_table::write_globals(const Input_objects* input_objects,
1612 const Stringpool* sympool,
1613 const Stringpool* dynpool, Output_file* of) const
1614 {
1615 if (parameters->get_size() == 32)
1616 {
1617 if (parameters->is_big_endian())
1618 {
1619 #ifdef HAVE_TARGET_32_BIG
1620 this->sized_write_globals<32, true>(input_objects, sympool,
1621 dynpool, of);
1622 #else
1623 gold_unreachable();
1624 #endif
1625 }
1626 else
1627 {
1628 #ifdef HAVE_TARGET_32_LITTLE
1629 this->sized_write_globals<32, false>(input_objects, sympool,
1630 dynpool, of);
1631 #else
1632 gold_unreachable();
1633 #endif
1634 }
1635 }
1636 else if (parameters->get_size() == 64)
1637 {
1638 if (parameters->is_big_endian())
1639 {
1640 #ifdef HAVE_TARGET_64_BIG
1641 this->sized_write_globals<64, true>(input_objects, sympool,
1642 dynpool, of);
1643 #else
1644 gold_unreachable();
1645 #endif
1646 }
1647 else
1648 {
1649 #ifdef HAVE_TARGET_64_LITTLE
1650 this->sized_write_globals<64, false>(input_objects, sympool,
1651 dynpool, of);
1652 #else
1653 gold_unreachable();
1654 #endif
1655 }
1656 }
1657 else
1658 gold_unreachable();
1659 }
1660
1661 // Write out the global symbols.
1662
1663 template<int size, bool big_endian>
1664 void
1665 Symbol_table::sized_write_globals(const Input_objects* input_objects,
1666 const Stringpool* sympool,
1667 const Stringpool* dynpool,
1668 Output_file* of) const
1669 {
1670 const Target* const target = input_objects->target();
1671
1672 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1673 unsigned int index = this->first_global_index_;
1674 const off_t oview_size = this->output_count_ * sym_size;
1675 unsigned char* const psyms = of->get_output_view(this->offset_, oview_size);
1676
1677 unsigned int dynamic_count = this->dynamic_count_;
1678 off_t dynamic_size = dynamic_count * sym_size;
1679 unsigned int first_dynamic_global_index = this->first_dynamic_global_index_;
1680 unsigned char* dynamic_view;
1681 if (this->dynamic_offset_ == 0)
1682 dynamic_view = NULL;
1683 else
1684 dynamic_view = of->get_output_view(this->dynamic_offset_, dynamic_size);
1685
1686 unsigned char* ps = psyms;
1687 for (Symbol_table_type::const_iterator p = this->table_.begin();
1688 p != this->table_.end();
1689 ++p)
1690 {
1691 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1692
1693 // Possibly warn about unresolved symbols in shared libraries.
1694 this->warn_about_undefined_dynobj_symbol(input_objects, sym);
1695
1696 unsigned int sym_index = sym->symtab_index();
1697 unsigned int dynsym_index;
1698 if (dynamic_view == NULL)
1699 dynsym_index = -1U;
1700 else
1701 dynsym_index = sym->dynsym_index();
1702
1703 if (sym_index == -1U && dynsym_index == -1U)
1704 {
1705 // This symbol is not included in the output file.
1706 continue;
1707 }
1708
1709 if (sym_index == index)
1710 ++index;
1711 else if (sym_index != -1U)
1712 {
1713 // We have already seen this symbol, because it has a
1714 // default version.
1715 gold_assert(sym_index < index);
1716 if (dynsym_index == -1U)
1717 continue;
1718 sym_index = -1U;
1719 }
1720
1721 unsigned int shndx;
1722 typename elfcpp::Elf_types<32>::Elf_Addr value = sym->value();
1723 switch (sym->source())
1724 {
1725 case Symbol::FROM_OBJECT:
1726 {
1727 unsigned int in_shndx = sym->shndx();
1728
1729 // FIXME: We need some target specific support here.
1730 if (in_shndx >= elfcpp::SHN_LORESERVE
1731 && in_shndx != elfcpp::SHN_ABS)
1732 {
1733 gold_error(_("%s: unsupported symbol section 0x%x"),
1734 sym->demangled_name().c_str(), in_shndx);
1735 shndx = in_shndx;
1736 }
1737 else
1738 {
1739 Object* symobj = sym->object();
1740 if (symobj->is_dynamic())
1741 {
1742 if (sym->needs_dynsym_value())
1743 value = target->dynsym_value(sym);
1744 shndx = elfcpp::SHN_UNDEF;
1745 }
1746 else if (in_shndx == elfcpp::SHN_UNDEF
1747 || in_shndx == elfcpp::SHN_ABS)
1748 shndx = in_shndx;
1749 else
1750 {
1751 Relobj* relobj = static_cast<Relobj*>(symobj);
1752 section_offset_type secoff;
1753 Output_section* os = relobj->output_section(in_shndx,
1754 &secoff);
1755 gold_assert(os != NULL);
1756 shndx = os->out_shndx();
1757 }
1758 }
1759 }
1760 break;
1761
1762 case Symbol::IN_OUTPUT_DATA:
1763 shndx = sym->output_data()->out_shndx();
1764 break;
1765
1766 case Symbol::IN_OUTPUT_SEGMENT:
1767 shndx = elfcpp::SHN_ABS;
1768 break;
1769
1770 case Symbol::CONSTANT:
1771 shndx = elfcpp::SHN_ABS;
1772 break;
1773
1774 default:
1775 gold_unreachable();
1776 }
1777
1778 if (sym_index != -1U)
1779 {
1780 this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
1781 sym, sym->value(), shndx, sympool, ps
1782 SELECT_SIZE_ENDIAN(size, big_endian));
1783 ps += sym_size;
1784 }
1785
1786 if (dynsym_index != -1U)
1787 {
1788 dynsym_index -= first_dynamic_global_index;
1789 gold_assert(dynsym_index < dynamic_count);
1790 unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
1791 this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
1792 sym, value, shndx, dynpool, pd
1793 SELECT_SIZE_ENDIAN(size, big_endian));
1794 }
1795 }
1796
1797 gold_assert(ps - psyms == oview_size);
1798
1799 of->write_output_view(this->offset_, oview_size, psyms);
1800 if (dynamic_view != NULL)
1801 of->write_output_view(this->dynamic_offset_, dynamic_size, dynamic_view);
1802 }
1803
1804 // Write out the symbol SYM, in section SHNDX, to P. POOL is the
1805 // strtab holding the name.
1806
1807 template<int size, bool big_endian>
1808 void
1809 Symbol_table::sized_write_symbol(
1810 Sized_symbol<size>* sym,
1811 typename elfcpp::Elf_types<size>::Elf_Addr value,
1812 unsigned int shndx,
1813 const Stringpool* pool,
1814 unsigned char* p
1815 ACCEPT_SIZE_ENDIAN) const
1816 {
1817 elfcpp::Sym_write<size, big_endian> osym(p);
1818 osym.put_st_name(pool->get_offset(sym->name()));
1819 osym.put_st_value(value);
1820 osym.put_st_size(sym->symsize());
1821 osym.put_st_info(elfcpp::elf_st_info(sym->binding(), sym->type()));
1822 osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
1823 osym.put_st_shndx(shndx);
1824 }
1825
1826 // Check for unresolved symbols in shared libraries. This is
1827 // controlled by the --allow-shlib-undefined option.
1828
1829 // We only warn about libraries for which we have seen all the
1830 // DT_NEEDED entries. We don't try to track down DT_NEEDED entries
1831 // which were not seen in this link. If we didn't see a DT_NEEDED
1832 // entry, we aren't going to be able to reliably report whether the
1833 // symbol is undefined.
1834
1835 // We also don't warn about libraries found in the system library
1836 // directory (the directory were we find libc.so); we assume that
1837 // those libraries are OK. This heuristic avoids problems in
1838 // GNU/Linux, in which -ldl can have undefined references satisfied by
1839 // ld-linux.so.
1840
1841 inline void
1842 Symbol_table::warn_about_undefined_dynobj_symbol(
1843 const Input_objects* input_objects,
1844 Symbol* sym) const
1845 {
1846 if (sym->source() == Symbol::FROM_OBJECT
1847 && sym->object()->is_dynamic()
1848 && sym->shndx() == elfcpp::SHN_UNDEF
1849 && sym->binding() != elfcpp::STB_WEAK
1850 && !parameters->allow_shlib_undefined()
1851 && !input_objects->target()->is_defined_by_abi(sym)
1852 && !input_objects->found_in_system_library_directory(sym->object()))
1853 {
1854 // A very ugly cast.
1855 Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
1856 if (!dynobj->has_unknown_needed_entries())
1857 gold_error(_("%s: undefined reference to '%s'"),
1858 sym->object()->name().c_str(),
1859 sym->demangled_name().c_str());
1860 }
1861 }
1862
1863 // Write out a section symbol. Return the update offset.
1864
1865 void
1866 Symbol_table::write_section_symbol(const Output_section *os,
1867 Output_file* of,
1868 off_t offset) const
1869 {
1870 if (parameters->get_size() == 32)
1871 {
1872 if (parameters->is_big_endian())
1873 {
1874 #ifdef HAVE_TARGET_32_BIG
1875 this->sized_write_section_symbol<32, true>(os, of, offset);
1876 #else
1877 gold_unreachable();
1878 #endif
1879 }
1880 else
1881 {
1882 #ifdef HAVE_TARGET_32_LITTLE
1883 this->sized_write_section_symbol<32, false>(os, of, offset);
1884 #else
1885 gold_unreachable();
1886 #endif
1887 }
1888 }
1889 else if (parameters->get_size() == 64)
1890 {
1891 if (parameters->is_big_endian())
1892 {
1893 #ifdef HAVE_TARGET_64_BIG
1894 this->sized_write_section_symbol<64, true>(os, of, offset);
1895 #else
1896 gold_unreachable();
1897 #endif
1898 }
1899 else
1900 {
1901 #ifdef HAVE_TARGET_64_LITTLE
1902 this->sized_write_section_symbol<64, false>(os, of, offset);
1903 #else
1904 gold_unreachable();
1905 #endif
1906 }
1907 }
1908 else
1909 gold_unreachable();
1910 }
1911
1912 // Write out a section symbol, specialized for size and endianness.
1913
1914 template<int size, bool big_endian>
1915 void
1916 Symbol_table::sized_write_section_symbol(const Output_section* os,
1917 Output_file* of,
1918 off_t offset) const
1919 {
1920 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1921
1922 unsigned char* pov = of->get_output_view(offset, sym_size);
1923
1924 elfcpp::Sym_write<size, big_endian> osym(pov);
1925 osym.put_st_name(0);
1926 osym.put_st_value(os->address());
1927 osym.put_st_size(0);
1928 osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
1929 elfcpp::STT_SECTION));
1930 osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
1931 osym.put_st_shndx(os->out_shndx());
1932
1933 of->write_output_view(offset, sym_size, pov);
1934 }
1935
1936 // Print statistical information to stderr. This is used for --stats.
1937
1938 void
1939 Symbol_table::print_stats() const
1940 {
1941 #if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP)
1942 fprintf(stderr, _("%s: symbol table entries: %zu; buckets: %zu\n"),
1943 program_name, this->table_.size(), this->table_.bucket_count());
1944 #else
1945 fprintf(stderr, _("%s: symbol table entries: %zu\n"),
1946 program_name, this->table_.size());
1947 #endif
1948 this->namepool_.print_stats("symbol table stringpool");
1949 }
1950
1951 // We check for ODR violations by looking for symbols with the same
1952 // name for which the debugging information reports that they were
1953 // defined in different source locations. When comparing the source
1954 // location, we consider instances with the same base filename and
1955 // line number to be the same. This is because different object
1956 // files/shared libraries can include the same header file using
1957 // different paths, and we don't want to report an ODR violation in
1958 // that case.
1959
1960 // This struct is used to compare line information, as returned by
1961 // Dwarf_line_info::one_addr2line. It implements a < comparison
1962 // operator used with std::set.
1963
1964 struct Odr_violation_compare
1965 {
1966 bool
1967 operator()(const std::string& s1, const std::string& s2) const
1968 {
1969 std::string::size_type pos1 = s1.rfind('/');
1970 std::string::size_type pos2 = s2.rfind('/');
1971 if (pos1 == std::string::npos
1972 || pos2 == std::string::npos)
1973 return s1 < s2;
1974 return s1.compare(pos1, std::string::npos,
1975 s2, pos2, std::string::npos) < 0;
1976 }
1977 };
1978
1979 // Check candidate_odr_violations_ to find symbols with the same name
1980 // but apparently different definitions (different source-file/line-no).
1981
1982 void
1983 Symbol_table::detect_odr_violations(const Task* task,
1984 const char* output_file_name) const
1985 {
1986 for (Odr_map::const_iterator it = candidate_odr_violations_.begin();
1987 it != candidate_odr_violations_.end();
1988 ++it)
1989 {
1990 const char* symbol_name = it->first;
1991 // We use a sorted set so the output is deterministic.
1992 std::set<std::string, Odr_violation_compare> line_nums;
1993
1994 for (Unordered_set<Symbol_location, Symbol_location_hash>::const_iterator
1995 locs = it->second.begin();
1996 locs != it->second.end();
1997 ++locs)
1998 {
1999 // We need to lock the object in order to read it. This
2000 // means that we have to run in a singleton Task. If we
2001 // want to run this in a general Task for better
2002 // performance, we will need one Task for object, plus
2003 // appropriate locking to ensure that we don't conflict with
2004 // other uses of the object.
2005 Task_lock_obj<Object> tl(task, locs->object);
2006 std::string lineno = Dwarf_line_info::one_addr2line(
2007 locs->object, locs->shndx, locs->offset);
2008 if (!lineno.empty())
2009 line_nums.insert(lineno);
2010 }
2011
2012 if (line_nums.size() > 1)
2013 {
2014 gold_warning(_("while linking %s: symbol '%s' defined in multiple "
2015 "places (possible ODR violation):"),
2016 output_file_name, demangle(symbol_name).c_str());
2017 for (std::set<std::string>::const_iterator it2 = line_nums.begin();
2018 it2 != line_nums.end();
2019 ++it2)
2020 fprintf(stderr, " %s\n", it2->c_str());
2021 }
2022 }
2023 }
2024
2025 // Warnings functions.
2026
2027 // Add a new warning.
2028
2029 void
2030 Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
2031 const std::string& warning)
2032 {
2033 name = symtab->canonicalize_name(name);
2034 this->warnings_[name].set(obj, warning);
2035 }
2036
2037 // Look through the warnings and mark the symbols for which we should
2038 // warn. This is called during Layout::finalize when we know the
2039 // sources for all the symbols.
2040
2041 void
2042 Warnings::note_warnings(Symbol_table* symtab)
2043 {
2044 for (Warning_table::iterator p = this->warnings_.begin();
2045 p != this->warnings_.end();
2046 ++p)
2047 {
2048 Symbol* sym = symtab->lookup(p->first, NULL);
2049 if (sym != NULL
2050 && sym->source() == Symbol::FROM_OBJECT
2051 && sym->object() == p->second.object)
2052 sym->set_has_warning();
2053 }
2054 }
2055
2056 // Issue a warning. This is called when we see a relocation against a
2057 // symbol for which has a warning.
2058
2059 template<int size, bool big_endian>
2060 void
2061 Warnings::issue_warning(const Symbol* sym,
2062 const Relocate_info<size, big_endian>* relinfo,
2063 size_t relnum, off_t reloffset) const
2064 {
2065 gold_assert(sym->has_warning());
2066 Warning_table::const_iterator p = this->warnings_.find(sym->name());
2067 gold_assert(p != this->warnings_.end());
2068 gold_warning_at_location(relinfo, relnum, reloffset,
2069 "%s", p->second.text.c_str());
2070 }
2071
2072 // Instantiate the templates we need. We could use the configure
2073 // script to restrict this to only the ones needed for implemented
2074 // targets.
2075
2076 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
2077 template
2078 void
2079 Sized_symbol<32>::allocate_common(Output_data*, Value_type);
2080 #endif
2081
2082 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
2083 template
2084 void
2085 Sized_symbol<64>::allocate_common(Output_data*, Value_type);
2086 #endif
2087
2088 #ifdef HAVE_TARGET_32_LITTLE
2089 template
2090 void
2091 Symbol_table::add_from_relobj<32, false>(
2092 Sized_relobj<32, false>* relobj,
2093 const unsigned char* syms,
2094 size_t count,
2095 const char* sym_names,
2096 size_t sym_name_size,
2097 Sized_relobj<32, true>::Symbols* sympointers);
2098 #endif
2099
2100 #ifdef HAVE_TARGET_32_BIG
2101 template
2102 void
2103 Symbol_table::add_from_relobj<32, true>(
2104 Sized_relobj<32, true>* relobj,
2105 const unsigned char* syms,
2106 size_t count,
2107 const char* sym_names,
2108 size_t sym_name_size,
2109 Sized_relobj<32, false>::Symbols* sympointers);
2110 #endif
2111
2112 #ifdef HAVE_TARGET_64_LITTLE
2113 template
2114 void
2115 Symbol_table::add_from_relobj<64, false>(
2116 Sized_relobj<64, false>* relobj,
2117 const unsigned char* syms,
2118 size_t count,
2119 const char* sym_names,
2120 size_t sym_name_size,
2121 Sized_relobj<64, true>::Symbols* sympointers);
2122 #endif
2123
2124 #ifdef HAVE_TARGET_64_BIG
2125 template
2126 void
2127 Symbol_table::add_from_relobj<64, true>(
2128 Sized_relobj<64, true>* relobj,
2129 const unsigned char* syms,
2130 size_t count,
2131 const char* sym_names,
2132 size_t sym_name_size,
2133 Sized_relobj<64, false>::Symbols* sympointers);
2134 #endif
2135
2136 #ifdef HAVE_TARGET_32_LITTLE
2137 template
2138 void
2139 Symbol_table::add_from_dynobj<32, false>(
2140 Sized_dynobj<32, false>* dynobj,
2141 const unsigned char* syms,
2142 size_t count,
2143 const char* sym_names,
2144 size_t sym_name_size,
2145 const unsigned char* versym,
2146 size_t versym_size,
2147 const std::vector<const char*>* version_map);
2148 #endif
2149
2150 #ifdef HAVE_TARGET_32_BIG
2151 template
2152 void
2153 Symbol_table::add_from_dynobj<32, true>(
2154 Sized_dynobj<32, true>* dynobj,
2155 const unsigned char* syms,
2156 size_t count,
2157 const char* sym_names,
2158 size_t sym_name_size,
2159 const unsigned char* versym,
2160 size_t versym_size,
2161 const std::vector<const char*>* version_map);
2162 #endif
2163
2164 #ifdef HAVE_TARGET_64_LITTLE
2165 template
2166 void
2167 Symbol_table::add_from_dynobj<64, false>(
2168 Sized_dynobj<64, false>* dynobj,
2169 const unsigned char* syms,
2170 size_t count,
2171 const char* sym_names,
2172 size_t sym_name_size,
2173 const unsigned char* versym,
2174 size_t versym_size,
2175 const std::vector<const char*>* version_map);
2176 #endif
2177
2178 #ifdef HAVE_TARGET_64_BIG
2179 template
2180 void
2181 Symbol_table::add_from_dynobj<64, true>(
2182 Sized_dynobj<64, true>* dynobj,
2183 const unsigned char* syms,
2184 size_t count,
2185 const char* sym_names,
2186 size_t sym_name_size,
2187 const unsigned char* versym,
2188 size_t versym_size,
2189 const std::vector<const char*>* version_map);
2190 #endif
2191
2192 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
2193 template
2194 void
2195 Symbol_table::define_with_copy_reloc<32>(
2196 const Target* target,
2197 Sized_symbol<32>* sym,
2198 Output_data* posd,
2199 elfcpp::Elf_types<32>::Elf_Addr value);
2200 #endif
2201
2202 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
2203 template
2204 void
2205 Symbol_table::define_with_copy_reloc<64>(
2206 const Target* target,
2207 Sized_symbol<64>* sym,
2208 Output_data* posd,
2209 elfcpp::Elf_types<64>::Elf_Addr value);
2210 #endif
2211
2212 #ifdef HAVE_TARGET_32_LITTLE
2213 template
2214 void
2215 Warnings::issue_warning<32, false>(const Symbol* sym,
2216 const Relocate_info<32, false>* relinfo,
2217 size_t relnum, off_t reloffset) const;
2218 #endif
2219
2220 #ifdef HAVE_TARGET_32_BIG
2221 template
2222 void
2223 Warnings::issue_warning<32, true>(const Symbol* sym,
2224 const Relocate_info<32, true>* relinfo,
2225 size_t relnum, off_t reloffset) const;
2226 #endif
2227
2228 #ifdef HAVE_TARGET_64_LITTLE
2229 template
2230 void
2231 Warnings::issue_warning<64, false>(const Symbol* sym,
2232 const Relocate_info<64, false>* relinfo,
2233 size_t relnum, off_t reloffset) const;
2234 #endif
2235
2236 #ifdef HAVE_TARGET_64_BIG
2237 template
2238 void
2239 Warnings::issue_warning<64, true>(const Symbol* sym,
2240 const Relocate_info<64, true>* relinfo,
2241 size_t relnum, off_t reloffset) const;
2242 #endif
2243
2244 } // End namespace gold.