Add threading support.
[external/binutils.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   this->needs_value_in_got_ = false;
74 }
75
76 // Return the demangled version of the symbol's name, but only
77 // if the --demangle flag was set.
78
79 static std::string
80 demangle(const char* name)
81 {
82   if (!parameters->demangle())
83     return name;
84
85   // cplus_demangle allocates memory for the result it returns,
86   // and returns NULL if the name is already demangled.
87   char* demangled_name = cplus_demangle(name, DMGL_ANSI | DMGL_PARAMS);
88   if (demangled_name == NULL)
89     return name;
90
91   std::string retval(demangled_name);
92   free(demangled_name);
93   return retval;
94 }
95
96 std::string
97 Symbol::demangled_name() const
98 {
99   return demangle(this->name());
100 }
101
102 // Initialize the fields in the base class Symbol for SYM in OBJECT.
103
104 template<int size, bool big_endian>
105 void
106 Symbol::init_base(const char* name, const char* version, Object* object,
107                   const elfcpp::Sym<size, big_endian>& sym)
108 {
109   this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
110                     sym.get_st_visibility(), sym.get_st_nonvis());
111   this->u_.from_object.object = object;
112   // FIXME: Handle SHN_XINDEX.
113   this->u_.from_object.shndx = sym.get_st_shndx();
114   this->source_ = FROM_OBJECT;
115   this->in_reg_ = !object->is_dynamic();
116   this->in_dyn_ = object->is_dynamic();
117 }
118
119 // Initialize the fields in the base class Symbol for a symbol defined
120 // in an Output_data.
121
122 void
123 Symbol::init_base(const char* name, Output_data* od, elfcpp::STT type,
124                   elfcpp::STB binding, elfcpp::STV visibility,
125                   unsigned char nonvis, bool offset_is_from_end)
126 {
127   this->init_fields(name, NULL, type, binding, visibility, nonvis);
128   this->u_.in_output_data.output_data = od;
129   this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
130   this->source_ = IN_OUTPUT_DATA;
131   this->in_reg_ = true;
132 }
133
134 // Initialize the fields in the base class Symbol for a symbol defined
135 // in an Output_segment.
136
137 void
138 Symbol::init_base(const char* name, Output_segment* os, elfcpp::STT type,
139                   elfcpp::STB binding, elfcpp::STV visibility,
140                   unsigned char nonvis, Segment_offset_base offset_base)
141 {
142   this->init_fields(name, NULL, type, binding, visibility, nonvis);
143   this->u_.in_output_segment.output_segment = os;
144   this->u_.in_output_segment.offset_base = offset_base;
145   this->source_ = IN_OUTPUT_SEGMENT;
146   this->in_reg_ = true;
147 }
148
149 // Initialize the fields in the base class Symbol for a symbol defined
150 // as a constant.
151
152 void
153 Symbol::init_base(const char* name, elfcpp::STT type,
154                   elfcpp::STB binding, elfcpp::STV visibility,
155                   unsigned char nonvis)
156 {
157   this->init_fields(name, NULL, type, binding, visibility, nonvis);
158   this->source_ = CONSTANT;
159   this->in_reg_ = true;
160 }
161
162 // Allocate a common symbol in the base.
163
164 void
165 Symbol::allocate_base_common(Output_data* od)
166 {
167   gold_assert(this->is_common());
168   this->source_ = IN_OUTPUT_DATA;
169   this->u_.in_output_data.output_data = od;
170   this->u_.in_output_data.offset_is_from_end = false;
171 }
172
173 // Initialize the fields in Sized_symbol for SYM in OBJECT.
174
175 template<int size>
176 template<bool big_endian>
177 void
178 Sized_symbol<size>::init(const char* name, const char* version, Object* object,
179                          const elfcpp::Sym<size, big_endian>& sym)
180 {
181   this->init_base(name, version, object, sym);
182   this->value_ = sym.get_st_value();
183   this->symsize_ = sym.get_st_size();
184 }
185
186 // Initialize the fields in Sized_symbol for a symbol defined in an
187 // Output_data.
188
189 template<int size>
190 void
191 Sized_symbol<size>::init(const char* name, Output_data* od,
192                          Value_type value, Size_type symsize,
193                          elfcpp::STT type, elfcpp::STB binding,
194                          elfcpp::STV visibility, unsigned char nonvis,
195                          bool offset_is_from_end)
196 {
197   this->init_base(name, od, type, binding, visibility, nonvis,
198                   offset_is_from_end);
199   this->value_ = value;
200   this->symsize_ = symsize;
201 }
202
203 // Initialize the fields in Sized_symbol for a symbol defined in an
204 // Output_segment.
205
206 template<int size>
207 void
208 Sized_symbol<size>::init(const char* name, Output_segment* os,
209                          Value_type value, Size_type symsize,
210                          elfcpp::STT type, elfcpp::STB binding,
211                          elfcpp::STV visibility, unsigned char nonvis,
212                          Segment_offset_base offset_base)
213 {
214   this->init_base(name, os, type, binding, visibility, nonvis, offset_base);
215   this->value_ = value;
216   this->symsize_ = symsize;
217 }
218
219 // Initialize the fields in Sized_symbol for a symbol defined as a
220 // constant.
221
222 template<int size>
223 void
224 Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
225                          elfcpp::STT type, elfcpp::STB binding,
226                          elfcpp::STV visibility, unsigned char nonvis)
227 {
228   this->init_base(name, type, binding, visibility, nonvis);
229   this->value_ = value;
230   this->symsize_ = symsize;
231 }
232
233 // Allocate a common symbol.
234
235 template<int size>
236 void
237 Sized_symbol<size>::allocate_common(Output_data* od, Value_type value)
238 {
239   this->allocate_base_common(od);
240   this->value_ = value;
241 }
242
243 // Return true if this symbol should be added to the dynamic symbol
244 // table.
245
246 inline bool
247 Symbol::should_add_dynsym_entry() const
248 {
249   // If the symbol is used by a dynamic relocation, we need to add it.
250   if (this->needs_dynsym_entry())
251     return true;
252
253   // If exporting all symbols or building a shared library,
254   // and the symbol is defined in a regular object and is
255   // externally visible, we need to add it.
256   if ((parameters->export_dynamic() || parameters->output_is_shared())
257       && !this->is_from_dynobj()
258       && this->is_externally_visible())
259     return true;
260
261   return false;
262 }
263
264 // Return true if the final value of this symbol is known at link
265 // time.
266
267 bool
268 Symbol::final_value_is_known() const
269 {
270   // If we are not generating an executable, then no final values are
271   // known, since they will change at runtime.
272   if (!parameters->output_is_executable())
273     return false;
274
275   // If the symbol is not from an object file, then it is defined, and
276   // known.
277   if (this->source_ != FROM_OBJECT)
278     return true;
279
280   // If the symbol is from a dynamic object, then the final value is
281   // not known.
282   if (this->object()->is_dynamic())
283     return false;
284
285   // If the symbol is not undefined (it is defined or common), then
286   // the final value is known.
287   if (!this->is_undefined())
288     return true;
289
290   // If the symbol is undefined, then whether the final value is known
291   // depends on whether we are doing a static link.  If we are doing a
292   // dynamic link, then the final value could be filled in at runtime.
293   // This could reasonably be the case for a weak undefined symbol.
294   return parameters->doing_static_link();
295 }
296
297 // Class Symbol_table.
298
299 Symbol_table::Symbol_table()
300   : saw_undefined_(0), offset_(0), table_(), namepool_(),
301     forwarders_(), commons_(), warnings_()
302 {
303 }
304
305 Symbol_table::~Symbol_table()
306 {
307 }
308
309 // The hash function.  The key is always canonicalized, so we use a
310 // simple combination of the pointers.
311
312 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 only called with
319 // canonicalized name and version strings, so we can use pointer
320 // comparison.
321
322 bool
323 Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
324                                           const Symbol_table_key& k2) const
325 {
326   return k1.first == k2.first && k1.second == k2.second;
327 }
328
329 // Make TO a symbol which forwards to FROM.
330
331 void
332 Symbol_table::make_forwarder(Symbol* from, Symbol* to)
333 {
334   gold_assert(from != to);
335   gold_assert(!from->is_forwarder() && !to->is_forwarder());
336   this->forwarders_[from] = to;
337   from->set_forwarder();
338 }
339
340 // Resolve the forwards from FROM, returning the real symbol.
341
342 Symbol*
343 Symbol_table::resolve_forwards(const Symbol* from) const
344 {
345   gold_assert(from->is_forwarder());
346   Unordered_map<const Symbol*, Symbol*>::const_iterator p =
347     this->forwarders_.find(from);
348   gold_assert(p != this->forwarders_.end());
349   return p->second;
350 }
351
352 // Look up a symbol by name.
353
354 Symbol*
355 Symbol_table::lookup(const char* name, const char* version) const
356 {
357   Stringpool::Key name_key;
358   name = this->namepool_.find(name, &name_key);
359   if (name == NULL)
360     return NULL;
361
362   Stringpool::Key version_key = 0;
363   if (version != NULL)
364     {
365       version = this->namepool_.find(version, &version_key);
366       if (version == NULL)
367         return NULL;
368     }
369
370   Symbol_table_key key(name_key, version_key);
371   Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
372   if (p == this->table_.end())
373     return NULL;
374   return p->second;
375 }
376
377 // Resolve a Symbol with another Symbol.  This is only used in the
378 // unusual case where there are references to both an unversioned
379 // symbol and a symbol with a version, and we then discover that that
380 // version is the default version.  Because this is unusual, we do
381 // this the slow way, by converting back to an ELF symbol.
382
383 template<int size, bool big_endian>
384 void
385 Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
386                       const char* version ACCEPT_SIZE_ENDIAN)
387 {
388   unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
389   elfcpp::Sym_write<size, big_endian> esym(buf);
390   // We don't bother to set the st_name field.
391   esym.put_st_value(from->value());
392   esym.put_st_size(from->symsize());
393   esym.put_st_info(from->binding(), from->type());
394   esym.put_st_other(from->visibility(), from->nonvis());
395   esym.put_st_shndx(from->shndx());
396   this->resolve(to, esym.sym(), esym.sym(), from->object(), version);
397   if (from->in_reg())
398     to->set_in_reg();
399   if (from->in_dyn())
400     to->set_in_dyn();
401 }
402
403 // Add one symbol from OBJECT to the symbol table.  NAME is symbol
404 // name and VERSION is the version; both are canonicalized.  DEF is
405 // whether this is the default version.
406
407 // If DEF is true, then this is the definition of a default version of
408 // a symbol.  That means that any lookup of NAME/NULL and any lookup
409 // of NAME/VERSION should always return the same symbol.  This is
410 // obvious for references, but in particular we want to do this for
411 // definitions: overriding NAME/NULL should also override
412 // NAME/VERSION.  If we don't do that, it would be very hard to
413 // override functions in a shared library which uses versioning.
414
415 // We implement this by simply making both entries in the hash table
416 // point to the same Symbol structure.  That is easy enough if this is
417 // the first time we see NAME/NULL or NAME/VERSION, but it is possible
418 // that we have seen both already, in which case they will both have
419 // independent entries in the symbol table.  We can't simply change
420 // the symbol table entry, because we have pointers to the entries
421 // attached to the object files.  So we mark the entry attached to the
422 // object file as a forwarder, and record it in the forwarders_ map.
423 // Note that entries in the hash table will never be marked as
424 // forwarders.
425 //
426 // SYM and ORIG_SYM are almost always the same.  ORIG_SYM is the
427 // symbol exactly as it existed in the input file.  SYM is usually
428 // that as well, but can be modified, for instance if we determine
429 // it's in a to-be-discarded section.
430
431 template<int size, bool big_endian>
432 Sized_symbol<size>*
433 Symbol_table::add_from_object(Object* object,
434                               const char *name,
435                               Stringpool::Key name_key,
436                               const char *version,
437                               Stringpool::Key version_key,
438                               bool def,
439                               const elfcpp::Sym<size, big_endian>& sym,
440                               const elfcpp::Sym<size, big_endian>& orig_sym)
441 {
442   Symbol* const snull = NULL;
443   std::pair<typename Symbol_table_type::iterator, bool> ins =
444     this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
445                                        snull));
446
447   std::pair<typename Symbol_table_type::iterator, bool> insdef =
448     std::make_pair(this->table_.end(), false);
449   if (def)
450     {
451       const Stringpool::Key vnull_key = 0;
452       insdef = this->table_.insert(std::make_pair(std::make_pair(name_key,
453                                                                  vnull_key),
454                                                   snull));
455     }
456
457   // ins.first: an iterator, which is a pointer to a pair.
458   // ins.first->first: the key (a pair of name and version).
459   // ins.first->second: the value (Symbol*).
460   // ins.second: true if new entry was inserted, false if not.
461
462   Sized_symbol<size>* ret;
463   bool was_undefined;
464   bool was_common;
465   if (!ins.second)
466     {
467       // We already have an entry for NAME/VERSION.
468       ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (ins.first->second
469                                                            SELECT_SIZE(size));
470       gold_assert(ret != NULL);
471
472       was_undefined = ret->is_undefined();
473       was_common = ret->is_common();
474
475       this->resolve(ret, sym, orig_sym, object, version);
476
477       if (def)
478         {
479           if (insdef.second)
480             {
481               // This is the first time we have seen NAME/NULL.  Make
482               // NAME/NULL point to NAME/VERSION.
483               insdef.first->second = ret;
484             }
485           else if (insdef.first->second != ret)
486             {
487               // This is the unfortunate case where we already have
488               // entries for both NAME/VERSION and NAME/NULL.
489               const Sized_symbol<size>* sym2;
490               sym2 = this->get_sized_symbol SELECT_SIZE_NAME(size) (
491                 insdef.first->second
492                 SELECT_SIZE(size));
493               Symbol_table::resolve SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
494                 ret, sym2, version SELECT_SIZE_ENDIAN(size, big_endian));
495               this->make_forwarder(insdef.first->second, ret);
496               insdef.first->second = ret;
497             }
498         }
499     }
500   else
501     {
502       // This is the first time we have seen NAME/VERSION.
503       gold_assert(ins.first->second == NULL);
504
505       was_undefined = false;
506       was_common = false;
507
508       if (def && !insdef.second)
509         {
510           // We already have an entry for NAME/NULL.  If we override
511           // it, then change it to NAME/VERSION.
512           ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (
513               insdef.first->second
514               SELECT_SIZE(size));
515           this->resolve(ret, sym, orig_sym, object, version);
516           ins.first->second = ret;
517         }
518       else
519         {
520           Sized_target<size, big_endian>* target =
521             object->sized_target SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
522                 SELECT_SIZE_ENDIAN_ONLY(size, big_endian));
523           if (!target->has_make_symbol())
524             ret = new Sized_symbol<size>();
525           else
526             {
527               ret = target->make_symbol();
528               if (ret == NULL)
529                 {
530                   // This means that we don't want a symbol table
531                   // entry after all.
532                   if (!def)
533                     this->table_.erase(ins.first);
534                   else
535                     {
536                       this->table_.erase(insdef.first);
537                       // Inserting insdef invalidated ins.
538                       this->table_.erase(std::make_pair(name_key,
539                                                         version_key));
540                     }
541                   return NULL;
542                 }
543             }
544
545           ret->init(name, version, object, sym);
546
547           ins.first->second = ret;
548           if (def)
549             {
550               // This is the first time we have seen NAME/NULL.  Point
551               // it at the new entry for NAME/VERSION.
552               gold_assert(insdef.second);
553               insdef.first->second = ret;
554             }
555         }
556     }
557
558   // Record every time we see a new undefined symbol, to speed up
559   // archive groups.
560   if (!was_undefined && ret->is_undefined())
561     ++this->saw_undefined_;
562
563   // Keep track of common symbols, to speed up common symbol
564   // allocation.
565   if (!was_common && ret->is_common())
566     this->commons_.push_back(ret);
567
568   return ret;
569 }
570
571 // Add all the symbols in a relocatable object to the hash table.
572
573 template<int size, bool big_endian>
574 void
575 Symbol_table::add_from_relobj(
576     Sized_relobj<size, big_endian>* relobj,
577     const unsigned char* syms,
578     size_t count,
579     const char* sym_names,
580     size_t sym_name_size,
581     typename Sized_relobj<size, big_endian>::Symbols* sympointers)
582 {
583   gold_assert(size == relobj->target()->get_size());
584   gold_assert(size == parameters->get_size());
585
586   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
587
588   const unsigned char* p = syms;
589   for (size_t i = 0; i < count; ++i, p += sym_size)
590     {
591       elfcpp::Sym<size, big_endian> sym(p);
592       elfcpp::Sym<size, big_endian>* psym = &sym;
593
594       unsigned int st_name = psym->get_st_name();
595       if (st_name >= sym_name_size)
596         {
597           relobj->error(_("bad global symbol name offset %u at %zu"),
598                         st_name, i);
599           continue;
600         }
601
602       const char* name = sym_names + st_name;
603
604       // A symbol defined in a section which we are not including must
605       // be treated as an undefined symbol.
606       unsigned char symbuf[sym_size];
607       elfcpp::Sym<size, big_endian> sym2(symbuf);
608       unsigned int st_shndx = psym->get_st_shndx();
609       if (st_shndx != elfcpp::SHN_UNDEF
610           && st_shndx < elfcpp::SHN_LORESERVE
611           && !relobj->is_section_included(st_shndx))
612         {
613           memcpy(symbuf, p, sym_size);
614           elfcpp::Sym_write<size, big_endian> sw(symbuf);
615           sw.put_st_shndx(elfcpp::SHN_UNDEF);
616           psym = &sym2;
617         }
618
619       // In an object file, an '@' in the name separates the symbol
620       // name from the version name.  If there are two '@' characters,
621       // this is the default version.
622       const char* ver = strchr(name, '@');
623
624       Sized_symbol<size>* res;
625       if (ver == NULL)
626         {
627           Stringpool::Key name_key;
628           name = this->namepool_.add(name, true, &name_key);
629           res = this->add_from_object(relobj, name, name_key, NULL, 0,
630                                       false, *psym, sym);
631         }
632       else
633         {
634           Stringpool::Key name_key;
635           name = this->namepool_.add_prefix(name, ver - name, &name_key);
636
637           bool def = false;
638           ++ver;
639           if (*ver == '@')
640             {
641               def = true;
642               ++ver;
643             }
644
645           Stringpool::Key ver_key;
646           ver = this->namepool_.add(ver, true, &ver_key);
647
648           res = this->add_from_object(relobj, name, name_key, ver, ver_key,
649                                       def, *psym, sym);
650         }
651
652       (*sympointers)[i] = res;
653     }
654 }
655
656 // Add all the symbols in a dynamic object to the hash table.
657
658 template<int size, bool big_endian>
659 void
660 Symbol_table::add_from_dynobj(
661     Sized_dynobj<size, big_endian>* dynobj,
662     const unsigned char* syms,
663     size_t count,
664     const char* sym_names,
665     size_t sym_name_size,
666     const unsigned char* versym,
667     size_t versym_size,
668     const std::vector<const char*>* version_map)
669 {
670   gold_assert(size == dynobj->target()->get_size());
671   gold_assert(size == parameters->get_size());
672
673   if (versym != NULL && versym_size / 2 < count)
674     {
675       dynobj->error(_("too few symbol versions"));
676       return;
677     }
678
679   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
680
681   // We keep a list of all STT_OBJECT symbols, so that we can resolve
682   // weak aliases.  This is necessary because if the dynamic object
683   // provides the same variable under two names, one of which is a
684   // weak definition, and the regular object refers to the weak
685   // definition, we have to put both the weak definition and the
686   // strong definition into the dynamic symbol table.  Given a weak
687   // definition, the only way that we can find the corresponding
688   // strong definition, if any, is to search the symbol table.
689   std::vector<Sized_symbol<size>*> object_symbols;
690
691   const unsigned char* p = syms;
692   const unsigned char* vs = versym;
693   for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
694     {
695       elfcpp::Sym<size, big_endian> sym(p);
696
697       // Ignore symbols with local binding.
698       if (sym.get_st_bind() == elfcpp::STB_LOCAL)
699         continue;
700
701       unsigned int st_name = sym.get_st_name();
702       if (st_name >= sym_name_size)
703         {
704           dynobj->error(_("bad symbol name offset %u at %zu"),
705                         st_name, i);
706           continue;
707         }
708
709       const char* name = sym_names + st_name;
710
711       Sized_symbol<size>* res;
712
713       if (versym == NULL)
714         {
715           Stringpool::Key name_key;
716           name = this->namepool_.add(name, true, &name_key);
717           res = this->add_from_object(dynobj, name, name_key, NULL, 0,
718                                       false, sym, sym);
719         }
720       else
721         {
722           // Read the version information.
723
724           unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
725
726           bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
727           v &= elfcpp::VERSYM_VERSION;
728
729           // The Sun documentation says that V can be VER_NDX_LOCAL,
730           // or VER_NDX_GLOBAL, or a version index.  The meaning of
731           // VER_NDX_LOCAL is defined as "Symbol has local scope."
732           // The old GNU linker will happily generate VER_NDX_LOCAL
733           // for an undefined symbol.  I don't know what the Sun
734           // linker will generate.
735
736           if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
737               && sym.get_st_shndx() != elfcpp::SHN_UNDEF)
738             {
739               // This symbol should not be visible outside the object.
740               continue;
741             }
742
743           // At this point we are definitely going to add this symbol.
744           Stringpool::Key name_key;
745           name = this->namepool_.add(name, true, &name_key);
746
747           if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
748               || v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
749             {
750               // This symbol does not have a version.
751               res = this->add_from_object(dynobj, name, name_key, NULL, 0,
752                                           false, sym, sym);
753             }
754           else
755             {
756               if (v >= version_map->size())
757                 {
758                   dynobj->error(_("versym for symbol %zu out of range: %u"),
759                                 i, v);
760                   continue;
761                 }
762
763               const char* version = (*version_map)[v];
764               if (version == NULL)
765                 {
766                   dynobj->error(_("versym for symbol %zu has no name: %u"),
767                                 i, v);
768                   continue;
769                 }
770
771               Stringpool::Key version_key;
772               version = this->namepool_.add(version, true, &version_key);
773
774               // If this is an absolute symbol, and the version name
775               // and symbol name are the same, then this is the
776               // version definition symbol.  These symbols exist to
777               // support using -u to pull in particular versions.  We
778               // do not want to record a version for them.
779               if (sym.get_st_shndx() == elfcpp::SHN_ABS
780                   && name_key == version_key)
781                 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
782                                             false, sym, sym);
783               else
784                 {
785                   const bool def = (!hidden
786                                     && (sym.get_st_shndx()
787                                         != elfcpp::SHN_UNDEF));
788                   res = this->add_from_object(dynobj, name, name_key, version,
789                                               version_key, def, sym, sym);
790                 }
791             }
792         }
793
794       if (sym.get_st_shndx() != elfcpp::SHN_UNDEF
795           && sym.get_st_type() == elfcpp::STT_OBJECT)
796         object_symbols.push_back(res);
797     }
798
799   this->record_weak_aliases(&object_symbols);
800 }
801
802 // This is used to sort weak aliases.  We sort them first by section
803 // index, then by offset, then by weak ahead of strong.
804
805 template<int size>
806 class Weak_alias_sorter
807 {
808  public:
809   bool operator()(const Sized_symbol<size>*, const Sized_symbol<size>*) const;
810 };
811
812 template<int size>
813 bool
814 Weak_alias_sorter<size>::operator()(const Sized_symbol<size>* s1,
815                                     const Sized_symbol<size>* s2) const
816 {
817   if (s1->shndx() != s2->shndx())
818     return s1->shndx() < s2->shndx();
819   if (s1->value() != s2->value())
820     return s1->value() < s2->value();
821   if (s1->binding() != s2->binding())
822     {
823       if (s1->binding() == elfcpp::STB_WEAK)
824         return true;
825       if (s2->binding() == elfcpp::STB_WEAK)
826         return false;
827     }
828   return std::string(s1->name()) < std::string(s2->name());
829 }
830
831 // SYMBOLS is a list of object symbols from a dynamic object.  Look
832 // for any weak aliases, and record them so that if we add the weak
833 // alias to the dynamic symbol table, we also add the corresponding
834 // strong symbol.
835
836 template<int size>
837 void
838 Symbol_table::record_weak_aliases(std::vector<Sized_symbol<size>*>* symbols)
839 {
840   // Sort the vector by section index, then by offset, then by weak
841   // ahead of strong.
842   std::sort(symbols->begin(), symbols->end(), Weak_alias_sorter<size>());
843
844   // Walk through the vector.  For each weak definition, record
845   // aliases.
846   for (typename std::vector<Sized_symbol<size>*>::const_iterator p =
847          symbols->begin();
848        p != symbols->end();
849        ++p)
850     {
851       if ((*p)->binding() != elfcpp::STB_WEAK)
852         continue;
853
854       // Build a circular list of weak aliases.  Each symbol points to
855       // the next one in the circular list.
856
857       Sized_symbol<size>* from_sym = *p;
858       typename std::vector<Sized_symbol<size>*>::const_iterator q;
859       for (q = p + 1; q != symbols->end(); ++q)
860         {
861           if ((*q)->shndx() != from_sym->shndx()
862               || (*q)->value() != from_sym->value())
863             break;
864
865           this->weak_aliases_[from_sym] = *q;
866           from_sym->set_has_alias();
867           from_sym = *q;
868         }
869
870       if (from_sym != *p)
871         {
872           this->weak_aliases_[from_sym] = *p;
873           from_sym->set_has_alias();
874         }
875
876       p = q - 1;
877     }
878 }
879
880 // Create and return a specially defined symbol.  If ONLY_IF_REF is
881 // true, then only create the symbol if there is a reference to it.
882 // If this does not return NULL, it sets *POLDSYM to the existing
883 // symbol if there is one.  This canonicalizes *PNAME and *PVERSION.
884
885 template<int size, bool big_endian>
886 Sized_symbol<size>*
887 Symbol_table::define_special_symbol(const Target* target, const char** pname,
888                                     const char** pversion, bool only_if_ref,
889                                     Sized_symbol<size>** poldsym
890                                     ACCEPT_SIZE_ENDIAN)
891 {
892   Symbol* oldsym;
893   Sized_symbol<size>* sym;
894   bool add_to_table = false;
895   typename Symbol_table_type::iterator add_loc = this->table_.end();
896
897   if (only_if_ref)
898     {
899       oldsym = this->lookup(*pname, *pversion);
900       if (oldsym == NULL || !oldsym->is_undefined())
901         return NULL;
902
903       *pname = oldsym->name();
904       *pversion = oldsym->version();
905     }
906   else
907     {
908       // Canonicalize NAME and VERSION.
909       Stringpool::Key name_key;
910       *pname = this->namepool_.add(*pname, true, &name_key);
911
912       Stringpool::Key version_key = 0;
913       if (*pversion != NULL)
914         *pversion = this->namepool_.add(*pversion, true, &version_key);
915
916       Symbol* const snull = NULL;
917       std::pair<typename Symbol_table_type::iterator, bool> ins =
918         this->table_.insert(std::make_pair(std::make_pair(name_key,
919                                                           version_key),
920                                            snull));
921
922       if (!ins.second)
923         {
924           // We already have a symbol table entry for NAME/VERSION.
925           oldsym = ins.first->second;
926           gold_assert(oldsym != NULL);
927         }
928       else
929         {
930           // We haven't seen this symbol before.
931           gold_assert(ins.first->second == NULL);
932           add_to_table = true;
933           add_loc = ins.first;
934           oldsym = NULL;
935         }
936     }
937
938   if (!target->has_make_symbol())
939     sym = new Sized_symbol<size>();
940   else
941     {
942       gold_assert(target->get_size() == size);
943       gold_assert(target->is_big_endian() ? big_endian : !big_endian);
944       typedef Sized_target<size, big_endian> My_target;
945       const My_target* sized_target =
946           static_cast<const My_target*>(target);
947       sym = sized_target->make_symbol();
948       if (sym == NULL)
949         return NULL;
950     }
951
952   if (add_to_table)
953     add_loc->second = sym;
954   else
955     gold_assert(oldsym != NULL);
956
957   *poldsym = this->get_sized_symbol SELECT_SIZE_NAME(size) (oldsym
958                                                             SELECT_SIZE(size));
959
960   return sym;
961 }
962
963 // Define a symbol based on an Output_data.
964
965 Symbol*
966 Symbol_table::define_in_output_data(const Target* target, const char* name,
967                                     const char* version, Output_data* od,
968                                     uint64_t value, uint64_t symsize,
969                                     elfcpp::STT type, elfcpp::STB binding,
970                                     elfcpp::STV visibility,
971                                     unsigned char nonvis,
972                                     bool offset_is_from_end,
973                                     bool only_if_ref)
974 {
975   if (parameters->get_size() == 32)
976     {
977 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
978       return this->do_define_in_output_data<32>(target, name, version, od,
979                                                 value, symsize, type, binding,
980                                                 visibility, nonvis,
981                                                 offset_is_from_end,
982                                                 only_if_ref);
983 #else
984       gold_unreachable();
985 #endif
986     }
987   else if (parameters->get_size() == 64)
988     {
989 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
990       return this->do_define_in_output_data<64>(target, name, version, od,
991                                                 value, symsize, type, binding,
992                                                 visibility, nonvis,
993                                                 offset_is_from_end,
994                                                 only_if_ref);
995 #else
996       gold_unreachable();
997 #endif
998     }
999   else
1000     gold_unreachable();
1001 }
1002
1003 // Define a symbol in an Output_data, sized version.
1004
1005 template<int size>
1006 Sized_symbol<size>*
1007 Symbol_table::do_define_in_output_data(
1008     const Target* target,
1009     const char* name,
1010     const char* version,
1011     Output_data* od,
1012     typename elfcpp::Elf_types<size>::Elf_Addr value,
1013     typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1014     elfcpp::STT type,
1015     elfcpp::STB binding,
1016     elfcpp::STV visibility,
1017     unsigned char nonvis,
1018     bool offset_is_from_end,
1019     bool only_if_ref)
1020 {
1021   Sized_symbol<size>* sym;
1022   Sized_symbol<size>* oldsym;
1023
1024   if (parameters->is_big_endian())
1025     {
1026 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1027       sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1028           target, &name, &version, only_if_ref, &oldsym
1029           SELECT_SIZE_ENDIAN(size, true));
1030 #else
1031       gold_unreachable();
1032 #endif
1033     }
1034   else
1035     {
1036 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1037       sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1038           target, &name, &version, only_if_ref, &oldsym
1039           SELECT_SIZE_ENDIAN(size, false));
1040 #else
1041       gold_unreachable();
1042 #endif
1043     }
1044
1045   if (sym == NULL)
1046     return NULL;
1047
1048   gold_assert(version == NULL || oldsym != NULL);
1049   sym->init(name, od, value, symsize, type, binding, visibility, nonvis,
1050             offset_is_from_end);
1051
1052   if (oldsym != NULL
1053       && Symbol_table::should_override_with_special(oldsym))
1054     this->override_with_special(oldsym, sym);
1055
1056   return sym;
1057 }
1058
1059 // Define a symbol based on an Output_segment.
1060
1061 Symbol*
1062 Symbol_table::define_in_output_segment(const Target* target, const char* name,
1063                                        const char* version, Output_segment* os,
1064                                        uint64_t value, uint64_t symsize,
1065                                        elfcpp::STT type, elfcpp::STB binding,
1066                                        elfcpp::STV visibility,
1067                                        unsigned char nonvis,
1068                                        Symbol::Segment_offset_base offset_base,
1069                                        bool only_if_ref)
1070 {
1071   if (parameters->get_size() == 32)
1072     {
1073 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1074       return this->do_define_in_output_segment<32>(target, name, version, os,
1075                                                    value, symsize, type,
1076                                                    binding, visibility, nonvis,
1077                                                    offset_base, only_if_ref);
1078 #else
1079       gold_unreachable();
1080 #endif
1081     }
1082   else if (parameters->get_size() == 64)
1083     {
1084 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1085       return this->do_define_in_output_segment<64>(target, name, version, os,
1086                                                    value, symsize, type,
1087                                                    binding, visibility, nonvis,
1088                                                    offset_base, only_if_ref);
1089 #else
1090       gold_unreachable();
1091 #endif
1092     }
1093   else
1094     gold_unreachable();
1095 }
1096
1097 // Define a symbol in an Output_segment, sized version.
1098
1099 template<int size>
1100 Sized_symbol<size>*
1101 Symbol_table::do_define_in_output_segment(
1102     const Target* target,
1103     const char* name,
1104     const char* version,
1105     Output_segment* os,
1106     typename elfcpp::Elf_types<size>::Elf_Addr value,
1107     typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1108     elfcpp::STT type,
1109     elfcpp::STB binding,
1110     elfcpp::STV visibility,
1111     unsigned char nonvis,
1112     Symbol::Segment_offset_base offset_base,
1113     bool only_if_ref)
1114 {
1115   Sized_symbol<size>* sym;
1116   Sized_symbol<size>* oldsym;
1117
1118   if (parameters->is_big_endian())
1119     {
1120 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1121       sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1122           target, &name, &version, only_if_ref, &oldsym
1123           SELECT_SIZE_ENDIAN(size, true));
1124 #else
1125       gold_unreachable();
1126 #endif
1127     }
1128   else
1129     {
1130 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1131       sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1132           target, &name, &version, only_if_ref, &oldsym
1133           SELECT_SIZE_ENDIAN(size, false));
1134 #else
1135       gold_unreachable();
1136 #endif
1137     }
1138
1139   if (sym == NULL)
1140     return NULL;
1141
1142   gold_assert(version == NULL || oldsym != NULL);
1143   sym->init(name, os, value, symsize, type, binding, visibility, nonvis,
1144             offset_base);
1145
1146   if (oldsym != NULL
1147       && Symbol_table::should_override_with_special(oldsym))
1148     this->override_with_special(oldsym, sym);
1149
1150   return sym;
1151 }
1152
1153 // Define a special symbol with a constant value.  It is a multiple
1154 // definition error if this symbol is already defined.
1155
1156 Symbol*
1157 Symbol_table::define_as_constant(const Target* target, const char* name,
1158                                  const char* version, uint64_t value,
1159                                  uint64_t symsize, elfcpp::STT type,
1160                                  elfcpp::STB binding, elfcpp::STV visibility,
1161                                  unsigned char nonvis, bool only_if_ref)
1162 {
1163   if (parameters->get_size() == 32)
1164     {
1165 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1166       return this->do_define_as_constant<32>(target, name, version, value,
1167                                              symsize, type, binding,
1168                                              visibility, nonvis, only_if_ref);
1169 #else
1170       gold_unreachable();
1171 #endif
1172     }
1173   else if (parameters->get_size() == 64)
1174     {
1175 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1176       return this->do_define_as_constant<64>(target, name, version, value,
1177                                              symsize, type, binding,
1178                                              visibility, nonvis, only_if_ref);
1179 #else
1180       gold_unreachable();
1181 #endif
1182     }
1183   else
1184     gold_unreachable();
1185 }
1186
1187 // Define a symbol as a constant, sized version.
1188
1189 template<int size>
1190 Sized_symbol<size>*
1191 Symbol_table::do_define_as_constant(
1192     const Target* target,
1193     const char* name,
1194     const char* version,
1195     typename elfcpp::Elf_types<size>::Elf_Addr value,
1196     typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1197     elfcpp::STT type,
1198     elfcpp::STB binding,
1199     elfcpp::STV visibility,
1200     unsigned char nonvis,
1201     bool only_if_ref)
1202 {
1203   Sized_symbol<size>* sym;
1204   Sized_symbol<size>* oldsym;
1205
1206   if (parameters->is_big_endian())
1207     {
1208 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1209       sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1210           target, &name, &version, only_if_ref, &oldsym
1211           SELECT_SIZE_ENDIAN(size, true));
1212 #else
1213       gold_unreachable();
1214 #endif
1215     }
1216   else
1217     {
1218 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1219       sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1220           target, &name, &version, only_if_ref, &oldsym
1221           SELECT_SIZE_ENDIAN(size, false));
1222 #else
1223       gold_unreachable();
1224 #endif
1225     }
1226
1227   if (sym == NULL)
1228     return NULL;
1229
1230   gold_assert(version == NULL || oldsym != NULL);
1231   sym->init(name, value, symsize, type, binding, visibility, nonvis);
1232
1233   if (oldsym != NULL
1234       && Symbol_table::should_override_with_special(oldsym))
1235     this->override_with_special(oldsym, sym);
1236
1237   return sym;
1238 }
1239
1240 // Define a set of symbols in output sections.
1241
1242 void
1243 Symbol_table::define_symbols(const Layout* layout, const Target* target,
1244                              int count, const Define_symbol_in_section* p)
1245 {
1246   for (int i = 0; i < count; ++i, ++p)
1247     {
1248       Output_section* os = layout->find_output_section(p->output_section);
1249       if (os != NULL)
1250         this->define_in_output_data(target, p->name, NULL, os, p->value,
1251                                     p->size, p->type, p->binding,
1252                                     p->visibility, p->nonvis,
1253                                     p->offset_is_from_end, p->only_if_ref);
1254       else
1255         this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
1256                                  p->binding, p->visibility, p->nonvis,
1257                                  p->only_if_ref);
1258     }
1259 }
1260
1261 // Define a set of symbols in output segments.
1262
1263 void
1264 Symbol_table::define_symbols(const Layout* layout, const Target* target,
1265                              int count, const Define_symbol_in_segment* p)
1266 {
1267   for (int i = 0; i < count; ++i, ++p)
1268     {
1269       Output_segment* os = layout->find_output_segment(p->segment_type,
1270                                                        p->segment_flags_set,
1271                                                        p->segment_flags_clear);
1272       if (os != NULL)
1273         this->define_in_output_segment(target, p->name, NULL, os, p->value,
1274                                        p->size, p->type, p->binding,
1275                                        p->visibility, p->nonvis,
1276                                        p->offset_base, p->only_if_ref);
1277       else
1278         this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
1279                                  p->binding, p->visibility, p->nonvis,
1280                                  p->only_if_ref);
1281     }
1282 }
1283
1284 // Define CSYM using a COPY reloc.  POSD is the Output_data where the
1285 // symbol should be defined--typically a .dyn.bss section.  VALUE is
1286 // the offset within POSD.
1287
1288 template<int size>
1289 void
1290 Symbol_table::define_with_copy_reloc(const Target* target,
1291                                      Sized_symbol<size>* csym,
1292                                      Output_data* posd, uint64_t value)
1293 {
1294   gold_assert(csym->is_from_dynobj());
1295   gold_assert(!csym->is_copied_from_dynobj());
1296   Object* object = csym->object();
1297   gold_assert(object->is_dynamic());
1298   Dynobj* dynobj = static_cast<Dynobj*>(object);
1299
1300   // Our copied variable has to override any variable in a shared
1301   // library.
1302   elfcpp::STB binding = csym->binding();
1303   if (binding == elfcpp::STB_WEAK)
1304     binding = elfcpp::STB_GLOBAL;
1305
1306   this->define_in_output_data(target, csym->name(), csym->version(),
1307                               posd, value, csym->symsize(),
1308                               csym->type(), binding,
1309                               csym->visibility(), csym->nonvis(),
1310                               false, false);
1311
1312   csym->set_is_copied_from_dynobj();
1313   csym->set_needs_dynsym_entry();
1314
1315   this->copied_symbol_dynobjs_[csym] = dynobj;
1316
1317   // We have now defined all aliases, but we have not entered them all
1318   // in the copied_symbol_dynobjs_ map.
1319   if (csym->has_alias())
1320     {
1321       Symbol* sym = csym;
1322       while (true)
1323         {
1324           sym = this->weak_aliases_[sym];
1325           if (sym == csym)
1326             break;
1327           gold_assert(sym->output_data() == posd);
1328
1329           sym->set_is_copied_from_dynobj();
1330           this->copied_symbol_dynobjs_[sym] = dynobj;
1331         }
1332     }
1333 }
1334
1335 // SYM is defined using a COPY reloc.  Return the dynamic object where
1336 // the original definition was found.
1337
1338 Dynobj*
1339 Symbol_table::get_copy_source(const Symbol* sym) const
1340 {
1341   gold_assert(sym->is_copied_from_dynobj());
1342   Copied_symbol_dynobjs::const_iterator p =
1343     this->copied_symbol_dynobjs_.find(sym);
1344   gold_assert(p != this->copied_symbol_dynobjs_.end());
1345   return p->second;
1346 }
1347
1348 // Set the dynamic symbol indexes.  INDEX is the index of the first
1349 // global dynamic symbol.  Pointers to the symbols are stored into the
1350 // vector SYMS.  The names are added to DYNPOOL.  This returns an
1351 // updated dynamic symbol index.
1352
1353 unsigned int
1354 Symbol_table::set_dynsym_indexes(const Target* target,
1355                                  unsigned int index,
1356                                  std::vector<Symbol*>* syms,
1357                                  Stringpool* dynpool,
1358                                  Versions* versions)
1359 {
1360   for (Symbol_table_type::iterator p = this->table_.begin();
1361        p != this->table_.end();
1362        ++p)
1363     {
1364       Symbol* sym = p->second;
1365
1366       // Note that SYM may already have a dynamic symbol index, since
1367       // some symbols appear more than once in the symbol table, with
1368       // and without a version.
1369
1370       if (!sym->should_add_dynsym_entry())
1371         sym->set_dynsym_index(-1U);
1372       else if (!sym->has_dynsym_index())
1373         {
1374           sym->set_dynsym_index(index);
1375           ++index;
1376           syms->push_back(sym);
1377           dynpool->add(sym->name(), false, NULL);
1378
1379           // Record any version information.
1380           if (sym->version() != NULL)
1381             versions->record_version(this, dynpool, sym);
1382         }
1383     }
1384
1385   // Finish up the versions.  In some cases this may add new dynamic
1386   // symbols.
1387   index = versions->finalize(target, this, index, syms);
1388
1389   return index;
1390 }
1391
1392 // Set the final values for all the symbols.  The index of the first
1393 // global symbol in the output file is INDEX.  Record the file offset
1394 // OFF.  Add their names to POOL.  Return the new file offset.
1395
1396 off_t
1397 Symbol_table::finalize(unsigned int index, off_t off, off_t dynoff,
1398                        size_t dyn_global_index, size_t dyncount,
1399                        Stringpool* pool)
1400 {
1401   off_t ret;
1402
1403   gold_assert(index != 0);
1404   this->first_global_index_ = index;
1405
1406   this->dynamic_offset_ = dynoff;
1407   this->first_dynamic_global_index_ = dyn_global_index;
1408   this->dynamic_count_ = dyncount;
1409
1410   if (parameters->get_size() == 32)
1411     {
1412 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
1413       ret = this->sized_finalize<32>(index, off, pool);
1414 #else
1415       gold_unreachable();
1416 #endif
1417     }
1418   else if (parameters->get_size() == 64)
1419     {
1420 #if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
1421       ret = this->sized_finalize<64>(index, off, pool);
1422 #else
1423       gold_unreachable();
1424 #endif
1425     }
1426   else
1427     gold_unreachable();
1428
1429   // Now that we have the final symbol table, we can reliably note
1430   // which symbols should get warnings.
1431   this->warnings_.note_warnings(this);
1432
1433   return ret;
1434 }
1435
1436 // Set the final value for all the symbols.  This is called after
1437 // Layout::finalize, so all the output sections have their final
1438 // address.
1439
1440 template<int size>
1441 off_t
1442 Symbol_table::sized_finalize(unsigned index, off_t off, Stringpool* pool)
1443 {
1444   off = align_address(off, size >> 3);
1445   this->offset_ = off;
1446
1447   size_t orig_index = index;
1448
1449   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1450   for (Symbol_table_type::iterator p = this->table_.begin();
1451        p != this->table_.end();
1452        ++p)
1453     {
1454       Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1455
1456       // FIXME: Here we need to decide which symbols should go into
1457       // the output file, based on --strip.
1458
1459       // The default version of a symbol may appear twice in the
1460       // symbol table.  We only need to finalize it once.
1461       if (sym->has_symtab_index())
1462         continue;
1463
1464       if (!sym->in_reg())
1465         {
1466           gold_assert(!sym->has_symtab_index());
1467           sym->set_symtab_index(-1U);
1468           gold_assert(sym->dynsym_index() == -1U);
1469           continue;
1470         }
1471
1472       typename Sized_symbol<size>::Value_type value;
1473
1474       switch (sym->source())
1475         {
1476         case Symbol::FROM_OBJECT:
1477           {
1478             unsigned int shndx = sym->shndx();
1479
1480             // FIXME: We need some target specific support here.
1481             if (shndx >= elfcpp::SHN_LORESERVE
1482                 && shndx != elfcpp::SHN_ABS)
1483               {
1484                 gold_error(_("%s: unsupported symbol section 0x%x"),
1485                            sym->demangled_name().c_str(), shndx);
1486                 shndx = elfcpp::SHN_UNDEF;
1487               }
1488
1489             Object* symobj = sym->object();
1490             if (symobj->is_dynamic())
1491               {
1492                 value = 0;
1493                 shndx = elfcpp::SHN_UNDEF;
1494               }
1495             else if (shndx == elfcpp::SHN_UNDEF)
1496               value = 0;
1497             else if (shndx == elfcpp::SHN_ABS)
1498               value = sym->value();
1499             else
1500               {
1501                 Relobj* relobj = static_cast<Relobj*>(symobj);
1502                 off_t secoff;
1503                 Output_section* os = relobj->output_section(shndx, &secoff);
1504
1505                 if (os == NULL)
1506                   {
1507                     sym->set_symtab_index(-1U);
1508                     gold_assert(sym->dynsym_index() == -1U);
1509                     continue;
1510                   }
1511
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 // We check for ODR violations by looking for symbols with the same
1901 // name for which the debugging information reports that they were
1902 // defined in different source locations.  When comparing the source
1903 // location, we consider instances with the same base filename and
1904 // line number to be the same.  This is because different object
1905 // files/shared libraries can include the same header file using
1906 // different paths, and we don't want to report an ODR violation in
1907 // that case.
1908
1909 // This struct is used to compare line information, as returned by
1910 // Dwarf_line_info::one_addr2line.  It imlements a < comparison
1911 // operator used with std::set.
1912
1913 struct Odr_violation_compare
1914 {
1915   bool
1916   operator()(const std::string& s1, const std::string& s2) const
1917   {
1918     std::string::size_type pos1 = s1.rfind('/');
1919     std::string::size_type pos2 = s2.rfind('/');
1920     if (pos1 == std::string::npos
1921         || pos2 == std::string::npos)
1922       return s1 < s2;
1923     return s1.compare(pos1, std::string::npos,
1924                       s2, pos2, std::string::npos) < 0;
1925   }
1926 };
1927
1928 // Check candidate_odr_violations_ to find symbols with the same name
1929 // but apparently different definitions (different source-file/line-no).
1930
1931 void
1932 Symbol_table::detect_odr_violations(const char* output_file_name) const
1933 {
1934   for (Odr_map::const_iterator it = candidate_odr_violations_.begin();
1935        it != candidate_odr_violations_.end();
1936        ++it)
1937     {
1938       const char* symbol_name = it->first;
1939       // We use a sorted set so the output is deterministic.
1940       std::set<std::string, Odr_violation_compare> line_nums;
1941
1942       for (Unordered_set<Symbol_location, Symbol_location_hash>::const_iterator
1943                locs = it->second.begin();
1944            locs != it->second.end();
1945            ++locs)
1946         {
1947           // We need to lock the object in order to read it.  This
1948           // means that we can not run inside a Task.  If we want to
1949           // run this in a Task for better performance, we will need
1950           // one Task for object, plus appropriate locking to ensure
1951           // that we don't conflict with other uses of the object.
1952           locs->object->lock();
1953           std::string lineno = Dwarf_line_info::one_addr2line(
1954               locs->object, locs->shndx, locs->offset);
1955           locs->object->unlock();
1956           if (!lineno.empty())
1957             line_nums.insert(lineno);
1958         }
1959
1960       if (line_nums.size() > 1)
1961         {
1962           gold_warning(_("while linking %s: symbol '%s' defined in multiple "
1963                          "places (possible ODR violation):"),
1964                        output_file_name, demangle(symbol_name).c_str());
1965           for (std::set<std::string>::const_iterator it2 = line_nums.begin();
1966                it2 != line_nums.end();
1967                ++it2)
1968             fprintf(stderr, "  %s\n", it2->c_str());
1969         }
1970     }
1971 }
1972
1973 // Warnings functions.
1974
1975 // Add a new warning.
1976
1977 void
1978 Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
1979                       unsigned int shndx)
1980 {
1981   name = symtab->canonicalize_name(name);
1982   this->warnings_[name].set(obj, shndx);
1983 }
1984
1985 // Look through the warnings and mark the symbols for which we should
1986 // warn.  This is called during Layout::finalize when we know the
1987 // sources for all the symbols.
1988
1989 void
1990 Warnings::note_warnings(Symbol_table* symtab)
1991 {
1992   for (Warning_table::iterator p = this->warnings_.begin();
1993        p != this->warnings_.end();
1994        ++p)
1995     {
1996       Symbol* sym = symtab->lookup(p->first, NULL);
1997       if (sym != NULL
1998           && sym->source() == Symbol::FROM_OBJECT
1999           && sym->object() == p->second.object)
2000         {
2001           sym->set_has_warning();
2002
2003           // Read the section contents to get the warning text.  It
2004           // would be nicer if we only did this if we have to actually
2005           // issue a warning.  Unfortunately, warnings are issued as
2006           // we relocate sections.  That means that we can not lock
2007           // the object then, as we might try to issue the same
2008           // warning multiple times simultaneously.
2009           {
2010             Task_locker_obj<Object> tl(*p->second.object);
2011             const unsigned char* c;
2012             off_t len;
2013             c = p->second.object->section_contents(p->second.shndx, &len,
2014                                                    false);
2015             p->second.set_text(reinterpret_cast<const char*>(c), len);
2016           }
2017         }
2018     }
2019 }
2020
2021 // Issue a warning.  This is called when we see a relocation against a
2022 // symbol for which has a warning.
2023
2024 template<int size, bool big_endian>
2025 void
2026 Warnings::issue_warning(const Symbol* sym,
2027                         const Relocate_info<size, big_endian>* relinfo,
2028                         size_t relnum, off_t reloffset) const
2029 {
2030   gold_assert(sym->has_warning());
2031   Warning_table::const_iterator p = this->warnings_.find(sym->name());
2032   gold_assert(p != this->warnings_.end());
2033   gold_warning_at_location(relinfo, relnum, reloffset,
2034                            "%s", p->second.text.c_str());
2035 }
2036
2037 // Instantiate the templates we need.  We could use the configure
2038 // script to restrict this to only the ones needed for implemented
2039 // targets.
2040
2041 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
2042 template
2043 void
2044 Sized_symbol<32>::allocate_common(Output_data*, Value_type);
2045 #endif
2046
2047 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
2048 template
2049 void
2050 Sized_symbol<64>::allocate_common(Output_data*, Value_type);
2051 #endif
2052
2053 #ifdef HAVE_TARGET_32_LITTLE
2054 template
2055 void
2056 Symbol_table::add_from_relobj<32, false>(
2057     Sized_relobj<32, false>* relobj,
2058     const unsigned char* syms,
2059     size_t count,
2060     const char* sym_names,
2061     size_t sym_name_size,
2062     Sized_relobj<32, true>::Symbols* sympointers);
2063 #endif
2064
2065 #ifdef HAVE_TARGET_32_BIG
2066 template
2067 void
2068 Symbol_table::add_from_relobj<32, true>(
2069     Sized_relobj<32, true>* relobj,
2070     const unsigned char* syms,
2071     size_t count,
2072     const char* sym_names,
2073     size_t sym_name_size,
2074     Sized_relobj<32, false>::Symbols* sympointers);
2075 #endif
2076
2077 #ifdef HAVE_TARGET_64_LITTLE
2078 template
2079 void
2080 Symbol_table::add_from_relobj<64, false>(
2081     Sized_relobj<64, false>* relobj,
2082     const unsigned char* syms,
2083     size_t count,
2084     const char* sym_names,
2085     size_t sym_name_size,
2086     Sized_relobj<64, true>::Symbols* sympointers);
2087 #endif
2088
2089 #ifdef HAVE_TARGET_64_BIG
2090 template
2091 void
2092 Symbol_table::add_from_relobj<64, true>(
2093     Sized_relobj<64, true>* relobj,
2094     const unsigned char* syms,
2095     size_t count,
2096     const char* sym_names,
2097     size_t sym_name_size,
2098     Sized_relobj<64, false>::Symbols* sympointers);
2099 #endif
2100
2101 #ifdef HAVE_TARGET_32_LITTLE
2102 template
2103 void
2104 Symbol_table::add_from_dynobj<32, false>(
2105     Sized_dynobj<32, false>* dynobj,
2106     const unsigned char* syms,
2107     size_t count,
2108     const char* sym_names,
2109     size_t sym_name_size,
2110     const unsigned char* versym,
2111     size_t versym_size,
2112     const std::vector<const char*>* version_map);
2113 #endif
2114
2115 #ifdef HAVE_TARGET_32_BIG
2116 template
2117 void
2118 Symbol_table::add_from_dynobj<32, true>(
2119     Sized_dynobj<32, true>* dynobj,
2120     const unsigned char* syms,
2121     size_t count,
2122     const char* sym_names,
2123     size_t sym_name_size,
2124     const unsigned char* versym,
2125     size_t versym_size,
2126     const std::vector<const char*>* version_map);
2127 #endif
2128
2129 #ifdef HAVE_TARGET_64_LITTLE
2130 template
2131 void
2132 Symbol_table::add_from_dynobj<64, false>(
2133     Sized_dynobj<64, false>* dynobj,
2134     const unsigned char* syms,
2135     size_t count,
2136     const char* sym_names,
2137     size_t sym_name_size,
2138     const unsigned char* versym,
2139     size_t versym_size,
2140     const std::vector<const char*>* version_map);
2141 #endif
2142
2143 #ifdef HAVE_TARGET_64_BIG
2144 template
2145 void
2146 Symbol_table::add_from_dynobj<64, true>(
2147     Sized_dynobj<64, true>* dynobj,
2148     const unsigned char* syms,
2149     size_t count,
2150     const char* sym_names,
2151     size_t sym_name_size,
2152     const unsigned char* versym,
2153     size_t versym_size,
2154     const std::vector<const char*>* version_map);
2155 #endif
2156
2157 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
2158 template
2159 void
2160 Symbol_table::define_with_copy_reloc<32>(const Target* target,
2161                                          Sized_symbol<32>* sym,
2162                                          Output_data* posd, uint64_t value);
2163 #endif
2164
2165 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
2166 template
2167 void
2168 Symbol_table::define_with_copy_reloc<64>(const Target* target,
2169                                          Sized_symbol<64>* sym,
2170                                          Output_data* posd, uint64_t value);
2171 #endif
2172
2173 #ifdef HAVE_TARGET_32_LITTLE
2174 template
2175 void
2176 Warnings::issue_warning<32, false>(const Symbol* sym,
2177                                    const Relocate_info<32, false>* relinfo,
2178                                    size_t relnum, off_t reloffset) const;
2179 #endif
2180
2181 #ifdef HAVE_TARGET_32_BIG
2182 template
2183 void
2184 Warnings::issue_warning<32, true>(const Symbol* sym,
2185                                   const Relocate_info<32, true>* relinfo,
2186                                   size_t relnum, off_t reloffset) const;
2187 #endif
2188
2189 #ifdef HAVE_TARGET_64_LITTLE
2190 template
2191 void
2192 Warnings::issue_warning<64, false>(const Symbol* sym,
2193                                    const Relocate_info<64, false>* relinfo,
2194                                    size_t relnum, off_t reloffset) const;
2195 #endif
2196
2197 #ifdef HAVE_TARGET_64_BIG
2198 template
2199 void
2200 Warnings::issue_warning<64, true>(const Symbol* sym,
2201                                   const Relocate_info<64, true>* relinfo,
2202                                   size_t relnum, off_t reloffset) const;
2203 #endif
2204
2205 } // End namespace gold.