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