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