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