]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/symtab.cc
From Craig Silverstein: check that we get environ right.
[thirdparty/binutils-gdb.git] / gold / symtab.cc
CommitLineData
14bfc3f5
ILT
1// symtab.cc -- the gold symbol table
2
6cb15b7f
ILT
3// Copyright 2006, 2007 Free Software Foundation, Inc.
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
14bfc3f5
ILT
23#include "gold.h"
24
14bfc3f5
ILT
25#include <stdint.h>
26#include <string>
27#include <utility>
28
29#include "object.h"
dbe717ef 30#include "dynobj.h"
75f65a3e 31#include "output.h"
61ba1cf9 32#include "target.h"
645f8123 33#include "workqueue.h"
14bfc3f5
ILT
34#include "symtab.h"
35
36namespace gold
37{
38
39// Class Symbol.
40
ead1e424
ILT
41// Initialize fields in Symbol. This initializes everything except u_
42// and source_.
14bfc3f5 43
14bfc3f5 44void
ead1e424
ILT
45Symbol::init_fields(const char* name, const char* version,
46 elfcpp::STT type, elfcpp::STB binding,
47 elfcpp::STV visibility, unsigned char nonvis)
14bfc3f5
ILT
48{
49 this->name_ = name;
50 this->version_ = version;
c06b7b0b
ILT
51 this->symtab_index_ = 0;
52 this->dynsym_index_ = 0;
ead1e424 53 this->got_offset_ = 0;
f4151f89 54 this->plt_offset_ = 0;
ead1e424
ILT
55 this->type_ = type;
56 this->binding_ = binding;
57 this->visibility_ = visibility;
58 this->nonvis_ = nonvis;
59 this->is_target_special_ = false;
1564db8d
ILT
60 this->is_def_ = false;
61 this->is_forwarder_ = false;
aeddab66 62 this->has_alias_ = false;
c06b7b0b 63 this->needs_dynsym_entry_ = false;
008db82e 64 this->in_reg_ = false;
ead1e424
ILT
65 this->in_dyn_ = false;
66 this->has_got_offset_ = false;
f4151f89 67 this->has_plt_offset_ = false;
f6ce93d6 68 this->has_warning_ = false;
ead1e424
ILT
69}
70
71// Initialize the fields in the base class Symbol for SYM in OBJECT.
72
73template<int size, bool big_endian>
74void
75Symbol::init_base(const char* name, const char* version, Object* object,
76 const elfcpp::Sym<size, big_endian>& sym)
77{
78 this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
79 sym.get_st_visibility(), sym.get_st_nonvis());
80 this->u_.from_object.object = object;
81 // FIXME: Handle SHN_XINDEX.
16649710 82 this->u_.from_object.shndx = sym.get_st_shndx();
ead1e424 83 this->source_ = FROM_OBJECT;
008db82e 84 this->in_reg_ = !object->is_dynamic();
1564db8d 85 this->in_dyn_ = object->is_dynamic();
14bfc3f5
ILT
86}
87
ead1e424
ILT
88// Initialize the fields in the base class Symbol for a symbol defined
89// in an Output_data.
90
91void
92Symbol::init_base(const char* name, Output_data* od, elfcpp::STT type,
93 elfcpp::STB binding, elfcpp::STV visibility,
94 unsigned char nonvis, bool offset_is_from_end)
95{
96 this->init_fields(name, NULL, type, binding, visibility, nonvis);
97 this->u_.in_output_data.output_data = od;
98 this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
99 this->source_ = IN_OUTPUT_DATA;
008db82e 100 this->in_reg_ = true;
ead1e424
ILT
101}
102
103// Initialize the fields in the base class Symbol for a symbol defined
104// in an Output_segment.
105
106void
107Symbol::init_base(const char* name, Output_segment* os, elfcpp::STT type,
108 elfcpp::STB binding, elfcpp::STV visibility,
109 unsigned char nonvis, Segment_offset_base offset_base)
110{
111 this->init_fields(name, NULL, type, binding, visibility, nonvis);
112 this->u_.in_output_segment.output_segment = os;
113 this->u_.in_output_segment.offset_base = offset_base;
114 this->source_ = IN_OUTPUT_SEGMENT;
008db82e 115 this->in_reg_ = true;
ead1e424
ILT
116}
117
118// Initialize the fields in the base class Symbol for a symbol defined
119// as a constant.
120
121void
122Symbol::init_base(const char* name, elfcpp::STT type,
123 elfcpp::STB binding, elfcpp::STV visibility,
124 unsigned char nonvis)
125{
126 this->init_fields(name, NULL, type, binding, visibility, nonvis);
127 this->source_ = CONSTANT;
008db82e 128 this->in_reg_ = true;
ead1e424
ILT
129}
130
131// Initialize the fields in Sized_symbol for SYM in OBJECT.
14bfc3f5
ILT
132
133template<int size>
134template<bool big_endian>
135void
136Sized_symbol<size>::init(const char* name, const char* version, Object* object,
137 const elfcpp::Sym<size, big_endian>& sym)
138{
139 this->init_base(name, version, object, sym);
140 this->value_ = sym.get_st_value();
ead1e424
ILT
141 this->symsize_ = sym.get_st_size();
142}
143
144// Initialize the fields in Sized_symbol for a symbol defined in an
145// Output_data.
146
147template<int size>
148void
149Sized_symbol<size>::init(const char* name, Output_data* od,
150 Value_type value, Size_type symsize,
151 elfcpp::STT type, elfcpp::STB binding,
152 elfcpp::STV visibility, unsigned char nonvis,
153 bool offset_is_from_end)
154{
155 this->init_base(name, od, type, binding, visibility, nonvis,
156 offset_is_from_end);
157 this->value_ = value;
158 this->symsize_ = symsize;
159}
160
161// Initialize the fields in Sized_symbol for a symbol defined in an
162// Output_segment.
163
164template<int size>
165void
166Sized_symbol<size>::init(const char* name, Output_segment* os,
167 Value_type value, Size_type symsize,
168 elfcpp::STT type, elfcpp::STB binding,
169 elfcpp::STV visibility, unsigned char nonvis,
170 Segment_offset_base offset_base)
171{
172 this->init_base(name, os, type, binding, visibility, nonvis, offset_base);
173 this->value_ = value;
174 this->symsize_ = symsize;
175}
176
177// Initialize the fields in Sized_symbol for a symbol defined as a
178// constant.
179
180template<int size>
181void
182Sized_symbol<size>::init(const char* name, Value_type value, Size_type symsize,
183 elfcpp::STT type, elfcpp::STB binding,
184 elfcpp::STV visibility, unsigned char nonvis)
185{
186 this->init_base(name, type, binding, visibility, nonvis);
187 this->value_ = value;
188 this->symsize_ = symsize;
14bfc3f5
ILT
189}
190
b3b74ddc
ILT
191// Return true if the final value of this symbol is known at link
192// time.
193
194bool
195Symbol::final_value_is_known() const
196{
197 // If we are not generating an executable, then no final values are
198 // known, since they will change at runtime.
199 if (!parameters->output_is_executable())
200 return false;
201
202 // If the symbol is not from an object file, then it is defined, and
203 // known.
204 if (this->source_ != FROM_OBJECT)
205 return true;
206
207 // If the symbol is from a dynamic object, then the final value is
208 // not known.
209 if (this->object()->is_dynamic())
210 return false;
211
212 // If the symbol is not undefined (it is defined or common), then
213 // the final value is known.
214 if (!this->is_undefined())
215 return true;
216
217 // If the symbol is undefined, then whether the final value is known
218 // depends on whether we are doing a static link. If we are doing a
219 // dynamic link, then the final value could be filled in at runtime.
220 // This could reasonably be the case for a weak undefined symbol.
221 return parameters->doing_static_link();
222}
223
14bfc3f5
ILT
224// Class Symbol_table.
225
226Symbol_table::Symbol_table()
9025d29d 227 : saw_undefined_(0), offset_(0), table_(), namepool_(),
f6ce93d6 228 forwarders_(), commons_(), warnings_()
14bfc3f5
ILT
229{
230}
231
232Symbol_table::~Symbol_table()
233{
234}
235
236// The hash function. The key is always canonicalized, so we use a
237// simple combination of the pointers.
238
239size_t
240Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key& key) const
241{
f0641a0b 242 return key.first ^ key.second;
14bfc3f5
ILT
243}
244
245// The symbol table key equality function. This is only called with
246// canonicalized name and version strings, so we can use pointer
247// comparison.
248
249bool
250Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
251 const Symbol_table_key& k2) const
252{
253 return k1.first == k2.first && k1.second == k2.second;
254}
255
256// Make TO a symbol which forwards to FROM.
257
258void
259Symbol_table::make_forwarder(Symbol* from, Symbol* to)
260{
a3ad94ed
ILT
261 gold_assert(from != to);
262 gold_assert(!from->is_forwarder() && !to->is_forwarder());
14bfc3f5
ILT
263 this->forwarders_[from] = to;
264 from->set_forwarder();
265}
266
61ba1cf9
ILT
267// Resolve the forwards from FROM, returning the real symbol.
268
14bfc3f5 269Symbol*
c06b7b0b 270Symbol_table::resolve_forwards(const Symbol* from) const
14bfc3f5 271{
a3ad94ed 272 gold_assert(from->is_forwarder());
c06b7b0b 273 Unordered_map<const Symbol*, Symbol*>::const_iterator p =
14bfc3f5 274 this->forwarders_.find(from);
a3ad94ed 275 gold_assert(p != this->forwarders_.end());
14bfc3f5
ILT
276 return p->second;
277}
278
61ba1cf9
ILT
279// Look up a symbol by name.
280
281Symbol*
282Symbol_table::lookup(const char* name, const char* version) const
283{
f0641a0b
ILT
284 Stringpool::Key name_key;
285 name = this->namepool_.find(name, &name_key);
61ba1cf9
ILT
286 if (name == NULL)
287 return NULL;
f0641a0b
ILT
288
289 Stringpool::Key version_key = 0;
61ba1cf9
ILT
290 if (version != NULL)
291 {
f0641a0b 292 version = this->namepool_.find(version, &version_key);
61ba1cf9
ILT
293 if (version == NULL)
294 return NULL;
295 }
296
f0641a0b 297 Symbol_table_key key(name_key, version_key);
61ba1cf9
ILT
298 Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
299 if (p == this->table_.end())
300 return NULL;
301 return p->second;
302}
303
14bfc3f5
ILT
304// Resolve a Symbol with another Symbol. This is only used in the
305// unusual case where there are references to both an unversioned
306// symbol and a symbol with a version, and we then discover that that
1564db8d
ILT
307// version is the default version. Because this is unusual, we do
308// this the slow way, by converting back to an ELF symbol.
14bfc3f5 309
1564db8d 310template<int size, bool big_endian>
14bfc3f5 311void
14b31740
ILT
312Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
313 const char* version ACCEPT_SIZE_ENDIAN)
14bfc3f5 314{
1564db8d
ILT
315 unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
316 elfcpp::Sym_write<size, big_endian> esym(buf);
317 // We don't bother to set the st_name field.
318 esym.put_st_value(from->value());
319 esym.put_st_size(from->symsize());
320 esym.put_st_info(from->binding(), from->type());
ead1e424 321 esym.put_st_other(from->visibility(), from->nonvis());
16649710 322 esym.put_st_shndx(from->shndx());
aeddab66 323 this->resolve(to, esym.sym(), from->object(), version);
1ebd95fd
ILT
324 if (from->in_reg())
325 to->set_in_reg();
326 if (from->in_dyn())
327 to->set_in_dyn();
14bfc3f5
ILT
328}
329
330// Add one symbol from OBJECT to the symbol table. NAME is symbol
331// name and VERSION is the version; both are canonicalized. DEF is
332// whether this is the default version.
333
334// If DEF is true, then this is the definition of a default version of
335// a symbol. That means that any lookup of NAME/NULL and any lookup
336// of NAME/VERSION should always return the same symbol. This is
337// obvious for references, but in particular we want to do this for
338// definitions: overriding NAME/NULL should also override
339// NAME/VERSION. If we don't do that, it would be very hard to
340// override functions in a shared library which uses versioning.
341
342// We implement this by simply making both entries in the hash table
343// point to the same Symbol structure. That is easy enough if this is
344// the first time we see NAME/NULL or NAME/VERSION, but it is possible
345// that we have seen both already, in which case they will both have
346// independent entries in the symbol table. We can't simply change
347// the symbol table entry, because we have pointers to the entries
348// attached to the object files. So we mark the entry attached to the
349// object file as a forwarder, and record it in the forwarders_ map.
350// Note that entries in the hash table will never be marked as
351// forwarders.
352
353template<int size, bool big_endian>
aeddab66 354Sized_symbol<size>*
f6ce93d6 355Symbol_table::add_from_object(Object* object,
14bfc3f5 356 const char *name,
f0641a0b
ILT
357 Stringpool::Key name_key,
358 const char *version,
359 Stringpool::Key version_key,
360 bool def,
14bfc3f5
ILT
361 const elfcpp::Sym<size, big_endian>& sym)
362{
363 Symbol* const snull = NULL;
364 std::pair<typename Symbol_table_type::iterator, bool> ins =
f0641a0b
ILT
365 this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
366 snull));
14bfc3f5
ILT
367
368 std::pair<typename Symbol_table_type::iterator, bool> insdef =
369 std::make_pair(this->table_.end(), false);
370 if (def)
371 {
f0641a0b
ILT
372 const Stringpool::Key vnull_key = 0;
373 insdef = this->table_.insert(std::make_pair(std::make_pair(name_key,
374 vnull_key),
14bfc3f5
ILT
375 snull));
376 }
377
378 // ins.first: an iterator, which is a pointer to a pair.
379 // ins.first->first: the key (a pair of name and version).
380 // ins.first->second: the value (Symbol*).
381 // ins.second: true if new entry was inserted, false if not.
382
1564db8d 383 Sized_symbol<size>* ret;
ead1e424
ILT
384 bool was_undefined;
385 bool was_common;
14bfc3f5
ILT
386 if (!ins.second)
387 {
388 // We already have an entry for NAME/VERSION.
593f47df
ILT
389 ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (ins.first->second
390 SELECT_SIZE(size));
a3ad94ed 391 gold_assert(ret != NULL);
ead1e424
ILT
392
393 was_undefined = ret->is_undefined();
394 was_common = ret->is_common();
395
aeddab66 396 this->resolve(ret, sym, object, version);
14bfc3f5
ILT
397
398 if (def)
399 {
400 if (insdef.second)
401 {
402 // This is the first time we have seen NAME/NULL. Make
403 // NAME/NULL point to NAME/VERSION.
404 insdef.first->second = ret;
405 }
dbe717ef 406 else if (insdef.first->second != ret)
14bfc3f5
ILT
407 {
408 // This is the unfortunate case where we already have
409 // entries for both NAME/VERSION and NAME/NULL.
274e99f9 410 const Sized_symbol<size>* sym2;
593f47df 411 sym2 = this->get_sized_symbol SELECT_SIZE_NAME(size) (
5482377d
ILT
412 insdef.first->second
413 SELECT_SIZE(size));
593f47df 414 Symbol_table::resolve SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
14b31740 415 ret, sym2, version SELECT_SIZE_ENDIAN(size, big_endian));
14bfc3f5
ILT
416 this->make_forwarder(insdef.first->second, ret);
417 insdef.first->second = ret;
418 }
419 }
420 }
421 else
422 {
423 // This is the first time we have seen NAME/VERSION.
a3ad94ed 424 gold_assert(ins.first->second == NULL);
ead1e424
ILT
425
426 was_undefined = false;
427 was_common = false;
428
14bfc3f5
ILT
429 if (def && !insdef.second)
430 {
14b31740
ILT
431 // We already have an entry for NAME/NULL. If we override
432 // it, then change it to NAME/VERSION.
593f47df
ILT
433 ret = this->get_sized_symbol SELECT_SIZE_NAME(size) (
434 insdef.first->second
435 SELECT_SIZE(size));
aeddab66 436 this->resolve(ret, sym, object, version);
14bfc3f5
ILT
437 ins.first->second = ret;
438 }
439 else
440 {
f6ce93d6
ILT
441 Sized_target<size, big_endian>* target =
442 object->sized_target SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
443 SELECT_SIZE_ENDIAN_ONLY(size, big_endian));
1564db8d
ILT
444 if (!target->has_make_symbol())
445 ret = new Sized_symbol<size>();
446 else
14bfc3f5 447 {
1564db8d
ILT
448 ret = target->make_symbol();
449 if (ret == NULL)
14bfc3f5
ILT
450 {
451 // This means that we don't want a symbol table
452 // entry after all.
453 if (!def)
454 this->table_.erase(ins.first);
455 else
456 {
457 this->table_.erase(insdef.first);
458 // Inserting insdef invalidated ins.
f0641a0b
ILT
459 this->table_.erase(std::make_pair(name_key,
460 version_key));
14bfc3f5
ILT
461 }
462 return NULL;
463 }
464 }
14bfc3f5 465
1564db8d
ILT
466 ret->init(name, version, object, sym);
467
14bfc3f5
ILT
468 ins.first->second = ret;
469 if (def)
470 {
471 // This is the first time we have seen NAME/NULL. Point
472 // it at the new entry for NAME/VERSION.
a3ad94ed 473 gold_assert(insdef.second);
14bfc3f5
ILT
474 insdef.first->second = ret;
475 }
476 }
477 }
478
ead1e424
ILT
479 // Record every time we see a new undefined symbol, to speed up
480 // archive groups.
481 if (!was_undefined && ret->is_undefined())
482 ++this->saw_undefined_;
483
484 // Keep track of common symbols, to speed up common symbol
485 // allocation.
486 if (!was_common && ret->is_common())
487 this->commons_.push_back(ret);
488
14bfc3f5
ILT
489 return ret;
490}
491
f6ce93d6 492// Add all the symbols in a relocatable object to the hash table.
14bfc3f5
ILT
493
494template<int size, bool big_endian>
495void
dbe717ef
ILT
496Symbol_table::add_from_relobj(
497 Sized_relobj<size, big_endian>* relobj,
f6ce93d6 498 const unsigned char* syms,
14bfc3f5
ILT
499 size_t count,
500 const char* sym_names,
501 size_t sym_name_size,
502 Symbol** sympointers)
503{
9025d29d
ILT
504 gold_assert(size == relobj->target()->get_size());
505 gold_assert(size == parameters->get_size());
14bfc3f5 506
a783673b
ILT
507 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
508
f6ce93d6 509 const unsigned char* p = syms;
a783673b 510 for (size_t i = 0; i < count; ++i, p += sym_size)
14bfc3f5
ILT
511 {
512 elfcpp::Sym<size, big_endian> sym(p);
a783673b 513 elfcpp::Sym<size, big_endian>* psym = &sym;
14bfc3f5 514
a783673b 515 unsigned int st_name = psym->get_st_name();
14bfc3f5
ILT
516 if (st_name >= sym_name_size)
517 {
75f2446e
ILT
518 relobj->error(_("bad global symbol name offset %u at %zu"),
519 st_name, i);
520 continue;
14bfc3f5
ILT
521 }
522
dbe717ef
ILT
523 const char* name = sym_names + st_name;
524
a783673b
ILT
525 // A symbol defined in a section which we are not including must
526 // be treated as an undefined symbol.
527 unsigned char symbuf[sym_size];
528 elfcpp::Sym<size, big_endian> sym2(symbuf);
529 unsigned int st_shndx = psym->get_st_shndx();
530 if (st_shndx != elfcpp::SHN_UNDEF
531 && st_shndx < elfcpp::SHN_LORESERVE
dbe717ef 532 && !relobj->is_section_included(st_shndx))
a783673b
ILT
533 {
534 memcpy(symbuf, p, sym_size);
535 elfcpp::Sym_write<size, big_endian> sw(symbuf);
536 sw.put_st_shndx(elfcpp::SHN_UNDEF);
537 psym = &sym2;
538 }
539
14bfc3f5
ILT
540 // In an object file, an '@' in the name separates the symbol
541 // name from the version name. If there are two '@' characters,
542 // this is the default version.
543 const char* ver = strchr(name, '@');
544
aeddab66 545 Sized_symbol<size>* res;
14bfc3f5
ILT
546 if (ver == NULL)
547 {
f0641a0b 548 Stringpool::Key name_key;
cfd73a4e 549 name = this->namepool_.add(name, true, &name_key);
dbe717ef 550 res = this->add_from_object(relobj, name, name_key, NULL, 0,
f0641a0b 551 false, *psym);
14bfc3f5
ILT
552 }
553 else
554 {
f0641a0b 555 Stringpool::Key name_key;
cfd73a4e 556 name = this->namepool_.add_prefix(name, ver - name, &name_key);
f0641a0b 557
14bfc3f5
ILT
558 bool def = false;
559 ++ver;
560 if (*ver == '@')
561 {
562 def = true;
563 ++ver;
564 }
f0641a0b
ILT
565
566 Stringpool::Key ver_key;
cfd73a4e 567 ver = this->namepool_.add(ver, true, &ver_key);
f0641a0b 568
dbe717ef 569 res = this->add_from_object(relobj, name, name_key, ver, ver_key,
f0641a0b 570 def, *psym);
14bfc3f5
ILT
571 }
572
573 *sympointers++ = res;
14bfc3f5
ILT
574 }
575}
576
dbe717ef
ILT
577// Add all the symbols in a dynamic object to the hash table.
578
579template<int size, bool big_endian>
580void
581Symbol_table::add_from_dynobj(
582 Sized_dynobj<size, big_endian>* dynobj,
583 const unsigned char* syms,
584 size_t count,
585 const char* sym_names,
586 size_t sym_name_size,
587 const unsigned char* versym,
588 size_t versym_size,
589 const std::vector<const char*>* version_map)
590{
9025d29d
ILT
591 gold_assert(size == dynobj->target()->get_size());
592 gold_assert(size == parameters->get_size());
dbe717ef
ILT
593
594 if (versym != NULL && versym_size / 2 < count)
595 {
75f2446e
ILT
596 dynobj->error(_("too few symbol versions"));
597 return;
dbe717ef
ILT
598 }
599
600 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
601
aeddab66
ILT
602 // We keep a list of all STT_OBJECT symbols, so that we can resolve
603 // weak aliases. This is necessary because if the dynamic object
604 // provides the same variable under two names, one of which is a
605 // weak definition, and the regular object refers to the weak
606 // definition, we have to put both the weak definition and the
607 // strong definition into the dynamic symbol table. Given a weak
608 // definition, the only way that we can find the corresponding
609 // strong definition, if any, is to search the symbol table.
610 std::vector<Sized_symbol<size>*> object_symbols;
611
dbe717ef
ILT
612 const unsigned char* p = syms;
613 const unsigned char* vs = versym;
614 for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
615 {
616 elfcpp::Sym<size, big_endian> sym(p);
617
618 // Ignore symbols with local binding.
619 if (sym.get_st_bind() == elfcpp::STB_LOCAL)
620 continue;
621
622 unsigned int st_name = sym.get_st_name();
623 if (st_name >= sym_name_size)
624 {
75f2446e
ILT
625 dynobj->error(_("bad symbol name offset %u at %zu"),
626 st_name, i);
627 continue;
dbe717ef
ILT
628 }
629
630 const char* name = sym_names + st_name;
631
aeddab66
ILT
632 Sized_symbol<size>* res;
633
dbe717ef
ILT
634 if (versym == NULL)
635 {
636 Stringpool::Key name_key;
cfd73a4e 637 name = this->namepool_.add(name, true, &name_key);
aeddab66
ILT
638 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
639 false, sym);
dbe717ef 640 }
aeddab66
ILT
641 else
642 {
643 // Read the version information.
dbe717ef 644
aeddab66 645 unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
dbe717ef 646
aeddab66
ILT
647 bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
648 v &= elfcpp::VERSYM_VERSION;
dbe717ef 649
aeddab66
ILT
650 // The Sun documentation says that V can be VER_NDX_LOCAL,
651 // or VER_NDX_GLOBAL, or a version index. The meaning of
652 // VER_NDX_LOCAL is defined as "Symbol has local scope."
653 // The old GNU linker will happily generate VER_NDX_LOCAL
654 // for an undefined symbol. I don't know what the Sun
655 // linker will generate.
dbe717ef 656
aeddab66
ILT
657 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
658 && sym.get_st_shndx() != elfcpp::SHN_UNDEF)
659 {
660 // This symbol should not be visible outside the object.
661 continue;
662 }
64707334 663
aeddab66
ILT
664 // At this point we are definitely going to add this symbol.
665 Stringpool::Key name_key;
666 name = this->namepool_.add(name, true, &name_key);
dbe717ef 667
aeddab66
ILT
668 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
669 || v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
670 {
671 // This symbol does not have a version.
672 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
673 false, sym);
674 }
675 else
676 {
677 if (v >= version_map->size())
678 {
679 dynobj->error(_("versym for symbol %zu out of range: %u"),
680 i, v);
681 continue;
682 }
dbe717ef 683
aeddab66
ILT
684 const char* version = (*version_map)[v];
685 if (version == NULL)
686 {
687 dynobj->error(_("versym for symbol %zu has no name: %u"),
688 i, v);
689 continue;
690 }
dbe717ef 691
aeddab66
ILT
692 Stringpool::Key version_key;
693 version = this->namepool_.add(version, true, &version_key);
694
695 // If this is an absolute symbol, and the version name
696 // and symbol name are the same, then this is the
697 // version definition symbol. These symbols exist to
698 // support using -u to pull in particular versions. We
699 // do not want to record a version for them.
700 if (sym.get_st_shndx() == elfcpp::SHN_ABS
701 && name_key == version_key)
702 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
703 false, sym);
704 else
705 {
706 const bool def = (!hidden
707 && (sym.get_st_shndx()
708 != elfcpp::SHN_UNDEF));
709 res = this->add_from_object(dynobj, name, name_key, version,
710 version_key, def, sym);
711 }
712 }
dbe717ef
ILT
713 }
714
aeddab66
ILT
715 if (sym.get_st_shndx() != elfcpp::SHN_UNDEF
716 && sym.get_st_type() == elfcpp::STT_OBJECT)
717 object_symbols.push_back(res);
718 }
719
720 this->record_weak_aliases(&object_symbols);
721}
722
723// This is used to sort weak aliases. We sort them first by section
724// index, then by offset, then by weak ahead of strong.
725
726template<int size>
727class Weak_alias_sorter
728{
729 public:
730 bool operator()(const Sized_symbol<size>*, const Sized_symbol<size>*) const;
731};
732
733template<int size>
734bool
735Weak_alias_sorter<size>::operator()(const Sized_symbol<size>* s1,
736 const Sized_symbol<size>* s2) const
737{
738 if (s1->shndx() != s2->shndx())
739 return s1->shndx() < s2->shndx();
740 if (s1->value() != s2->value())
741 return s1->value() < s2->value();
742 if (s1->binding() != s2->binding())
743 {
744 if (s1->binding() == elfcpp::STB_WEAK)
745 return true;
746 if (s2->binding() == elfcpp::STB_WEAK)
747 return false;
748 }
749 return std::string(s1->name()) < std::string(s2->name());
750}
dbe717ef 751
aeddab66
ILT
752// SYMBOLS is a list of object symbols from a dynamic object. Look
753// for any weak aliases, and record them so that if we add the weak
754// alias to the dynamic symbol table, we also add the corresponding
755// strong symbol.
dbe717ef 756
aeddab66
ILT
757template<int size>
758void
759Symbol_table::record_weak_aliases(std::vector<Sized_symbol<size>*>* symbols)
760{
761 // Sort the vector by section index, then by offset, then by weak
762 // ahead of strong.
763 std::sort(symbols->begin(), symbols->end(), Weak_alias_sorter<size>());
764
765 // Walk through the vector. For each weak definition, record
766 // aliases.
767 for (typename std::vector<Sized_symbol<size>*>::const_iterator p =
768 symbols->begin();
769 p != symbols->end();
770 ++p)
771 {
772 if ((*p)->binding() != elfcpp::STB_WEAK)
773 continue;
774
775 // Build a circular list of weak aliases. Each symbol points to
776 // the next one in the circular list.
777
778 Sized_symbol<size>* from_sym = *p;
779 typename std::vector<Sized_symbol<size>*>::const_iterator q;
780 for (q = p + 1; q != symbols->end(); ++q)
dbe717ef 781 {
aeddab66
ILT
782 if ((*q)->shndx() != from_sym->shndx()
783 || (*q)->value() != from_sym->value())
784 break;
785
786 this->weak_aliases_[from_sym] = *q;
787 from_sym->set_has_alias();
788 from_sym = *q;
dbe717ef
ILT
789 }
790
aeddab66
ILT
791 if (from_sym != *p)
792 {
793 this->weak_aliases_[from_sym] = *p;
794 from_sym->set_has_alias();
795 }
dbe717ef 796
aeddab66 797 p = q - 1;
dbe717ef
ILT
798 }
799}
800
ead1e424
ILT
801// Create and return a specially defined symbol. If ONLY_IF_REF is
802// true, then only create the symbol if there is a reference to it.
86f2e683 803// If this does not return NULL, it sets *POLDSYM to the existing
306d9ef0 804// symbol if there is one. This canonicalizes *PNAME and *PVERSION.
ead1e424
ILT
805
806template<int size, bool big_endian>
807Sized_symbol<size>*
306d9ef0
ILT
808Symbol_table::define_special_symbol(const Target* target, const char** pname,
809 const char** pversion, bool only_if_ref,
86f2e683 810 Sized_symbol<size>** poldsym
593f47df 811 ACCEPT_SIZE_ENDIAN)
ead1e424 812{
ead1e424
ILT
813 Symbol* oldsym;
814 Sized_symbol<size>* sym;
86f2e683
ILT
815 bool add_to_table = false;
816 typename Symbol_table_type::iterator add_loc = this->table_.end();
ead1e424
ILT
817
818 if (only_if_ref)
819 {
306d9ef0 820 oldsym = this->lookup(*pname, *pversion);
f6ce93d6 821 if (oldsym == NULL || !oldsym->is_undefined())
ead1e424 822 return NULL;
306d9ef0
ILT
823
824 *pname = oldsym->name();
825 *pversion = oldsym->version();
ead1e424
ILT
826 }
827 else
828 {
14b31740 829 // Canonicalize NAME and VERSION.
f0641a0b 830 Stringpool::Key name_key;
cfd73a4e 831 *pname = this->namepool_.add(*pname, true, &name_key);
ead1e424 832
14b31740 833 Stringpool::Key version_key = 0;
306d9ef0 834 if (*pversion != NULL)
cfd73a4e 835 *pversion = this->namepool_.add(*pversion, true, &version_key);
14b31740 836
ead1e424 837 Symbol* const snull = NULL;
ead1e424 838 std::pair<typename Symbol_table_type::iterator, bool> ins =
14b31740
ILT
839 this->table_.insert(std::make_pair(std::make_pair(name_key,
840 version_key),
ead1e424
ILT
841 snull));
842
843 if (!ins.second)
844 {
14b31740 845 // We already have a symbol table entry for NAME/VERSION.
ead1e424 846 oldsym = ins.first->second;
a3ad94ed 847 gold_assert(oldsym != NULL);
ead1e424
ILT
848 }
849 else
850 {
851 // We haven't seen this symbol before.
a3ad94ed 852 gold_assert(ins.first->second == NULL);
86f2e683
ILT
853 add_to_table = true;
854 add_loc = ins.first;
ead1e424
ILT
855 oldsym = NULL;
856 }
857 }
858
86f2e683
ILT
859 if (!target->has_make_symbol())
860 sym = new Sized_symbol<size>();
861 else
ead1e424 862 {
86f2e683
ILT
863 gold_assert(target->get_size() == size);
864 gold_assert(target->is_big_endian() ? big_endian : !big_endian);
865 typedef Sized_target<size, big_endian> My_target;
866 const My_target* sized_target =
867 static_cast<const My_target*>(target);
868 sym = sized_target->make_symbol();
869 if (sym == NULL)
870 return NULL;
871 }
ead1e424 872
86f2e683
ILT
873 if (add_to_table)
874 add_loc->second = sym;
875 else
876 gold_assert(oldsym != NULL);
ead1e424 877
86f2e683
ILT
878 *poldsym = this->get_sized_symbol SELECT_SIZE_NAME(size) (oldsym
879 SELECT_SIZE(size));
ead1e424
ILT
880
881 return sym;
882}
883
884// Define a symbol based on an Output_data.
885
14b31740
ILT
886Symbol*
887Symbol_table::define_in_output_data(const Target* target, const char* name,
888 const char* version, Output_data* od,
ead1e424
ILT
889 uint64_t value, uint64_t symsize,
890 elfcpp::STT type, elfcpp::STB binding,
891 elfcpp::STV visibility,
892 unsigned char nonvis,
893 bool offset_is_from_end,
894 bool only_if_ref)
895{
9025d29d 896 if (parameters->get_size() == 32)
86f2e683
ILT
897 {
898#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
899 return this->do_define_in_output_data<32>(target, name, version, od,
900 value, symsize, type, binding,
901 visibility, nonvis,
902 offset_is_from_end,
903 only_if_ref);
904#else
905 gold_unreachable();
906#endif
907 }
9025d29d 908 else if (parameters->get_size() == 64)
86f2e683
ILT
909 {
910#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
911 return this->do_define_in_output_data<64>(target, name, version, od,
912 value, symsize, type, binding,
913 visibility, nonvis,
914 offset_is_from_end,
915 only_if_ref);
916#else
917 gold_unreachable();
918#endif
919 }
ead1e424 920 else
a3ad94ed 921 gold_unreachable();
ead1e424
ILT
922}
923
924// Define a symbol in an Output_data, sized version.
925
926template<int size>
14b31740 927Sized_symbol<size>*
ead1e424 928Symbol_table::do_define_in_output_data(
14b31740 929 const Target* target,
ead1e424 930 const char* name,
14b31740 931 const char* version,
ead1e424
ILT
932 Output_data* od,
933 typename elfcpp::Elf_types<size>::Elf_Addr value,
934 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
935 elfcpp::STT type,
936 elfcpp::STB binding,
937 elfcpp::STV visibility,
938 unsigned char nonvis,
939 bool offset_is_from_end,
940 bool only_if_ref)
941{
942 Sized_symbol<size>* sym;
86f2e683 943 Sized_symbol<size>* oldsym;
ead1e424 944
9025d29d 945 if (parameters->is_big_endian())
193a53d9
ILT
946 {
947#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
948 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
306d9ef0 949 target, &name, &version, only_if_ref, &oldsym
193a53d9
ILT
950 SELECT_SIZE_ENDIAN(size, true));
951#else
952 gold_unreachable();
953#endif
954 }
ead1e424 955 else
193a53d9
ILT
956 {
957#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
958 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
306d9ef0 959 target, &name, &version, only_if_ref, &oldsym
193a53d9
ILT
960 SELECT_SIZE_ENDIAN(size, false));
961#else
962 gold_unreachable();
963#endif
964 }
ead1e424
ILT
965
966 if (sym == NULL)
14b31740 967 return NULL;
ead1e424 968
d4f5281b 969 gold_assert(version == NULL || oldsym != NULL);
ead1e424
ILT
970 sym->init(name, od, value, symsize, type, binding, visibility, nonvis,
971 offset_is_from_end);
14b31740 972
86f2e683
ILT
973 if (oldsym != NULL
974 && Symbol_table::should_override_with_special(oldsym))
aeddab66 975 this->override_with_special(oldsym, sym);
86f2e683 976
14b31740 977 return sym;
ead1e424
ILT
978}
979
980// Define a symbol based on an Output_segment.
981
14b31740
ILT
982Symbol*
983Symbol_table::define_in_output_segment(const Target* target, const char* name,
984 const char* version, Output_segment* os,
ead1e424
ILT
985 uint64_t value, uint64_t symsize,
986 elfcpp::STT type, elfcpp::STB binding,
987 elfcpp::STV visibility,
988 unsigned char nonvis,
989 Symbol::Segment_offset_base offset_base,
990 bool only_if_ref)
991{
9025d29d 992 if (parameters->get_size() == 32)
86f2e683
ILT
993 {
994#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
995 return this->do_define_in_output_segment<32>(target, name, version, os,
996 value, symsize, type,
997 binding, visibility, nonvis,
998 offset_base, only_if_ref);
999#else
1000 gold_unreachable();
1001#endif
1002 }
9025d29d 1003 else if (parameters->get_size() == 64)
86f2e683
ILT
1004 {
1005#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1006 return this->do_define_in_output_segment<64>(target, name, version, os,
1007 value, symsize, type,
1008 binding, visibility, nonvis,
1009 offset_base, only_if_ref);
1010#else
1011 gold_unreachable();
1012#endif
1013 }
ead1e424 1014 else
a3ad94ed 1015 gold_unreachable();
ead1e424
ILT
1016}
1017
1018// Define a symbol in an Output_segment, sized version.
1019
1020template<int size>
14b31740 1021Sized_symbol<size>*
ead1e424 1022Symbol_table::do_define_in_output_segment(
14b31740 1023 const Target* target,
ead1e424 1024 const char* name,
14b31740 1025 const char* version,
ead1e424
ILT
1026 Output_segment* os,
1027 typename elfcpp::Elf_types<size>::Elf_Addr value,
1028 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1029 elfcpp::STT type,
1030 elfcpp::STB binding,
1031 elfcpp::STV visibility,
1032 unsigned char nonvis,
1033 Symbol::Segment_offset_base offset_base,
1034 bool only_if_ref)
1035{
1036 Sized_symbol<size>* sym;
86f2e683 1037 Sized_symbol<size>* oldsym;
ead1e424 1038
9025d29d
ILT
1039 if (parameters->is_big_endian())
1040 {
1041#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
1042 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, true) (
1043 target, &name, &version, only_if_ref, &oldsym
1044 SELECT_SIZE_ENDIAN(size, true));
1045#else
1046 gold_unreachable();
1047#endif
1048 }
ead1e424 1049 else
9025d29d
ILT
1050 {
1051#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
1052 sym = this->define_special_symbol SELECT_SIZE_ENDIAN_NAME(size, false) (
1053 target, &name, &version, only_if_ref, &oldsym
1054 SELECT_SIZE_ENDIAN(size, false));
1055#else
1056 gold_unreachable();
1057#endif
1058 }
ead1e424
ILT
1059
1060 if (sym == NULL)
14b31740 1061 return NULL;
ead1e424 1062
d4f5281b 1063 gold_assert(version == NULL || oldsym != NULL);
ead1e424
ILT
1064 sym->init(name, os, value, symsize, type, binding, visibility, nonvis,
1065 offset_base);
14b31740 1066
86f2e683
ILT
1067 if (oldsym != NULL
1068 && Symbol_table::should_override_with_special(oldsym))
aeddab66 1069 this->override_with_special(oldsym, sym);
86f2e683 1070
14b31740 1071 return sym;
ead1e424
ILT
1072}
1073
1074// Define a special symbol with a constant value. It is a multiple
1075// definition error if this symbol is already defined.
1076
14b31740
ILT
1077Symbol*
1078Symbol_table::define_as_constant(const Target* target, const char* name,
1079 const char* version, uint64_t value,
1080 uint64_t symsize, elfcpp::STT type,
1081 elfcpp::STB binding, elfcpp::STV visibility,
1082 unsigned char nonvis, bool only_if_ref)
ead1e424 1083{
9025d29d 1084 if (parameters->get_size() == 32)
86f2e683
ILT
1085 {
1086#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1087 return this->do_define_as_constant<32>(target, name, version, value,
1088 symsize, type, binding,
1089 visibility, nonvis, only_if_ref);
1090#else
1091 gold_unreachable();
1092#endif
1093 }
9025d29d 1094 else if (parameters->get_size() == 64)
86f2e683
ILT
1095 {
1096#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1097 return this->do_define_as_constant<64>(target, name, version, value,
1098 symsize, type, binding,
1099 visibility, nonvis, only_if_ref);
1100#else
1101 gold_unreachable();
1102#endif
1103 }
ead1e424 1104 else
a3ad94ed 1105 gold_unreachable();
ead1e424
ILT
1106}
1107
1108// Define a symbol as a constant, sized version.
1109
1110template<int size>
14b31740 1111Sized_symbol<size>*
ead1e424 1112Symbol_table::do_define_as_constant(
14b31740 1113 const Target* target,
ead1e424 1114 const char* name,
14b31740 1115 const char* version,
ead1e424
ILT
1116 typename elfcpp::Elf_types<size>::Elf_Addr value,
1117 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1118 elfcpp::STT type,
1119 elfcpp::STB binding,
1120 elfcpp::STV visibility,
1121 unsigned char nonvis,
1122 bool only_if_ref)
1123{
1124 Sized_symbol<size>* sym;
86f2e683 1125 Sized_symbol<size>* oldsym;
ead1e424 1126
9025d29d
ILT
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 }
ead1e424 1137 else
9025d29d
ILT
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 }
ead1e424
ILT
1147
1148 if (sym == NULL)
14b31740 1149 return NULL;
ead1e424 1150
d4f5281b 1151 gold_assert(version == NULL || oldsym != NULL);
ead1e424 1152 sym->init(name, value, symsize, type, binding, visibility, nonvis);
14b31740 1153
86f2e683
ILT
1154 if (oldsym != NULL
1155 && Symbol_table::should_override_with_special(oldsym))
aeddab66 1156 this->override_with_special(oldsym, sym);
86f2e683 1157
14b31740 1158 return sym;
ead1e424
ILT
1159}
1160
1161// Define a set of symbols in output sections.
1162
1163void
14b31740
ILT
1164Symbol_table::define_symbols(const Layout* layout, const Target* target,
1165 int count, const Define_symbol_in_section* p)
ead1e424
ILT
1166{
1167 for (int i = 0; i < count; ++i, ++p)
1168 {
1169 Output_section* os = layout->find_output_section(p->output_section);
1170 if (os != NULL)
14b31740
ILT
1171 this->define_in_output_data(target, p->name, NULL, os, p->value,
1172 p->size, p->type, p->binding,
1173 p->visibility, p->nonvis,
1174 p->offset_is_from_end, p->only_if_ref);
ead1e424 1175 else
14b31740 1176 this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
ead1e424
ILT
1177 p->binding, p->visibility, p->nonvis,
1178 p->only_if_ref);
1179 }
1180}
1181
1182// Define a set of symbols in output segments.
1183
1184void
14b31740
ILT
1185Symbol_table::define_symbols(const Layout* layout, const Target* target,
1186 int count, const Define_symbol_in_segment* p)
ead1e424
ILT
1187{
1188 for (int i = 0; i < count; ++i, ++p)
1189 {
1190 Output_segment* os = layout->find_output_segment(p->segment_type,
1191 p->segment_flags_set,
1192 p->segment_flags_clear);
1193 if (os != NULL)
14b31740
ILT
1194 this->define_in_output_segment(target, p->name, NULL, os, p->value,
1195 p->size, p->type, p->binding,
1196 p->visibility, p->nonvis,
1197 p->offset_base, p->only_if_ref);
ead1e424 1198 else
14b31740 1199 this->define_as_constant(target, p->name, NULL, 0, p->size, p->type,
ead1e424
ILT
1200 p->binding, p->visibility, p->nonvis,
1201 p->only_if_ref);
1202 }
1203}
1204
a3ad94ed
ILT
1205// Set the dynamic symbol indexes. INDEX is the index of the first
1206// global dynamic symbol. Pointers to the symbols are stored into the
1207// vector SYMS. The names are added to DYNPOOL. This returns an
1208// updated dynamic symbol index.
1209
1210unsigned int
14b31740
ILT
1211Symbol_table::set_dynsym_indexes(const General_options* options,
1212 const Target* target,
1213 unsigned int index,
a3ad94ed 1214 std::vector<Symbol*>* syms,
14b31740
ILT
1215 Stringpool* dynpool,
1216 Versions* versions)
a3ad94ed
ILT
1217{
1218 for (Symbol_table_type::iterator p = this->table_.begin();
1219 p != this->table_.end();
1220 ++p)
1221 {
1222 Symbol* sym = p->second;
16649710
ILT
1223
1224 // Note that SYM may already have a dynamic symbol index, since
1225 // some symbols appear more than once in the symbol table, with
1226 // and without a version.
1227
a6badf5a
ILT
1228 if (!sym->needs_dynsym_entry()
1229 && (!options->export_dynamic()
1230 || !sym->in_reg()
1231 || !sym->is_externally_visible()))
16649710
ILT
1232 sym->set_dynsym_index(-1U);
1233 else if (!sym->has_dynsym_index())
a3ad94ed
ILT
1234 {
1235 sym->set_dynsym_index(index);
1236 ++index;
1237 syms->push_back(sym);
cfd73a4e 1238 dynpool->add(sym->name(), false, NULL);
14b31740
ILT
1239
1240 // Record any version information.
1241 if (sym->version() != NULL)
1242 versions->record_version(options, dynpool, sym);
a3ad94ed
ILT
1243 }
1244 }
1245
14b31740
ILT
1246 // Finish up the versions. In some cases this may add new dynamic
1247 // symbols.
1248 index = versions->finalize(target, this, index, syms);
1249
a3ad94ed
ILT
1250 return index;
1251}
1252
c06b7b0b
ILT
1253// Set the final values for all the symbols. The index of the first
1254// global symbol in the output file is INDEX. Record the file offset
75f65a3e 1255// OFF. Add their names to POOL. Return the new file offset.
54dc6425 1256
75f65a3e 1257off_t
16649710
ILT
1258Symbol_table::finalize(unsigned int index, off_t off, off_t dynoff,
1259 size_t dyn_global_index, size_t dyncount,
1260 Stringpool* pool)
54dc6425 1261{
f6ce93d6
ILT
1262 off_t ret;
1263
a3ad94ed 1264 gold_assert(index != 0);
c06b7b0b
ILT
1265 this->first_global_index_ = index;
1266
16649710
ILT
1267 this->dynamic_offset_ = dynoff;
1268 this->first_dynamic_global_index_ = dyn_global_index;
1269 this->dynamic_count_ = dyncount;
1270
9025d29d
ILT
1271 if (parameters->get_size() == 32)
1272 {
1273#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
1274 ret = this->sized_finalize<32>(index, off, pool);
1275#else
1276 gold_unreachable();
1277#endif
1278 }
1279 else if (parameters->get_size() == 64)
1280 {
1281#if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
1282 ret = this->sized_finalize<64>(index, off, pool);
1283#else
1284 gold_unreachable();
1285#endif
1286 }
61ba1cf9 1287 else
a3ad94ed 1288 gold_unreachable();
f6ce93d6
ILT
1289
1290 // Now that we have the final symbol table, we can reliably note
1291 // which symbols should get warnings.
1292 this->warnings_.note_warnings(this);
1293
1294 return ret;
75f65a3e
ILT
1295}
1296
ead1e424
ILT
1297// Set the final value for all the symbols. This is called after
1298// Layout::finalize, so all the output sections have their final
1299// address.
75f65a3e
ILT
1300
1301template<int size>
1302off_t
c06b7b0b 1303Symbol_table::sized_finalize(unsigned index, off_t off, Stringpool* pool)
75f65a3e 1304{
ead1e424 1305 off = align_address(off, size >> 3);
75f65a3e
ILT
1306 this->offset_ = off;
1307
c06b7b0b
ILT
1308 size_t orig_index = index;
1309
75f65a3e 1310 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
c06b7b0b
ILT
1311 for (Symbol_table_type::iterator p = this->table_.begin();
1312 p != this->table_.end();
1313 ++p)
54dc6425 1314 {
75f65a3e 1315 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
54dc6425 1316
75f65a3e 1317 // FIXME: Here we need to decide which symbols should go into
a3ad94ed
ILT
1318 // the output file, based on --strip.
1319
1320 // The default version of a symbol may appear twice in the
1321 // symbol table. We only need to finalize it once.
1322 if (sym->has_symtab_index())
1323 continue;
75f65a3e 1324
008db82e
ILT
1325 if (!sym->in_reg())
1326 {
1327 gold_assert(!sym->has_symtab_index());
1328 sym->set_symtab_index(-1U);
1329 gold_assert(sym->dynsym_index() == -1U);
1330 continue;
1331 }
1332
ead1e424 1333 typename Sized_symbol<size>::Value_type value;
75f65a3e 1334
ead1e424 1335 switch (sym->source())
75f65a3e 1336 {
ead1e424
ILT
1337 case Symbol::FROM_OBJECT:
1338 {
16649710 1339 unsigned int shndx = sym->shndx();
ead1e424
ILT
1340
1341 // FIXME: We need some target specific support here.
16649710
ILT
1342 if (shndx >= elfcpp::SHN_LORESERVE
1343 && shndx != elfcpp::SHN_ABS)
ead1e424 1344 {
75f2446e
ILT
1345 gold_error(_("%s: unsupported symbol section 0x%x"),
1346 sym->name(), shndx);
1347 shndx = elfcpp::SHN_UNDEF;
ead1e424
ILT
1348 }
1349
f6ce93d6
ILT
1350 Object* symobj = sym->object();
1351 if (symobj->is_dynamic())
1352 {
1353 value = 0;
16649710 1354 shndx = elfcpp::SHN_UNDEF;
f6ce93d6 1355 }
16649710 1356 else if (shndx == elfcpp::SHN_UNDEF)
ead1e424 1357 value = 0;
16649710 1358 else if (shndx == elfcpp::SHN_ABS)
ead1e424
ILT
1359 value = sym->value();
1360 else
1361 {
f6ce93d6 1362 Relobj* relobj = static_cast<Relobj*>(symobj);
ead1e424 1363 off_t secoff;
16649710 1364 Output_section* os = relobj->output_section(shndx, &secoff);
ead1e424
ILT
1365
1366 if (os == NULL)
1367 {
c06b7b0b 1368 sym->set_symtab_index(-1U);
16649710 1369 gold_assert(sym->dynsym_index() == -1U);
ead1e424
ILT
1370 continue;
1371 }
1372
1373 value = sym->value() + os->address() + secoff;
1374 }
1375 }
1376 break;
1377
1378 case Symbol::IN_OUTPUT_DATA:
1379 {
1380 Output_data* od = sym->output_data();
1381 value = sym->value() + od->address();
1382 if (sym->offset_is_from_end())
1383 value += od->data_size();
1384 }
1385 break;
1386
1387 case Symbol::IN_OUTPUT_SEGMENT:
1388 {
1389 Output_segment* os = sym->output_segment();
1390 value = sym->value() + os->vaddr();
1391 switch (sym->offset_base())
1392 {
1393 case Symbol::SEGMENT_START:
1394 break;
1395 case Symbol::SEGMENT_END:
1396 value += os->memsz();
1397 break;
1398 case Symbol::SEGMENT_BSS:
1399 value += os->filesz();
1400 break;
1401 default:
a3ad94ed 1402 gold_unreachable();
ead1e424
ILT
1403 }
1404 }
1405 break;
1406
1407 case Symbol::CONSTANT:
1408 value = sym->value();
1409 break;
1410
1411 default:
a3ad94ed 1412 gold_unreachable();
54dc6425 1413 }
ead1e424
ILT
1414
1415 sym->set_value(value);
9e2dcb77
ILT
1416
1417 if (parameters->strip_all())
1418 sym->set_symtab_index(-1U);
1419 else
1420 {
1421 sym->set_symtab_index(index);
cfd73a4e 1422 pool->add(sym->name(), false, NULL);
9e2dcb77
ILT
1423 ++index;
1424 off += sym_size;
1425 }
54dc6425 1426 }
75f65a3e 1427
c06b7b0b 1428 this->output_count_ = index - orig_index;
61ba1cf9 1429
75f65a3e 1430 return off;
54dc6425
ILT
1431}
1432
61ba1cf9
ILT
1433// Write out the global symbols.
1434
1435void
1436Symbol_table::write_globals(const Target* target, const Stringpool* sympool,
16649710 1437 const Stringpool* dynpool, Output_file* of) const
61ba1cf9 1438{
9025d29d 1439 if (parameters->get_size() == 32)
61ba1cf9 1440 {
9025d29d
ILT
1441 if (parameters->is_big_endian())
1442 {
1443#ifdef HAVE_TARGET_32_BIG
1444 this->sized_write_globals<32, true>(target, sympool, dynpool, of);
1445#else
1446 gold_unreachable();
1447#endif
1448 }
61ba1cf9 1449 else
9025d29d
ILT
1450 {
1451#ifdef HAVE_TARGET_32_LITTLE
1452 this->sized_write_globals<32, false>(target, sympool, dynpool, of);
1453#else
1454 gold_unreachable();
1455#endif
1456 }
61ba1cf9 1457 }
9025d29d 1458 else if (parameters->get_size() == 64)
61ba1cf9 1459 {
9025d29d
ILT
1460 if (parameters->is_big_endian())
1461 {
1462#ifdef HAVE_TARGET_64_BIG
1463 this->sized_write_globals<64, true>(target, sympool, dynpool, of);
1464#else
1465 gold_unreachable();
1466#endif
1467 }
61ba1cf9 1468 else
9025d29d
ILT
1469 {
1470#ifdef HAVE_TARGET_64_LITTLE
1471 this->sized_write_globals<64, false>(target, sympool, dynpool, of);
1472#else
1473 gold_unreachable();
1474#endif
1475 }
61ba1cf9
ILT
1476 }
1477 else
a3ad94ed 1478 gold_unreachable();
61ba1cf9
ILT
1479}
1480
1481// Write out the global symbols.
1482
1483template<int size, bool big_endian>
1484void
ab5c9e90 1485Symbol_table::sized_write_globals(const Target* target,
61ba1cf9 1486 const Stringpool* sympool,
16649710 1487 const Stringpool* dynpool,
61ba1cf9
ILT
1488 Output_file* of) const
1489{
1490 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
c06b7b0b
ILT
1491 unsigned int index = this->first_global_index_;
1492 const off_t oview_size = this->output_count_ * sym_size;
16649710
ILT
1493 unsigned char* const psyms = of->get_output_view(this->offset_, oview_size);
1494
1495 unsigned int dynamic_count = this->dynamic_count_;
1496 off_t dynamic_size = dynamic_count * sym_size;
1497 unsigned int first_dynamic_global_index = this->first_dynamic_global_index_;
1498 unsigned char* dynamic_view;
1499 if (this->dynamic_offset_ == 0)
1500 dynamic_view = NULL;
1501 else
1502 dynamic_view = of->get_output_view(this->dynamic_offset_, dynamic_size);
c06b7b0b 1503
61ba1cf9
ILT
1504 unsigned char* ps = psyms;
1505 for (Symbol_table_type::const_iterator p = this->table_.begin();
1506 p != this->table_.end();
1507 ++p)
1508 {
1509 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
1510
a3ad94ed 1511 unsigned int sym_index = sym->symtab_index();
16649710
ILT
1512 unsigned int dynsym_index;
1513 if (dynamic_view == NULL)
1514 dynsym_index = -1U;
1515 else
1516 dynsym_index = sym->dynsym_index();
1517
1518 if (sym_index == -1U && dynsym_index == -1U)
a3ad94ed
ILT
1519 {
1520 // This symbol is not included in the output file.
1521 continue;
1522 }
16649710
ILT
1523
1524 if (sym_index == index)
1525 ++index;
1526 else if (sym_index != -1U)
a3ad94ed
ILT
1527 {
1528 // We have already seen this symbol, because it has a
1529 // default version.
1530 gold_assert(sym_index < index);
16649710
ILT
1531 if (dynsym_index == -1U)
1532 continue;
1533 sym_index = -1U;
a3ad94ed 1534 }
c06b7b0b 1535
ead1e424 1536 unsigned int shndx;
ab5c9e90 1537 typename elfcpp::Elf_types<32>::Elf_Addr value = sym->value();
ead1e424
ILT
1538 switch (sym->source())
1539 {
1540 case Symbol::FROM_OBJECT:
1541 {
16649710 1542 unsigned int in_shndx = sym->shndx();
ead1e424
ILT
1543
1544 // FIXME: We need some target specific support here.
16649710
ILT
1545 if (in_shndx >= elfcpp::SHN_LORESERVE
1546 && in_shndx != elfcpp::SHN_ABS)
ead1e424 1547 {
75f2446e
ILT
1548 gold_error(_("%s: unsupported symbol section 0x%x"),
1549 sym->name(), in_shndx);
1550 shndx = in_shndx;
f6ce93d6 1551 }
ead1e424
ILT
1552 else
1553 {
75f2446e
ILT
1554 Object* symobj = sym->object();
1555 if (symobj->is_dynamic())
1556 {
1557 if (sym->needs_dynsym_value())
1558 value = target->dynsym_value(sym);
1559 shndx = elfcpp::SHN_UNDEF;
1560 }
1561 else if (in_shndx == elfcpp::SHN_UNDEF
1562 || in_shndx == elfcpp::SHN_ABS)
1563 shndx = in_shndx;
1564 else
1565 {
1566 Relobj* relobj = static_cast<Relobj*>(symobj);
1567 off_t secoff;
1568 Output_section* os = relobj->output_section(in_shndx,
1569 &secoff);
1570 gold_assert(os != NULL);
1571 shndx = os->out_shndx();
1572 }
ead1e424
ILT
1573 }
1574 }
1575 break;
1576
1577 case Symbol::IN_OUTPUT_DATA:
1578 shndx = sym->output_data()->out_shndx();
1579 break;
1580
1581 case Symbol::IN_OUTPUT_SEGMENT:
1582 shndx = elfcpp::SHN_ABS;
1583 break;
1584
1585 case Symbol::CONSTANT:
1586 shndx = elfcpp::SHN_ABS;
1587 break;
1588
1589 default:
a3ad94ed 1590 gold_unreachable();
ead1e424 1591 }
61ba1cf9 1592
16649710
ILT
1593 if (sym_index != -1U)
1594 {
6a469986 1595 this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
ab5c9e90 1596 sym, sym->value(), shndx, sympool, ps
6a469986 1597 SELECT_SIZE_ENDIAN(size, big_endian));
16649710
ILT
1598 ps += sym_size;
1599 }
61ba1cf9 1600
16649710
ILT
1601 if (dynsym_index != -1U)
1602 {
1603 dynsym_index -= first_dynamic_global_index;
1604 gold_assert(dynsym_index < dynamic_count);
1605 unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
6a469986 1606 this->sized_write_symbol SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
ab5c9e90 1607 sym, value, shndx, dynpool, pd
6a469986 1608 SELECT_SIZE_ENDIAN(size, big_endian));
16649710 1609 }
61ba1cf9
ILT
1610 }
1611
a3ad94ed 1612 gold_assert(ps - psyms == oview_size);
c06b7b0b
ILT
1613
1614 of->write_output_view(this->offset_, oview_size, psyms);
16649710
ILT
1615 if (dynamic_view != NULL)
1616 of->write_output_view(this->dynamic_offset_, dynamic_size, dynamic_view);
1617}
1618
1619// Write out the symbol SYM, in section SHNDX, to P. POOL is the
1620// strtab holding the name.
1621
1622template<int size, bool big_endian>
1623void
ab5c9e90
ILT
1624Symbol_table::sized_write_symbol(
1625 Sized_symbol<size>* sym,
1626 typename elfcpp::Elf_types<size>::Elf_Addr value,
1627 unsigned int shndx,
1628 const Stringpool* pool,
1629 unsigned char* p
1630 ACCEPT_SIZE_ENDIAN) const
16649710
ILT
1631{
1632 elfcpp::Sym_write<size, big_endian> osym(p);
1633 osym.put_st_name(pool->get_offset(sym->name()));
ab5c9e90 1634 osym.put_st_value(value);
16649710
ILT
1635 osym.put_st_size(sym->symsize());
1636 osym.put_st_info(elfcpp::elf_st_info(sym->binding(), sym->type()));
1637 osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
1638 osym.put_st_shndx(shndx);
61ba1cf9
ILT
1639}
1640
a3ad94ed
ILT
1641// Write out a section symbol. Return the update offset.
1642
1643void
9025d29d 1644Symbol_table::write_section_symbol(const Output_section *os,
a3ad94ed
ILT
1645 Output_file* of,
1646 off_t offset) const
1647{
9025d29d 1648 if (parameters->get_size() == 32)
a3ad94ed 1649 {
9025d29d
ILT
1650 if (parameters->is_big_endian())
1651 {
1652#ifdef HAVE_TARGET_32_BIG
1653 this->sized_write_section_symbol<32, true>(os, of, offset);
1654#else
1655 gold_unreachable();
1656#endif
1657 }
a3ad94ed 1658 else
9025d29d
ILT
1659 {
1660#ifdef HAVE_TARGET_32_LITTLE
1661 this->sized_write_section_symbol<32, false>(os, of, offset);
1662#else
1663 gold_unreachable();
1664#endif
1665 }
a3ad94ed 1666 }
9025d29d 1667 else if (parameters->get_size() == 64)
a3ad94ed 1668 {
9025d29d
ILT
1669 if (parameters->is_big_endian())
1670 {
1671#ifdef HAVE_TARGET_64_BIG
1672 this->sized_write_section_symbol<64, true>(os, of, offset);
1673#else
1674 gold_unreachable();
1675#endif
1676 }
a3ad94ed 1677 else
9025d29d
ILT
1678 {
1679#ifdef HAVE_TARGET_64_LITTLE
1680 this->sized_write_section_symbol<64, false>(os, of, offset);
1681#else
1682 gold_unreachable();
1683#endif
1684 }
a3ad94ed
ILT
1685 }
1686 else
1687 gold_unreachable();
1688}
1689
1690// Write out a section symbol, specialized for size and endianness.
1691
1692template<int size, bool big_endian>
1693void
1694Symbol_table::sized_write_section_symbol(const Output_section* os,
1695 Output_file* of,
1696 off_t offset) const
1697{
1698 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1699
1700 unsigned char* pov = of->get_output_view(offset, sym_size);
1701
1702 elfcpp::Sym_write<size, big_endian> osym(pov);
1703 osym.put_st_name(0);
1704 osym.put_st_value(os->address());
1705 osym.put_st_size(0);
1706 osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
1707 elfcpp::STT_SECTION));
1708 osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
1709 osym.put_st_shndx(os->out_shndx());
1710
1711 of->write_output_view(offset, sym_size, pov);
1712}
1713
f6ce93d6
ILT
1714// Warnings functions.
1715
1716// Add a new warning.
1717
1718void
1719Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
1720 unsigned int shndx)
1721{
1722 name = symtab->canonicalize_name(name);
1723 this->warnings_[name].set(obj, shndx);
1724}
1725
1726// Look through the warnings and mark the symbols for which we should
1727// warn. This is called during Layout::finalize when we know the
1728// sources for all the symbols.
1729
1730void
1731Warnings::note_warnings(Symbol_table* symtab)
1732{
1733 for (Warning_table::iterator p = this->warnings_.begin();
1734 p != this->warnings_.end();
1735 ++p)
1736 {
1737 Symbol* sym = symtab->lookup(p->first, NULL);
1738 if (sym != NULL
1739 && sym->source() == Symbol::FROM_OBJECT
1740 && sym->object() == p->second.object)
1741 {
1742 sym->set_has_warning();
1743
1744 // Read the section contents to get the warning text. It
1745 // would be nicer if we only did this if we have to actually
1746 // issue a warning. Unfortunately, warnings are issued as
1747 // we relocate sections. That means that we can not lock
1748 // the object then, as we might try to issue the same
1749 // warning multiple times simultaneously.
645f8123
ILT
1750 {
1751 Task_locker_obj<Object> tl(*p->second.object);
1752 const unsigned char* c;
1753 off_t len;
9eb9fa57
ILT
1754 c = p->second.object->section_contents(p->second.shndx, &len,
1755 false);
645f8123
ILT
1756 p->second.set_text(reinterpret_cast<const char*>(c), len);
1757 }
f6ce93d6
ILT
1758 }
1759 }
1760}
1761
1762// Issue a warning. This is called when we see a relocation against a
1763// symbol for which has a warning.
1764
75f2446e 1765template<int size, bool big_endian>
f6ce93d6 1766void
75f2446e
ILT
1767Warnings::issue_warning(const Symbol* sym,
1768 const Relocate_info<size, big_endian>* relinfo,
1769 size_t relnum, off_t reloffset) const
f6ce93d6 1770{
a3ad94ed 1771 gold_assert(sym->has_warning());
f6ce93d6 1772 Warning_table::const_iterator p = this->warnings_.find(sym->name());
a3ad94ed 1773 gold_assert(p != this->warnings_.end());
75f2446e
ILT
1774 gold_warning_at_location(relinfo, relnum, reloffset,
1775 "%s", p->second.text.c_str());
f6ce93d6
ILT
1776}
1777
14bfc3f5
ILT
1778// Instantiate the templates we need. We could use the configure
1779// script to restrict this to only the ones needed for implemented
1780// targets.
1781
193a53d9 1782#ifdef HAVE_TARGET_32_LITTLE
14bfc3f5
ILT
1783template
1784void
193a53d9
ILT
1785Symbol_table::add_from_relobj<32, false>(
1786 Sized_relobj<32, false>* relobj,
f6ce93d6 1787 const unsigned char* syms,
14bfc3f5
ILT
1788 size_t count,
1789 const char* sym_names,
1790 size_t sym_name_size,
1791 Symbol** sympointers);
193a53d9 1792#endif
14bfc3f5 1793
193a53d9 1794#ifdef HAVE_TARGET_32_BIG
14bfc3f5
ILT
1795template
1796void
193a53d9
ILT
1797Symbol_table::add_from_relobj<32, true>(
1798 Sized_relobj<32, true>* relobj,
f6ce93d6 1799 const unsigned char* syms,
14bfc3f5
ILT
1800 size_t count,
1801 const char* sym_names,
1802 size_t sym_name_size,
1803 Symbol** sympointers);
193a53d9 1804#endif
14bfc3f5 1805
193a53d9 1806#ifdef HAVE_TARGET_64_LITTLE
14bfc3f5
ILT
1807template
1808void
193a53d9
ILT
1809Symbol_table::add_from_relobj<64, false>(
1810 Sized_relobj<64, false>* relobj,
f6ce93d6 1811 const unsigned char* syms,
14bfc3f5
ILT
1812 size_t count,
1813 const char* sym_names,
1814 size_t sym_name_size,
1815 Symbol** sympointers);
193a53d9 1816#endif
14bfc3f5 1817
193a53d9 1818#ifdef HAVE_TARGET_64_BIG
14bfc3f5
ILT
1819template
1820void
193a53d9
ILT
1821Symbol_table::add_from_relobj<64, true>(
1822 Sized_relobj<64, true>* relobj,
f6ce93d6 1823 const unsigned char* syms,
14bfc3f5
ILT
1824 size_t count,
1825 const char* sym_names,
1826 size_t sym_name_size,
1827 Symbol** sympointers);
193a53d9 1828#endif
14bfc3f5 1829
193a53d9 1830#ifdef HAVE_TARGET_32_LITTLE
dbe717ef
ILT
1831template
1832void
193a53d9
ILT
1833Symbol_table::add_from_dynobj<32, false>(
1834 Sized_dynobj<32, false>* dynobj,
dbe717ef
ILT
1835 const unsigned char* syms,
1836 size_t count,
1837 const char* sym_names,
1838 size_t sym_name_size,
1839 const unsigned char* versym,
1840 size_t versym_size,
1841 const std::vector<const char*>* version_map);
193a53d9 1842#endif
dbe717ef 1843
193a53d9 1844#ifdef HAVE_TARGET_32_BIG
dbe717ef
ILT
1845template
1846void
193a53d9
ILT
1847Symbol_table::add_from_dynobj<32, true>(
1848 Sized_dynobj<32, true>* dynobj,
dbe717ef
ILT
1849 const unsigned char* syms,
1850 size_t count,
1851 const char* sym_names,
1852 size_t sym_name_size,
1853 const unsigned char* versym,
1854 size_t versym_size,
1855 const std::vector<const char*>* version_map);
193a53d9 1856#endif
dbe717ef 1857
193a53d9 1858#ifdef HAVE_TARGET_64_LITTLE
dbe717ef
ILT
1859template
1860void
193a53d9
ILT
1861Symbol_table::add_from_dynobj<64, false>(
1862 Sized_dynobj<64, false>* dynobj,
dbe717ef
ILT
1863 const unsigned char* syms,
1864 size_t count,
1865 const char* sym_names,
1866 size_t sym_name_size,
1867 const unsigned char* versym,
1868 size_t versym_size,
1869 const std::vector<const char*>* version_map);
193a53d9 1870#endif
dbe717ef 1871
193a53d9 1872#ifdef HAVE_TARGET_64_BIG
dbe717ef
ILT
1873template
1874void
193a53d9
ILT
1875Symbol_table::add_from_dynobj<64, true>(
1876 Sized_dynobj<64, true>* dynobj,
dbe717ef
ILT
1877 const unsigned char* syms,
1878 size_t count,
1879 const char* sym_names,
1880 size_t sym_name_size,
1881 const unsigned char* versym,
1882 size_t versym_size,
1883 const std::vector<const char*>* version_map);
193a53d9 1884#endif
dbe717ef 1885
75f2446e
ILT
1886#ifdef HAVE_TARGET_32_LITTLE
1887template
1888void
1889Warnings::issue_warning<32, false>(const Symbol* sym,
1890 const Relocate_info<32, false>* relinfo,
1891 size_t relnum, off_t reloffset) const;
1892#endif
1893
1894#ifdef HAVE_TARGET_32_BIG
1895template
1896void
1897Warnings::issue_warning<32, true>(const Symbol* sym,
1898 const Relocate_info<32, true>* relinfo,
1899 size_t relnum, off_t reloffset) const;
1900#endif
1901
1902#ifdef HAVE_TARGET_64_LITTLE
1903template
1904void
1905Warnings::issue_warning<64, false>(const Symbol* sym,
1906 const Relocate_info<64, false>* relinfo,
1907 size_t relnum, off_t reloffset) const;
1908#endif
1909
1910#ifdef HAVE_TARGET_64_BIG
1911template
1912void
1913Warnings::issue_warning<64, true>(const Symbol* sym,
1914 const Relocate_info<64, true>* relinfo,
1915 size_t relnum, off_t reloffset) const;
1916#endif
1917
1918
14bfc3f5 1919} // End namespace gold.