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