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