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