Add support for -E/--export-dynamic. Also clean up --help output a bit.
[external/binutils.git] / gold / symtab.cc
1 // symtab.cc -- the gold symbol table
2
3 #include "gold.h"
4
5 #include <stdint.h>
6 #include <string>
7 #include <utility>
8
9 #include "object.h"
10 #include "dynobj.h"
11 #include "output.h"
12 #include "target.h"
13 #include "workqueue.h"
14 #include "symtab.h"
15
16 namespace gold
17 {
18
19 // Class Symbol.
20
21 // Initialize fields in Symbol.  This initializes everything except u_
22 // and source_.
23
24 void
25 Symbol::init_fields(const char* name, const char* version,
26                     elfcpp::STT type, elfcpp::STB binding,
27                     elfcpp::STV visibility, unsigned char nonvis)
28 {
29   this->name_ = name;
30   this->version_ = version;
31   this->symtab_index_ = 0;
32   this->dynsym_index_ = 0;
33   this->got_offset_ = 0;
34   this->type_ = type;
35   this->binding_ = binding;
36   this->visibility_ = visibility;
37   this->nonvis_ = nonvis;
38   this->is_target_special_ = false;
39   this->is_def_ = false;
40   this->is_forwarder_ = false;
41   this->needs_dynsym_entry_ = false;
42   this->in_reg_ = false;
43   this->in_dyn_ = false;
44   this->has_got_offset_ = false;
45   this->has_warning_ = false;
46 }
47
48 // Initialize the fields in the base class Symbol for SYM in OBJECT.
49
50 template<int size, bool big_endian>
51 void
52 Symbol::init_base(const char* name, const char* version, Object* object,
53                   const elfcpp::Sym<size, big_endian>& sym)
54 {
55   this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
56                     sym.get_st_visibility(), sym.get_st_nonvis());
57   this->u_.from_object.object = object;
58   // FIXME: Handle SHN_XINDEX.
59   this->u_.from_object.shndx = sym.get_st_shndx();
60   this->source_ = FROM_OBJECT;
61   this->in_reg_ = !object->is_dynamic();
62   this->in_dyn_ = object->is_dynamic();
63 }
64
65 // Initialize the fields in the base class Symbol for a symbol defined
66 // in an Output_data.
67
68 void
69 Symbol::init_base(const char* name, Output_data* od, elfcpp::STT type,
70                   elfcpp::STB binding, elfcpp::STV visibility,
71                   unsigned char nonvis, bool offset_is_from_end)
72 {
73   this->init_fields(name, NULL, type, binding, visibility, nonvis);
74   this->u_.in_output_data.output_data = od;
75   this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
76   this->source_ = IN_OUTPUT_DATA;
77   this->in_reg_ = true;
78 }
79
80 // Initialize the fields in the base class Symbol for a symbol defined
81 // in an Output_segment.
82
83 void
84 Symbol::init_base(const char* name, Output_segment* os, elfcpp::STT type,
85                   elfcpp::STB binding, elfcpp::STV visibility,
86                   unsigned char nonvis, Segment_offset_base offset_base)
87 {
88   this->init_fields(name, NULL, type, binding, visibility, nonvis);
89   this->u_.in_output_segment.output_segment = os;
90   this->u_.in_output_segment.offset_base = offset_base;
91   this->source_ = IN_OUTPUT_SEGMENT;
92   this->in_reg_ = true;
93 }
94
95 // Initialize the fields in the base class Symbol for a symbol defined
96 // as a constant.
97
98 void
99 Symbol::init_base(const char* name, elfcpp::STT type,
100                   elfcpp::STB binding, elfcpp::STV visibility,
101                   unsigned char nonvis)
102 {
103   this->init_fields(name, NULL, type, binding, visibility, nonvis);
104   this->source_ = CONSTANT;
105   this->in_reg_ = true;
106 }
107
108 // Initialize the fields in Sized_symbol for SYM in OBJECT.
109
110 template<int size>
111 template<bool big_endian>
112 void
113 Sized_symbol<size>::init(const char* name, const char* version, Object* object,
114                          const elfcpp::Sym<size, big_endian>& sym)
115 {
116   this->init_base(name, version, object, sym);
117   this->value_ = sym.get_st_value();
118   this->symsize_ = sym.get_st_size();
119 }
120
121 // Initialize the fields in Sized_symbol for a symbol defined in an
122 // Output_data.
123
124 template<int size>
125 void
126 Sized_symbol<size>::init(const char* name, Output_data* od,
127                          Value_type value, Size_type symsize,
128                          elfcpp::STT type, elfcpp::STB binding,
129                          elfcpp::STV visibility, unsigned char nonvis,
130                          bool offset_is_from_end)
131 {
132   this->init_base(name, od, type, binding, visibility, nonvis,
133                   offset_is_from_end);
134   this->value_ = value;
135   this->symsize_ = symsize;
136 }
137
138 // Initialize the fields in Sized_symbol for a symbol defined in an
139 // Output_segment.
140
141 template<int size>
142 void
143 Sized_symbol<size>::init(const char* name, Output_segment* os,
144                          Value_type value, Size_type symsize,
145                          elfcpp::STT type, elfcpp::STB binding,
146                          elfcpp::STV visibility, unsigned char nonvis,
147                          Segment_offset_base offset_base)
148 {
149   this->init_base(name, os, type, binding, visibility, nonvis, offset_base);
150   this->value_ = value;
151   this->symsize_ = symsize;
152 }
153
154 // Initialize the fields in Sized_symbol for a symbol defined as a
155 // constant.
156
157 template<int size>
158 void
159 Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
160                          elfcpp::STT type, elfcpp::STB binding,
161                          elfcpp::STV visibility, unsigned char nonvis)
162 {
163   this->init_base(name, type, binding, visibility, nonvis);
164   this->value_ = value;
165   this->symsize_ = symsize;
166 }
167
168 // Class Symbol_table.
169
170 Symbol_table::Symbol_table()
171   : size_(0), saw_undefined_(0), offset_(0), table_(), namepool_(),
172     forwarders_(), commons_(), warnings_()
173 {
174 }
175
176 Symbol_table::~Symbol_table()
177 {
178 }
179
180 // The hash function.  The key is always canonicalized, so we use a
181 // simple combination of the pointers.
182
183 size_t
184 Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key& key) const
185 {
186   return key.first ^ key.second;
187 }
188
189 // The symbol table key equality function.  This is only called with
190 // canonicalized name and version strings, so we can use pointer
191 // comparison.
192
193 bool
194 Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
195                                           const Symbol_table_key& k2) const
196 {
197   return k1.first == k2.first && k1.second == k2.second;
198 }
199
200 // Make TO a symbol which forwards to FROM.  
201
202 void
203 Symbol_table::make_forwarder(Symbol* from, Symbol* to)
204 {
205   gold_assert(from != to);
206   gold_assert(!from->is_forwarder() && !to->is_forwarder());
207   this->forwarders_[from] = to;
208   from->set_forwarder();
209 }
210
211 // Resolve the forwards from FROM, returning the real symbol.
212
213 Symbol*
214 Symbol_table::resolve_forwards(const Symbol* from) const
215 {
216   gold_assert(from->is_forwarder());
217   Unordered_map<const Symbol*, Symbol*>::const_iterator p =
218     this->forwarders_.find(from);
219   gold_assert(p != this->forwarders_.end());
220   return p->second;
221 }
222
223 // Look up a symbol by name.
224
225 Symbol*
226 Symbol_table::lookup(const char* name, const char* version) const
227 {
228   Stringpool::Key name_key;
229   name = this->namepool_.find(name, &name_key);
230   if (name == NULL)
231     return NULL;
232
233   Stringpool::Key version_key = 0;
234   if (version != NULL)
235     {
236       version = this->namepool_.find(version, &version_key);
237       if (version == NULL)
238         return NULL;
239     }
240
241   Symbol_table_key key(name_key, version_key);
242   Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
243   if (p == this->table_.end())
244     return NULL;
245   return p->second;
246 }
247
248 // Resolve a Symbol with another Symbol.  This is only used in the
249 // unusual case where there are references to both an unversioned
250 // symbol and a symbol with a version, and we then discover that that
251 // version is the default version.  Because this is unusual, we do
252 // this the slow way, by converting back to an ELF symbol.
253
254 template<int size, bool big_endian>
255 void
256 Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
257                       const char* version ACCEPT_SIZE_ENDIAN)
258 {
259   unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
260   elfcpp::Sym_write<size, big_endian> esym(buf);
261   // We don't bother to set the st_name field.
262   esym.put_st_value(from->value());
263   esym.put_st_size(from->symsize());
264   esym.put_st_info(from->binding(), from->type());
265   esym.put_st_other(from->visibility(), from->nonvis());
266   esym.put_st_shndx(from->shndx());
267   Symbol_table::resolve(to, esym.sym(), from->object(), version);
268 }
269
270 // Add one symbol from OBJECT to the symbol table.  NAME is symbol
271 // name and VERSION is the version; both are canonicalized.  DEF is
272 // whether this is the default version.
273
274 // If DEF is true, then this is the definition of a default version of
275 // a symbol.  That means that any lookup of NAME/NULL and any lookup
276 // of NAME/VERSION should always return the same symbol.  This is
277 // obvious for references, but in particular we want to do this for
278 // definitions: overriding NAME/NULL should also override
279 // NAME/VERSION.  If we don't do that, it would be very hard to
280 // override functions in a shared library which uses versioning.
281
282 // We implement this by simply making both entries in the hash table
283 // point to the same Symbol structure.  That is easy enough if this is
284 // the first time we see NAME/NULL or NAME/VERSION, but it is possible
285 // that we have seen both already, in which case they will both have
286 // independent entries in the symbol table.  We can't simply change
287 // the symbol table entry, because we have pointers to the entries
288 // attached to the object files.  So we mark the entry attached to the
289 // object file as a forwarder, and record it in the forwarders_ map.
290 // Note that entries in the hash table will never be marked as
291 // forwarders.
292
293 template<int size, bool big_endian>
294 Symbol*
295 Symbol_table::add_from_object(Object* object,
296                               const char *name,
297                               Stringpool::Key name_key,
298                               const char *version,
299                               Stringpool::Key version_key,
300                               bool def,
301                               const elfcpp::Sym<size, big_endian>& sym)
302 {
303   Symbol* const snull = NULL;
304   std::pair<typename Symbol_table_type::iterator, bool> ins =
305     this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
306                                        snull));
307
308   std::pair<typename Symbol_table_type::iterator, bool> insdef =
309     std::make_pair(this->table_.end(), false);
310   if (def)
311     {
312       const Stringpool::Key vnull_key = 0;
313       insdef = this->table_.insert(std::make_pair(std::make_pair(name_key,
314                                                                  vnull_key),
315                                                   snull));
316     }
317
318   // ins.first: an iterator, which is a pointer to a pair.
319   // ins.first->first: the key (a pair of name and version).
320   // ins.first->second: the value (Symbol*).
321   // ins.second: true if new entry was inserted, false if not.
322
323   Sized_symbol<size>* ret;
324   bool was_undefined;
325   bool was_common;
326   if (!ins.second)
327     {
328       // We already have an entry for NAME/VERSION.
329       ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (ins.first->second
330                                                            SELECT_SIZE(size));
331       gold_assert(ret != NULL);
332
333       was_undefined = ret->is_undefined();
334       was_common = ret->is_common();
335
336       Symbol_table::resolve(ret, sym, object, version);
337
338       if (def)
339         {
340           if (insdef.second)
341             {
342               // This is the first time we have seen NAME/NULL.  Make
343               // NAME/NULL point to NAME/VERSION.
344               insdef.first->second = ret;
345             }
346           else if (insdef.first->second != ret)
347             {
348               // This is the unfortunate case where we already have
349               // entries for both NAME/VERSION and NAME/NULL.
350               const Sized_symbol<size>* sym2;
351               sym2 = this->get_sized_symbol SELECT_SIZE_NAME(size) (
352                 insdef.first->second
353                 SELECT_SIZE(size));
354               Symbol_table::resolve SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
355                 ret, sym2, version SELECT_SIZE_ENDIAN(size, big_endian));
356               this->make_forwarder(insdef.first->second, ret);
357               insdef.first->second = ret;
358             }
359         }
360     }
361   else
362     {
363       // This is the first time we have seen NAME/VERSION.
364       gold_assert(ins.first->second == NULL);
365
366       was_undefined = false;
367       was_common = false;
368
369       if (def && !insdef.second)
370         {
371           // We already have an entry for NAME/NULL.  If we override
372           // it, then change it to NAME/VERSION.
373           ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (
374               insdef.first->second
375               SELECT_SIZE(size));
376           Symbol_table::resolve(ret, sym, object, version);
377           ins.first->second = ret;
378         }
379       else
380         {
381           Sized_target<size, big_endian>* target =
382             object->sized_target SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
383                 SELECT_SIZE_ENDIAN_ONLY(size, big_endian));
384           if (!target->has_make_symbol())
385             ret = new Sized_symbol<size>();
386           else
387             {
388               ret = target->make_symbol();
389               if (ret == NULL)
390                 {
391                   // This means that we don't want a symbol table
392                   // entry after all.
393                   if (!def)
394                     this->table_.erase(ins.first);
395                   else
396                     {
397                       this->table_.erase(insdef.first);
398                       // Inserting insdef invalidated ins.
399                       this->table_.erase(std::make_pair(name_key,
400                                                         version_key));
401                     }
402                   return NULL;
403                 }
404             }
405
406           ret->init(name, version, object, sym);
407
408           ins.first->second = ret;
409           if (def)
410             {
411               // This is the first time we have seen NAME/NULL.  Point
412               // it at the new entry for NAME/VERSION.
413               gold_assert(insdef.second);
414               insdef.first->second = ret;
415             }
416         }
417     }
418
419   // Record every time we see a new undefined symbol, to speed up
420   // archive groups.
421   if (!was_undefined && ret->is_undefined())
422     ++this->saw_undefined_;
423
424   // Keep track of common symbols, to speed up common symbol
425   // allocation.
426   if (!was_common && ret->is_common())
427     this->commons_.push_back(ret);
428
429   return ret;
430 }
431
432 // Add all the symbols in a relocatable object to the hash table.
433
434 template<int size, bool big_endian>
435 void
436 Symbol_table::add_from_relobj(
437     Sized_relobj<size, big_endian>* relobj,
438     const unsigned char* syms,
439     size_t count,
440     const char* sym_names,
441     size_t sym_name_size,
442     Symbol** sympointers)
443 {
444   // We take the size from the first object we see.
445   if (this->get_size() == 0)
446     this->set_size(size);
447
448   if (size != this->get_size() || size != relobj->target()->get_size())
449     {
450       fprintf(stderr, _("%s: %s: mixing 32-bit and 64-bit ELF objects\n"),
451               program_name, relobj->name().c_str());
452       gold_exit(false);
453     }
454
455   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
456
457   const unsigned char* p = syms;
458   for (size_t i = 0; i < count; ++i, p += sym_size)
459     {
460       elfcpp::Sym<size, big_endian> sym(p);
461       elfcpp::Sym<size, big_endian>* psym = &sym;
462
463       unsigned int st_name = psym->get_st_name();
464       if (st_name >= sym_name_size)
465         {
466           fprintf(stderr,
467                   _("%s: %s: bad global symbol name offset %u at %lu\n"),
468                   program_name, relobj->name().c_str(), st_name,
469                   static_cast<unsigned long>(i));
470           gold_exit(false);
471         }
472
473       const char* name = sym_names + st_name;
474
475       // A symbol defined in a section which we are not including must
476       // be treated as an undefined symbol.
477       unsigned char symbuf[sym_size];
478       elfcpp::Sym<size, big_endian> sym2(symbuf);
479       unsigned int st_shndx = psym->get_st_shndx();
480       if (st_shndx != elfcpp::SHN_UNDEF
481           && st_shndx < elfcpp::SHN_LORESERVE
482           && !relobj->is_section_included(st_shndx))
483         {
484           memcpy(symbuf, p, sym_size);
485           elfcpp::Sym_write<size, big_endian> sw(symbuf);
486           sw.put_st_shndx(elfcpp::SHN_UNDEF);
487           psym = &sym2;
488         }
489
490       // In an object file, an '@' in the name separates the symbol
491       // name from the version name.  If there are two '@' characters,
492       // this is the default version.
493       const char* ver = strchr(name, '@');
494
495       Symbol* res;
496       if (ver == NULL)
497         {
498           Stringpool::Key name_key;
499           name = this->namepool_.add(name, &name_key);
500           res = this->add_from_object(relobj, name, name_key, NULL, 0,
501                                       false, *psym);
502         }
503       else
504         {
505           Stringpool::Key name_key;
506           name = this->namepool_.add(name, ver - name, &name_key);
507
508           bool def = false;
509           ++ver;
510           if (*ver == '@')
511             {
512               def = true;
513               ++ver;
514             }
515
516           Stringpool::Key ver_key;
517           ver = this->namepool_.add(ver, &ver_key);
518
519           res = this->add_from_object(relobj, name, name_key, ver, ver_key,
520                                       def, *psym);
521         }
522
523       *sympointers++ = res;
524     }
525 }
526
527 // Add all the symbols in a dynamic object to the hash table.
528
529 template<int size, bool big_endian>
530 void
531 Symbol_table::add_from_dynobj(
532     Sized_dynobj<size, big_endian>* dynobj,
533     const unsigned char* syms,
534     size_t count,
535     const char* sym_names,
536     size_t sym_name_size,
537     const unsigned char* versym,
538     size_t versym_size,
539     const std::vector<const char*>* version_map)
540 {
541   // We take the size from the first object we see.
542   if (this->get_size() == 0)
543     this->set_size(size);
544
545   if (size != this->get_size() || size != dynobj->target()->get_size())
546     {
547       fprintf(stderr, _("%s: %s: mixing 32-bit and 64-bit ELF objects\n"),
548               program_name, dynobj->name().c_str());
549       gold_exit(false);
550     }
551
552   if (versym != NULL && versym_size / 2 < count)
553     {
554       fprintf(stderr, _("%s: %s: too few symbol versions\n"),
555               program_name, dynobj->name().c_str());
556       gold_exit(false);
557     }
558
559   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
560
561   const unsigned char* p = syms;
562   const unsigned char* vs = versym;
563   for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
564     {
565       elfcpp::Sym<size, big_endian> sym(p);
566
567       // Ignore symbols with local binding.
568       if (sym.get_st_bind() == elfcpp::STB_LOCAL)
569         continue;
570
571       unsigned int st_name = sym.get_st_name();
572       if (st_name >= sym_name_size)
573         {
574           fprintf(stderr, _("%s: %s: bad symbol name offset %u at %lu\n"),
575                   program_name, dynobj->name().c_str(), st_name,
576                   static_cast<unsigned long>(i));
577           gold_exit(false);
578         }
579
580       const char* name = sym_names + st_name;
581
582       if (versym == NULL)
583         {
584           Stringpool::Key name_key;
585           name = this->namepool_.add(name, &name_key);
586           this->add_from_object(dynobj, name, name_key, NULL, 0,
587                                 false, sym);
588           continue;
589         }
590
591       // Read the version information.
592
593       unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
594
595       bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
596       v &= elfcpp::VERSYM_VERSION;
597
598       if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL))
599         {
600           // This symbol should not be visible outside the object.
601           continue;
602         }
603
604       // At this point we are definitely going to add this symbol.
605       Stringpool::Key name_key;
606       name = this->namepool_.add(name, &name_key);
607
608       if (v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
609         {
610           // This symbol does not have a version.
611           this->add_from_object(dynobj, name, name_key, NULL, 0, false, sym);
612           continue;
613         }
614
615       if (v >= version_map->size())
616         {
617           fprintf(stderr,
618                   _("%s: %s: versym for symbol %zu out of range: %u\n"),
619                   program_name, dynobj->name().c_str(), i, v);
620           gold_exit(false);
621         }
622
623       const char* version = (*version_map)[v];
624       if (version == NULL)
625         {
626           fprintf(stderr, _("%s: %s: versym for symbol %zu has no name: %u\n"),
627                   program_name, dynobj->name().c_str(), i, v);
628           gold_exit(false);
629         }
630
631       Stringpool::Key version_key;
632       version = this->namepool_.add(version, &version_key);
633
634       // If this is an absolute symbol, and the version name and
635       // symbol name are the same, then this is the version definition
636       // symbol.  These symbols exist to support using -u to pull in
637       // particular versions.  We do not want to record a version for
638       // them.
639       if (sym.get_st_shndx() == elfcpp::SHN_ABS && name_key == version_key)
640         {
641           this->add_from_object(dynobj, name, name_key, NULL, 0, false, sym);
642           continue;
643         }
644
645       const bool def = !hidden && sym.get_st_shndx() != elfcpp::SHN_UNDEF;
646
647       this->add_from_object(dynobj, name, name_key, version, version_key,
648                             def, sym);
649     }
650 }
651
652 // Create and return a specially defined symbol.  If ONLY_IF_REF is
653 // true, then only create the symbol if there is a reference to it.
654
655 template<int size, bool big_endian>
656 Sized_symbol<size>*
657 Symbol_table::define_special_symbol(const Target* target, const char* name,
658                                     const char* version, bool only_if_ref
659                                     ACCEPT_SIZE_ENDIAN)
660 {
661   gold_assert(this->size_ == size);
662
663   Symbol* oldsym;
664   Sized_symbol<size>* sym;
665
666   if (only_if_ref)
667     {
668       oldsym = this->lookup(name, version);
669       if (oldsym == NULL || !oldsym->is_undefined())
670         return NULL;
671       sym = NULL;
672
673       // Canonicalize NAME and VERSION.
674       name = oldsym->name();
675       version = oldsym->version();
676     }
677   else
678     {
679       // Canonicalize NAME and VERSION.
680       Stringpool::Key name_key;
681       name = this->namepool_.add(name, &name_key);
682
683       Stringpool::Key version_key = 0;
684       if (version != NULL)
685         version = this->namepool_.add(version, &version_key);
686
687       Symbol* const snull = NULL;
688       std::pair<typename Symbol_table_type::iterator, bool> ins =
689         this->table_.insert(std::make_pair(std::make_pair(name_key,
690                                                           version_key),
691                                            snull));
692
693       if (!ins.second)
694         {
695           // We already have a symbol table entry for NAME/VERSION.
696           oldsym = ins.first->second;
697           gold_assert(oldsym != NULL);
698           sym = NULL;
699         }
700       else
701         {
702           // We haven't seen this symbol before.
703           gold_assert(ins.first->second == NULL);
704
705           if (!target->has_make_symbol())
706             sym = new Sized_symbol<size>();
707           else
708             {
709               gold_assert(target->get_size() == size);
710               gold_assert(target->is_big_endian() ? big_endian : !big_endian);
711               typedef Sized_target<size, big_endian> My_target;
712               const My_target* sized_target =
713                 static_cast<const My_target*>(target);
714               sym = sized_target->make_symbol();
715               if (sym == NULL)
716                 return NULL;
717             }
718
719           ins.first->second = sym;
720           oldsym = NULL;
721         }
722     }
723
724   if (oldsym != NULL)
725     {
726       gold_assert(sym == NULL);
727
728       sym = this->get_sized_symbol SELECT_SIZE_NAME(size) (oldsym
729                                                            SELECT_SIZE(size));
730       gold_assert(sym->source() == Symbol::FROM_OBJECT);
731       const int old_shndx = sym->shndx();
732       if (old_shndx != elfcpp::SHN_UNDEF
733           && old_shndx != elfcpp::SHN_COMMON
734           && !sym->object()->is_dynamic())
735         {
736           fprintf(stderr, "%s: linker defined: multiple definition of %s\n",
737                   program_name, name);
738           // FIXME: Report old location.  Record that we have seen an
739           // error.
740           return NULL;
741         }
742
743       // Our new definition is going to override the old reference.
744     }
745
746   return sym;
747 }
748
749 // Define a symbol based on an Output_data.
750
751 Symbol*
752 Symbol_table::define_in_output_data(const Target* target, const char* name,
753                                     const char* version, Output_data* od,
754                                     uint64_t value, uint64_t symsize,
755                                     elfcpp::STT type, elfcpp::STB binding,
756                                     elfcpp::STV visibility,
757                                     unsigned char nonvis,
758                                     bool offset_is_from_end,
759                                     bool only_if_ref)
760 {
761   gold_assert(target->get_size() == this->size_);
762   if (this->size_ == 32)
763     return this->do_define_in_output_data<32>(target, name, version, od, value,
764                                               symsize, type, binding,
765                                               visibility, nonvis,
766                                               offset_is_from_end, only_if_ref);
767   else if (this->size_ == 64)
768     return this->do_define_in_output_data<64>(target, name, version, od, value,
769                                               symsize, type, binding,
770                                               visibility, nonvis,
771                                               offset_is_from_end, only_if_ref);
772   else
773     gold_unreachable();
774 }
775
776 // Define a symbol in an Output_data, sized version.
777
778 template<int size>
779 Sized_symbol<size>*
780 Symbol_table::do_define_in_output_data(
781     const Target* target,
782     const char* name,
783     const char* version,
784     Output_data* od,
785     typename elfcpp::Elf_types<size>::Elf_Addr value,
786     typename elfcpp::Elf_types<size>::Elf_WXword symsize,
787     elfcpp::STT type,
788     elfcpp::STB binding,
789     elfcpp::STV visibility,
790     unsigned char nonvis,
791     bool offset_is_from_end,
792     bool only_if_ref)
793 {
794   Sized_symbol<size>* sym;
795
796   if (target->is_big_endian())
797     sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
798         target, name, version, only_if_ref
799         SELECT_SIZE_ENDIAN(size, true));
800   else
801     sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
802         target, name, version, only_if_ref
803         SELECT_SIZE_ENDIAN(size, false));
804
805   if (sym == NULL)
806     return NULL;
807
808   sym->init(name, od, value, symsize, type, binding, visibility, nonvis,
809             offset_is_from_end);
810
811   return sym;
812 }
813
814 // Define a symbol based on an Output_segment.
815
816 Symbol*
817 Symbol_table::define_in_output_segment(const Target* target, const char* name,
818                                        const char* version, Output_segment* os,
819                                        uint64_t value, uint64_t symsize,
820                                        elfcpp::STT type, elfcpp::STB binding,
821                                        elfcpp::STV visibility,
822                                        unsigned char nonvis,
823                                        Symbol::Segment_offset_base offset_base,
824                                        bool only_if_ref)
825 {
826   gold_assert(target->get_size() == this->size_);
827   if (this->size_ == 32)
828     return this->do_define_in_output_segment<32>(target, name, version, os,
829                                                  value, symsize, type, binding,
830                                                  visibility, nonvis,
831                                                  offset_base, only_if_ref);
832   else if (this->size_ == 64)
833     return this->do_define_in_output_segment<64>(target, name, version, os,
834                                                  value, symsize, type, binding,
835                                                  visibility, nonvis,
836                                                  offset_base, only_if_ref);
837   else
838     gold_unreachable();
839 }
840
841 // Define a symbol in an Output_segment, sized version.
842
843 template<int size>
844 Sized_symbol<size>*
845 Symbol_table::do_define_in_output_segment(
846     const Target* target,
847     const char* name,
848     const char* version,
849     Output_segment* os,
850     typename elfcpp::Elf_types<size>::Elf_Addr value,
851     typename elfcpp::Elf_types<size>::Elf_WXword symsize,
852     elfcpp::STT type,
853     elfcpp::STB binding,
854     elfcpp::STV visibility,
855     unsigned char nonvis,
856     Symbol::Segment_offset_base offset_base,
857     bool only_if_ref)
858 {
859   Sized_symbol<size>* sym;
860
861   if (target->is_big_endian())
862     sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
863         target, name, version, only_if_ref
864         SELECT_SIZE_ENDIAN(size, true));
865   else
866     sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
867         target, name, version, only_if_ref
868         SELECT_SIZE_ENDIAN(size, false));
869
870   if (sym == NULL)
871     return NULL;
872
873   sym->init(name, os, value, symsize, type, binding, visibility, nonvis,
874             offset_base);
875
876   return sym;
877 }
878
879 // Define a special symbol with a constant value.  It is a multiple
880 // definition error if this symbol is already defined.
881
882 Symbol*
883 Symbol_table::define_as_constant(const Target* target, const char* name,
884                                  const char* version, uint64_t value,
885                                  uint64_t symsize, elfcpp::STT type,
886                                  elfcpp::STB binding, elfcpp::STV visibility,
887                                  unsigned char nonvis, bool only_if_ref)
888 {
889   gold_assert(target->get_size() == this->size_);
890   if (this->size_ == 32)
891     return this->do_define_as_constant<32>(target, name, version, value,
892                                            symsize, type, binding, visibility,
893                                            nonvis, only_if_ref);
894   else if (this->size_ == 64)
895     return this->do_define_as_constant<64>(target, name, version, value,
896                                            symsize, type, binding, visibility,
897                                            nonvis, only_if_ref);
898   else
899     gold_unreachable();
900 }
901
902 // Define a symbol as a constant, sized version.
903
904 template<int size>
905 Sized_symbol<size>*
906 Symbol_table::do_define_as_constant(
907     const Target* target,
908     const char* name,
909     const char* version,
910     typename elfcpp::Elf_types<size>::Elf_Addr value,
911     typename elfcpp::Elf_types<size>::Elf_WXword symsize,
912     elfcpp::STT type,
913     elfcpp::STB binding,
914     elfcpp::STV visibility,
915     unsigned char nonvis,
916     bool only_if_ref)
917 {
918   Sized_symbol<size>* sym;
919
920   if (target->is_big_endian())
921     sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
922         target, name, version, only_if_ref
923         SELECT_SIZE_ENDIAN(size, true));
924   else
925     sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
926         target, name, version, only_if_ref
927         SELECT_SIZE_ENDIAN(size, false));
928
929   if (sym == NULL)
930     return NULL;
931
932   sym->init(name, value, symsize, type, binding, visibility, nonvis);
933
934   return sym;
935 }
936
937 // Define a set of symbols in output sections.
938
939 void
940 Symbol_table::define_symbols(const Layout* layout, const Target* target,
941                              int count, const Define_symbol_in_section* p)
942 {
943   for (int i = 0; i < count; ++i, ++p)
944     {
945       Output_section* os = layout->find_output_section(p->output_section);
946       if (os != NULL)
947         this->define_in_output_data(target, p->name, NULL, os, p->value,
948                                     p->size, p->type, p->binding,
949                                     p->visibility, p->nonvis,
950                                     p->offset_is_from_end, p->only_if_ref);
951       else
952         this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
953                                  p->binding, p->visibility, p->nonvis,
954                                  p->only_if_ref);
955     }
956 }
957
958 // Define a set of symbols in output segments.
959
960 void
961 Symbol_table::define_symbols(const Layout* layout, const Target* target,
962                              int count, const Define_symbol_in_segment* p)
963 {
964   for (int i = 0; i < count; ++i, ++p)
965     {
966       Output_segment* os = layout->find_output_segment(p->segment_type,
967                                                        p->segment_flags_set,
968                                                        p->segment_flags_clear);
969       if (os != NULL)
970         this->define_in_output_segment(target, p->name, NULL, os, p->value,
971                                        p->size, p->type, p->binding,
972                                        p->visibility, p->nonvis,
973                                        p->offset_base, p->only_if_ref);
974       else
975         this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
976                                  p->binding, p->visibility, p->nonvis,
977                                  p->only_if_ref);
978     }
979 }
980
981 // Set the dynamic symbol indexes.  INDEX is the index of the first
982 // global dynamic symbol.  Pointers to the symbols are stored into the
983 // vector SYMS.  The names are added to DYNPOOL.  This returns an
984 // updated dynamic symbol index.
985
986 unsigned int
987 Symbol_table::set_dynsym_indexes(const General_options* options,
988                                  const Target* target,
989                                  unsigned int index,
990                                  std::vector<Symbol*>* syms,
991                                  Stringpool* dynpool,
992                                  Versions* versions)
993 {
994   for (Symbol_table_type::iterator p = this->table_.begin();
995        p != this->table_.end();
996        ++p)
997     {
998       Symbol* sym = p->second;
999
1000       // Note that SYM may already have a dynamic symbol index, since
1001       // some symbols appear more than once in the symbol table, with
1002       // and without a version.
1003
1004       if (!sym->needs_dynsym_entry()
1005           && (!options->export_dynamic()
1006               || !sym->in_reg()
1007               || !sym->is_externally_visible()))
1008         sym->set_dynsym_index(-1U);
1009       else if (!sym->has_dynsym_index())
1010         {
1011           sym->set_dynsym_index(index);
1012           ++index;
1013           syms->push_back(sym);
1014           dynpool->add(sym->name(), NULL);
1015
1016           // Record any version information.
1017           if (sym->version() != NULL)
1018             versions->record_version(options, dynpool, sym);
1019         }
1020     }
1021
1022   // Finish up the versions.  In some cases this may add new dynamic
1023   // symbols.
1024   index = versions->finalize(target, this, index, syms);
1025
1026   return index;
1027 }
1028
1029 // Set the final values for all the symbols.  The index of the first
1030 // global symbol in the output file is INDEX.  Record the file offset
1031 // OFF.  Add their names to POOL.  Return the new file offset.
1032
1033 off_t
1034 Symbol_table::finalize(unsigned int index, off_t off, off_t dynoff,
1035                        size_t dyn_global_index, size_t dyncount,
1036                        Stringpool* pool)
1037 {
1038   off_t ret;
1039
1040   gold_assert(index != 0);
1041   this->first_global_index_ = index;
1042
1043   this->dynamic_offset_ = dynoff;
1044   this->first_dynamic_global_index_ = dyn_global_index;
1045   this->dynamic_count_ = dyncount;
1046
1047   if (this->size_ == 32)
1048     ret = this->sized_finalize<32>(index, off, pool);
1049   else if (this->size_ == 64)
1050     ret = this->sized_finalize<64>(index, off, pool);
1051   else
1052     gold_unreachable();
1053
1054   // Now that we have the final symbol table, we can reliably note
1055   // which symbols should get warnings.
1056   this->warnings_.note_warnings(this);
1057
1058   return ret;
1059 }
1060
1061 // Set the final value for all the symbols.  This is called after
1062 // Layout::finalize, so all the output sections have their final
1063 // address.
1064
1065 template<int size>
1066 off_t
1067 Symbol_table::sized_finalize(unsigned index, off_t off, Stringpool* pool)
1068 {
1069   off = align_address(off, size >> 3);
1070   this->offset_ = off;
1071
1072   size_t orig_index = index;
1073
1074   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1075   for (Symbol_table_type::iterator p = this->table_.begin();
1076        p != this->table_.end();
1077        ++p)
1078     {
1079       Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1080
1081       // FIXME: Here we need to decide which symbols should go into
1082       // the output file, based on --strip.
1083
1084       // The default version of a symbol may appear twice in the
1085       // symbol table.  We only need to finalize it once.
1086       if (sym->has_symtab_index())
1087         continue;
1088
1089       if (!sym->in_reg())
1090         {
1091           gold_assert(!sym->has_symtab_index());
1092           sym->set_symtab_index(-1U);
1093           gold_assert(sym->dynsym_index() == -1U);
1094           continue;
1095         }
1096
1097       typename Sized_symbol<size>::Value_type value;
1098
1099       switch (sym->source())
1100         {
1101         case Symbol::FROM_OBJECT:
1102           {
1103             unsigned int shndx = sym->shndx();
1104
1105             // FIXME: We need some target specific support here.
1106             if (shndx >= elfcpp::SHN_LORESERVE
1107                 && shndx != elfcpp::SHN_ABS)
1108               {
1109                 fprintf(stderr, _("%s: %s: unsupported symbol section 0x%x\n"),
1110                         program_name, sym->name(), shndx);
1111                 gold_exit(false);
1112               }
1113
1114             Object* symobj = sym->object();
1115             if (symobj->is_dynamic())
1116               {
1117                 value = 0;
1118                 shndx = elfcpp::SHN_UNDEF;
1119               }
1120             else if (shndx == elfcpp::SHN_UNDEF)
1121               value = 0;
1122             else if (shndx == elfcpp::SHN_ABS)
1123               value = sym->value();
1124             else
1125               {
1126                 Relobj* relobj = static_cast<Relobj*>(symobj);
1127                 off_t secoff;
1128                 Output_section* os = relobj->output_section(shndx, &secoff);
1129
1130                 if (os == NULL)
1131                   {
1132                     sym->set_symtab_index(-1U);
1133                     gold_assert(sym->dynsym_index() == -1U);
1134                     continue;
1135                   }
1136
1137                 value = sym->value() + os->address() + secoff;
1138               }
1139           }
1140           break;
1141
1142         case Symbol::IN_OUTPUT_DATA:
1143           {
1144             Output_data* od = sym->output_data();
1145             value = sym->value() + od->address();
1146             if (sym->offset_is_from_end())
1147               value += od->data_size();
1148           }
1149           break;
1150
1151         case Symbol::IN_OUTPUT_SEGMENT:
1152           {
1153             Output_segment* os = sym->output_segment();
1154             value = sym->value() + os->vaddr();
1155             switch (sym->offset_base())
1156               {
1157               case Symbol::SEGMENT_START:
1158                 break;
1159               case Symbol::SEGMENT_END:
1160                 value += os->memsz();
1161                 break;
1162               case Symbol::SEGMENT_BSS:
1163                 value += os->filesz();
1164                 break;
1165               default:
1166                 gold_unreachable();
1167               }
1168           }
1169           break;
1170
1171         case Symbol::CONSTANT:
1172           value = sym->value();
1173           break;
1174
1175         default:
1176           gold_unreachable();
1177         }
1178
1179       sym->set_value(value);
1180       sym->set_symtab_index(index);
1181       pool->add(sym->name(), NULL);
1182       ++index;
1183       off += sym_size;
1184     }
1185
1186   this->output_count_ = index - orig_index;
1187
1188   return off;
1189 }
1190
1191 // Write out the global symbols.
1192
1193 void
1194 Symbol_table::write_globals(const Target* target, const Stringpool* sympool,
1195                             const Stringpool* dynpool, Output_file* of) const
1196 {
1197   if (this->size_ == 32)
1198     {
1199       if (target->is_big_endian())
1200         this->sized_write_globals<32, true>(target, sympool, dynpool, of);
1201       else
1202         this->sized_write_globals<32, false>(target, sympool, dynpool, of);
1203     }
1204   else if (this->size_ == 64)
1205     {
1206       if (target->is_big_endian())
1207         this->sized_write_globals<64, true>(target, sympool, dynpool, of);
1208       else
1209         this->sized_write_globals<64, false>(target, sympool, dynpool, of);
1210     }
1211   else
1212     gold_unreachable();
1213 }
1214
1215 // Write out the global symbols.
1216
1217 template<int size, bool big_endian>
1218 void
1219 Symbol_table::sized_write_globals(const Target*,
1220                                   const Stringpool* sympool,
1221                                   const Stringpool* dynpool,
1222                                   Output_file* of) const
1223 {
1224   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1225   unsigned int index = this->first_global_index_;
1226   const off_t oview_size = this->output_count_ * sym_size;
1227   unsigned char* const psyms = of->get_output_view(this->offset_, oview_size);
1228
1229   unsigned int dynamic_count = this->dynamic_count_;
1230   off_t dynamic_size = dynamic_count * sym_size;
1231   unsigned int first_dynamic_global_index = this->first_dynamic_global_index_;
1232   unsigned char* dynamic_view;
1233   if (this->dynamic_offset_ == 0)
1234     dynamic_view = NULL;
1235   else
1236     dynamic_view = of->get_output_view(this->dynamic_offset_, dynamic_size);
1237
1238   unsigned char* ps = psyms;
1239   for (Symbol_table_type::const_iterator p = this->table_.begin();
1240        p != this->table_.end();
1241        ++p)
1242     {
1243       Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1244
1245       unsigned int sym_index = sym->symtab_index();
1246       unsigned int dynsym_index;
1247       if (dynamic_view == NULL)
1248         dynsym_index = -1U;
1249       else
1250         dynsym_index = sym->dynsym_index();
1251
1252       if (sym_index == -1U && dynsym_index == -1U)
1253         {
1254           // This symbol is not included in the output file.
1255           continue;
1256         }
1257
1258       if (sym_index == index)
1259         ++index;
1260       else if (sym_index != -1U)
1261         {
1262           // We have already seen this symbol, because it has a
1263           // default version.
1264           gold_assert(sym_index < index);
1265           if (dynsym_index == -1U)
1266             continue;
1267           sym_index = -1U;
1268         }
1269
1270       unsigned int shndx;
1271       switch (sym->source())
1272         {
1273         case Symbol::FROM_OBJECT:
1274           {
1275             unsigned int in_shndx = sym->shndx();
1276
1277             // FIXME: We need some target specific support here.
1278             if (in_shndx >= elfcpp::SHN_LORESERVE
1279                 && in_shndx != elfcpp::SHN_ABS)
1280               {
1281                 fprintf(stderr, _("%s: %s: unsupported symbol section 0x%x\n"),
1282                         program_name, sym->name(), in_shndx);
1283                 gold_exit(false);
1284               }
1285
1286             Object* symobj = sym->object();
1287             if (symobj->is_dynamic())
1288               {
1289                 // FIXME.
1290                 shndx = elfcpp::SHN_UNDEF;
1291               }
1292             else if (in_shndx == elfcpp::SHN_UNDEF
1293                      || in_shndx == elfcpp::SHN_ABS)
1294               shndx = in_shndx;
1295             else
1296               {
1297                 Relobj* relobj = static_cast<Relobj*>(symobj);
1298                 off_t secoff;
1299                 Output_section* os = relobj->output_section(in_shndx, &secoff);
1300                 gold_assert(os != NULL);
1301                 shndx = os->out_shndx();
1302               }
1303           }
1304           break;
1305
1306         case Symbol::IN_OUTPUT_DATA:
1307           shndx = sym->output_data()->out_shndx();
1308           break;
1309
1310         case Symbol::IN_OUTPUT_SEGMENT:
1311           shndx = elfcpp::SHN_ABS;
1312           break;
1313
1314         case Symbol::CONSTANT:
1315           shndx = elfcpp::SHN_ABS;
1316           break;
1317
1318         default:
1319           gold_unreachable();
1320         }
1321
1322       if (sym_index != -1U)
1323         {
1324           this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
1325               sym, shndx, sympool, ps
1326               SELECT_SIZE_ENDIAN(size, big_endian));
1327           ps += sym_size;
1328         }
1329
1330       if (dynsym_index != -1U)
1331         {
1332           dynsym_index -= first_dynamic_global_index;
1333           gold_assert(dynsym_index < dynamic_count);
1334           unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
1335           this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
1336               sym, shndx, dynpool, pd
1337               SELECT_SIZE_ENDIAN(size, big_endian));
1338         }
1339     }
1340
1341   gold_assert(ps - psyms == oview_size);
1342
1343   of->write_output_view(this->offset_, oview_size, psyms);
1344   if (dynamic_view != NULL)
1345     of->write_output_view(this->dynamic_offset_, dynamic_size, dynamic_view);
1346 }
1347
1348 // Write out the symbol SYM, in section SHNDX, to P.  POOL is the
1349 // strtab holding the name.
1350
1351 template<int size, bool big_endian>
1352 void
1353 Symbol_table::sized_write_symbol(Sized_symbol<size>* sym,
1354                                  unsigned int shndx,
1355                                  const Stringpool* pool,
1356                                  unsigned char* p
1357                                  ACCEPT_SIZE_ENDIAN) const
1358 {
1359   elfcpp::Sym_write<size, big_endian> osym(p);
1360   osym.put_st_name(pool->get_offset(sym->name()));
1361   osym.put_st_value(sym->value());
1362   osym.put_st_size(sym->symsize());
1363   osym.put_st_info(elfcpp::elf_st_info(sym->binding(), sym->type()));
1364   osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
1365   osym.put_st_shndx(shndx);
1366 }
1367
1368 // Write out a section symbol.  Return the update offset.
1369
1370 void
1371 Symbol_table::write_section_symbol(const Target* target,
1372                                    const Output_section *os,
1373                                    Output_file* of,
1374                                    off_t offset) const
1375 {
1376   if (this->size_ == 32)
1377     {
1378       if (target->is_big_endian())
1379         this->sized_write_section_symbol<32, true>(os, of, offset);
1380       else
1381         this->sized_write_section_symbol<32, false>(os, of, offset);
1382     }
1383   else if (this->size_ == 64)
1384     {
1385       if (target->is_big_endian())
1386         this->sized_write_section_symbol<64, true>(os, of, offset);
1387       else
1388         this->sized_write_section_symbol<64, false>(os, of, offset);
1389     }
1390   else
1391     gold_unreachable();
1392 }
1393
1394 // Write out a section symbol, specialized for size and endianness.
1395
1396 template<int size, bool big_endian>
1397 void
1398 Symbol_table::sized_write_section_symbol(const Output_section* os,
1399                                          Output_file* of,
1400                                          off_t offset) const
1401 {
1402   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1403
1404   unsigned char* pov = of->get_output_view(offset, sym_size);
1405
1406   elfcpp::Sym_write<size, big_endian> osym(pov);
1407   osym.put_st_name(0);
1408   osym.put_st_value(os->address());
1409   osym.put_st_size(0);
1410   osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
1411                                        elfcpp::STT_SECTION));
1412   osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
1413   osym.put_st_shndx(os->out_shndx());
1414
1415   of->write_output_view(offset, sym_size, pov);
1416 }
1417
1418 // Warnings functions.
1419
1420 // Add a new warning.
1421
1422 void
1423 Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
1424                       unsigned int shndx)
1425 {
1426   name = symtab->canonicalize_name(name);
1427   this->warnings_[name].set(obj, shndx);
1428 }
1429
1430 // Look through the warnings and mark the symbols for which we should
1431 // warn.  This is called during Layout::finalize when we know the
1432 // sources for all the symbols.
1433
1434 void
1435 Warnings::note_warnings(Symbol_table* symtab)
1436 {
1437   for (Warning_table::iterator p = this->warnings_.begin();
1438        p != this->warnings_.end();
1439        ++p)
1440     {
1441       Symbol* sym = symtab->lookup(p->first, NULL);
1442       if (sym != NULL
1443           && sym->source() == Symbol::FROM_OBJECT
1444           && sym->object() == p->second.object)
1445         {
1446           sym->set_has_warning();
1447
1448           // Read the section contents to get the warning text.  It
1449           // would be nicer if we only did this if we have to actually
1450           // issue a warning.  Unfortunately, warnings are issued as
1451           // we relocate sections.  That means that we can not lock
1452           // the object then, as we might try to issue the same
1453           // warning multiple times simultaneously.
1454           {
1455             Task_locker_obj<Object> tl(*p->second.object);
1456             const unsigned char* c;
1457             off_t len;
1458             c = p->second.object->section_contents(p->second.shndx, &len);
1459             p->second.set_text(reinterpret_cast<const char*>(c), len);
1460           }
1461         }
1462     }
1463 }
1464
1465 // Issue a warning.  This is called when we see a relocation against a
1466 // symbol for which has a warning.
1467
1468 void
1469 Warnings::issue_warning(const Symbol* sym, const std::string& location) const
1470 {
1471   gold_assert(sym->has_warning());
1472   Warning_table::const_iterator p = this->warnings_.find(sym->name());
1473   gold_assert(p != this->warnings_.end());
1474   fprintf(stderr, _("%s: %s: warning: %s\n"), program_name, location.c_str(),
1475           p->second.text.c_str());
1476 }
1477
1478 // Instantiate the templates we need.  We could use the configure
1479 // script to restrict this to only the ones needed for implemented
1480 // targets.
1481
1482 template
1483 void
1484 Symbol_table::add_from_relobj<32, true>(
1485     Sized_relobj<32, true>* relobj,
1486     const unsigned char* syms,
1487     size_t count,
1488     const char* sym_names,
1489     size_t sym_name_size,
1490     Symbol** sympointers);
1491
1492 template
1493 void
1494 Symbol_table::add_from_relobj<32, false>(
1495     Sized_relobj<32, false>* relobj,
1496     const unsigned char* syms,
1497     size_t count,
1498     const char* sym_names,
1499     size_t sym_name_size,
1500     Symbol** sympointers);
1501
1502 template
1503 void
1504 Symbol_table::add_from_relobj<64, true>(
1505     Sized_relobj<64, true>* relobj,
1506     const unsigned char* syms,
1507     size_t count,
1508     const char* sym_names,
1509     size_t sym_name_size,
1510     Symbol** sympointers);
1511
1512 template
1513 void
1514 Symbol_table::add_from_relobj<64, false>(
1515     Sized_relobj<64, false>* relobj,
1516     const unsigned char* syms,
1517     size_t count,
1518     const char* sym_names,
1519     size_t sym_name_size,
1520     Symbol** sympointers);
1521
1522 template
1523 void
1524 Symbol_table::add_from_dynobj<32, true>(
1525     Sized_dynobj<32, true>* dynobj,
1526     const unsigned char* syms,
1527     size_t count,
1528     const char* sym_names,
1529     size_t sym_name_size,
1530     const unsigned char* versym,
1531     size_t versym_size,
1532     const std::vector<const char*>* version_map);
1533
1534 template
1535 void
1536 Symbol_table::add_from_dynobj<32, false>(
1537     Sized_dynobj<32, false>* dynobj,
1538     const unsigned char* syms,
1539     size_t count,
1540     const char* sym_names,
1541     size_t sym_name_size,
1542     const unsigned char* versym,
1543     size_t versym_size,
1544     const std::vector<const char*>* version_map);
1545
1546 template
1547 void
1548 Symbol_table::add_from_dynobj<64, true>(
1549     Sized_dynobj<64, true>* dynobj,
1550     const unsigned char* syms,
1551     size_t count,
1552     const char* sym_names,
1553     size_t sym_name_size,
1554     const unsigned char* versym,
1555     size_t versym_size,
1556     const std::vector<const char*>* version_map);
1557
1558 template
1559 void
1560 Symbol_table::add_from_dynobj<64, false>(
1561     Sized_dynobj<64, false>* dynobj,
1562     const unsigned char* syms,
1563     size_t count,
1564     const char* sym_names,
1565     size_t sym_name_size,
1566     const unsigned char* versym,
1567     size_t versym_size,
1568     const std::vector<const char*>* version_map);
1569
1570 } // End namespace gold.