]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/symtab.cc
PR 6811
[thirdparty/binutils-gdb.git] / gold / symtab.cc
CommitLineData
14bfc3f5
ILT
1// symtab.cc -- the gold symbol table
2
6d03d481 3// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6cb15b7f
ILT
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
04bf7072 25#include <cstring>
14bfc3f5 26#include <stdint.h>
04bf7072 27#include <algorithm>
70e654ba 28#include <set>
14bfc3f5
ILT
29#include <string>
30#include <utility>
a2b1aa12 31#include "demangle.h"
14bfc3f5 32
6d03d481 33#include "gc.h"
14bfc3f5 34#include "object.h"
70e654ba 35#include "dwarf_reader.h"
dbe717ef 36#include "dynobj.h"
75f65a3e 37#include "output.h"
61ba1cf9 38#include "target.h"
645f8123 39#include "workqueue.h"
14bfc3f5 40#include "symtab.h"
c82fbeee 41#include "demangle.h" // needed for --dynamic-list-cpp-new
89fc3421 42#include "plugin.h"
14bfc3f5
ILT
43
44namespace gold
45{
46
47// Class Symbol.
48
ead1e424
ILT
49// Initialize fields in Symbol. This initializes everything except u_
50// and source_.
14bfc3f5 51
14bfc3f5 52void
ead1e424
ILT
53Symbol::init_fields(const char* name, const char* version,
54 elfcpp::STT type, elfcpp::STB binding,
55 elfcpp::STV visibility, unsigned char nonvis)
14bfc3f5
ILT
56{
57 this->name_ = name;
58 this->version_ = version;
c06b7b0b
ILT
59 this->symtab_index_ = 0;
60 this->dynsym_index_ = 0;
0a65a3a7 61 this->got_offsets_.init();
f4151f89 62 this->plt_offset_ = 0;
ead1e424
ILT
63 this->type_ = type;
64 this->binding_ = binding;
65 this->visibility_ = visibility;
66 this->nonvis_ = nonvis;
67 this->is_target_special_ = false;
1564db8d
ILT
68 this->is_def_ = false;
69 this->is_forwarder_ = false;
aeddab66 70 this->has_alias_ = false;
c06b7b0b 71 this->needs_dynsym_entry_ = false;
008db82e 72 this->in_reg_ = false;
ead1e424 73 this->in_dyn_ = false;
f4151f89 74 this->has_plt_offset_ = false;
f6ce93d6 75 this->has_warning_ = false;
46fe1623 76 this->is_copied_from_dynobj_ = false;
55a93433 77 this->is_forced_local_ = false;
d491d34e 78 this->is_ordinary_shndx_ = false;
89fc3421 79 this->in_real_elf_ = false;
ead1e424
ILT
80}
81
a2b1aa12
ILT
82// Return the demangled version of the symbol's name, but only
83// if the --demangle flag was set.
84
85static std::string
86demangle(const char* name)
87{
086a1841 88 if (!parameters->options().do_demangle())
ff541f30
ILT
89 return name;
90
a2b1aa12
ILT
91 // cplus_demangle allocates memory for the result it returns,
92 // and returns NULL if the name is already demangled.
93 char* demangled_name = cplus_demangle(name, DMGL_ANSI | DMGL_PARAMS);
94 if (demangled_name == NULL)
95 return name;
96
97 std::string retval(demangled_name);
98 free(demangled_name);
99 return retval;
100}
101
102std::string
103Symbol::demangled_name() const
104{
ff541f30 105 return demangle(this->name());
a2b1aa12
ILT
106}
107
ead1e424
ILT
108// Initialize the fields in the base class Symbol for SYM in OBJECT.
109
110template<int size, bool big_endian>
111void
f3e9c5c5
ILT
112Symbol::init_base_object(const char* name, const char* version, Object* object,
113 const elfcpp::Sym<size, big_endian>& sym,
114 unsigned int st_shndx, bool is_ordinary)
ead1e424
ILT
115{
116 this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
117 sym.get_st_visibility(), sym.get_st_nonvis());
118 this->u_.from_object.object = object;
d491d34e
ILT
119 this->u_.from_object.shndx = st_shndx;
120 this->is_ordinary_shndx_ = is_ordinary;
ead1e424 121 this->source_ = FROM_OBJECT;
008db82e 122 this->in_reg_ = !object->is_dynamic();
1564db8d 123 this->in_dyn_ = object->is_dynamic();
89fc3421 124 this->in_real_elf_ = object->pluginobj() == NULL;
14bfc3f5
ILT
125}
126
ead1e424
ILT
127// Initialize the fields in the base class Symbol for a symbol defined
128// in an Output_data.
129
130void
75517b77
ILT
131Symbol::init_base_output_data(const char* name, const char* version,
132 Output_data* od, elfcpp::STT type,
133 elfcpp::STB binding, elfcpp::STV visibility,
134 unsigned char nonvis, bool offset_is_from_end)
ead1e424 135{
75517b77 136 this->init_fields(name, version, type, binding, visibility, nonvis);
ead1e424
ILT
137 this->u_.in_output_data.output_data = od;
138 this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
139 this->source_ = IN_OUTPUT_DATA;
008db82e 140 this->in_reg_ = true;
89fc3421 141 this->in_real_elf_ = true;
ead1e424
ILT
142}
143
144// Initialize the fields in the base class Symbol for a symbol defined
145// in an Output_segment.
146
147void
75517b77
ILT
148Symbol::init_base_output_segment(const char* name, const char* version,
149 Output_segment* os, elfcpp::STT type,
150 elfcpp::STB binding, elfcpp::STV visibility,
151 unsigned char nonvis,
f3e9c5c5 152 Segment_offset_base offset_base)
ead1e424 153{
75517b77 154 this->init_fields(name, version, type, binding, visibility, nonvis);
ead1e424
ILT
155 this->u_.in_output_segment.output_segment = os;
156 this->u_.in_output_segment.offset_base = offset_base;
157 this->source_ = IN_OUTPUT_SEGMENT;
008db82e 158 this->in_reg_ = true;
89fc3421 159 this->in_real_elf_ = true;
ead1e424
ILT
160}
161
162// Initialize the fields in the base class Symbol for a symbol defined
163// as a constant.
164
165void
75517b77
ILT
166Symbol::init_base_constant(const char* name, const char* version,
167 elfcpp::STT type, elfcpp::STB binding,
168 elfcpp::STV visibility, unsigned char nonvis)
f3e9c5c5 169{
75517b77 170 this->init_fields(name, version, type, binding, visibility, nonvis);
f3e9c5c5
ILT
171 this->source_ = IS_CONSTANT;
172 this->in_reg_ = true;
89fc3421 173 this->in_real_elf_ = true;
f3e9c5c5
ILT
174}
175
176// Initialize the fields in the base class Symbol for an undefined
177// symbol.
178
179void
75517b77
ILT
180Symbol::init_base_undefined(const char* name, const char* version,
181 elfcpp::STT type, elfcpp::STB binding,
182 elfcpp::STV visibility, unsigned char nonvis)
ead1e424 183{
75517b77 184 this->init_fields(name, version, type, binding, visibility, nonvis);
d7ab2a47 185 this->dynsym_index_ = -1U;
f3e9c5c5 186 this->source_ = IS_UNDEFINED;
008db82e 187 this->in_reg_ = true;
89fc3421 188 this->in_real_elf_ = true;
ead1e424
ILT
189}
190
c7912668
ILT
191// Allocate a common symbol in the base.
192
193void
194Symbol::allocate_base_common(Output_data* od)
195{
196 gold_assert(this->is_common());
197 this->source_ = IN_OUTPUT_DATA;
198 this->u_.in_output_data.output_data = od;
199 this->u_.in_output_data.offset_is_from_end = false;
200}
201
ead1e424 202// Initialize the fields in Sized_symbol for SYM in OBJECT.
14bfc3f5
ILT
203
204template<int size>
205template<bool big_endian>
206void
f3e9c5c5
ILT
207Sized_symbol<size>::init_object(const char* name, const char* version,
208 Object* object,
209 const elfcpp::Sym<size, big_endian>& sym,
210 unsigned int st_shndx, bool is_ordinary)
14bfc3f5 211{
f3e9c5c5 212 this->init_base_object(name, version, object, sym, st_shndx, is_ordinary);
14bfc3f5 213 this->value_ = sym.get_st_value();
ead1e424
ILT
214 this->symsize_ = sym.get_st_size();
215}
216
217// Initialize the fields in Sized_symbol for a symbol defined in an
218// Output_data.
219
220template<int size>
221void
75517b77
ILT
222Sized_symbol<size>::init_output_data(const char* name, const char* version,
223 Output_data* od, Value_type value,
224 Size_type symsize, elfcpp::STT type,
225 elfcpp::STB binding,
f3e9c5c5
ILT
226 elfcpp::STV visibility,
227 unsigned char nonvis,
228 bool offset_is_from_end)
ead1e424 229{
75517b77
ILT
230 this->init_base_output_data(name, version, od, type, binding, visibility,
231 nonvis, offset_is_from_end);
ead1e424
ILT
232 this->value_ = value;
233 this->symsize_ = symsize;
234}
235
236// Initialize the fields in Sized_symbol for a symbol defined in an
237// Output_segment.
238
239template<int size>
240void
75517b77
ILT
241Sized_symbol<size>::init_output_segment(const char* name, const char* version,
242 Output_segment* os, Value_type value,
243 Size_type symsize, elfcpp::STT type,
244 elfcpp::STB binding,
f3e9c5c5
ILT
245 elfcpp::STV visibility,
246 unsigned char nonvis,
247 Segment_offset_base offset_base)
ead1e424 248{
75517b77
ILT
249 this->init_base_output_segment(name, version, os, type, binding, visibility,
250 nonvis, offset_base);
ead1e424
ILT
251 this->value_ = value;
252 this->symsize_ = symsize;
253}
254
255// Initialize the fields in Sized_symbol for a symbol defined as a
256// constant.
257
258template<int size>
259void
75517b77
ILT
260Sized_symbol<size>::init_constant(const char* name, const char* version,
261 Value_type value, Size_type symsize,
262 elfcpp::STT type, elfcpp::STB binding,
263 elfcpp::STV visibility, unsigned char nonvis)
ead1e424 264{
75517b77 265 this->init_base_constant(name, version, type, binding, visibility, nonvis);
ead1e424
ILT
266 this->value_ = value;
267 this->symsize_ = symsize;
14bfc3f5
ILT
268}
269
f3e9c5c5
ILT
270// Initialize the fields in Sized_symbol for an undefined symbol.
271
272template<int size>
273void
75517b77
ILT
274Sized_symbol<size>::init_undefined(const char* name, const char* version,
275 elfcpp::STT type, elfcpp::STB binding,
276 elfcpp::STV visibility, unsigned char nonvis)
f3e9c5c5 277{
75517b77 278 this->init_base_undefined(name, version, type, binding, visibility, nonvis);
f3e9c5c5
ILT
279 this->value_ = 0;
280 this->symsize_ = 0;
281}
282
c7912668
ILT
283// Allocate a common symbol.
284
285template<int size>
286void
287Sized_symbol<size>::allocate_common(Output_data* od, Value_type value)
288{
289 this->allocate_base_common(od);
290 this->value_ = value;
291}
292
c82fbeee
CS
293// The ""'s around str ensure str is a string literal, so sizeof works.
294#define strprefix(var, str) (strncmp(var, str, sizeof("" str "") - 1) == 0)
295
436ca963
ILT
296// Return true if this symbol should be added to the dynamic symbol
297// table.
298
299inline bool
300Symbol::should_add_dynsym_entry() const
301{
302 // If the symbol is used by a dynamic relocation, we need to add it.
303 if (this->needs_dynsym_entry())
304 return true;
305
6d03d481
ST
306 // If this symbol's section is not added, the symbol need not be added.
307 // The section may have been GCed. Note that export_dynamic is being
308 // overridden here. This should not be done for shared objects.
309 if (parameters->options().gc_sections()
310 && !parameters->options().shared()
311 && this->source() == Symbol::FROM_OBJECT
312 && !this->object()->is_dynamic())
313 {
314 Relobj* relobj = static_cast<Relobj*>(this->object());
315 bool is_ordinary;
316 unsigned int shndx = this->shndx(&is_ordinary);
317 if (is_ordinary && shndx != elfcpp::SHN_UNDEF
318 && !relobj->is_section_included(shndx))
319 return false;
320 }
321
55a93433
ILT
322 // If the symbol was forced local in a version script, do not add it.
323 if (this->is_forced_local())
324 return false;
325
c82fbeee
CS
326 // If the symbol was forced dynamic in a --dynamic-list file, add it.
327 if (parameters->options().in_dynamic_list(this->name()))
328 return true;
329
330 // If dynamic-list-data was specified, add any STT_OBJECT.
331 if (parameters->options().dynamic_list_data()
332 && !this->is_from_dynobj()
333 && this->type() == elfcpp::STT_OBJECT)
334 return true;
335
336 // If --dynamic-list-cpp-new was specified, add any new/delete symbol.
337 // If --dynamic-list-cpp-typeinfo was specified, add any typeinfo symbols.
338 if ((parameters->options().dynamic_list_cpp_new()
339 || parameters->options().dynamic_list_cpp_typeinfo())
340 && !this->is_from_dynobj())
341 {
342 // TODO(csilvers): We could probably figure out if we're an operator
343 // new/delete or typeinfo without the need to demangle.
344 char* demangled_name = cplus_demangle(this->name(),
345 DMGL_ANSI | DMGL_PARAMS);
346 if (demangled_name == NULL)
347 {
348 // Not a C++ symbol, so it can't satisfy these flags
349 }
350 else if (parameters->options().dynamic_list_cpp_new()
351 && (strprefix(demangled_name, "operator new")
352 || strprefix(demangled_name, "operator delete")))
353 {
354 free(demangled_name);
355 return true;
356 }
357 else if (parameters->options().dynamic_list_cpp_typeinfo()
358 && (strprefix(demangled_name, "typeinfo name for")
359 || strprefix(demangled_name, "typeinfo for")))
360 {
361 free(demangled_name);
362 return true;
363 }
364 else
365 free(demangled_name);
366 }
367
436ca963
ILT
368 // If exporting all symbols or building a shared library,
369 // and the symbol is defined in a regular object and is
370 // externally visible, we need to add it.
8851ecca 371 if ((parameters->options().export_dynamic() || parameters->options().shared())
436ca963
ILT
372 && !this->is_from_dynobj()
373 && this->is_externally_visible())
374 return true;
375
376 return false;
377}
378
b3b74ddc
ILT
379// Return true if the final value of this symbol is known at link
380// time.
381
382bool
383Symbol::final_value_is_known() const
384{
385 // If we are not generating an executable, then no final values are
386 // known, since they will change at runtime.
8851ecca 387 if (parameters->options().shared() || parameters->options().relocatable())
b3b74ddc
ILT
388 return false;
389
f3e9c5c5
ILT
390 // If the symbol is not from an object file, and is not undefined,
391 // then it is defined, and known.
b3b74ddc 392 if (this->source_ != FROM_OBJECT)
f3e9c5c5
ILT
393 {
394 if (this->source_ != IS_UNDEFINED)
395 return true;
396 }
397 else
398 {
399 // If the symbol is from a dynamic object, then the final value
400 // is not known.
401 if (this->object()->is_dynamic())
402 return false;
b3b74ddc 403
f3e9c5c5
ILT
404 // If the symbol is not undefined (it is defined or common),
405 // then the final value is known.
406 if (!this->is_undefined())
407 return true;
408 }
b3b74ddc
ILT
409
410 // If the symbol is undefined, then whether the final value is known
411 // depends on whether we are doing a static link. If we are doing a
412 // dynamic link, then the final value could be filled in at runtime.
413 // This could reasonably be the case for a weak undefined symbol.
414 return parameters->doing_static_link();
415}
416
77e65537 417// Return the output section where this symbol is defined.
a445fddf 418
77e65537
ILT
419Output_section*
420Symbol::output_section() const
a445fddf
ILT
421{
422 switch (this->source_)
423 {
424 case FROM_OBJECT:
77e65537
ILT
425 {
426 unsigned int shndx = this->u_.from_object.shndx;
d491d34e 427 if (shndx != elfcpp::SHN_UNDEF && this->is_ordinary_shndx_)
77e65537
ILT
428 {
429 gold_assert(!this->u_.from_object.object->is_dynamic());
89fc3421 430 gold_assert(this->u_.from_object.object->pluginobj() == NULL);
77e65537 431 Relobj* relobj = static_cast<Relobj*>(this->u_.from_object.object);
ef9beddf 432 return relobj->output_section(shndx);
77e65537
ILT
433 }
434 return NULL;
435 }
436
a445fddf 437 case IN_OUTPUT_DATA:
77e65537
ILT
438 return this->u_.in_output_data.output_data->output_section();
439
a445fddf 440 case IN_OUTPUT_SEGMENT:
f3e9c5c5
ILT
441 case IS_CONSTANT:
442 case IS_UNDEFINED:
77e65537
ILT
443 return NULL;
444
445 default:
446 gold_unreachable();
447 }
448}
449
450// Set the symbol's output section. This is used for symbols defined
451// in scripts. This should only be called after the symbol table has
452// been finalized.
453
454void
455Symbol::set_output_section(Output_section* os)
456{
457 switch (this->source_)
458 {
459 case FROM_OBJECT:
460 case IN_OUTPUT_DATA:
461 gold_assert(this->output_section() == os);
462 break;
f3e9c5c5 463 case IS_CONSTANT:
77e65537
ILT
464 this->source_ = IN_OUTPUT_DATA;
465 this->u_.in_output_data.output_data = os;
466 this->u_.in_output_data.offset_is_from_end = false;
467 break;
468 case IN_OUTPUT_SEGMENT:
f3e9c5c5 469 case IS_UNDEFINED:
a445fddf
ILT
470 default:
471 gold_unreachable();
472 }
473}
474
14bfc3f5
ILT
475// Class Symbol_table.
476
09124467
ILT
477Symbol_table::Symbol_table(unsigned int count,
478 const Version_script_info& version_script)
6d013333 479 : saw_undefined_(0), offset_(0), table_(count), namepool_(),
155a0dd7 480 forwarders_(), commons_(), tls_commons_(), forced_locals_(), warnings_(),
6d03d481 481 version_script_(version_script), gc_(NULL)
14bfc3f5 482{
6d013333 483 namepool_.reserve(count);
14bfc3f5
ILT
484}
485
486Symbol_table::~Symbol_table()
487{
488}
489
ad8f37d1 490// The hash function. The key values are Stringpool keys.
14bfc3f5 491
ad8f37d1 492inline size_t
14bfc3f5
ILT
493Symbol_table::Symbol_table_hash::operator()(const Symbol_table_key& key) const
494{
f0641a0b 495 return key.first ^ key.second;
14bfc3f5
ILT
496}
497
ad8f37d1
ILT
498// The symbol table key equality function. This is called with
499// Stringpool keys.
14bfc3f5 500
ad8f37d1 501inline bool
14bfc3f5
ILT
502Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
503 const Symbol_table_key& k2) const
504{
505 return k1.first == k2.first && k1.second == k2.second;
506}
507
6d03d481
ST
508// For symbols that have been listed with -u option, add them to the
509// work list to avoid gc'ing them.
510
511void
512Symbol_table::gc_mark_undef_symbols()
513{
514 for (options::String_set::const_iterator p =
515 parameters->options().undefined_begin();
516 p != parameters->options().undefined_end();
517 ++p)
518 {
519 const char* name = p->c_str();
520 Symbol* sym = this->lookup(name);
521 gold_assert (sym != NULL);
522 if (sym->source() == Symbol::FROM_OBJECT
523 && !sym->object()->is_dynamic())
524 {
525 Relobj* obj = static_cast<Relobj*>(sym->object());
526 bool is_ordinary;
527 unsigned int shndx = sym->shndx(&is_ordinary);
528 if (is_ordinary)
529 {
530 gold_assert(this->gc_ != NULL);
531 this->gc_->worklist().push(Section_id(obj, shndx));
532 }
533 }
534 }
535}
536
537void
538Symbol_table::gc_mark_symbol_for_shlib(Symbol* sym)
539{
540 if (!sym->is_from_dynobj()
541 && sym->is_externally_visible())
542 {
543 //Add the object and section to the work list.
544 Relobj* obj = static_cast<Relobj*>(sym->object());
545 bool is_ordinary;
546 unsigned int shndx = sym->shndx(&is_ordinary);
547 if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
548 {
549 gold_assert(this->gc_!= NULL);
550 this->gc_->worklist().push(Section_id(obj, shndx));
551 }
552 }
553}
554
555// When doing garbage collection, keep symbols that have been seen in
556// dynamic objects.
557inline void
558Symbol_table::gc_mark_dyn_syms(Symbol* sym)
559{
560 if (sym->in_dyn() && sym->source() == Symbol::FROM_OBJECT
561 && !sym->object()->is_dynamic())
562 {
563 Relobj *obj = static_cast<Relobj*>(sym->object());
564 bool is_ordinary;
565 unsigned int shndx = sym->shndx(&is_ordinary);
566 if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
567 {
568 gold_assert(this->gc_ != NULL);
569 this->gc_->worklist().push(Section_id(obj, shndx));
570 }
571 }
572}
573
dd8670e5 574// Make TO a symbol which forwards to FROM.
14bfc3f5
ILT
575
576void
577Symbol_table::make_forwarder(Symbol* from, Symbol* to)
578{
a3ad94ed
ILT
579 gold_assert(from != to);
580 gold_assert(!from->is_forwarder() && !to->is_forwarder());
14bfc3f5
ILT
581 this->forwarders_[from] = to;
582 from->set_forwarder();
583}
584
61ba1cf9
ILT
585// Resolve the forwards from FROM, returning the real symbol.
586
14bfc3f5 587Symbol*
c06b7b0b 588Symbol_table::resolve_forwards(const Symbol* from) const
14bfc3f5 589{
a3ad94ed 590 gold_assert(from->is_forwarder());
c06b7b0b 591 Unordered_map<const Symbol*, Symbol*>::const_iterator p =
14bfc3f5 592 this->forwarders_.find(from);
a3ad94ed 593 gold_assert(p != this->forwarders_.end());
14bfc3f5
ILT
594 return p->second;
595}
596
61ba1cf9
ILT
597// Look up a symbol by name.
598
599Symbol*
600Symbol_table::lookup(const char* name, const char* version) const
601{
f0641a0b
ILT
602 Stringpool::Key name_key;
603 name = this->namepool_.find(name, &name_key);
61ba1cf9
ILT
604 if (name == NULL)
605 return NULL;
f0641a0b
ILT
606
607 Stringpool::Key version_key = 0;
61ba1cf9
ILT
608 if (version != NULL)
609 {
f0641a0b 610 version = this->namepool_.find(version, &version_key);
61ba1cf9
ILT
611 if (version == NULL)
612 return NULL;
613 }
614
f0641a0b 615 Symbol_table_key key(name_key, version_key);
61ba1cf9
ILT
616 Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
617 if (p == this->table_.end())
618 return NULL;
619 return p->second;
620}
621
14bfc3f5
ILT
622// Resolve a Symbol with another Symbol. This is only used in the
623// unusual case where there are references to both an unversioned
624// symbol and a symbol with a version, and we then discover that that
1564db8d
ILT
625// version is the default version. Because this is unusual, we do
626// this the slow way, by converting back to an ELF symbol.
14bfc3f5 627
1564db8d 628template<int size, bool big_endian>
14bfc3f5 629void
95d14cd3 630Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from)
14bfc3f5 631{
1564db8d
ILT
632 unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
633 elfcpp::Sym_write<size, big_endian> esym(buf);
d491d34e 634 // We don't bother to set the st_name or the st_shndx field.
1564db8d
ILT
635 esym.put_st_value(from->value());
636 esym.put_st_size(from->symsize());
637 esym.put_st_info(from->binding(), from->type());
ead1e424 638 esym.put_st_other(from->visibility(), from->nonvis());
d491d34e
ILT
639 bool is_ordinary;
640 unsigned int shndx = from->shndx(&is_ordinary);
641 this->resolve(to, esym.sym(), shndx, is_ordinary, shndx, from->object(),
95d14cd3 642 from->version());
1ebd95fd
ILT
643 if (from->in_reg())
644 to->set_in_reg();
645 if (from->in_dyn())
646 to->set_in_dyn();
6d03d481
ST
647 if (parameters->options().gc_sections())
648 this->gc_mark_dyn_syms(to);
14bfc3f5
ILT
649}
650
0602e05a
ILT
651// Record that a symbol is forced to be local by a version script or
652// by visibility.
55a93433
ILT
653
654void
655Symbol_table::force_local(Symbol* sym)
656{
657 if (!sym->is_defined() && !sym->is_common())
658 return;
659 if (sym->is_forced_local())
660 {
661 // We already got this one.
662 return;
663 }
664 sym->set_is_forced_local();
665 this->forced_locals_.push_back(sym);
666}
667
0864d551
ILT
668// Adjust NAME for wrapping, and update *NAME_KEY if necessary. This
669// is only called for undefined symbols, when at least one --wrap
670// option was used.
671
672const char*
673Symbol_table::wrap_symbol(Object* object, const char* name,
674 Stringpool::Key* name_key)
675{
676 // For some targets, we need to ignore a specific character when
677 // wrapping, and add it back later.
678 char prefix = '\0';
679 if (name[0] == object->target()->wrap_char())
680 {
681 prefix = name[0];
682 ++name;
683 }
684
c5818ff1 685 if (parameters->options().is_wrap(name))
0864d551
ILT
686 {
687 // Turn NAME into __wrap_NAME.
688 std::string s;
689 if (prefix != '\0')
690 s += prefix;
691 s += "__wrap_";
692 s += name;
693
694 // This will give us both the old and new name in NAMEPOOL_, but
695 // that is OK. Only the versions we need will wind up in the
696 // real string table in the output file.
697 return this->namepool_.add(s.c_str(), true, name_key);
698 }
699
700 const char* const real_prefix = "__real_";
701 const size_t real_prefix_length = strlen(real_prefix);
702 if (strncmp(name, real_prefix, real_prefix_length) == 0
c5818ff1 703 && parameters->options().is_wrap(name + real_prefix_length))
0864d551
ILT
704 {
705 // Turn __real_NAME into NAME.
706 std::string s;
707 if (prefix != '\0')
708 s += prefix;
709 s += name + real_prefix_length;
710 return this->namepool_.add(s.c_str(), true, name_key);
711 }
712
713 return name;
714}
715
14bfc3f5
ILT
716// Add one symbol from OBJECT to the symbol table. NAME is symbol
717// name and VERSION is the version; both are canonicalized. DEF is
d491d34e
ILT
718// whether this is the default version. ST_SHNDX is the symbol's
719// section index; IS_ORDINARY is whether this is a normal section
720// rather than a special code.
14bfc3f5
ILT
721
722// If DEF is true, then this is the definition of a default version of
723// a symbol. That means that any lookup of NAME/NULL and any lookup
724// of NAME/VERSION should always return the same symbol. This is
725// obvious for references, but in particular we want to do this for
726// definitions: overriding NAME/NULL should also override
727// NAME/VERSION. If we don't do that, it would be very hard to
728// override functions in a shared library which uses versioning.
729
730// We implement this by simply making both entries in the hash table
731// point to the same Symbol structure. That is easy enough if this is
732// the first time we see NAME/NULL or NAME/VERSION, but it is possible
733// that we have seen both already, in which case they will both have
734// independent entries in the symbol table. We can't simply change
735// the symbol table entry, because we have pointers to the entries
736// attached to the object files. So we mark the entry attached to the
737// object file as a forwarder, and record it in the forwarders_ map.
738// Note that entries in the hash table will never be marked as
739// forwarders.
70e654ba 740//
d491d34e
ILT
741// ORIG_ST_SHNDX and ST_SHNDX are almost always the same.
742// ORIG_ST_SHNDX is the section index in the input file, or SHN_UNDEF
743// for a special section code. ST_SHNDX may be modified if the symbol
744// is defined in a section being discarded.
14bfc3f5
ILT
745
746template<int size, bool big_endian>
aeddab66 747Sized_symbol<size>*
f6ce93d6 748Symbol_table::add_from_object(Object* object,
14bfc3f5 749 const char *name,
f0641a0b
ILT
750 Stringpool::Key name_key,
751 const char *version,
752 Stringpool::Key version_key,
753 bool def,
70e654ba 754 const elfcpp::Sym<size, big_endian>& sym,
d491d34e
ILT
755 unsigned int st_shndx,
756 bool is_ordinary,
757 unsigned int orig_st_shndx)
14bfc3f5 758{
c5818ff1
CC
759 // Print a message if this symbol is being traced.
760 if (parameters->options().is_trace_symbol(name))
761 {
d491d34e 762 if (orig_st_shndx == elfcpp::SHN_UNDEF)
c5818ff1
CC
763 gold_info(_("%s: reference to %s"), object->name().c_str(), name);
764 else
765 gold_info(_("%s: definition of %s"), object->name().c_str(), name);
766 }
767
0864d551
ILT
768 // For an undefined symbol, we may need to adjust the name using
769 // --wrap.
d491d34e 770 if (orig_st_shndx == elfcpp::SHN_UNDEF
c5818ff1 771 && parameters->options().any_wrap())
0864d551
ILT
772 {
773 const char* wrap_name = this->wrap_symbol(object, name, &name_key);
774 if (wrap_name != name)
775 {
776 // If we see a reference to malloc with version GLIBC_2.0,
777 // and we turn it into a reference to __wrap_malloc, then we
778 // discard the version number. Otherwise the user would be
779 // required to specify the correct version for
780 // __wrap_malloc.
781 version = NULL;
782 version_key = 0;
783 name = wrap_name;
784 }
785 }
786
14bfc3f5
ILT
787 Symbol* const snull = NULL;
788 std::pair<typename Symbol_table_type::iterator, bool> ins =
f0641a0b
ILT
789 this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
790 snull));
14bfc3f5
ILT
791
792 std::pair<typename Symbol_table_type::iterator, bool> insdef =
793 std::make_pair(this->table_.end(), false);
794 if (def)
795 {
f0641a0b
ILT
796 const Stringpool::Key vnull_key = 0;
797 insdef = this->table_.insert(std::make_pair(std::make_pair(name_key,
798 vnull_key),
14bfc3f5
ILT
799 snull));
800 }
801
802 // ins.first: an iterator, which is a pointer to a pair.
803 // ins.first->first: the key (a pair of name and version).
804 // ins.first->second: the value (Symbol*).
805 // ins.second: true if new entry was inserted, false if not.
806
1564db8d 807 Sized_symbol<size>* ret;
ead1e424
ILT
808 bool was_undefined;
809 bool was_common;
14bfc3f5
ILT
810 if (!ins.second)
811 {
812 // We already have an entry for NAME/VERSION.
7d1a9ebb 813 ret = this->get_sized_symbol<size>(ins.first->second);
a3ad94ed 814 gold_assert(ret != NULL);
ead1e424
ILT
815
816 was_undefined = ret->is_undefined();
817 was_common = ret->is_common();
818
d491d34e
ILT
819 this->resolve(ret, sym, st_shndx, is_ordinary, orig_st_shndx, object,
820 version);
6d03d481
ST
821 if (parameters->options().gc_sections())
822 this->gc_mark_dyn_syms(ret);
14bfc3f5
ILT
823
824 if (def)
825 {
826 if (insdef.second)
827 {
828 // This is the first time we have seen NAME/NULL. Make
829 // NAME/NULL point to NAME/VERSION.
830 insdef.first->second = ret;
831 }
a18f591e 832 else if (insdef.first->second != ret)
14bfc3f5
ILT
833 {
834 // This is the unfortunate case where we already have
a18f591e
ILT
835 // entries for both NAME/VERSION and NAME/NULL. We now
836 // see a symbol NAME/VERSION where VERSION is the
837 // default version. We have already resolved this new
838 // symbol with the existing NAME/VERSION symbol.
839
840 // It's possible that NAME/NULL and NAME/VERSION are
841 // both defined in regular objects. This can only
842 // happen if one object file defines foo and another
843 // defines foo@@ver. This is somewhat obscure, but we
844 // call it a multiple definition error.
845
846 // It's possible that NAME/NULL actually has a version,
847 // in which case it won't be the same as VERSION. This
848 // happens with ver_test_7.so in the testsuite for the
849 // symbol t2_2. We see t2_2@@VER2, so we define both
850 // t2_2/VER2 and t2_2/NULL. We then see an unadorned
851 // t2_2 in an object file and give it version VER1 from
852 // the version script. This looks like a default
853 // definition for VER1, so it looks like we should merge
854 // t2_2/NULL with t2_2/VER1. That doesn't make sense,
855 // but it's not obvious that this is an error, either.
856 // So we just punt.
857
858 // If one of the symbols has non-default visibility, and
859 // the other is defined in a shared object, then they
860 // are different symbols.
861
862 // Otherwise, we just resolve the symbols as though they
863 // were the same.
864
865 if (insdef.first->second->version() != NULL)
866 {
867 gold_assert(insdef.first->second->version() != version);
868 def = false;
869 }
870 else if (ret->visibility() != elfcpp::STV_DEFAULT
871 && insdef.first->second->is_from_dynobj())
872 def = false;
873 else if (insdef.first->second->visibility() != elfcpp::STV_DEFAULT
874 && ret->is_from_dynobj())
875 def = false;
876 else
877 {
878 const Sized_symbol<size>* sym2;
879 sym2 = this->get_sized_symbol<size>(insdef.first->second);
95d14cd3 880 Symbol_table::resolve<size, big_endian>(ret, sym2);
a18f591e
ILT
881 this->make_forwarder(insdef.first->second, ret);
882 insdef.first->second = ret;
883 }
14bfc3f5 884 }
479f6503
ILT
885 else
886 def = false;
14bfc3f5
ILT
887 }
888 }
889 else
890 {
891 // This is the first time we have seen NAME/VERSION.
a3ad94ed 892 gold_assert(ins.first->second == NULL);
ead1e424 893
14bfc3f5
ILT
894 if (def && !insdef.second)
895 {
14b31740
ILT
896 // We already have an entry for NAME/NULL. If we override
897 // it, then change it to NAME/VERSION.
7d1a9ebb 898 ret = this->get_sized_symbol<size>(insdef.first->second);
18e6b24e
ILT
899
900 was_undefined = ret->is_undefined();
901 was_common = ret->is_common();
902
d491d34e
ILT
903 this->resolve(ret, sym, st_shndx, is_ordinary, orig_st_shndx, object,
904 version);
6d03d481
ST
905 if (parameters->options().gc_sections())
906 this->gc_mark_dyn_syms(ret);
14bfc3f5
ILT
907 ins.first->second = ret;
908 }
909 else
910 {
18e6b24e
ILT
911 was_undefined = false;
912 was_common = false;
913
f6ce93d6 914 Sized_target<size, big_endian>* target =
7d1a9ebb 915 object->sized_target<size, big_endian>();
1564db8d
ILT
916 if (!target->has_make_symbol())
917 ret = new Sized_symbol<size>();
918 else
14bfc3f5 919 {
1564db8d
ILT
920 ret = target->make_symbol();
921 if (ret == NULL)
14bfc3f5
ILT
922 {
923 // This means that we don't want a symbol table
924 // entry after all.
925 if (!def)
926 this->table_.erase(ins.first);
927 else
928 {
929 this->table_.erase(insdef.first);
930 // Inserting insdef invalidated ins.
f0641a0b
ILT
931 this->table_.erase(std::make_pair(name_key,
932 version_key));
14bfc3f5
ILT
933 }
934 return NULL;
935 }
936 }
14bfc3f5 937
f3e9c5c5 938 ret->init_object(name, version, object, sym, st_shndx, is_ordinary);
1564db8d 939
14bfc3f5
ILT
940 ins.first->second = ret;
941 if (def)
942 {
943 // This is the first time we have seen NAME/NULL. Point
944 // it at the new entry for NAME/VERSION.
a3ad94ed 945 gold_assert(insdef.second);
14bfc3f5
ILT
946 insdef.first->second = ret;
947 }
948 }
949 }
950
ead1e424
ILT
951 // Record every time we see a new undefined symbol, to speed up
952 // archive groups.
953 if (!was_undefined && ret->is_undefined())
954 ++this->saw_undefined_;
955
956 // Keep track of common symbols, to speed up common symbol
957 // allocation.
958 if (!was_common && ret->is_common())
155a0dd7
ILT
959 {
960 if (ret->type() != elfcpp::STT_TLS)
961 this->commons_.push_back(ret);
962 else
963 this->tls_commons_.push_back(ret);
964 }
ead1e424 965
0602e05a
ILT
966 // If we're not doing a relocatable link, then any symbol with
967 // hidden or internal visibility is local.
968 if ((ret->visibility() == elfcpp::STV_HIDDEN
969 || ret->visibility() == elfcpp::STV_INTERNAL)
970 && (ret->binding() == elfcpp::STB_GLOBAL
971 || ret->binding() == elfcpp::STB_WEAK)
972 && !parameters->options().relocatable())
973 this->force_local(ret);
974
be3e6201
ILT
975 if (def)
976 ret->set_is_default();
14bfc3f5
ILT
977 return ret;
978}
979
f6ce93d6 980// Add all the symbols in a relocatable object to the hash table.
14bfc3f5
ILT
981
982template<int size, bool big_endian>
983void
dbe717ef
ILT
984Symbol_table::add_from_relobj(
985 Sized_relobj<size, big_endian>* relobj,
f6ce93d6 986 const unsigned char* syms,
14bfc3f5 987 size_t count,
d491d34e 988 size_t symndx_offset,
14bfc3f5
ILT
989 const char* sym_names,
990 size_t sym_name_size,
92de84a6
ILT
991 typename Sized_relobj<size, big_endian>::Symbols* sympointers,
992 size_t *defined)
14bfc3f5 993{
92de84a6
ILT
994 *defined = 0;
995
9025d29d 996 gold_assert(size == relobj->target()->get_size());
8851ecca 997 gold_assert(size == parameters->target().get_size());
14bfc3f5 998
a783673b
ILT
999 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1000
88dd47ac
ILT
1001 const bool just_symbols = relobj->just_symbols();
1002
f6ce93d6 1003 const unsigned char* p = syms;
a783673b 1004 for (size_t i = 0; i < count; ++i, p += sym_size)
14bfc3f5 1005 {
92de84a6
ILT
1006 (*sympointers)[i] = NULL;
1007
14bfc3f5
ILT
1008 elfcpp::Sym<size, big_endian> sym(p);
1009
d491d34e 1010 unsigned int st_name = sym.get_st_name();
14bfc3f5
ILT
1011 if (st_name >= sym_name_size)
1012 {
75f2446e
ILT
1013 relobj->error(_("bad global symbol name offset %u at %zu"),
1014 st_name, i);
1015 continue;
14bfc3f5
ILT
1016 }
1017
dbe717ef
ILT
1018 const char* name = sym_names + st_name;
1019
d491d34e
ILT
1020 bool is_ordinary;
1021 unsigned int st_shndx = relobj->adjust_sym_shndx(i + symndx_offset,
1022 sym.get_st_shndx(),
1023 &is_ordinary);
1024 unsigned int orig_st_shndx = st_shndx;
1025 if (!is_ordinary)
1026 orig_st_shndx = elfcpp::SHN_UNDEF;
1027
92de84a6
ILT
1028 if (st_shndx != elfcpp::SHN_UNDEF)
1029 ++*defined;
1030
a783673b
ILT
1031 // A symbol defined in a section which we are not including must
1032 // be treated as an undefined symbol.
a783673b 1033 if (st_shndx != elfcpp::SHN_UNDEF
d491d34e 1034 && is_ordinary
dbe717ef 1035 && !relobj->is_section_included(st_shndx))
d491d34e 1036 st_shndx = elfcpp::SHN_UNDEF;
a783673b 1037
14bfc3f5
ILT
1038 // In an object file, an '@' in the name separates the symbol
1039 // name from the version name. If there are two '@' characters,
1040 // this is the default version.
1041 const char* ver = strchr(name, '@');
057ead22 1042 Stringpool::Key ver_key = 0;
09124467 1043 int namelen = 0;
55a93433 1044 // DEF: is the version default? LOCAL: is the symbol forced local?
09124467 1045 bool def = false;
55a93433 1046 bool local = false;
09124467
ILT
1047
1048 if (ver != NULL)
1049 {
1050 // The symbol name is of the form foo@VERSION or foo@@VERSION
1051 namelen = ver - name;
1052 ++ver;
1053 if (*ver == '@')
1054 {
1055 def = true;
1056 ++ver;
1057 }
057ead22 1058 ver = this->namepool_.add(ver, true, &ver_key);
09124467 1059 }
5871526f
ILT
1060 // We don't want to assign a version to an undefined symbol,
1061 // even if it is listed in the version script. FIXME: What
1062 // about a common symbol?
057ead22
ILT
1063 else
1064 {
1065 namelen = strlen(name);
1066 if (!this->version_script_.empty()
1067 && st_shndx != elfcpp::SHN_UNDEF)
1068 {
1069 // The symbol name did not have a version, but the
1070 // version script may assign a version anyway.
1071 std::string version;
1072 if (this->version_script_.get_symbol_version(name, &version))
1073 {
1074 // The version can be empty if the version script is
1075 // only used to force some symbols to be local.
1076 if (!version.empty())
1077 {
1078 ver = this->namepool_.add_with_length(version.c_str(),
1079 version.length(),
1080 true,
1081 &ver_key);
1082 def = true;
1083 }
1084 }
1085 else if (this->version_script_.symbol_is_local(name))
1086 local = true;
1087 }
1088 }
14bfc3f5 1089
d491d34e
ILT
1090 elfcpp::Sym<size, big_endian>* psym = &sym;
1091 unsigned char symbuf[sym_size];
1092 elfcpp::Sym<size, big_endian> sym2(symbuf);
88dd47ac
ILT
1093 if (just_symbols)
1094 {
d491d34e 1095 memcpy(symbuf, p, sym_size);
88dd47ac 1096 elfcpp::Sym_write<size, big_endian> sw(symbuf);
d491d34e 1097 if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary)
88dd47ac
ILT
1098 {
1099 // Symbol values in object files are section relative.
1100 // This is normally what we want, but since here we are
1101 // converting the symbol to absolute we need to add the
1102 // section address. The section address in an object
1103 // file is normally zero, but people can use a linker
1104 // script to change it.
d491d34e
ILT
1105 sw.put_st_value(sym.get_st_value()
1106 + relobj->section_address(orig_st_shndx));
88dd47ac 1107 }
d491d34e
ILT
1108 st_shndx = elfcpp::SHN_ABS;
1109 is_ordinary = false;
88dd47ac
ILT
1110 psym = &sym2;
1111 }
1112
057ead22
ILT
1113 Stringpool::Key name_key;
1114 name = this->namepool_.add_with_length(name, namelen, true,
1115 &name_key);
1116
aeddab66 1117 Sized_symbol<size>* res;
057ead22
ILT
1118 res = this->add_from_object(relobj, name, name_key, ver, ver_key,
1119 def, *psym, st_shndx, is_ordinary,
1120 orig_st_shndx);
6d03d481
ST
1121
1122 // If building a shared library using garbage collection, do not
1123 // treat externally visible symbols as garbage.
1124 if (parameters->options().gc_sections()
1125 && parameters->options().shared())
1126 this->gc_mark_symbol_for_shlib(res);
f0641a0b 1127
057ead22
ILT
1128 if (local)
1129 this->force_local(res);
14bfc3f5 1130
730cdc88 1131 (*sympointers)[i] = res;
14bfc3f5
ILT
1132 }
1133}
1134
89fc3421
CC
1135// Add a symbol from a plugin-claimed file.
1136
1137template<int size, bool big_endian>
1138Symbol*
1139Symbol_table::add_from_pluginobj(
1140 Sized_pluginobj<size, big_endian>* obj,
1141 const char* name,
1142 const char* ver,
1143 elfcpp::Sym<size, big_endian>* sym)
1144{
1145 unsigned int st_shndx = sym->get_st_shndx();
1146
1147 Stringpool::Key ver_key = 0;
1148 bool def = false;
1149 bool local = false;
1150
1151 if (ver != NULL)
1152 {
1153 ver = this->namepool_.add(ver, true, &ver_key);
1154 }
1155 // We don't want to assign a version to an undefined symbol,
1156 // even if it is listed in the version script. FIXME: What
1157 // about a common symbol?
1158 else
1159 {
1160 if (!this->version_script_.empty()
1161 && st_shndx != elfcpp::SHN_UNDEF)
1162 {
1163 // The symbol name did not have a version, but the
1164 // version script may assign a version anyway.
1165 std::string version;
1166 if (this->version_script_.get_symbol_version(name, &version))
1167 {
1168 // The version can be empty if the version script is
1169 // only used to force some symbols to be local.
1170 if (!version.empty())
1171 {
1172 ver = this->namepool_.add_with_length(version.c_str(),
1173 version.length(),
1174 true,
1175 &ver_key);
1176 def = true;
1177 }
1178 }
1179 else if (this->version_script_.symbol_is_local(name))
1180 local = true;
1181 }
1182 }
1183
1184 Stringpool::Key name_key;
1185 name = this->namepool_.add(name, true, &name_key);
1186
1187 Sized_symbol<size>* res;
1188 res = this->add_from_object(obj, name, name_key, ver, ver_key,
1189 def, *sym, st_shndx, true, st_shndx);
1190
1191 if (local)
0602e05a 1192 this->force_local(res);
89fc3421
CC
1193
1194 return res;
1195}
1196
dbe717ef
ILT
1197// Add all the symbols in a dynamic object to the hash table.
1198
1199template<int size, bool big_endian>
1200void
1201Symbol_table::add_from_dynobj(
1202 Sized_dynobj<size, big_endian>* dynobj,
1203 const unsigned char* syms,
1204 size_t count,
1205 const char* sym_names,
1206 size_t sym_name_size,
1207 const unsigned char* versym,
1208 size_t versym_size,
92de84a6
ILT
1209 const std::vector<const char*>* version_map,
1210 typename Sized_relobj<size, big_endian>::Symbols* sympointers,
1211 size_t* defined)
dbe717ef 1212{
92de84a6
ILT
1213 *defined = 0;
1214
9025d29d 1215 gold_assert(size == dynobj->target()->get_size());
8851ecca 1216 gold_assert(size == parameters->target().get_size());
dbe717ef 1217
88dd47ac
ILT
1218 if (dynobj->just_symbols())
1219 {
1220 gold_error(_("--just-symbols does not make sense with a shared object"));
1221 return;
1222 }
1223
dbe717ef
ILT
1224 if (versym != NULL && versym_size / 2 < count)
1225 {
75f2446e
ILT
1226 dynobj->error(_("too few symbol versions"));
1227 return;
dbe717ef
ILT
1228 }
1229
1230 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1231
aeddab66
ILT
1232 // We keep a list of all STT_OBJECT symbols, so that we can resolve
1233 // weak aliases. This is necessary because if the dynamic object
1234 // provides the same variable under two names, one of which is a
1235 // weak definition, and the regular object refers to the weak
1236 // definition, we have to put both the weak definition and the
1237 // strong definition into the dynamic symbol table. Given a weak
1238 // definition, the only way that we can find the corresponding
1239 // strong definition, if any, is to search the symbol table.
1240 std::vector<Sized_symbol<size>*> object_symbols;
1241
dbe717ef
ILT
1242 const unsigned char* p = syms;
1243 const unsigned char* vs = versym;
1244 for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
1245 {
1246 elfcpp::Sym<size, big_endian> sym(p);
1247
92de84a6
ILT
1248 if (sympointers != NULL)
1249 (*sympointers)[i] = NULL;
1250
65778909
ILT
1251 // Ignore symbols with local binding or that have
1252 // internal or hidden visibility.
1253 if (sym.get_st_bind() == elfcpp::STB_LOCAL
1254 || sym.get_st_visibility() == elfcpp::STV_INTERNAL
1255 || sym.get_st_visibility() == elfcpp::STV_HIDDEN)
dbe717ef
ILT
1256 continue;
1257
8bdcdf2c
ILT
1258 // A protected symbol in a shared library must be treated as a
1259 // normal symbol when viewed from outside the shared library.
1260 // Implement this by overriding the visibility here.
1261 elfcpp::Sym<size, big_endian>* psym = &sym;
1262 unsigned char symbuf[sym_size];
1263 elfcpp::Sym<size, big_endian> sym2(symbuf);
1264 if (sym.get_st_visibility() == elfcpp::STV_PROTECTED)
1265 {
1266 memcpy(symbuf, p, sym_size);
1267 elfcpp::Sym_write<size, big_endian> sw(symbuf);
1268 sw.put_st_other(elfcpp::STV_DEFAULT, sym.get_st_nonvis());
1269 psym = &sym2;
1270 }
1271
1272 unsigned int st_name = psym->get_st_name();
dbe717ef
ILT
1273 if (st_name >= sym_name_size)
1274 {
75f2446e
ILT
1275 dynobj->error(_("bad symbol name offset %u at %zu"),
1276 st_name, i);
1277 continue;
dbe717ef
ILT
1278 }
1279
1280 const char* name = sym_names + st_name;
1281
d491d34e 1282 bool is_ordinary;
8bdcdf2c 1283 unsigned int st_shndx = dynobj->adjust_sym_shndx(i, psym->get_st_shndx(),
d491d34e
ILT
1284 &is_ordinary);
1285
92de84a6
ILT
1286 if (st_shndx != elfcpp::SHN_UNDEF)
1287 ++*defined;
1288
aeddab66
ILT
1289 Sized_symbol<size>* res;
1290
dbe717ef
ILT
1291 if (versym == NULL)
1292 {
1293 Stringpool::Key name_key;
cfd73a4e 1294 name = this->namepool_.add(name, true, &name_key);
aeddab66 1295 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
8bdcdf2c 1296 false, *psym, st_shndx, is_ordinary,
d491d34e 1297 st_shndx);
dbe717ef 1298 }
aeddab66
ILT
1299 else
1300 {
1301 // Read the version information.
dbe717ef 1302
aeddab66 1303 unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
dbe717ef 1304
aeddab66
ILT
1305 bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
1306 v &= elfcpp::VERSYM_VERSION;
dbe717ef 1307
aeddab66
ILT
1308 // The Sun documentation says that V can be VER_NDX_LOCAL,
1309 // or VER_NDX_GLOBAL, or a version index. The meaning of
1310 // VER_NDX_LOCAL is defined as "Symbol has local scope."
1311 // The old GNU linker will happily generate VER_NDX_LOCAL
1312 // for an undefined symbol. I don't know what the Sun
1313 // linker will generate.
dbe717ef 1314
aeddab66 1315 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
d491d34e 1316 && st_shndx != elfcpp::SHN_UNDEF)
aeddab66
ILT
1317 {
1318 // This symbol should not be visible outside the object.
1319 continue;
1320 }
64707334 1321
aeddab66
ILT
1322 // At this point we are definitely going to add this symbol.
1323 Stringpool::Key name_key;
1324 name = this->namepool_.add(name, true, &name_key);
dbe717ef 1325
aeddab66
ILT
1326 if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
1327 || v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
1328 {
1329 // This symbol does not have a version.
1330 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
8bdcdf2c 1331 false, *psym, st_shndx, is_ordinary,
d491d34e 1332 st_shndx);
aeddab66
ILT
1333 }
1334 else
1335 {
1336 if (v >= version_map->size())
1337 {
1338 dynobj->error(_("versym for symbol %zu out of range: %u"),
1339 i, v);
1340 continue;
1341 }
dbe717ef 1342
aeddab66
ILT
1343 const char* version = (*version_map)[v];
1344 if (version == NULL)
1345 {
1346 dynobj->error(_("versym for symbol %zu has no name: %u"),
1347 i, v);
1348 continue;
1349 }
dbe717ef 1350
aeddab66
ILT
1351 Stringpool::Key version_key;
1352 version = this->namepool_.add(version, true, &version_key);
1353
1354 // If this is an absolute symbol, and the version name
1355 // and symbol name are the same, then this is the
1356 // version definition symbol. These symbols exist to
1357 // support using -u to pull in particular versions. We
1358 // do not want to record a version for them.
d491d34e
ILT
1359 if (st_shndx == elfcpp::SHN_ABS
1360 && !is_ordinary
aeddab66
ILT
1361 && name_key == version_key)
1362 res = this->add_from_object(dynobj, name, name_key, NULL, 0,
8bdcdf2c 1363 false, *psym, st_shndx, is_ordinary,
d491d34e 1364 st_shndx);
aeddab66
ILT
1365 else
1366 {
1367 const bool def = (!hidden
d491d34e 1368 && st_shndx != elfcpp::SHN_UNDEF);
aeddab66 1369 res = this->add_from_object(dynobj, name, name_key, version,
8bdcdf2c 1370 version_key, def, *psym, st_shndx,
d491d34e 1371 is_ordinary, st_shndx);
aeddab66
ILT
1372 }
1373 }
dbe717ef
ILT
1374 }
1375
99a37bfd 1376 // Note that it is possible that RES was overridden by an
a4bb589a 1377 // earlier object, in which case it can't be aliased here.
d491d34e
ILT
1378 if (st_shndx != elfcpp::SHN_UNDEF
1379 && is_ordinary
8bdcdf2c 1380 && psym->get_st_type() == elfcpp::STT_OBJECT
99a37bfd
ILT
1381 && res->source() == Symbol::FROM_OBJECT
1382 && res->object() == dynobj)
aeddab66 1383 object_symbols.push_back(res);
92de84a6
ILT
1384
1385 if (sympointers != NULL)
1386 (*sympointers)[i] = res;
aeddab66
ILT
1387 }
1388
1389 this->record_weak_aliases(&object_symbols);
1390}
1391
1392// This is used to sort weak aliases. We sort them first by section
1393// index, then by offset, then by weak ahead of strong.
1394
1395template<int size>
1396class Weak_alias_sorter
1397{
1398 public:
1399 bool operator()(const Sized_symbol<size>*, const Sized_symbol<size>*) const;
1400};
1401
1402template<int size>
1403bool
1404Weak_alias_sorter<size>::operator()(const Sized_symbol<size>* s1,
1405 const Sized_symbol<size>* s2) const
1406{
d491d34e
ILT
1407 bool is_ordinary;
1408 unsigned int s1_shndx = s1->shndx(&is_ordinary);
1409 gold_assert(is_ordinary);
1410 unsigned int s2_shndx = s2->shndx(&is_ordinary);
1411 gold_assert(is_ordinary);
1412 if (s1_shndx != s2_shndx)
1413 return s1_shndx < s2_shndx;
1414
aeddab66
ILT
1415 if (s1->value() != s2->value())
1416 return s1->value() < s2->value();
1417 if (s1->binding() != s2->binding())
1418 {
1419 if (s1->binding() == elfcpp::STB_WEAK)
1420 return true;
1421 if (s2->binding() == elfcpp::STB_WEAK)
1422 return false;
1423 }
1424 return std::string(s1->name()) < std::string(s2->name());
1425}
dbe717ef 1426
aeddab66
ILT
1427// SYMBOLS is a list of object symbols from a dynamic object. Look
1428// for any weak aliases, and record them so that if we add the weak
1429// alias to the dynamic symbol table, we also add the corresponding
1430// strong symbol.
dbe717ef 1431
aeddab66
ILT
1432template<int size>
1433void
1434Symbol_table::record_weak_aliases(std::vector<Sized_symbol<size>*>* symbols)
1435{
1436 // Sort the vector by section index, then by offset, then by weak
1437 // ahead of strong.
1438 std::sort(symbols->begin(), symbols->end(), Weak_alias_sorter<size>());
1439
1440 // Walk through the vector. For each weak definition, record
1441 // aliases.
1442 for (typename std::vector<Sized_symbol<size>*>::const_iterator p =
1443 symbols->begin();
1444 p != symbols->end();
1445 ++p)
1446 {
1447 if ((*p)->binding() != elfcpp::STB_WEAK)
1448 continue;
1449
1450 // Build a circular list of weak aliases. Each symbol points to
1451 // the next one in the circular list.
1452
1453 Sized_symbol<size>* from_sym = *p;
1454 typename std::vector<Sized_symbol<size>*>::const_iterator q;
1455 for (q = p + 1; q != symbols->end(); ++q)
dbe717ef 1456 {
d491d34e
ILT
1457 bool dummy;
1458 if ((*q)->shndx(&dummy) != from_sym->shndx(&dummy)
aeddab66
ILT
1459 || (*q)->value() != from_sym->value())
1460 break;
1461
1462 this->weak_aliases_[from_sym] = *q;
1463 from_sym->set_has_alias();
1464 from_sym = *q;
dbe717ef
ILT
1465 }
1466
aeddab66
ILT
1467 if (from_sym != *p)
1468 {
1469 this->weak_aliases_[from_sym] = *p;
1470 from_sym->set_has_alias();
1471 }
dbe717ef 1472
aeddab66 1473 p = q - 1;
dbe717ef
ILT
1474 }
1475}
1476
ead1e424
ILT
1477// Create and return a specially defined symbol. If ONLY_IF_REF is
1478// true, then only create the symbol if there is a reference to it.
86f2e683 1479// If this does not return NULL, it sets *POLDSYM to the existing
306d9ef0 1480// symbol if there is one. This canonicalizes *PNAME and *PVERSION.
ead1e424
ILT
1481
1482template<int size, bool big_endian>
1483Sized_symbol<size>*
9b07f471
ILT
1484Symbol_table::define_special_symbol(const char** pname, const char** pversion,
1485 bool only_if_ref,
7d1a9ebb 1486 Sized_symbol<size>** poldsym)
ead1e424 1487{
ead1e424
ILT
1488 Symbol* oldsym;
1489 Sized_symbol<size>* sym;
86f2e683
ILT
1490 bool add_to_table = false;
1491 typename Symbol_table_type::iterator add_loc = this->table_.end();
ead1e424 1492
55a93433
ILT
1493 // If the caller didn't give us a version, see if we get one from
1494 // the version script.
057ead22 1495 std::string v;
55a93433
ILT
1496 if (*pversion == NULL)
1497 {
057ead22
ILT
1498 if (this->version_script_.get_symbol_version(*pname, &v))
1499 {
1500 if (!v.empty())
1501 *pversion = v.c_str();
1502 }
55a93433
ILT
1503 }
1504
ead1e424
ILT
1505 if (only_if_ref)
1506 {
306d9ef0 1507 oldsym = this->lookup(*pname, *pversion);
f6ce93d6 1508 if (oldsym == NULL || !oldsym->is_undefined())
ead1e424 1509 return NULL;
306d9ef0
ILT
1510
1511 *pname = oldsym->name();
1512 *pversion = oldsym->version();
ead1e424
ILT
1513 }
1514 else
1515 {
14b31740 1516 // Canonicalize NAME and VERSION.
f0641a0b 1517 Stringpool::Key name_key;
cfd73a4e 1518 *pname = this->namepool_.add(*pname, true, &name_key);
ead1e424 1519
14b31740 1520 Stringpool::Key version_key = 0;
306d9ef0 1521 if (*pversion != NULL)
cfd73a4e 1522 *pversion = this->namepool_.add(*pversion, true, &version_key);
14b31740 1523
ead1e424 1524 Symbol* const snull = NULL;
ead1e424 1525 std::pair<typename Symbol_table_type::iterator, bool> ins =
14b31740
ILT
1526 this->table_.insert(std::make_pair(std::make_pair(name_key,
1527 version_key),
ead1e424
ILT
1528 snull));
1529
1530 if (!ins.second)
1531 {
14b31740 1532 // We already have a symbol table entry for NAME/VERSION.
ead1e424 1533 oldsym = ins.first->second;
a3ad94ed 1534 gold_assert(oldsym != NULL);
ead1e424
ILT
1535 }
1536 else
1537 {
1538 // We haven't seen this symbol before.
a3ad94ed 1539 gold_assert(ins.first->second == NULL);
86f2e683
ILT
1540 add_to_table = true;
1541 add_loc = ins.first;
ead1e424
ILT
1542 oldsym = NULL;
1543 }
1544 }
1545
8851ecca
ILT
1546 const Target& target = parameters->target();
1547 if (!target.has_make_symbol())
86f2e683
ILT
1548 sym = new Sized_symbol<size>();
1549 else
ead1e424 1550 {
8851ecca
ILT
1551 gold_assert(target.get_size() == size);
1552 gold_assert(target.is_big_endian() ? big_endian : !big_endian);
86f2e683
ILT
1553 typedef Sized_target<size, big_endian> My_target;
1554 const My_target* sized_target =
8851ecca 1555 static_cast<const My_target*>(&target);
86f2e683
ILT
1556 sym = sized_target->make_symbol();
1557 if (sym == NULL)
1558 return NULL;
1559 }
ead1e424 1560
86f2e683
ILT
1561 if (add_to_table)
1562 add_loc->second = sym;
1563 else
1564 gold_assert(oldsym != NULL);
ead1e424 1565
7d1a9ebb 1566 *poldsym = this->get_sized_symbol<size>(oldsym);
ead1e424
ILT
1567
1568 return sym;
1569}
1570
1571// Define a symbol based on an Output_data.
1572
14b31740 1573Symbol*
9b07f471
ILT
1574Symbol_table::define_in_output_data(const char* name,
1575 const char* version,
1576 Output_data* od,
1577 uint64_t value,
1578 uint64_t symsize,
1579 elfcpp::STT type,
1580 elfcpp::STB binding,
ead1e424
ILT
1581 elfcpp::STV visibility,
1582 unsigned char nonvis,
1583 bool offset_is_from_end,
1584 bool only_if_ref)
1585{
8851ecca 1586 if (parameters->target().get_size() == 32)
86f2e683
ILT
1587 {
1588#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
9b07f471 1589 return this->do_define_in_output_data<32>(name, version, od,
86f2e683
ILT
1590 value, symsize, type, binding,
1591 visibility, nonvis,
1592 offset_is_from_end,
1593 only_if_ref);
1594#else
1595 gold_unreachable();
1596#endif
1597 }
8851ecca 1598 else if (parameters->target().get_size() == 64)
86f2e683
ILT
1599 {
1600#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
9b07f471 1601 return this->do_define_in_output_data<64>(name, version, od,
86f2e683
ILT
1602 value, symsize, type, binding,
1603 visibility, nonvis,
1604 offset_is_from_end,
1605 only_if_ref);
1606#else
1607 gold_unreachable();
1608#endif
1609 }
ead1e424 1610 else
a3ad94ed 1611 gold_unreachable();
ead1e424
ILT
1612}
1613
1614// Define a symbol in an Output_data, sized version.
1615
1616template<int size>
14b31740 1617Sized_symbol<size>*
ead1e424 1618Symbol_table::do_define_in_output_data(
ead1e424 1619 const char* name,
14b31740 1620 const char* version,
ead1e424
ILT
1621 Output_data* od,
1622 typename elfcpp::Elf_types<size>::Elf_Addr value,
1623 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1624 elfcpp::STT type,
1625 elfcpp::STB binding,
1626 elfcpp::STV visibility,
1627 unsigned char nonvis,
1628 bool offset_is_from_end,
1629 bool only_if_ref)
1630{
1631 Sized_symbol<size>* sym;
86f2e683 1632 Sized_symbol<size>* oldsym;
ead1e424 1633
8851ecca 1634 if (parameters->target().is_big_endian())
193a53d9
ILT
1635 {
1636#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
7d1a9ebb
ILT
1637 sym = this->define_special_symbol<size, true>(&name, &version,
1638 only_if_ref, &oldsym);
193a53d9
ILT
1639#else
1640 gold_unreachable();
1641#endif
1642 }
ead1e424 1643 else
193a53d9
ILT
1644 {
1645#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
7d1a9ebb
ILT
1646 sym = this->define_special_symbol<size, false>(&name, &version,
1647 only_if_ref, &oldsym);
193a53d9
ILT
1648#else
1649 gold_unreachable();
1650#endif
1651 }
ead1e424
ILT
1652
1653 if (sym == NULL)
14b31740 1654 return NULL;
ead1e424 1655
75517b77
ILT
1656 sym->init_output_data(name, version, od, value, symsize, type, binding,
1657 visibility, nonvis, offset_is_from_end);
14b31740 1658
e5756efb 1659 if (oldsym == NULL)
55a93433
ILT
1660 {
1661 if (binding == elfcpp::STB_LOCAL
1662 || this->version_script_.symbol_is_local(name))
1663 this->force_local(sym);
75517b77
ILT
1664 else if (version != NULL)
1665 sym->set_is_default();
55a93433
ILT
1666 return sym;
1667 }
86f2e683 1668
e5756efb
ILT
1669 if (Symbol_table::should_override_with_special(oldsym))
1670 this->override_with_special(oldsym, sym);
1671 delete sym;
1672 return oldsym;
ead1e424
ILT
1673}
1674
1675// Define a symbol based on an Output_segment.
1676
14b31740 1677Symbol*
9b07f471 1678Symbol_table::define_in_output_segment(const char* name,
14b31740 1679 const char* version, Output_segment* os,
9b07f471
ILT
1680 uint64_t value,
1681 uint64_t symsize,
1682 elfcpp::STT type,
1683 elfcpp::STB binding,
ead1e424
ILT
1684 elfcpp::STV visibility,
1685 unsigned char nonvis,
1686 Symbol::Segment_offset_base offset_base,
1687 bool only_if_ref)
1688{
8851ecca 1689 if (parameters->target().get_size() == 32)
86f2e683
ILT
1690 {
1691#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
9b07f471 1692 return this->do_define_in_output_segment<32>(name, version, os,
86f2e683
ILT
1693 value, symsize, type,
1694 binding, visibility, nonvis,
1695 offset_base, only_if_ref);
1696#else
1697 gold_unreachable();
1698#endif
1699 }
8851ecca 1700 else if (parameters->target().get_size() == 64)
86f2e683
ILT
1701 {
1702#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
9b07f471 1703 return this->do_define_in_output_segment<64>(name, version, os,
86f2e683
ILT
1704 value, symsize, type,
1705 binding, visibility, nonvis,
1706 offset_base, only_if_ref);
1707#else
1708 gold_unreachable();
1709#endif
1710 }
ead1e424 1711 else
a3ad94ed 1712 gold_unreachable();
ead1e424
ILT
1713}
1714
1715// Define a symbol in an Output_segment, sized version.
1716
1717template<int size>
14b31740 1718Sized_symbol<size>*
ead1e424 1719Symbol_table::do_define_in_output_segment(
ead1e424 1720 const char* name,
14b31740 1721 const char* version,
ead1e424
ILT
1722 Output_segment* os,
1723 typename elfcpp::Elf_types<size>::Elf_Addr value,
1724 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1725 elfcpp::STT type,
1726 elfcpp::STB binding,
1727 elfcpp::STV visibility,
1728 unsigned char nonvis,
1729 Symbol::Segment_offset_base offset_base,
1730 bool only_if_ref)
1731{
1732 Sized_symbol<size>* sym;
86f2e683 1733 Sized_symbol<size>* oldsym;
ead1e424 1734
8851ecca 1735 if (parameters->target().is_big_endian())
9025d29d
ILT
1736 {
1737#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
7d1a9ebb
ILT
1738 sym = this->define_special_symbol<size, true>(&name, &version,
1739 only_if_ref, &oldsym);
9025d29d
ILT
1740#else
1741 gold_unreachable();
1742#endif
1743 }
ead1e424 1744 else
9025d29d
ILT
1745 {
1746#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
7d1a9ebb
ILT
1747 sym = this->define_special_symbol<size, false>(&name, &version,
1748 only_if_ref, &oldsym);
9025d29d
ILT
1749#else
1750 gold_unreachable();
1751#endif
1752 }
ead1e424
ILT
1753
1754 if (sym == NULL)
14b31740 1755 return NULL;
ead1e424 1756
75517b77 1757 sym->init_output_segment(name, version, os, value, symsize, type, binding,
f3e9c5c5 1758 visibility, nonvis, offset_base);
14b31740 1759
e5756efb 1760 if (oldsym == NULL)
55a93433
ILT
1761 {
1762 if (binding == elfcpp::STB_LOCAL
1763 || this->version_script_.symbol_is_local(name))
1764 this->force_local(sym);
75517b77
ILT
1765 else if (version != NULL)
1766 sym->set_is_default();
55a93433
ILT
1767 return sym;
1768 }
86f2e683 1769
e5756efb
ILT
1770 if (Symbol_table::should_override_with_special(oldsym))
1771 this->override_with_special(oldsym, sym);
1772 delete sym;
1773 return oldsym;
ead1e424
ILT
1774}
1775
1776// Define a special symbol with a constant value. It is a multiple
1777// definition error if this symbol is already defined.
1778
14b31740 1779Symbol*
9b07f471
ILT
1780Symbol_table::define_as_constant(const char* name,
1781 const char* version,
1782 uint64_t value,
1783 uint64_t symsize,
1784 elfcpp::STT type,
1785 elfcpp::STB binding,
1786 elfcpp::STV visibility,
1787 unsigned char nonvis,
caa9d5d9
ILT
1788 bool only_if_ref,
1789 bool force_override)
ead1e424 1790{
8851ecca 1791 if (parameters->target().get_size() == 32)
86f2e683
ILT
1792 {
1793#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
9b07f471 1794 return this->do_define_as_constant<32>(name, version, value,
86f2e683 1795 symsize, type, binding,
caa9d5d9
ILT
1796 visibility, nonvis, only_if_ref,
1797 force_override);
86f2e683
ILT
1798#else
1799 gold_unreachable();
1800#endif
1801 }
8851ecca 1802 else if (parameters->target().get_size() == 64)
86f2e683
ILT
1803 {
1804#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
9b07f471 1805 return this->do_define_as_constant<64>(name, version, value,
86f2e683 1806 symsize, type, binding,
caa9d5d9
ILT
1807 visibility, nonvis, only_if_ref,
1808 force_override);
86f2e683
ILT
1809#else
1810 gold_unreachable();
1811#endif
1812 }
ead1e424 1813 else
a3ad94ed 1814 gold_unreachable();
ead1e424
ILT
1815}
1816
1817// Define a symbol as a constant, sized version.
1818
1819template<int size>
14b31740 1820Sized_symbol<size>*
ead1e424 1821Symbol_table::do_define_as_constant(
ead1e424 1822 const char* name,
14b31740 1823 const char* version,
ead1e424
ILT
1824 typename elfcpp::Elf_types<size>::Elf_Addr value,
1825 typename elfcpp::Elf_types<size>::Elf_WXword symsize,
1826 elfcpp::STT type,
1827 elfcpp::STB binding,
1828 elfcpp::STV visibility,
1829 unsigned char nonvis,
caa9d5d9
ILT
1830 bool only_if_ref,
1831 bool force_override)
ead1e424
ILT
1832{
1833 Sized_symbol<size>* sym;
86f2e683 1834 Sized_symbol<size>* oldsym;
ead1e424 1835
8851ecca 1836 if (parameters->target().is_big_endian())
9025d29d
ILT
1837 {
1838#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
7d1a9ebb
ILT
1839 sym = this->define_special_symbol<size, true>(&name, &version,
1840 only_if_ref, &oldsym);
9025d29d
ILT
1841#else
1842 gold_unreachable();
1843#endif
1844 }
ead1e424 1845 else
9025d29d
ILT
1846 {
1847#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
7d1a9ebb
ILT
1848 sym = this->define_special_symbol<size, false>(&name, &version,
1849 only_if_ref, &oldsym);
9025d29d
ILT
1850#else
1851 gold_unreachable();
1852#endif
1853 }
ead1e424
ILT
1854
1855 if (sym == NULL)
14b31740 1856 return NULL;
ead1e424 1857
75517b77
ILT
1858 sym->init_constant(name, version, value, symsize, type, binding, visibility,
1859 nonvis);
14b31740 1860
e5756efb 1861 if (oldsym == NULL)
55a93433 1862 {
686c8caf
ILT
1863 // Version symbols are absolute symbols with name == version.
1864 // We don't want to force them to be local.
1865 if ((version == NULL
1866 || name != version
1867 || value != 0)
1868 && (binding == elfcpp::STB_LOCAL
1869 || this->version_script_.symbol_is_local(name)))
55a93433 1870 this->force_local(sym);
75517b77
ILT
1871 else if (version != NULL
1872 && (name != version || value != 0))
1873 sym->set_is_default();
55a93433
ILT
1874 return sym;
1875 }
86f2e683 1876
caa9d5d9 1877 if (force_override || Symbol_table::should_override_with_special(oldsym))
e5756efb
ILT
1878 this->override_with_special(oldsym, sym);
1879 delete sym;
1880 return oldsym;
ead1e424
ILT
1881}
1882
1883// Define a set of symbols in output sections.
1884
1885void
9b07f471 1886Symbol_table::define_symbols(const Layout* layout, int count,
a445fddf
ILT
1887 const Define_symbol_in_section* p,
1888 bool only_if_ref)
ead1e424
ILT
1889{
1890 for (int i = 0; i < count; ++i, ++p)
1891 {
1892 Output_section* os = layout->find_output_section(p->output_section);
1893 if (os != NULL)
9b07f471 1894 this->define_in_output_data(p->name, NULL, os, p->value,
14b31740
ILT
1895 p->size, p->type, p->binding,
1896 p->visibility, p->nonvis,
a445fddf
ILT
1897 p->offset_is_from_end,
1898 only_if_ref || p->only_if_ref);
ead1e424 1899 else
9b07f471 1900 this->define_as_constant(p->name, NULL, 0, p->size, p->type,
ead1e424 1901 p->binding, p->visibility, p->nonvis,
caa9d5d9
ILT
1902 only_if_ref || p->only_if_ref,
1903 false);
ead1e424
ILT
1904 }
1905}
1906
1907// Define a set of symbols in output segments.
1908
1909void
9b07f471 1910Symbol_table::define_symbols(const Layout* layout, int count,
a445fddf
ILT
1911 const Define_symbol_in_segment* p,
1912 bool only_if_ref)
ead1e424
ILT
1913{
1914 for (int i = 0; i < count; ++i, ++p)
1915 {
1916 Output_segment* os = layout->find_output_segment(p->segment_type,
1917 p->segment_flags_set,
1918 p->segment_flags_clear);
1919 if (os != NULL)
9b07f471 1920 this->define_in_output_segment(p->name, NULL, os, p->value,
14b31740
ILT
1921 p->size, p->type, p->binding,
1922 p->visibility, p->nonvis,
a445fddf
ILT
1923 p->offset_base,
1924 only_if_ref || p->only_if_ref);
ead1e424 1925 else
9b07f471 1926 this->define_as_constant(p->name, NULL, 0, p->size, p->type,
ead1e424 1927 p->binding, p->visibility, p->nonvis,
caa9d5d9
ILT
1928 only_if_ref || p->only_if_ref,
1929 false);
ead1e424
ILT
1930 }
1931}
1932
46fe1623
ILT
1933// Define CSYM using a COPY reloc. POSD is the Output_data where the
1934// symbol should be defined--typically a .dyn.bss section. VALUE is
1935// the offset within POSD.
1936
1937template<int size>
1938void
fe8718a4 1939Symbol_table::define_with_copy_reloc(
fe8718a4
ILT
1940 Sized_symbol<size>* csym,
1941 Output_data* posd,
1942 typename elfcpp::Elf_types<size>::Elf_Addr value)
46fe1623
ILT
1943{
1944 gold_assert(csym->is_from_dynobj());
1945 gold_assert(!csym->is_copied_from_dynobj());
1946 Object* object = csym->object();
1947 gold_assert(object->is_dynamic());
1948 Dynobj* dynobj = static_cast<Dynobj*>(object);
1949
1950 // Our copied variable has to override any variable in a shared
1951 // library.
1952 elfcpp::STB binding = csym->binding();
1953 if (binding == elfcpp::STB_WEAK)
1954 binding = elfcpp::STB_GLOBAL;
1955
9b07f471 1956 this->define_in_output_data(csym->name(), csym->version(),
46fe1623
ILT
1957 posd, value, csym->symsize(),
1958 csym->type(), binding,
1959 csym->visibility(), csym->nonvis(),
1960 false, false);
1961
1962 csym->set_is_copied_from_dynobj();
1963 csym->set_needs_dynsym_entry();
1964
1965 this->copied_symbol_dynobjs_[csym] = dynobj;
1966
1967 // We have now defined all aliases, but we have not entered them all
1968 // in the copied_symbol_dynobjs_ map.
1969 if (csym->has_alias())
1970 {
1971 Symbol* sym = csym;
1972 while (true)
1973 {
1974 sym = this->weak_aliases_[sym];
1975 if (sym == csym)
1976 break;
1977 gold_assert(sym->output_data() == posd);
1978
1979 sym->set_is_copied_from_dynobj();
1980 this->copied_symbol_dynobjs_[sym] = dynobj;
1981 }
1982 }
1983}
1984
1985// SYM is defined using a COPY reloc. Return the dynamic object where
1986// the original definition was found.
1987
1988Dynobj*
1989Symbol_table::get_copy_source(const Symbol* sym) const
1990{
1991 gold_assert(sym->is_copied_from_dynobj());
1992 Copied_symbol_dynobjs::const_iterator p =
1993 this->copied_symbol_dynobjs_.find(sym);
1994 gold_assert(p != this->copied_symbol_dynobjs_.end());
1995 return p->second;
1996}
1997
f3e9c5c5
ILT
1998// Add any undefined symbols named on the command line.
1999
2000void
2001Symbol_table::add_undefined_symbols_from_command_line()
2002{
2003 if (parameters->options().any_undefined())
2004 {
2005 if (parameters->target().get_size() == 32)
2006 {
5adf9721 2007#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
f3e9c5c5
ILT
2008 this->do_add_undefined_symbols_from_command_line<32>();
2009#else
2010 gold_unreachable();
2011#endif
2012 }
2013 else if (parameters->target().get_size() == 64)
2014 {
2015#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
2016 this->do_add_undefined_symbols_from_command_line<64>();
2017#else
2018 gold_unreachable();
2019#endif
2020 }
2021 else
2022 gold_unreachable();
2023 }
2024}
2025
2026template<int size>
2027void
2028Symbol_table::do_add_undefined_symbols_from_command_line()
2029{
2030 for (options::String_set::const_iterator p =
2031 parameters->options().undefined_begin();
2032 p != parameters->options().undefined_end();
2033 ++p)
2034 {
2035 const char* name = p->c_str();
2036
2037 if (this->lookup(name) != NULL)
2038 continue;
2039
2040 const char* version = NULL;
2041
2042 Sized_symbol<size>* sym;
2043 Sized_symbol<size>* oldsym;
2044 if (parameters->target().is_big_endian())
2045 {
2046#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
2047 sym = this->define_special_symbol<size, true>(&name, &version,
2048 false, &oldsym);
2049#else
2050 gold_unreachable();
2051#endif
2052 }
2053 else
2054 {
2055#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
2056 sym = this->define_special_symbol<size, false>(&name, &version,
2057 false, &oldsym);
2058#else
2059 gold_unreachable();
2060#endif
2061 }
2062
2063 gold_assert(oldsym == NULL);
2064
75517b77 2065 sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
f3e9c5c5
ILT
2066 elfcpp::STV_DEFAULT, 0);
2067 ++this->saw_undefined_;
2068 }
2069}
2070
a3ad94ed
ILT
2071// Set the dynamic symbol indexes. INDEX is the index of the first
2072// global dynamic symbol. Pointers to the symbols are stored into the
2073// vector SYMS. The names are added to DYNPOOL. This returns an
2074// updated dynamic symbol index.
2075
2076unsigned int
9b07f471 2077Symbol_table::set_dynsym_indexes(unsigned int index,
a3ad94ed 2078 std::vector<Symbol*>* syms,
14b31740
ILT
2079 Stringpool* dynpool,
2080 Versions* versions)
a3ad94ed
ILT
2081{
2082 for (Symbol_table_type::iterator p = this->table_.begin();
2083 p != this->table_.end();
2084 ++p)
2085 {
2086 Symbol* sym = p->second;
16649710
ILT
2087
2088 // Note that SYM may already have a dynamic symbol index, since
2089 // some symbols appear more than once in the symbol table, with
2090 // and without a version.
2091
436ca963 2092 if (!sym->should_add_dynsym_entry())
16649710
ILT
2093 sym->set_dynsym_index(-1U);
2094 else if (!sym->has_dynsym_index())
a3ad94ed
ILT
2095 {
2096 sym->set_dynsym_index(index);
2097 ++index;
2098 syms->push_back(sym);
cfd73a4e 2099 dynpool->add(sym->name(), false, NULL);
14b31740
ILT
2100
2101 // Record any version information.
09124467
ILT
2102 if (sym->version() != NULL)
2103 versions->record_version(this, dynpool, sym);
a3ad94ed
ILT
2104 }
2105 }
2106
14b31740
ILT
2107 // Finish up the versions. In some cases this may add new dynamic
2108 // symbols.
9b07f471 2109 index = versions->finalize(this, index, syms);
14b31740 2110
a3ad94ed
ILT
2111 return index;
2112}
2113
c06b7b0b 2114// Set the final values for all the symbols. The index of the first
55a93433
ILT
2115// global symbol in the output file is *PLOCAL_SYMCOUNT. Record the
2116// file offset OFF. Add their names to POOL. Return the new file
2117// offset. Update *PLOCAL_SYMCOUNT if necessary.
54dc6425 2118
75f65a3e 2119off_t
55a93433
ILT
2120Symbol_table::finalize(off_t off, off_t dynoff, size_t dyn_global_index,
2121 size_t dyncount, Stringpool* pool,
2122 unsigned int *plocal_symcount)
54dc6425 2123{
f6ce93d6
ILT
2124 off_t ret;
2125
55a93433
ILT
2126 gold_assert(*plocal_symcount != 0);
2127 this->first_global_index_ = *plocal_symcount;
c06b7b0b 2128
16649710
ILT
2129 this->dynamic_offset_ = dynoff;
2130 this->first_dynamic_global_index_ = dyn_global_index;
2131 this->dynamic_count_ = dyncount;
2132
8851ecca 2133 if (parameters->target().get_size() == 32)
9025d29d
ILT
2134 {
2135#if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
55a93433 2136 ret = this->sized_finalize<32>(off, pool, plocal_symcount);
9025d29d
ILT
2137#else
2138 gold_unreachable();
2139#endif
2140 }
8851ecca 2141 else if (parameters->target().get_size() == 64)
9025d29d
ILT
2142 {
2143#if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
55a93433 2144 ret = this->sized_finalize<64>(off, pool, plocal_symcount);
9025d29d
ILT
2145#else
2146 gold_unreachable();
2147#endif
2148 }
61ba1cf9 2149 else
a3ad94ed 2150 gold_unreachable();
f6ce93d6
ILT
2151
2152 // Now that we have the final symbol table, we can reliably note
2153 // which symbols should get warnings.
cb295612 2154 this->warnings_.note_warnings(this);
f6ce93d6
ILT
2155
2156 return ret;
75f65a3e
ILT
2157}
2158
55a93433
ILT
2159// SYM is going into the symbol table at *PINDEX. Add the name to
2160// POOL, update *PINDEX and *POFF.
2161
2162template<int size>
2163void
2164Symbol_table::add_to_final_symtab(Symbol* sym, Stringpool* pool,
2165 unsigned int* pindex, off_t* poff)
2166{
2167 sym->set_symtab_index(*pindex);
2168 pool->add(sym->name(), false, NULL);
2169 ++*pindex;
2170 *poff += elfcpp::Elf_sizes<size>::sym_size;
2171}
2172
ead1e424
ILT
2173// Set the final value for all the symbols. This is called after
2174// Layout::finalize, so all the output sections have their final
2175// address.
75f65a3e
ILT
2176
2177template<int size>
2178off_t
55a93433
ILT
2179Symbol_table::sized_finalize(off_t off, Stringpool* pool,
2180 unsigned int* plocal_symcount)
75f65a3e 2181{
ead1e424 2182 off = align_address(off, size >> 3);
75f65a3e
ILT
2183 this->offset_ = off;
2184
55a93433
ILT
2185 unsigned int index = *plocal_symcount;
2186 const unsigned int orig_index = index;
c06b7b0b 2187
55a93433
ILT
2188 // First do all the symbols which have been forced to be local, as
2189 // they must appear before all global symbols.
2190 for (Forced_locals::iterator p = this->forced_locals_.begin();
2191 p != this->forced_locals_.end();
2192 ++p)
2193 {
2194 Symbol* sym = *p;
2195 gold_assert(sym->is_forced_local());
2196 if (this->sized_finalize_symbol<size>(sym))
2197 {
2198 this->add_to_final_symtab<size>(sym, pool, &index, &off);
2199 ++*plocal_symcount;
2200 }
2201 }
2202
2203 // Now do all the remaining symbols.
c06b7b0b
ILT
2204 for (Symbol_table_type::iterator p = this->table_.begin();
2205 p != this->table_.end();
2206 ++p)
54dc6425 2207 {
55a93433
ILT
2208 Symbol* sym = p->second;
2209 if (this->sized_finalize_symbol<size>(sym))
2210 this->add_to_final_symtab<size>(sym, pool, &index, &off);
2211 }
54dc6425 2212
55a93433 2213 this->output_count_ = index - orig_index;
a3ad94ed 2214
55a93433
ILT
2215 return off;
2216}
75f65a3e 2217
55a93433
ILT
2218// Finalize the symbol SYM. This returns true if the symbol should be
2219// added to the symbol table, false otherwise.
008db82e 2220
55a93433
ILT
2221template<int size>
2222bool
2223Symbol_table::sized_finalize_symbol(Symbol* unsized_sym)
2224{
ef9beddf
ILT
2225 typedef typename Sized_symbol<size>::Value_type Value_type;
2226
55a93433 2227 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(unsized_sym);
75f65a3e 2228
55a93433
ILT
2229 // The default version of a symbol may appear twice in the symbol
2230 // table. We only need to finalize it once.
2231 if (sym->has_symtab_index())
2232 return false;
ead1e424 2233
55a93433
ILT
2234 if (!sym->in_reg())
2235 {
2236 gold_assert(!sym->has_symtab_index());
2237 sym->set_symtab_index(-1U);
2238 gold_assert(sym->dynsym_index() == -1U);
2239 return false;
2240 }
ead1e424 2241
ef9beddf 2242 Value_type value;
ead1e424 2243
55a93433
ILT
2244 switch (sym->source())
2245 {
2246 case Symbol::FROM_OBJECT:
2247 {
d491d34e
ILT
2248 bool is_ordinary;
2249 unsigned int shndx = sym->shndx(&is_ordinary);
ead1e424 2250
55a93433 2251 // FIXME: We need some target specific support here.
d491d34e 2252 if (!is_ordinary
0dfbdef4
ILT
2253 && shndx != elfcpp::SHN_ABS
2254 && shndx != elfcpp::SHN_COMMON)
55a93433
ILT
2255 {
2256 gold_error(_("%s: unsupported symbol section 0x%x"),
2257 sym->demangled_name().c_str(), shndx);
2258 shndx = elfcpp::SHN_UNDEF;
ead1e424 2259 }
ead1e424 2260
55a93433
ILT
2261 Object* symobj = sym->object();
2262 if (symobj->is_dynamic())
ead1e424 2263 {
55a93433
ILT
2264 value = 0;
2265 shndx = elfcpp::SHN_UNDEF;
ead1e424 2266 }
89fc3421
CC
2267 else if (symobj->pluginobj() != NULL)
2268 {
2269 value = 0;
2270 shndx = elfcpp::SHN_UNDEF;
2271 }
55a93433
ILT
2272 else if (shndx == elfcpp::SHN_UNDEF)
2273 value = 0;
d491d34e
ILT
2274 else if (!is_ordinary
2275 && (shndx == elfcpp::SHN_ABS || shndx == elfcpp::SHN_COMMON))
55a93433
ILT
2276 value = sym->value();
2277 else
ead1e424 2278 {
55a93433 2279 Relobj* relobj = static_cast<Relobj*>(symobj);
ef9beddf 2280 Output_section* os = relobj->output_section(shndx);
55a93433
ILT
2281
2282 if (os == NULL)
ead1e424 2283 {
55a93433 2284 sym->set_symtab_index(-1U);
6d03d481
ST
2285 bool static_or_reloc = (parameters->doing_static_link() ||
2286 parameters->options().relocatable());
2287 gold_assert(static_or_reloc || sym->dynsym_index() == -1U);
2288
55a93433 2289 return false;
ead1e424 2290 }
55a93433 2291
ef9beddf 2292 uint64_t secoff64 = relobj->output_section_offset(shndx);
eff45813
CC
2293 if (secoff64 == -1ULL)
2294 {
2295 // The section needs special handling (e.g., a merge section).
2296 value = os->output_address(relobj, shndx, sym->value());
2297 }
2298 else
2299 {
2300 Value_type secoff =
2301 convert_types<Value_type, uint64_t>(secoff64);
2302 if (sym->type() == elfcpp::STT_TLS)
2303 value = sym->value() + os->tls_offset() + secoff;
2304 else
2305 value = sym->value() + os->address() + secoff;
2306 }
ead1e424 2307 }
55a93433
ILT
2308 }
2309 break;
2310
2311 case Symbol::IN_OUTPUT_DATA:
2312 {
2313 Output_data* od = sym->output_data();
155a0dd7
ILT
2314 value = sym->value();
2315 if (sym->type() != elfcpp::STT_TLS)
2316 value += od->address();
2317 else
2318 {
2319 Output_section* os = od->output_section();
2320 gold_assert(os != NULL);
2321 value += os->tls_offset() + (od->address() - os->address());
2322 }
55a93433
ILT
2323 if (sym->offset_is_from_end())
2324 value += od->data_size();
2325 }
2326 break;
2327
2328 case Symbol::IN_OUTPUT_SEGMENT:
2329 {
2330 Output_segment* os = sym->output_segment();
edfbb029
CC
2331 value = sym->value();
2332 if (sym->type() != elfcpp::STT_TLS)
2333 value += os->vaddr();
55a93433
ILT
2334 switch (sym->offset_base())
2335 {
2336 case Symbol::SEGMENT_START:
2337 break;
2338 case Symbol::SEGMENT_END:
2339 value += os->memsz();
2340 break;
2341 case Symbol::SEGMENT_BSS:
2342 value += os->filesz();
2343 break;
2344 default:
2345 gold_unreachable();
2346 }
2347 }
2348 break;
ead1e424 2349
f3e9c5c5 2350 case Symbol::IS_CONSTANT:
55a93433
ILT
2351 value = sym->value();
2352 break;
ead1e424 2353
f3e9c5c5
ILT
2354 case Symbol::IS_UNDEFINED:
2355 value = 0;
2356 break;
2357
55a93433
ILT
2358 default:
2359 gold_unreachable();
2360 }
ead1e424 2361
55a93433 2362 sym->set_value(value);
9e2dcb77 2363
8851ecca 2364 if (parameters->options().strip_all())
55a93433
ILT
2365 {
2366 sym->set_symtab_index(-1U);
2367 return false;
54dc6425 2368 }
75f65a3e 2369
55a93433 2370 return true;
54dc6425
ILT
2371}
2372
61ba1cf9
ILT
2373// Write out the global symbols.
2374
2375void
fd9d194f 2376Symbol_table::write_globals(const Stringpool* sympool,
d491d34e
ILT
2377 const Stringpool* dynpool,
2378 Output_symtab_xindex* symtab_xindex,
2379 Output_symtab_xindex* dynsym_xindex,
2380 Output_file* of) const
61ba1cf9 2381{
8851ecca 2382 switch (parameters->size_and_endianness())
61ba1cf9 2383 {
9025d29d 2384#ifdef HAVE_TARGET_32_LITTLE
8851ecca 2385 case Parameters::TARGET_32_LITTLE:
fd9d194f 2386 this->sized_write_globals<32, false>(sympool, dynpool, symtab_xindex,
d491d34e 2387 dynsym_xindex, of);
8851ecca 2388 break;
9025d29d 2389#endif
8851ecca
ILT
2390#ifdef HAVE_TARGET_32_BIG
2391 case Parameters::TARGET_32_BIG:
fd9d194f 2392 this->sized_write_globals<32, true>(sympool, dynpool, symtab_xindex,
d491d34e 2393 dynsym_xindex, of);
8851ecca 2394 break;
9025d29d 2395#endif
9025d29d 2396#ifdef HAVE_TARGET_64_LITTLE
8851ecca 2397 case Parameters::TARGET_64_LITTLE:
fd9d194f 2398 this->sized_write_globals<64, false>(sympool, dynpool, symtab_xindex,
d491d34e 2399 dynsym_xindex, of);
8851ecca 2400 break;
9025d29d 2401#endif
8851ecca
ILT
2402#ifdef HAVE_TARGET_64_BIG
2403 case Parameters::TARGET_64_BIG:
fd9d194f 2404 this->sized_write_globals<64, true>(sympool, dynpool, symtab_xindex,
d491d34e 2405 dynsym_xindex, of);
8851ecca
ILT
2406 break;
2407#endif
2408 default:
2409 gold_unreachable();
61ba1cf9 2410 }
61ba1cf9
ILT
2411}
2412
2413// Write out the global symbols.
2414
2415template<int size, bool big_endian>
2416void
fd9d194f 2417Symbol_table::sized_write_globals(const Stringpool* sympool,
16649710 2418 const Stringpool* dynpool,
d491d34e
ILT
2419 Output_symtab_xindex* symtab_xindex,
2420 Output_symtab_xindex* dynsym_xindex,
61ba1cf9
ILT
2421 Output_file* of) const
2422{
8851ecca 2423 const Target& target = parameters->target();
9a2d6984 2424
61ba1cf9 2425 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
55a93433
ILT
2426
2427 const unsigned int output_count = this->output_count_;
2428 const section_size_type oview_size = output_count * sym_size;
2429 const unsigned int first_global_index = this->first_global_index_;
5fe2a0f5
ILT
2430 unsigned char* psyms;
2431 if (this->offset_ == 0 || output_count == 0)
2432 psyms = NULL;
2433 else
2434 psyms = of->get_output_view(this->offset_, oview_size);
16649710 2435
55a93433
ILT
2436 const unsigned int dynamic_count = this->dynamic_count_;
2437 const section_size_type dynamic_size = dynamic_count * sym_size;
2438 const unsigned int first_dynamic_global_index =
2439 this->first_dynamic_global_index_;
16649710 2440 unsigned char* dynamic_view;
5fe2a0f5 2441 if (this->dynamic_offset_ == 0 || dynamic_count == 0)
16649710
ILT
2442 dynamic_view = NULL;
2443 else
2444 dynamic_view = of->get_output_view(this->dynamic_offset_, dynamic_size);
c06b7b0b 2445
61ba1cf9
ILT
2446 for (Symbol_table_type::const_iterator p = this->table_.begin();
2447 p != this->table_.end();
2448 ++p)
2449 {
2450 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
2451
9a2d6984 2452 // Possibly warn about unresolved symbols in shared libraries.
fd9d194f 2453 this->warn_about_undefined_dynobj_symbol(sym);
e2827e5f 2454
a3ad94ed 2455 unsigned int sym_index = sym->symtab_index();
16649710
ILT
2456 unsigned int dynsym_index;
2457 if (dynamic_view == NULL)
2458 dynsym_index = -1U;
2459 else
2460 dynsym_index = sym->dynsym_index();
2461
2462 if (sym_index == -1U && dynsym_index == -1U)
a3ad94ed
ILT
2463 {
2464 // This symbol is not included in the output file.
2465 continue;
2466 }
16649710 2467
ead1e424 2468 unsigned int shndx;
88dd47ac
ILT
2469 typename elfcpp::Elf_types<size>::Elf_Addr sym_value = sym->value();
2470 typename elfcpp::Elf_types<size>::Elf_Addr dynsym_value = sym_value;
ead1e424
ILT
2471 switch (sym->source())
2472 {
2473 case Symbol::FROM_OBJECT:
2474 {
d491d34e
ILT
2475 bool is_ordinary;
2476 unsigned int in_shndx = sym->shndx(&is_ordinary);
ead1e424
ILT
2477
2478 // FIXME: We need some target specific support here.
d491d34e 2479 if (!is_ordinary
0dfbdef4
ILT
2480 && in_shndx != elfcpp::SHN_ABS
2481 && in_shndx != elfcpp::SHN_COMMON)
ead1e424 2482 {
75f2446e 2483 gold_error(_("%s: unsupported symbol section 0x%x"),
a2b1aa12 2484 sym->demangled_name().c_str(), in_shndx);
75f2446e 2485 shndx = in_shndx;
f6ce93d6 2486 }
ead1e424
ILT
2487 else
2488 {
75f2446e
ILT
2489 Object* symobj = sym->object();
2490 if (symobj->is_dynamic())
2491 {
2492 if (sym->needs_dynsym_value())
8851ecca 2493 dynsym_value = target.dynsym_value(sym);
75f2446e
ILT
2494 shndx = elfcpp::SHN_UNDEF;
2495 }
89fc3421
CC
2496 else if (symobj->pluginobj() != NULL)
2497 shndx = elfcpp::SHN_UNDEF;
75f2446e 2498 else if (in_shndx == elfcpp::SHN_UNDEF
d491d34e
ILT
2499 || (!is_ordinary
2500 && (in_shndx == elfcpp::SHN_ABS
2501 || in_shndx == elfcpp::SHN_COMMON)))
75f2446e
ILT
2502 shndx = in_shndx;
2503 else
2504 {
2505 Relobj* relobj = static_cast<Relobj*>(symobj);
ef9beddf 2506 Output_section* os = relobj->output_section(in_shndx);
75f2446e
ILT
2507 gold_assert(os != NULL);
2508 shndx = os->out_shndx();
88dd47ac 2509
d491d34e
ILT
2510 if (shndx >= elfcpp::SHN_LORESERVE)
2511 {
2512 if (sym_index != -1U)
2513 symtab_xindex->add(sym_index, shndx);
2514 if (dynsym_index != -1U)
2515 dynsym_xindex->add(dynsym_index, shndx);
2516 shndx = elfcpp::SHN_XINDEX;
2517 }
2518
88dd47ac
ILT
2519 // In object files symbol values are section
2520 // relative.
8851ecca 2521 if (parameters->options().relocatable())
88dd47ac 2522 sym_value -= os->address();
75f2446e 2523 }
ead1e424
ILT
2524 }
2525 }
2526 break;
2527
2528 case Symbol::IN_OUTPUT_DATA:
2529 shndx = sym->output_data()->out_shndx();
d491d34e
ILT
2530 if (shndx >= elfcpp::SHN_LORESERVE)
2531 {
2532 if (sym_index != -1U)
2533 symtab_xindex->add(sym_index, shndx);
2534 if (dynsym_index != -1U)
2535 dynsym_xindex->add(dynsym_index, shndx);
2536 shndx = elfcpp::SHN_XINDEX;
2537 }
ead1e424
ILT
2538 break;
2539
2540 case Symbol::IN_OUTPUT_SEGMENT:
2541 shndx = elfcpp::SHN_ABS;
2542 break;
2543
f3e9c5c5 2544 case Symbol::IS_CONSTANT:
ead1e424
ILT
2545 shndx = elfcpp::SHN_ABS;
2546 break;
2547
f3e9c5c5
ILT
2548 case Symbol::IS_UNDEFINED:
2549 shndx = elfcpp::SHN_UNDEF;
2550 break;
2551
ead1e424 2552 default:
a3ad94ed 2553 gold_unreachable();
ead1e424 2554 }
61ba1cf9 2555
16649710
ILT
2556 if (sym_index != -1U)
2557 {
55a93433
ILT
2558 sym_index -= first_global_index;
2559 gold_assert(sym_index < output_count);
2560 unsigned char* ps = psyms + (sym_index * sym_size);
7d1a9ebb
ILT
2561 this->sized_write_symbol<size, big_endian>(sym, sym_value, shndx,
2562 sympool, ps);
16649710 2563 }
61ba1cf9 2564
16649710
ILT
2565 if (dynsym_index != -1U)
2566 {
2567 dynsym_index -= first_dynamic_global_index;
2568 gold_assert(dynsym_index < dynamic_count);
2569 unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
7d1a9ebb
ILT
2570 this->sized_write_symbol<size, big_endian>(sym, dynsym_value, shndx,
2571 dynpool, pd);
16649710 2572 }
61ba1cf9
ILT
2573 }
2574
c06b7b0b 2575 of->write_output_view(this->offset_, oview_size, psyms);
16649710
ILT
2576 if (dynamic_view != NULL)
2577 of->write_output_view(this->dynamic_offset_, dynamic_size, dynamic_view);
2578}
2579
2580// Write out the symbol SYM, in section SHNDX, to P. POOL is the
2581// strtab holding the name.
2582
2583template<int size, bool big_endian>
2584void
ab5c9e90
ILT
2585Symbol_table::sized_write_symbol(
2586 Sized_symbol<size>* sym,
2587 typename elfcpp::Elf_types<size>::Elf_Addr value,
2588 unsigned int shndx,
2589 const Stringpool* pool,
7d1a9ebb 2590 unsigned char* p) const
16649710
ILT
2591{
2592 elfcpp::Sym_write<size, big_endian> osym(p);
2593 osym.put_st_name(pool->get_offset(sym->name()));
ab5c9e90 2594 osym.put_st_value(value);
58e54ac2
CD
2595 // Use a symbol size of zero for undefined symbols from shared libraries.
2596 if (shndx == elfcpp::SHN_UNDEF && sym->is_from_dynobj())
2597 osym.put_st_size(0);
2598 else
2599 osym.put_st_size(sym->symsize());
55a93433
ILT
2600 // A version script may have overridden the default binding.
2601 if (sym->is_forced_local())
2602 osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL, sym->type()));
2603 else
2604 osym.put_st_info(elfcpp::elf_st_info(sym->binding(), sym->type()));
16649710
ILT
2605 osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
2606 osym.put_st_shndx(shndx);
61ba1cf9
ILT
2607}
2608
9a2d6984
ILT
2609// Check for unresolved symbols in shared libraries. This is
2610// controlled by the --allow-shlib-undefined option.
2611
2612// We only warn about libraries for which we have seen all the
2613// DT_NEEDED entries. We don't try to track down DT_NEEDED entries
2614// which were not seen in this link. If we didn't see a DT_NEEDED
2615// entry, we aren't going to be able to reliably report whether the
2616// symbol is undefined.
2617
fd9d194f
ILT
2618// We also don't warn about libraries found in a system library
2619// directory (e.g., /lib or /usr/lib); we assume that those libraries
2620// are OK. This heuristic avoids problems on GNU/Linux, in which -ldl
2621// can have undefined references satisfied by ld-linux.so.
9a2d6984
ILT
2622
2623inline void
fd9d194f 2624Symbol_table::warn_about_undefined_dynobj_symbol(Symbol* sym) const
9a2d6984 2625{
d491d34e 2626 bool dummy;
9a2d6984
ILT
2627 if (sym->source() == Symbol::FROM_OBJECT
2628 && sym->object()->is_dynamic()
d491d34e 2629 && sym->shndx(&dummy) == elfcpp::SHN_UNDEF
9a2d6984 2630 && sym->binding() != elfcpp::STB_WEAK
8851ecca
ILT
2631 && !parameters->options().allow_shlib_undefined()
2632 && !parameters->target().is_defined_by_abi(sym)
fd9d194f 2633 && !sym->object()->is_in_system_directory())
9a2d6984
ILT
2634 {
2635 // A very ugly cast.
2636 Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
2637 if (!dynobj->has_unknown_needed_entries())
f073bbf7 2638 gold_undefined_symbol(sym);
9a2d6984
ILT
2639 }
2640}
2641
a3ad94ed
ILT
2642// Write out a section symbol. Return the update offset.
2643
2644void
9025d29d 2645Symbol_table::write_section_symbol(const Output_section *os,
d491d34e 2646 Output_symtab_xindex* symtab_xindex,
a3ad94ed
ILT
2647 Output_file* of,
2648 off_t offset) const
2649{
8851ecca 2650 switch (parameters->size_and_endianness())
a3ad94ed 2651 {
9025d29d 2652#ifdef HAVE_TARGET_32_LITTLE
8851ecca 2653 case Parameters::TARGET_32_LITTLE:
d491d34e
ILT
2654 this->sized_write_section_symbol<32, false>(os, symtab_xindex, of,
2655 offset);
8851ecca 2656 break;
9025d29d 2657#endif
8851ecca
ILT
2658#ifdef HAVE_TARGET_32_BIG
2659 case Parameters::TARGET_32_BIG:
d491d34e
ILT
2660 this->sized_write_section_symbol<32, true>(os, symtab_xindex, of,
2661 offset);
8851ecca 2662 break;
9025d29d 2663#endif
9025d29d 2664#ifdef HAVE_TARGET_64_LITTLE
8851ecca 2665 case Parameters::TARGET_64_LITTLE:
d491d34e
ILT
2666 this->sized_write_section_symbol<64, false>(os, symtab_xindex, of,
2667 offset);
8851ecca 2668 break;
9025d29d 2669#endif
8851ecca
ILT
2670#ifdef HAVE_TARGET_64_BIG
2671 case Parameters::TARGET_64_BIG:
d491d34e
ILT
2672 this->sized_write_section_symbol<64, true>(os, symtab_xindex, of,
2673 offset);
8851ecca
ILT
2674 break;
2675#endif
2676 default:
2677 gold_unreachable();
a3ad94ed 2678 }
a3ad94ed
ILT
2679}
2680
2681// Write out a section symbol, specialized for size and endianness.
2682
2683template<int size, bool big_endian>
2684void
2685Symbol_table::sized_write_section_symbol(const Output_section* os,
d491d34e 2686 Output_symtab_xindex* symtab_xindex,
a3ad94ed
ILT
2687 Output_file* of,
2688 off_t offset) const
2689{
2690 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
2691
2692 unsigned char* pov = of->get_output_view(offset, sym_size);
2693
2694 elfcpp::Sym_write<size, big_endian> osym(pov);
2695 osym.put_st_name(0);
2696 osym.put_st_value(os->address());
2697 osym.put_st_size(0);
2698 osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
2699 elfcpp::STT_SECTION));
2700 osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
d491d34e
ILT
2701
2702 unsigned int shndx = os->out_shndx();
2703 if (shndx >= elfcpp::SHN_LORESERVE)
2704 {
2705 symtab_xindex->add(os->symtab_index(), shndx);
2706 shndx = elfcpp::SHN_XINDEX;
2707 }
2708 osym.put_st_shndx(shndx);
a3ad94ed
ILT
2709
2710 of->write_output_view(offset, sym_size, pov);
2711}
2712
abaa3995
ILT
2713// Print statistical information to stderr. This is used for --stats.
2714
2715void
2716Symbol_table::print_stats() const
2717{
2718#if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP)
2719 fprintf(stderr, _("%s: symbol table entries: %zu; buckets: %zu\n"),
2720 program_name, this->table_.size(), this->table_.bucket_count());
2721#else
2722 fprintf(stderr, _("%s: symbol table entries: %zu\n"),
2723 program_name, this->table_.size());
2724#endif
ad8f37d1 2725 this->namepool_.print_stats("symbol table stringpool");
abaa3995
ILT
2726}
2727
ff541f30
ILT
2728// We check for ODR violations by looking for symbols with the same
2729// name for which the debugging information reports that they were
2730// defined in different source locations. When comparing the source
2731// location, we consider instances with the same base filename and
2732// line number to be the same. This is because different object
2733// files/shared libraries can include the same header file using
2734// different paths, and we don't want to report an ODR violation in
2735// that case.
2736
2737// This struct is used to compare line information, as returned by
7bf1f802 2738// Dwarf_line_info::one_addr2line. It implements a < comparison
ff541f30
ILT
2739// operator used with std::set.
2740
2741struct Odr_violation_compare
2742{
2743 bool
2744 operator()(const std::string& s1, const std::string& s2) const
2745 {
2746 std::string::size_type pos1 = s1.rfind('/');
2747 std::string::size_type pos2 = s2.rfind('/');
2748 if (pos1 == std::string::npos
2749 || pos2 == std::string::npos)
2750 return s1 < s2;
2751 return s1.compare(pos1, std::string::npos,
2752 s2, pos2, std::string::npos) < 0;
2753 }
2754};
2755
70e654ba
ILT
2756// Check candidate_odr_violations_ to find symbols with the same name
2757// but apparently different definitions (different source-file/line-no).
2758
2759void
17a1d0a9
ILT
2760Symbol_table::detect_odr_violations(const Task* task,
2761 const char* output_file_name) const
70e654ba
ILT
2762{
2763 for (Odr_map::const_iterator it = candidate_odr_violations_.begin();
2764 it != candidate_odr_violations_.end();
2765 ++it)
2766 {
2767 const char* symbol_name = it->first;
2768 // We use a sorted set so the output is deterministic.
ff541f30 2769 std::set<std::string, Odr_violation_compare> line_nums;
70e654ba 2770
b01c0a4a
ILT
2771 for (Unordered_set<Symbol_location, Symbol_location_hash>::const_iterator
2772 locs = it->second.begin();
2773 locs != it->second.end();
2774 ++locs)
70e654ba
ILT
2775 {
2776 // We need to lock the object in order to read it. This
17a1d0a9
ILT
2777 // means that we have to run in a singleton Task. If we
2778 // want to run this in a general Task for better
2779 // performance, we will need one Task for object, plus
2780 // appropriate locking to ensure that we don't conflict with
e4e5049b
CS
2781 // other uses of the object. Also note, one_addr2line is not
2782 // currently thread-safe.
17a1d0a9 2783 Task_lock_obj<Object> tl(task, locs->object);
e4e5049b 2784 // 16 is the size of the object-cache that one_addr2line should use.
a55ce7fe 2785 std::string lineno = Dwarf_line_info::one_addr2line(
e4e5049b 2786 locs->object, locs->shndx, locs->offset, 16);
70e654ba
ILT
2787 if (!lineno.empty())
2788 line_nums.insert(lineno);
2789 }
2790
2791 if (line_nums.size() > 1)
2792 {
dd8670e5 2793 gold_warning(_("while linking %s: symbol '%s' defined in multiple "
78f15696 2794 "places (possible ODR violation):"),
a2b1aa12 2795 output_file_name, demangle(symbol_name).c_str());
70e654ba
ILT
2796 for (std::set<std::string>::const_iterator it2 = line_nums.begin();
2797 it2 != line_nums.end();
2798 ++it2)
2799 fprintf(stderr, " %s\n", it2->c_str());
2800 }
2801 }
e4e5049b
CS
2802 // We only call one_addr2line() in this function, so we can clear its cache.
2803 Dwarf_line_info::clear_addr2line_cache();
70e654ba
ILT
2804}
2805
f6ce93d6
ILT
2806// Warnings functions.
2807
2808// Add a new warning.
2809
2810void
2811Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
cb295612 2812 const std::string& warning)
f6ce93d6
ILT
2813{
2814 name = symtab->canonicalize_name(name);
cb295612 2815 this->warnings_[name].set(obj, warning);
f6ce93d6
ILT
2816}
2817
2818// Look through the warnings and mark the symbols for which we should
2819// warn. This is called during Layout::finalize when we know the
2820// sources for all the symbols.
2821
2822void
cb295612 2823Warnings::note_warnings(Symbol_table* symtab)
f6ce93d6
ILT
2824{
2825 for (Warning_table::iterator p = this->warnings_.begin();
2826 p != this->warnings_.end();
2827 ++p)
2828 {
2829 Symbol* sym = symtab->lookup(p->first, NULL);
2830 if (sym != NULL
2831 && sym->source() == Symbol::FROM_OBJECT
2832 && sym->object() == p->second.object)
cb295612 2833 sym->set_has_warning();
f6ce93d6
ILT
2834 }
2835}
2836
2837// Issue a warning. This is called when we see a relocation against a
2838// symbol for which has a warning.
2839
75f2446e 2840template<int size, bool big_endian>
f6ce93d6 2841void
75f2446e
ILT
2842Warnings::issue_warning(const Symbol* sym,
2843 const Relocate_info<size, big_endian>* relinfo,
2844 size_t relnum, off_t reloffset) const
f6ce93d6 2845{
a3ad94ed 2846 gold_assert(sym->has_warning());
f6ce93d6 2847 Warning_table::const_iterator p = this->warnings_.find(sym->name());
a3ad94ed 2848 gold_assert(p != this->warnings_.end());
75f2446e
ILT
2849 gold_warning_at_location(relinfo, relnum, reloffset,
2850 "%s", p->second.text.c_str());
f6ce93d6
ILT
2851}
2852
14bfc3f5
ILT
2853// Instantiate the templates we need. We could use the configure
2854// script to restrict this to only the ones needed for implemented
2855// targets.
2856
c7912668
ILT
2857#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
2858template
2859void
2860Sized_symbol<32>::allocate_common(Output_data*, Value_type);
2861#endif
2862
2863#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
2864template
2865void
2866Sized_symbol<64>::allocate_common(Output_data*, Value_type);
2867#endif
2868
193a53d9 2869#ifdef HAVE_TARGET_32_LITTLE
14bfc3f5
ILT
2870template
2871void
193a53d9
ILT
2872Symbol_table::add_from_relobj<32, false>(
2873 Sized_relobj<32, false>* relobj,
f6ce93d6 2874 const unsigned char* syms,
14bfc3f5 2875 size_t count,
d491d34e 2876 size_t symndx_offset,
14bfc3f5
ILT
2877 const char* sym_names,
2878 size_t sym_name_size,
ae6dce4d 2879 Sized_relobj<32, false>::Symbols* sympointers,
92de84a6 2880 size_t* defined);
193a53d9 2881#endif
14bfc3f5 2882
193a53d9 2883#ifdef HAVE_TARGET_32_BIG
14bfc3f5
ILT
2884template
2885void
193a53d9
ILT
2886Symbol_table::add_from_relobj<32, true>(
2887 Sized_relobj<32, true>* relobj,
f6ce93d6 2888 const unsigned char* syms,
14bfc3f5 2889 size_t count,
d491d34e 2890 size_t symndx_offset,
14bfc3f5
ILT
2891 const char* sym_names,
2892 size_t sym_name_size,
ae6dce4d 2893 Sized_relobj<32, true>::Symbols* sympointers,
92de84a6 2894 size_t* defined);
193a53d9 2895#endif
14bfc3f5 2896
193a53d9 2897#ifdef HAVE_TARGET_64_LITTLE
14bfc3f5
ILT
2898template
2899void
193a53d9
ILT
2900Symbol_table::add_from_relobj<64, false>(
2901 Sized_relobj<64, false>* relobj,
f6ce93d6 2902 const unsigned char* syms,
14bfc3f5 2903 size_t count,
d491d34e 2904 size_t symndx_offset,
14bfc3f5
ILT
2905 const char* sym_names,
2906 size_t sym_name_size,
ae6dce4d 2907 Sized_relobj<64, false>::Symbols* sympointers,
92de84a6 2908 size_t* defined);
193a53d9 2909#endif
14bfc3f5 2910
193a53d9 2911#ifdef HAVE_TARGET_64_BIG
14bfc3f5
ILT
2912template
2913void
193a53d9
ILT
2914Symbol_table::add_from_relobj<64, true>(
2915 Sized_relobj<64, true>* relobj,
f6ce93d6 2916 const unsigned char* syms,
14bfc3f5 2917 size_t count,
d491d34e 2918 size_t symndx_offset,
14bfc3f5
ILT
2919 const char* sym_names,
2920 size_t sym_name_size,
ae6dce4d 2921 Sized_relobj<64, true>::Symbols* sympointers,
92de84a6 2922 size_t* defined);
193a53d9 2923#endif
14bfc3f5 2924
89fc3421
CC
2925#ifdef HAVE_TARGET_32_LITTLE
2926template
2927Symbol*
2928Symbol_table::add_from_pluginobj<32, false>(
2929 Sized_pluginobj<32, false>* obj,
2930 const char* name,
2931 const char* ver,
2932 elfcpp::Sym<32, false>* sym);
2933#endif
2934
2935#ifdef HAVE_TARGET_32_BIG
2936template
2937Symbol*
2938Symbol_table::add_from_pluginobj<32, true>(
2939 Sized_pluginobj<32, true>* obj,
2940 const char* name,
2941 const char* ver,
2942 elfcpp::Sym<32, true>* sym);
2943#endif
2944
2945#ifdef HAVE_TARGET_64_LITTLE
2946template
2947Symbol*
2948Symbol_table::add_from_pluginobj<64, false>(
2949 Sized_pluginobj<64, false>* obj,
2950 const char* name,
2951 const char* ver,
2952 elfcpp::Sym<64, false>* sym);
2953#endif
2954
2955#ifdef HAVE_TARGET_64_BIG
2956template
2957Symbol*
2958Symbol_table::add_from_pluginobj<64, true>(
2959 Sized_pluginobj<64, true>* obj,
2960 const char* name,
2961 const char* ver,
2962 elfcpp::Sym<64, true>* sym);
2963#endif
2964
193a53d9 2965#ifdef HAVE_TARGET_32_LITTLE
dbe717ef
ILT
2966template
2967void
193a53d9
ILT
2968Symbol_table::add_from_dynobj<32, false>(
2969 Sized_dynobj<32, false>* dynobj,
dbe717ef
ILT
2970 const unsigned char* syms,
2971 size_t count,
2972 const char* sym_names,
2973 size_t sym_name_size,
2974 const unsigned char* versym,
2975 size_t versym_size,
92de84a6
ILT
2976 const std::vector<const char*>* version_map,
2977 Sized_relobj<32, false>::Symbols* sympointers,
2978 size_t* defined);
193a53d9 2979#endif
dbe717ef 2980
193a53d9 2981#ifdef HAVE_TARGET_32_BIG
dbe717ef
ILT
2982template
2983void
193a53d9
ILT
2984Symbol_table::add_from_dynobj<32, true>(
2985 Sized_dynobj<32, true>* dynobj,
dbe717ef
ILT
2986 const unsigned char* syms,
2987 size_t count,
2988 const char* sym_names,
2989 size_t sym_name_size,
2990 const unsigned char* versym,
2991 size_t versym_size,
92de84a6
ILT
2992 const std::vector<const char*>* version_map,
2993 Sized_relobj<32, true>::Symbols* sympointers,
2994 size_t* defined);
193a53d9 2995#endif
dbe717ef 2996
193a53d9 2997#ifdef HAVE_TARGET_64_LITTLE
dbe717ef
ILT
2998template
2999void
193a53d9
ILT
3000Symbol_table::add_from_dynobj<64, false>(
3001 Sized_dynobj<64, false>* dynobj,
dbe717ef
ILT
3002 const unsigned char* syms,
3003 size_t count,
3004 const char* sym_names,
3005 size_t sym_name_size,
3006 const unsigned char* versym,
3007 size_t versym_size,
92de84a6
ILT
3008 const std::vector<const char*>* version_map,
3009 Sized_relobj<64, false>::Symbols* sympointers,
3010 size_t* defined);
193a53d9 3011#endif
dbe717ef 3012
193a53d9 3013#ifdef HAVE_TARGET_64_BIG
dbe717ef
ILT
3014template
3015void
193a53d9
ILT
3016Symbol_table::add_from_dynobj<64, true>(
3017 Sized_dynobj<64, true>* dynobj,
dbe717ef
ILT
3018 const unsigned char* syms,
3019 size_t count,
3020 const char* sym_names,
3021 size_t sym_name_size,
3022 const unsigned char* versym,
3023 size_t versym_size,
92de84a6
ILT
3024 const std::vector<const char*>* version_map,
3025 Sized_relobj<64, true>::Symbols* sympointers,
3026 size_t* defined);
193a53d9 3027#endif
dbe717ef 3028
46fe1623
ILT
3029#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
3030template
3031void
fe8718a4 3032Symbol_table::define_with_copy_reloc<32>(
fe8718a4
ILT
3033 Sized_symbol<32>* sym,
3034 Output_data* posd,
3035 elfcpp::Elf_types<32>::Elf_Addr value);
46fe1623
ILT
3036#endif
3037
3038#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
3039template
3040void
fe8718a4 3041Symbol_table::define_with_copy_reloc<64>(
fe8718a4
ILT
3042 Sized_symbol<64>* sym,
3043 Output_data* posd,
3044 elfcpp::Elf_types<64>::Elf_Addr value);
46fe1623
ILT
3045#endif
3046
75f2446e
ILT
3047#ifdef HAVE_TARGET_32_LITTLE
3048template
3049void
3050Warnings::issue_warning<32, false>(const Symbol* sym,
3051 const Relocate_info<32, false>* relinfo,
3052 size_t relnum, off_t reloffset) const;
3053#endif
3054
3055#ifdef HAVE_TARGET_32_BIG
3056template
3057void
3058Warnings::issue_warning<32, true>(const Symbol* sym,
3059 const Relocate_info<32, true>* relinfo,
3060 size_t relnum, off_t reloffset) const;
3061#endif
3062
3063#ifdef HAVE_TARGET_64_LITTLE
3064template
3065void
3066Warnings::issue_warning<64, false>(const Symbol* sym,
3067 const Relocate_info<64, false>* relinfo,
3068 size_t relnum, off_t reloffset) const;
3069#endif
3070
3071#ifdef HAVE_TARGET_64_BIG
3072template
3073void
3074Warnings::issue_warning<64, true>(const Symbol* sym,
3075 const Relocate_info<64, true>* relinfo,
3076 size_t relnum, off_t reloffset) const;
3077#endif
3078
14bfc3f5 3079} // End namespace gold.