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