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