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