Commit | Line | Data |
---|---|---|
14bfc3f5 ILT |
1 | // resolve.cc -- symbol resolution for gold |
2 | ||
b90efa5b | 3 | // Copyright (C) 2006-2015 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 | ||
25 | #include "elfcpp.h" | |
26 | #include "target.h" | |
27 | #include "object.h" | |
28 | #include "symtab.h" | |
89fc3421 | 29 | #include "plugin.h" |
14bfc3f5 ILT |
30 | |
31 | namespace gold | |
32 | { | |
33 | ||
1564db8d ILT |
34 | // Symbol methods used in this file. |
35 | ||
75517b77 ILT |
36 | // This symbol is being overridden by another symbol whose version is |
37 | // VERSION. Update the VERSION_ field accordingly. | |
38 | ||
39 | inline void | |
2ea97941 | 40 | Symbol::override_version(const char* version) |
75517b77 | 41 | { |
2ea97941 | 42 | if (version == NULL) |
75517b77 ILT |
43 | { |
44 | // This is the case where this symbol is NAME/VERSION, and the | |
45 | // version was not marked as hidden. That makes it the default | |
46 | // version, so we create NAME/NULL. Later we see another symbol | |
47 | // NAME/NULL, and that symbol is overriding this one. In this | |
48 | // case, since NAME/VERSION is the default, we make NAME/NULL | |
49 | // override NAME/VERSION as well. They are already the same | |
50 | // Symbol structure. Setting the VERSION_ field to NULL ensures | |
51 | // that it will be output with the correct, empty, version. | |
2ea97941 | 52 | this->version_ = version; |
75517b77 ILT |
53 | } |
54 | else | |
55 | { | |
56 | // This is the case where this symbol is NAME/VERSION_ONE, and | |
57 | // now we see NAME/VERSION_TWO, and NAME/VERSION_TWO is | |
58 | // overriding NAME. If VERSION_ONE and VERSION_TWO are | |
59 | // different, then this can only happen when VERSION_ONE is NULL | |
60 | // and VERSION_TWO is not hidden. | |
2ea97941 ILT |
61 | gold_assert(this->version_ == version || this->version_ == NULL); |
62 | this->version_ = version; | |
75517b77 ILT |
63 | } |
64 | } | |
65 | ||
0602e05a ILT |
66 | // This symbol is being overidden by another symbol whose visibility |
67 | // is VISIBILITY. Updated the VISIBILITY_ field accordingly. | |
68 | ||
69 | inline void | |
2ea97941 | 70 | Symbol::override_visibility(elfcpp::STV visibility) |
0602e05a ILT |
71 | { |
72 | // The rule for combining visibility is that we always choose the | |
73 | // most constrained visibility. In order of increasing constraint, | |
74 | // visibility goes PROTECTED, HIDDEN, INTERNAL. This is the reverse | |
75 | // of the numeric values, so the effect is that we always want the | |
76 | // smallest non-zero value. | |
2ea97941 | 77 | if (visibility != elfcpp::STV_DEFAULT) |
0602e05a ILT |
78 | { |
79 | if (this->visibility_ == elfcpp::STV_DEFAULT) | |
2ea97941 ILT |
80 | this->visibility_ = visibility; |
81 | else if (this->visibility_ > visibility) | |
82 | this->visibility_ = visibility; | |
0602e05a ILT |
83 | } |
84 | } | |
85 | ||
1564db8d ILT |
86 | // Override the fields in Symbol. |
87 | ||
88 | template<int size, bool big_endian> | |
89 | void | |
90 | Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym, | |
d491d34e | 91 | unsigned int st_shndx, bool is_ordinary, |
2ea97941 | 92 | Object* object, const char* version) |
1564db8d | 93 | { |
a3ad94ed | 94 | gold_assert(this->source_ == FROM_OBJECT); |
2ea97941 ILT |
95 | this->u_.from_object.object = object; |
96 | this->override_version(version); | |
d491d34e ILT |
97 | this->u_.from_object.shndx = st_shndx; |
98 | this->is_ordinary_shndx_ = is_ordinary; | |
32364e50 CC |
99 | // Don't override st_type from plugin placeholder symbols. |
100 | if (object->pluginobj() == NULL) | |
358de988 L |
101 | { |
102 | // Turn IFUNC symbols from shared libraries into normal FUNC symbols. | |
103 | elfcpp::STT type = sym.get_st_type(); | |
104 | if (object->is_dynamic() && type == elfcpp::STT_GNU_IFUNC) | |
105 | type = elfcpp::STT_FUNC; | |
106 | this->type_ = type; | |
107 | } | |
1564db8d | 108 | this->binding_ = sym.get_st_bind(); |
0602e05a | 109 | this->override_visibility(sym.get_st_visibility()); |
ead1e424 | 110 | this->nonvis_ = sym.get_st_nonvis(); |
2ea97941 | 111 | if (object->is_dynamic()) |
0d4f1889 ILT |
112 | this->in_dyn_ = true; |
113 | else | |
114 | this->in_reg_ = true; | |
1564db8d ILT |
115 | } |
116 | ||
117 | // Override the fields in Sized_symbol. | |
118 | ||
119 | template<int size> | |
120 | template<bool big_endian> | |
121 | void | |
122 | Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym, | |
d491d34e | 123 | unsigned st_shndx, bool is_ordinary, |
2ea97941 | 124 | Object* object, const char* version) |
1564db8d | 125 | { |
2ea97941 | 126 | this->override_base(sym, st_shndx, is_ordinary, object, version); |
1564db8d | 127 | this->value_ = sym.get_st_value(); |
ead1e424 | 128 | this->symsize_ = sym.get_st_size(); |
1564db8d ILT |
129 | } |
130 | ||
aeddab66 ILT |
131 | // Override TOSYM with symbol FROMSYM, defined in OBJECT, with version |
132 | // VERSION. This handles all aliases of TOSYM. | |
133 | ||
134 | template<int size, bool big_endian> | |
135 | void | |
136 | Symbol_table::override(Sized_symbol<size>* tosym, | |
137 | const elfcpp::Sym<size, big_endian>& fromsym, | |
d491d34e | 138 | unsigned int st_shndx, bool is_ordinary, |
2ea97941 | 139 | Object* object, const char* version) |
aeddab66 | 140 | { |
2ea97941 | 141 | tosym->override(fromsym, st_shndx, is_ordinary, object, version); |
aeddab66 ILT |
142 | if (tosym->has_alias()) |
143 | { | |
144 | Symbol* sym = this->weak_aliases_[tosym]; | |
145 | gold_assert(sym != NULL); | |
7d1a9ebb | 146 | Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
147 | do |
148 | { | |
2ea97941 | 149 | ssym->override(fromsym, st_shndx, is_ordinary, object, version); |
aeddab66 ILT |
150 | sym = this->weak_aliases_[ssym]; |
151 | gold_assert(sym != NULL); | |
7d1a9ebb | 152 | ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
153 | } |
154 | while (ssym != tosym); | |
155 | } | |
156 | } | |
157 | ||
86f2e683 ILT |
158 | // The resolve functions build a little code for each symbol. |
159 | // Bit 0: 0 for global, 1 for weak. | |
160 | // Bit 1: 0 for regular object, 1 for shared object | |
161 | // Bits 2-3: 0 for normal, 1 for undefined, 2 for common | |
162 | // This gives us values from 0 to 11. | |
163 | ||
164 | static const int global_or_weak_shift = 0; | |
165 | static const unsigned int global_flag = 0 << global_or_weak_shift; | |
166 | static const unsigned int weak_flag = 1 << global_or_weak_shift; | |
167 | ||
168 | static const int regular_or_dynamic_shift = 1; | |
169 | static const unsigned int regular_flag = 0 << regular_or_dynamic_shift; | |
170 | static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift; | |
171 | ||
172 | static const int def_undef_or_common_shift = 2; | |
173 | static const unsigned int def_flag = 0 << def_undef_or_common_shift; | |
174 | static const unsigned int undef_flag = 1 << def_undef_or_common_shift; | |
175 | static const unsigned int common_flag = 2 << def_undef_or_common_shift; | |
176 | ||
70e654ba ILT |
177 | // This convenience function combines all the flags based on facts |
178 | // about the symbol. | |
179 | ||
180 | static unsigned int | |
181 | symbol_to_bits(elfcpp::STB binding, bool is_dynamic, | |
b8cf5075 | 182 | unsigned int shndx, bool is_ordinary) |
70e654ba ILT |
183 | { |
184 | unsigned int bits; | |
185 | ||
186 | switch (binding) | |
187 | { | |
188 | case elfcpp::STB_GLOBAL: | |
adcf2816 | 189 | case elfcpp::STB_GNU_UNIQUE: |
70e654ba ILT |
190 | bits = global_flag; |
191 | break; | |
192 | ||
193 | case elfcpp::STB_WEAK: | |
194 | bits = weak_flag; | |
195 | break; | |
196 | ||
197 | case elfcpp::STB_LOCAL: | |
198 | // We should only see externally visible symbols in the symbol | |
199 | // table. | |
200 | gold_error(_("invalid STB_LOCAL symbol in external symbols")); | |
201 | bits = global_flag; | |
202 | ||
203 | default: | |
204 | // Any target which wants to handle STB_LOOS, etc., needs to | |
205 | // define a resolve method. | |
ac897c20 | 206 | gold_error(_("unsupported symbol binding %d"), static_cast<int>(binding)); |
70e654ba ILT |
207 | bits = global_flag; |
208 | } | |
209 | ||
210 | if (is_dynamic) | |
211 | bits |= dynamic_flag; | |
212 | else | |
213 | bits |= regular_flag; | |
214 | ||
215 | switch (shndx) | |
216 | { | |
217 | case elfcpp::SHN_UNDEF: | |
218 | bits |= undef_flag; | |
219 | break; | |
220 | ||
221 | case elfcpp::SHN_COMMON: | |
d491d34e ILT |
222 | if (!is_ordinary) |
223 | bits |= common_flag; | |
70e654ba ILT |
224 | break; |
225 | ||
226 | default: | |
b8cf5075 | 227 | if (!is_ordinary && Symbol::is_common_shndx(shndx)) |
8a5e3e08 | 228 | bits |= common_flag; |
70e654ba ILT |
229 | else |
230 | bits |= def_flag; | |
231 | break; | |
232 | } | |
233 | ||
234 | return bits; | |
235 | } | |
236 | ||
14bfc3f5 | 237 | // Resolve a symbol. This is called the second and subsequent times |
d491d34e ILT |
238 | // we see a symbol. TO is the pre-existing symbol. ST_SHNDX is the |
239 | // section index for SYM, possibly adjusted for many sections. | |
240 | // IS_ORDINARY is whether ST_SHNDX is a normal section index rather | |
241 | // than a special code. ORIG_ST_SHNDX is the original section index, | |
242 | // before any munging because of discarded sections, except that all | |
95d14cd3 | 243 | // non-ordinary section indexes are mapped to SHN_UNDEF. VERSION is |
d491d34e | 244 | // the version of SYM. |
14bfc3f5 ILT |
245 | |
246 | template<int size, bool big_endian> | |
247 | void | |
1564db8d | 248 | Symbol_table::resolve(Sized_symbol<size>* to, |
14bfc3f5 | 249 | const elfcpp::Sym<size, big_endian>& sym, |
d491d34e ILT |
250 | unsigned int st_shndx, bool is_ordinary, |
251 | unsigned int orig_st_shndx, | |
b45e00b3 CC |
252 | Object* object, const char* version, |
253 | bool is_default_version) | |
14bfc3f5 | 254 | { |
534b4e5f ILT |
255 | // It's possible for a symbol to be defined in an object file |
256 | // using .symver to give it a version, and for there to also be | |
257 | // a linker script giving that symbol the same version. We | |
258 | // don't want to give a multiple-definition error for this | |
259 | // harmless redefinition. | |
260 | bool to_is_ordinary; | |
261 | if (to->source() == Symbol::FROM_OBJECT | |
262 | && to->object() == object | |
263 | && is_ordinary | |
264 | && to->is_defined() | |
265 | && to->shndx(&to_is_ordinary) == st_shndx | |
266 | && to_is_ordinary | |
267 | && to->value() == sym.get_st_value()) | |
268 | return; | |
269 | ||
029ba973 | 270 | if (parameters->target().has_resolve()) |
14bfc3f5 | 271 | { |
274e99f9 | 272 | Sized_target<size, big_endian>* sized_target; |
029ba973 | 273 | sized_target = parameters->sized_target<size, big_endian>(); |
14b31740 | 274 | sized_target->resolve(to, sym, object, version); |
14bfc3f5 ILT |
275 | return; |
276 | } | |
277 | ||
86f2e683 ILT |
278 | if (!object->is_dynamic()) |
279 | { | |
b8cf5075 CC |
280 | if (sym.get_st_type() == elfcpp::STT_COMMON |
281 | && (is_ordinary || !Symbol::is_common_shndx(st_shndx))) | |
282 | { | |
283 | gold_warning(_("STT_COMMON symbol '%s' in %s " | |
284 | "is not in a common section"), | |
285 | to->demangled_name().c_str(), | |
286 | to->object()->name().c_str()); | |
287 | return; | |
288 | } | |
86f2e683 ILT |
289 | // Record that we've seen this symbol in a regular object. |
290 | to->set_in_reg(); | |
291 | } | |
2da73f13 CC |
292 | else if (st_shndx == elfcpp::SHN_UNDEF |
293 | && (to->visibility() == elfcpp::STV_HIDDEN | |
294 | || to->visibility() == elfcpp::STV_INTERNAL)) | |
645afe0c | 295 | { |
c20ceeb2 YW |
296 | // The symbol is hidden, so a reference from a shared object |
297 | // cannot bind to it. We tried issuing a warning in this case, | |
298 | // but that produces false positives when the symbol is | |
299 | // actually resolved in a different shared object (PR 15574). | |
645afe0c CC |
300 | return; |
301 | } | |
86f2e683 ILT |
302 | else |
303 | { | |
304 | // Record that we've seen this symbol in a dynamic object. | |
305 | to->set_in_dyn(); | |
306 | } | |
14bfc3f5 | 307 | |
89fc3421 CC |
308 | // Record if we've seen this symbol in a real ELF object (i.e., the |
309 | // symbol is referenced from outside the world known to the plugin). | |
f7c5b166 | 310 | if (object->pluginobj() == NULL && !object->is_dynamic()) |
89fc3421 CC |
311 | to->set_in_real_elf(); |
312 | ||
313 | // If we're processing replacement files, allow new symbols to override | |
314 | // the placeholders from the plugin objects. | |
6168c2a1 RÁE |
315 | // Treat common symbols specially since it is possible that an ELF |
316 | // file increased the size of the alignment. | |
89fc3421 CC |
317 | if (to->source() == Symbol::FROM_OBJECT) |
318 | { | |
319 | Pluginobj* obj = to->object()->pluginobj(); | |
320 | if (obj != NULL | |
1707f183 | 321 | && parameters->options().plugins()->in_replacement_phase()) |
89fc3421 | 322 | { |
1707f183 CC |
323 | bool adjust_common = false; |
324 | typename Sized_symbol<size>::Size_type tosize = 0; | |
325 | typename Sized_symbol<size>::Value_type tovalue = 0; | |
b8cf5075 CC |
326 | if (to->is_common() |
327 | && !is_ordinary && Symbol::is_common_shndx(st_shndx)) | |
1707f183 CC |
328 | { |
329 | adjust_common = true; | |
db4c9594 CC |
330 | tosize = to->symsize(); |
331 | tovalue = to->value(); | |
1707f183 CC |
332 | } |
333 | this->override(to, sym, st_shndx, is_ordinary, object, version); | |
334 | if (adjust_common) | |
335 | { | |
336 | if (tosize > to->symsize()) | |
337 | to->set_symsize(tosize); | |
338 | if (tovalue > to->value()) | |
339 | to->set_value(tovalue); | |
340 | } | |
341 | return; | |
89fc3421 CC |
342 | } |
343 | } | |
344 | ||
ba4d53bf ILT |
345 | // A new weak undefined reference, merging with an old weak |
346 | // reference, could be a One Definition Rule (ODR) violation -- | |
347 | // especially if the types or sizes of the references differ. We'll | |
348 | // store such pairs and look them up later to make sure they | |
349 | // actually refer to the same lines of code. We also check | |
350 | // combinations of weak and strong, which might occur if one case is | |
351 | // inline and the other is not. (Note: not all ODR violations can | |
352 | // be found this way, and not everything this finds is an ODR | |
353 | // violation. But it's helpful to warn about.) | |
ba4d53bf ILT |
354 | if (parameters->options().detect_odr_violations() |
355 | && (sym.get_st_bind() == elfcpp::STB_WEAK | |
356 | || to->binding() == elfcpp::STB_WEAK) | |
357 | && orig_st_shndx != elfcpp::SHN_UNDEF | |
358 | && to->shndx(&to_is_ordinary) != elfcpp::SHN_UNDEF | |
359 | && to_is_ordinary | |
360 | && sym.get_st_size() != 0 // Ignore weird 0-sized symbols. | |
361 | && to->symsize() != 0 | |
362 | && (sym.get_st_type() != to->type() | |
363 | || sym.get_st_size() != to->symsize()) | |
364 | // C does not have a concept of ODR, so we only need to do this | |
365 | // on C++ symbols. These have (mangled) names starting with _Z. | |
366 | && to->name()[0] == '_' && to->name()[1] == 'Z') | |
367 | { | |
368 | Symbol_location fromloc | |
76677ad0 | 369 | = { object, orig_st_shndx, static_cast<off_t>(sym.get_st_value()) }; |
ba4d53bf | 370 | Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary), |
76677ad0 | 371 | static_cast<off_t>(to->value()) }; |
ba4d53bf ILT |
372 | this->candidate_odr_violations_[to->name()].insert(fromloc); |
373 | this->candidate_odr_violations_[to->name()].insert(toloc); | |
374 | } | |
375 | ||
32364e50 CC |
376 | // Plugins don't provide a symbol type, so adopt the existing type |
377 | // if the FROM symbol is from a plugin. | |
378 | elfcpp::STT fromtype = (object->pluginobj() != NULL | |
379 | ? to->type() | |
380 | : sym.get_st_type()); | |
70e654ba ILT |
381 | unsigned int frombits = symbol_to_bits(sym.get_st_bind(), |
382 | object->is_dynamic(), | |
b8cf5075 | 383 | st_shndx, is_ordinary); |
14bfc3f5 | 384 | |
86f2e683 | 385 | bool adjust_common_sizes; |
ce279a62 | 386 | bool adjust_dyndef; |
1ae4d23b | 387 | typename Sized_symbol<size>::Size_type tosize = to->symsize(); |
32364e50 | 388 | if (Symbol_table::should_override(to, frombits, fromtype, OBJECT, |
62855347 | 389 | object, &adjust_common_sizes, |
b45e00b3 | 390 | &adjust_dyndef, is_default_version)) |
86f2e683 | 391 | { |
ce279a62 | 392 | elfcpp::STB tobinding = to->binding(); |
fd325007 | 393 | typename Sized_symbol<size>::Value_type tovalue = to->value(); |
d491d34e | 394 | this->override(to, sym, st_shndx, is_ordinary, object, version); |
fd325007 ILT |
395 | if (adjust_common_sizes) |
396 | { | |
397 | if (tosize > to->symsize()) | |
398 | to->set_symsize(tosize); | |
399 | if (tovalue > to->value()) | |
400 | to->set_value(tovalue); | |
401 | } | |
ce279a62 CC |
402 | if (adjust_dyndef) |
403 | { | |
404 | // We are overriding an UNDEF or WEAK UNDEF with a DYN DEF. | |
405 | // Remember which kind of UNDEF it was for future reference. | |
406 | to->set_undef_binding(tobinding); | |
407 | } | |
86f2e683 ILT |
408 | } |
409 | else | |
410 | { | |
fd325007 ILT |
411 | if (adjust_common_sizes) |
412 | { | |
413 | if (sym.get_st_size() > tosize) | |
414 | to->set_symsize(sym.get_st_size()); | |
415 | if (sym.get_st_value() > to->value()) | |
416 | to->set_value(sym.get_st_value()); | |
417 | } | |
ce279a62 CC |
418 | if (adjust_dyndef) |
419 | { | |
420 | // We are keeping a DYN DEF after seeing an UNDEF or WEAK UNDEF. | |
421 | // Remember which kind of UNDEF it was. | |
422 | to->set_undef_binding(sym.get_st_bind()); | |
423 | } | |
0602e05a ILT |
424 | // The ELF ABI says that even for a reference to a symbol we |
425 | // merge the visibility. | |
426 | to->override_visibility(sym.get_st_visibility()); | |
86f2e683 | 427 | } |
70e654ba | 428 | |
1ae4d23b ILT |
429 | if (adjust_common_sizes && parameters->options().warn_common()) |
430 | { | |
431 | if (tosize > sym.get_st_size()) | |
432 | Symbol_table::report_resolve_problem(false, | |
433 | _("common of '%s' overriding " | |
434 | "smaller common"), | |
99fff23b | 435 | to, OBJECT, object); |
1ae4d23b ILT |
436 | else if (tosize < sym.get_st_size()) |
437 | Symbol_table::report_resolve_problem(false, | |
438 | _("common of '%s' overidden by " | |
439 | "larger common"), | |
99fff23b | 440 | to, OBJECT, object); |
1ae4d23b ILT |
441 | else |
442 | Symbol_table::report_resolve_problem(false, | |
443 | _("multiple common of '%s'"), | |
99fff23b | 444 | to, OBJECT, object); |
1ae4d23b | 445 | } |
86f2e683 ILT |
446 | } |
447 | ||
448 | // Handle the core of symbol resolution. This is called with the | |
449 | // existing symbol, TO, and a bitflag describing the new symbol. This | |
450 | // returns true if we should override the existing symbol with the new | |
451 | // one, and returns false otherwise. It sets *ADJUST_COMMON_SIZES to | |
452 | // true if we should set the symbol size to the maximum of the TO and | |
453 | // FROM sizes. It handles error conditions. | |
454 | ||
455 | bool | |
456 | Symbol_table::should_override(const Symbol* to, unsigned int frombits, | |
62855347 ILT |
457 | elfcpp::STT fromtype, Defined defined, |
458 | Object* object, bool* adjust_common_sizes, | |
b45e00b3 | 459 | bool* adjust_dyndef, bool is_default_version) |
86f2e683 ILT |
460 | { |
461 | *adjust_common_sizes = false; | |
ce279a62 | 462 | *adjust_dyndef = false; |
86f2e683 | 463 | |
e5756efb | 464 | unsigned int tobits; |
f3e9c5c5 | 465 | if (to->source() == Symbol::IS_UNDEFINED) |
b8cf5075 | 466 | tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_UNDEF, true); |
f3e9c5c5 | 467 | else if (to->source() != Symbol::FROM_OBJECT) |
b8cf5075 | 468 | tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false); |
e5756efb | 469 | else |
d491d34e ILT |
470 | { |
471 | bool is_ordinary; | |
472 | unsigned int shndx = to->shndx(&is_ordinary); | |
473 | tobits = symbol_to_bits(to->binding(), | |
474 | to->object()->is_dynamic(), | |
475 | shndx, | |
b8cf5075 | 476 | is_ordinary); |
d491d34e | 477 | } |
14bfc3f5 | 478 | |
32364e50 CC |
479 | if ((to->type() == elfcpp::STT_TLS) ^ (fromtype == elfcpp::STT_TLS) |
480 | && !to->is_placeholder()) | |
62855347 ILT |
481 | Symbol_table::report_resolve_problem(true, |
482 | _("symbol '%s' used as both __thread " | |
483 | "and non-__thread"), | |
484 | to, defined, object); | |
1564db8d | 485 | |
14bfc3f5 ILT |
486 | // We use a giant switch table for symbol resolution. This code is |
487 | // unwieldy, but: 1) it is efficient; 2) we definitely handle all | |
488 | // cases; 3) it is easy to change the handling of a particular case. | |
489 | // The alternative would be a series of conditionals, but it is easy | |
490 | // to get the ordering wrong. This could also be done as a table, | |
491 | // but that is no easier to understand than this large switch | |
492 | // statement. | |
493 | ||
86f2e683 ILT |
494 | // These are the values generated by the bit codes. |
495 | enum | |
496 | { | |
497 | DEF = global_flag | regular_flag | def_flag, | |
498 | WEAK_DEF = weak_flag | regular_flag | def_flag, | |
499 | DYN_DEF = global_flag | dynamic_flag | def_flag, | |
500 | DYN_WEAK_DEF = weak_flag | dynamic_flag | def_flag, | |
501 | UNDEF = global_flag | regular_flag | undef_flag, | |
502 | WEAK_UNDEF = weak_flag | regular_flag | undef_flag, | |
503 | DYN_UNDEF = global_flag | dynamic_flag | undef_flag, | |
504 | DYN_WEAK_UNDEF = weak_flag | dynamic_flag | undef_flag, | |
505 | COMMON = global_flag | regular_flag | common_flag, | |
506 | WEAK_COMMON = weak_flag | regular_flag | common_flag, | |
507 | DYN_COMMON = global_flag | dynamic_flag | common_flag, | |
508 | DYN_WEAK_COMMON = weak_flag | dynamic_flag | common_flag | |
509 | }; | |
510 | ||
14bfc3f5 ILT |
511 | switch (tobits * 16 + frombits) |
512 | { | |
513 | case DEF * 16 + DEF: | |
12e14209 | 514 | // Two definitions of the same symbol. |
878405a8 ILT |
515 | |
516 | // If either symbol is defined by an object included using | |
517 | // --just-symbols, then don't warn. This is for compatibility | |
518 | // with the GNU linker. FIXME: This is a hack. | |
519 | if ((to->source() == Symbol::FROM_OBJECT && to->object()->just_symbols()) | |
99fff23b | 520 | || (object != NULL && object->just_symbols())) |
878405a8 ILT |
521 | return false; |
522 | ||
9c4ae156 | 523 | if (!parameters->options().muldefs()) |
30bc8c46 ILT |
524 | Symbol_table::report_resolve_problem(true, |
525 | _("multiple definition of '%s'"), | |
526 | to, defined, object); | |
86f2e683 | 527 | return false; |
14bfc3f5 ILT |
528 | |
529 | case WEAK_DEF * 16 + DEF: | |
1564db8d ILT |
530 | // We've seen a weak definition, and now we see a strong |
531 | // definition. In the original SVR4 linker, this was treated as | |
532 | // a multiple definition error. In the Solaris linker and the | |
533 | // GNU linker, a weak definition followed by a regular | |
534 | // definition causes the weak definition to be overridden. We | |
535 | // are currently compatible with the GNU linker. In the future | |
536 | // we should add a target specific option to change this. | |
537 | // FIXME. | |
86f2e683 | 538 | return true; |
14bfc3f5 ILT |
539 | |
540 | case DYN_DEF * 16 + DEF: | |
541 | case DYN_WEAK_DEF * 16 + DEF: | |
1564db8d ILT |
542 | // We've seen a definition in a dynamic object, and now we see a |
543 | // definition in a regular object. The definition in the | |
544 | // regular object overrides the definition in the dynamic | |
545 | // object. | |
86f2e683 | 546 | return true; |
1564db8d | 547 | |
14bfc3f5 ILT |
548 | case UNDEF * 16 + DEF: |
549 | case WEAK_UNDEF * 16 + DEF: | |
550 | case DYN_UNDEF * 16 + DEF: | |
551 | case DYN_WEAK_UNDEF * 16 + DEF: | |
1564db8d ILT |
552 | // We've seen an undefined reference, and now we see a |
553 | // definition. We use the definition. | |
86f2e683 | 554 | return true; |
1564db8d | 555 | |
14bfc3f5 ILT |
556 | case COMMON * 16 + DEF: |
557 | case WEAK_COMMON * 16 + DEF: | |
558 | case DYN_COMMON * 16 + DEF: | |
559 | case DYN_WEAK_COMMON * 16 + DEF: | |
1564db8d | 560 | // We've seen a common symbol and now we see a definition. The |
1ae4d23b ILT |
561 | // definition overrides. |
562 | if (parameters->options().warn_common()) | |
563 | Symbol_table::report_resolve_problem(false, | |
564 | _("definition of '%s' overriding " | |
565 | "common"), | |
99fff23b | 566 | to, defined, object); |
86f2e683 | 567 | return true; |
14bfc3f5 ILT |
568 | |
569 | case DEF * 16 + WEAK_DEF: | |
570 | case WEAK_DEF * 16 + WEAK_DEF: | |
1564db8d ILT |
571 | // We've seen a definition and now we see a weak definition. We |
572 | // ignore the new weak definition. | |
86f2e683 | 573 | return false; |
1564db8d | 574 | |
14bfc3f5 ILT |
575 | case DYN_DEF * 16 + WEAK_DEF: |
576 | case DYN_WEAK_DEF * 16 + WEAK_DEF: | |
1564db8d ILT |
577 | // We've seen a dynamic definition and now we see a regular weak |
578 | // definition. The regular weak definition overrides. | |
86f2e683 | 579 | return true; |
1564db8d | 580 | |
14bfc3f5 ILT |
581 | case UNDEF * 16 + WEAK_DEF: |
582 | case WEAK_UNDEF * 16 + WEAK_DEF: | |
583 | case DYN_UNDEF * 16 + WEAK_DEF: | |
584 | case DYN_WEAK_UNDEF * 16 + WEAK_DEF: | |
1564db8d | 585 | // A weak definition of a currently undefined symbol. |
86f2e683 | 586 | return true; |
1564db8d | 587 | |
14bfc3f5 ILT |
588 | case COMMON * 16 + WEAK_DEF: |
589 | case WEAK_COMMON * 16 + WEAK_DEF: | |
1564db8d | 590 | // A weak definition does not override a common definition. |
86f2e683 | 591 | return false; |
1564db8d | 592 | |
14bfc3f5 ILT |
593 | case DYN_COMMON * 16 + WEAK_DEF: |
594 | case DYN_WEAK_COMMON * 16 + WEAK_DEF: | |
1564db8d | 595 | // A weak definition does override a definition in a dynamic |
1ae4d23b ILT |
596 | // object. |
597 | if (parameters->options().warn_common()) | |
598 | Symbol_table::report_resolve_problem(false, | |
599 | _("definition of '%s' overriding " | |
600 | "dynamic common definition"), | |
99fff23b | 601 | to, defined, object); |
86f2e683 | 602 | return true; |
14bfc3f5 ILT |
603 | |
604 | case DEF * 16 + DYN_DEF: | |
605 | case WEAK_DEF * 16 + DYN_DEF: | |
b45e00b3 CC |
606 | // Ignore a dynamic definition if we already have a definition. |
607 | return false; | |
608 | ||
14bfc3f5 ILT |
609 | case DYN_DEF * 16 + DYN_DEF: |
610 | case DYN_WEAK_DEF * 16 + DYN_DEF: | |
b45e00b3 CC |
611 | // Ignore a dynamic definition if we already have a definition, |
612 | // unless the existing definition is an unversioned definition | |
613 | // in the same dynamic object, and the new definition is a | |
614 | // default version. | |
615 | if (to->object() == object | |
616 | && to->version() == NULL | |
617 | && is_default_version) | |
618 | return true; | |
86f2e683 | 619 | return false; |
1564db8d | 620 | |
14bfc3f5 | 621 | case UNDEF * 16 + DYN_DEF: |
14bfc3f5 ILT |
622 | case DYN_UNDEF * 16 + DYN_DEF: |
623 | case DYN_WEAK_UNDEF * 16 + DYN_DEF: | |
1564db8d | 624 | // Use a dynamic definition if we have a reference. |
86f2e683 | 625 | return true; |
1564db8d | 626 | |
ce279a62 CC |
627 | case WEAK_UNDEF * 16 + DYN_DEF: |
628 | // When overriding a weak undef by a dynamic definition, | |
629 | // we need to remember that the original undef was weak. | |
630 | *adjust_dyndef = true; | |
631 | return true; | |
632 | ||
14bfc3f5 ILT |
633 | case COMMON * 16 + DYN_DEF: |
634 | case WEAK_COMMON * 16 + DYN_DEF: | |
635 | case DYN_COMMON * 16 + DYN_DEF: | |
636 | case DYN_WEAK_COMMON * 16 + DYN_DEF: | |
1564db8d ILT |
637 | // Ignore a dynamic definition if we already have a common |
638 | // definition. | |
86f2e683 | 639 | return false; |
14bfc3f5 ILT |
640 | |
641 | case DEF * 16 + DYN_WEAK_DEF: | |
642 | case WEAK_DEF * 16 + DYN_WEAK_DEF: | |
643 | case DYN_DEF * 16 + DYN_WEAK_DEF: | |
644 | case DYN_WEAK_DEF * 16 + DYN_WEAK_DEF: | |
1564db8d ILT |
645 | // Ignore a weak dynamic definition if we already have a |
646 | // definition. | |
86f2e683 | 647 | return false; |
1564db8d | 648 | |
14bfc3f5 | 649 | case UNDEF * 16 + DYN_WEAK_DEF: |
74f67560 DK |
650 | // When overriding an undef by a dynamic weak definition, |
651 | // we need to remember that the original undef was not weak. | |
652 | *adjust_dyndef = true; | |
653 | return true; | |
654 | ||
14bfc3f5 ILT |
655 | case DYN_UNDEF * 16 + DYN_WEAK_DEF: |
656 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF: | |
1564db8d | 657 | // Use a weak dynamic definition if we have a reference. |
86f2e683 | 658 | return true; |
1564db8d | 659 | |
ce279a62 CC |
660 | case WEAK_UNDEF * 16 + DYN_WEAK_DEF: |
661 | // When overriding a weak undef by a dynamic definition, | |
662 | // we need to remember that the original undef was weak. | |
663 | *adjust_dyndef = true; | |
664 | return true; | |
665 | ||
14bfc3f5 ILT |
666 | case COMMON * 16 + DYN_WEAK_DEF: |
667 | case WEAK_COMMON * 16 + DYN_WEAK_DEF: | |
668 | case DYN_COMMON * 16 + DYN_WEAK_DEF: | |
669 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF: | |
1564db8d ILT |
670 | // Ignore a weak dynamic definition if we already have a common |
671 | // definition. | |
86f2e683 | 672 | return false; |
14bfc3f5 ILT |
673 | |
674 | case DEF * 16 + UNDEF: | |
675 | case WEAK_DEF * 16 + UNDEF: | |
14bfc3f5 | 676 | case UNDEF * 16 + UNDEF: |
ead1e424 | 677 | // A new undefined reference tells us nothing. |
86f2e683 | 678 | return false; |
ead1e424 | 679 | |
ce279a62 CC |
680 | case DYN_DEF * 16 + UNDEF: |
681 | case DYN_WEAK_DEF * 16 + UNDEF: | |
682 | // For a dynamic def, we need to remember which kind of undef we see. | |
683 | *adjust_dyndef = true; | |
684 | return false; | |
685 | ||
14bfc3f5 ILT |
686 | case WEAK_UNDEF * 16 + UNDEF: |
687 | case DYN_UNDEF * 16 + UNDEF: | |
688 | case DYN_WEAK_UNDEF * 16 + UNDEF: | |
ead1e424 | 689 | // A strong undef overrides a dynamic or weak undef. |
86f2e683 | 690 | return true; |
ead1e424 | 691 | |
14bfc3f5 ILT |
692 | case COMMON * 16 + UNDEF: |
693 | case WEAK_COMMON * 16 + UNDEF: | |
694 | case DYN_COMMON * 16 + UNDEF: | |
695 | case DYN_WEAK_COMMON * 16 + UNDEF: | |
1564db8d | 696 | // A new undefined reference tells us nothing. |
86f2e683 | 697 | return false; |
14bfc3f5 ILT |
698 | |
699 | case DEF * 16 + WEAK_UNDEF: | |
700 | case WEAK_DEF * 16 + WEAK_UNDEF: | |
14bfc3f5 ILT |
701 | case UNDEF * 16 + WEAK_UNDEF: |
702 | case WEAK_UNDEF * 16 + WEAK_UNDEF: | |
703 | case DYN_UNDEF * 16 + WEAK_UNDEF: | |
14bfc3f5 ILT |
704 | case COMMON * 16 + WEAK_UNDEF: |
705 | case WEAK_COMMON * 16 + WEAK_UNDEF: | |
706 | case DYN_COMMON * 16 + WEAK_UNDEF: | |
707 | case DYN_WEAK_COMMON * 16 + WEAK_UNDEF: | |
a4649286 DK |
708 | // A new weak undefined reference tells us nothing unless the |
709 | // exisiting symbol is a dynamic weak reference. | |
86f2e683 | 710 | return false; |
14bfc3f5 | 711 | |
a4649286 DK |
712 | case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF: |
713 | // A new weak reference overrides an existing dynamic weak reference. | |
714 | // This is necessary because a dynamic weak reference remembers | |
715 | // the old binding, which may not be weak. If we keeps the existing | |
716 | // dynamic weak reference, the weakness may be dropped in the output. | |
717 | return true; | |
718 | ||
ce279a62 CC |
719 | case DYN_DEF * 16 + WEAK_UNDEF: |
720 | case DYN_WEAK_DEF * 16 + WEAK_UNDEF: | |
721 | // For a dynamic def, we need to remember which kind of undef we see. | |
722 | *adjust_dyndef = true; | |
723 | return false; | |
724 | ||
14bfc3f5 ILT |
725 | case DEF * 16 + DYN_UNDEF: |
726 | case WEAK_DEF * 16 + DYN_UNDEF: | |
727 | case DYN_DEF * 16 + DYN_UNDEF: | |
728 | case DYN_WEAK_DEF * 16 + DYN_UNDEF: | |
729 | case UNDEF * 16 + DYN_UNDEF: | |
730 | case WEAK_UNDEF * 16 + DYN_UNDEF: | |
731 | case DYN_UNDEF * 16 + DYN_UNDEF: | |
732 | case DYN_WEAK_UNDEF * 16 + DYN_UNDEF: | |
733 | case COMMON * 16 + DYN_UNDEF: | |
734 | case WEAK_COMMON * 16 + DYN_UNDEF: | |
735 | case DYN_COMMON * 16 + DYN_UNDEF: | |
736 | case DYN_WEAK_COMMON * 16 + DYN_UNDEF: | |
1564db8d | 737 | // A new dynamic undefined reference tells us nothing. |
86f2e683 | 738 | return false; |
14bfc3f5 ILT |
739 | |
740 | case DEF * 16 + DYN_WEAK_UNDEF: | |
741 | case WEAK_DEF * 16 + DYN_WEAK_UNDEF: | |
742 | case DYN_DEF * 16 + DYN_WEAK_UNDEF: | |
743 | case DYN_WEAK_DEF * 16 + DYN_WEAK_UNDEF: | |
744 | case UNDEF * 16 + DYN_WEAK_UNDEF: | |
745 | case WEAK_UNDEF * 16 + DYN_WEAK_UNDEF: | |
746 | case DYN_UNDEF * 16 + DYN_WEAK_UNDEF: | |
747 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_UNDEF: | |
748 | case COMMON * 16 + DYN_WEAK_UNDEF: | |
749 | case WEAK_COMMON * 16 + DYN_WEAK_UNDEF: | |
750 | case DYN_COMMON * 16 + DYN_WEAK_UNDEF: | |
751 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_UNDEF: | |
1564db8d | 752 | // A new weak dynamic undefined reference tells us nothing. |
86f2e683 | 753 | return false; |
14bfc3f5 ILT |
754 | |
755 | case DEF * 16 + COMMON: | |
1564db8d | 756 | // A common symbol does not override a definition. |
1ae4d23b ILT |
757 | if (parameters->options().warn_common()) |
758 | Symbol_table::report_resolve_problem(false, | |
759 | _("common '%s' overridden by " | |
760 | "previous definition"), | |
99fff23b | 761 | to, defined, object); |
86f2e683 | 762 | return false; |
1564db8d | 763 | |
14bfc3f5 ILT |
764 | case WEAK_DEF * 16 + COMMON: |
765 | case DYN_DEF * 16 + COMMON: | |
766 | case DYN_WEAK_DEF * 16 + COMMON: | |
1564db8d ILT |
767 | // A common symbol does override a weak definition or a dynamic |
768 | // definition. | |
86f2e683 | 769 | return true; |
1564db8d | 770 | |
14bfc3f5 ILT |
771 | case UNDEF * 16 + COMMON: |
772 | case WEAK_UNDEF * 16 + COMMON: | |
773 | case DYN_UNDEF * 16 + COMMON: | |
774 | case DYN_WEAK_UNDEF * 16 + COMMON: | |
1564db8d | 775 | // A common symbol is a definition for a reference. |
86f2e683 | 776 | return true; |
1564db8d | 777 | |
14bfc3f5 | 778 | case COMMON * 16 + COMMON: |
ead1e424 | 779 | // Set the size to the maximum. |
86f2e683 ILT |
780 | *adjust_common_sizes = true; |
781 | return false; | |
ead1e424 | 782 | |
14bfc3f5 | 783 | case WEAK_COMMON * 16 + COMMON: |
ead1e424 ILT |
784 | // I'm not sure just what a weak common symbol means, but |
785 | // presumably it can be overridden by a regular common symbol. | |
86f2e683 | 786 | return true; |
ead1e424 | 787 | |
14bfc3f5 ILT |
788 | case DYN_COMMON * 16 + COMMON: |
789 | case DYN_WEAK_COMMON * 16 + COMMON: | |
86f2e683 ILT |
790 | // Use the real common symbol, but adjust the size if necessary. |
791 | *adjust_common_sizes = true; | |
792 | return true; | |
14bfc3f5 ILT |
793 | |
794 | case DEF * 16 + WEAK_COMMON: | |
795 | case WEAK_DEF * 16 + WEAK_COMMON: | |
796 | case DYN_DEF * 16 + WEAK_COMMON: | |
797 | case DYN_WEAK_DEF * 16 + WEAK_COMMON: | |
ead1e424 ILT |
798 | // Whatever a weak common symbol is, it won't override a |
799 | // definition. | |
86f2e683 | 800 | return false; |
ead1e424 | 801 | |
14bfc3f5 ILT |
802 | case UNDEF * 16 + WEAK_COMMON: |
803 | case WEAK_UNDEF * 16 + WEAK_COMMON: | |
804 | case DYN_UNDEF * 16 + WEAK_COMMON: | |
805 | case DYN_WEAK_UNDEF * 16 + WEAK_COMMON: | |
ead1e424 | 806 | // A weak common symbol is better than an undefined symbol. |
86f2e683 | 807 | return true; |
ead1e424 | 808 | |
14bfc3f5 ILT |
809 | case COMMON * 16 + WEAK_COMMON: |
810 | case WEAK_COMMON * 16 + WEAK_COMMON: | |
811 | case DYN_COMMON * 16 + WEAK_COMMON: | |
812 | case DYN_WEAK_COMMON * 16 + WEAK_COMMON: | |
ead1e424 ILT |
813 | // Ignore a weak common symbol in the presence of a real common |
814 | // symbol. | |
86f2e683 | 815 | return false; |
14bfc3f5 ILT |
816 | |
817 | case DEF * 16 + DYN_COMMON: | |
818 | case WEAK_DEF * 16 + DYN_COMMON: | |
819 | case DYN_DEF * 16 + DYN_COMMON: | |
820 | case DYN_WEAK_DEF * 16 + DYN_COMMON: | |
ead1e424 ILT |
821 | // Ignore a dynamic common symbol in the presence of a |
822 | // definition. | |
86f2e683 | 823 | return false; |
ead1e424 | 824 | |
14bfc3f5 ILT |
825 | case UNDEF * 16 + DYN_COMMON: |
826 | case WEAK_UNDEF * 16 + DYN_COMMON: | |
827 | case DYN_UNDEF * 16 + DYN_COMMON: | |
828 | case DYN_WEAK_UNDEF * 16 + DYN_COMMON: | |
ead1e424 | 829 | // A dynamic common symbol is a definition of sorts. |
86f2e683 | 830 | return true; |
ead1e424 | 831 | |
14bfc3f5 ILT |
832 | case COMMON * 16 + DYN_COMMON: |
833 | case WEAK_COMMON * 16 + DYN_COMMON: | |
834 | case DYN_COMMON * 16 + DYN_COMMON: | |
835 | case DYN_WEAK_COMMON * 16 + DYN_COMMON: | |
ead1e424 | 836 | // Set the size to the maximum. |
86f2e683 ILT |
837 | *adjust_common_sizes = true; |
838 | return false; | |
14bfc3f5 ILT |
839 | |
840 | case DEF * 16 + DYN_WEAK_COMMON: | |
841 | case WEAK_DEF * 16 + DYN_WEAK_COMMON: | |
842 | case DYN_DEF * 16 + DYN_WEAK_COMMON: | |
843 | case DYN_WEAK_DEF * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 844 | // A common symbol is ignored in the face of a definition. |
86f2e683 | 845 | return false; |
ead1e424 | 846 | |
14bfc3f5 ILT |
847 | case UNDEF * 16 + DYN_WEAK_COMMON: |
848 | case WEAK_UNDEF * 16 + DYN_WEAK_COMMON: | |
849 | case DYN_UNDEF * 16 + DYN_WEAK_COMMON: | |
850 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 851 | // I guess a weak common symbol is better than a definition. |
86f2e683 | 852 | return true; |
ead1e424 | 853 | |
14bfc3f5 ILT |
854 | case COMMON * 16 + DYN_WEAK_COMMON: |
855 | case WEAK_COMMON * 16 + DYN_WEAK_COMMON: | |
856 | case DYN_COMMON * 16 + DYN_WEAK_COMMON: | |
857 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 858 | // Set the size to the maximum. |
86f2e683 ILT |
859 | *adjust_common_sizes = true; |
860 | return false; | |
1564db8d ILT |
861 | |
862 | default: | |
a3ad94ed | 863 | gold_unreachable(); |
14bfc3f5 ILT |
864 | } |
865 | } | |
866 | ||
1ae4d23b ILT |
867 | // Issue an error or warning due to symbol resolution. IS_ERROR |
868 | // indicates an error rather than a warning. MSG is the error | |
869 | // message; it is expected to have a %s for the symbol name. TO is | |
99fff23b ILT |
870 | // the existing symbol. DEFINED/OBJECT is where the new symbol was |
871 | // found. | |
1ae4d23b ILT |
872 | |
873 | // FIXME: We should have better location information here. When the | |
874 | // symbol is defined, we should be able to pull the location from the | |
875 | // debug info if there is any. | |
876 | ||
877 | void | |
878 | Symbol_table::report_resolve_problem(bool is_error, const char* msg, | |
99fff23b ILT |
879 | const Symbol* to, Defined defined, |
880 | Object* object) | |
1ae4d23b ILT |
881 | { |
882 | std::string demangled(to->demangled_name()); | |
883 | size_t len = strlen(msg) + demangled.length() + 10; | |
884 | char* buf = new char[len]; | |
885 | snprintf(buf, len, msg, demangled.c_str()); | |
886 | ||
887 | const char* objname; | |
99fff23b ILT |
888 | switch (defined) |
889 | { | |
890 | case OBJECT: | |
891 | objname = object->name().c_str(); | |
892 | break; | |
893 | case COPY: | |
894 | objname = _("COPY reloc"); | |
895 | break; | |
896 | case DEFSYM: | |
897 | case UNDEFINED: | |
898 | objname = _("command line"); | |
899 | break; | |
900 | case SCRIPT: | |
901 | objname = _("linker script"); | |
902 | break; | |
903 | case PREDEFINED: | |
5146f448 | 904 | case INCREMENTAL_BASE: |
99fff23b ILT |
905 | objname = _("linker defined"); |
906 | break; | |
907 | default: | |
908 | gold_unreachable(); | |
909 | } | |
1ae4d23b ILT |
910 | |
911 | if (is_error) | |
912 | gold_error("%s: %s", objname, buf); | |
913 | else | |
914 | gold_warning("%s: %s", objname, buf); | |
915 | ||
916 | delete[] buf; | |
917 | ||
918 | if (to->source() == Symbol::FROM_OBJECT) | |
919 | objname = to->object()->name().c_str(); | |
920 | else | |
921 | objname = _("command line"); | |
922 | gold_info("%s: %s: previous definition here", program_name, objname); | |
923 | } | |
924 | ||
86f2e683 ILT |
925 | // A special case of should_override which is only called for a strong |
926 | // defined symbol from a regular object file. This is used when | |
927 | // defining special symbols. | |
928 | ||
929 | bool | |
62855347 ILT |
930 | Symbol_table::should_override_with_special(const Symbol* to, |
931 | elfcpp::STT fromtype, | |
932 | Defined defined) | |
86f2e683 ILT |
933 | { |
934 | bool adjust_common_sizes; | |
ce279a62 | 935 | bool adjust_dyn_def; |
86f2e683 | 936 | unsigned int frombits = global_flag | regular_flag | def_flag; |
62855347 ILT |
937 | bool ret = Symbol_table::should_override(to, frombits, fromtype, defined, |
938 | NULL, &adjust_common_sizes, | |
b45e00b3 | 939 | &adjust_dyn_def, false); |
ce279a62 | 940 | gold_assert(!adjust_common_sizes && !adjust_dyn_def); |
86f2e683 ILT |
941 | return ret; |
942 | } | |
943 | ||
944 | // Override symbol base with a special symbol. | |
945 | ||
946 | void | |
947 | Symbol::override_base_with_special(const Symbol* from) | |
948 | { | |
21131061 ILT |
949 | bool same_name = this->name_ == from->name_; |
950 | gold_assert(same_name || this->has_alias()); | |
46fe1623 | 951 | |
d1bddd3c CC |
952 | // If we are overriding an undef, remember the original binding. |
953 | if (this->is_undefined()) | |
954 | this->set_undef_binding(this->binding_); | |
955 | ||
86f2e683 ILT |
956 | this->source_ = from->source_; |
957 | switch (from->source_) | |
958 | { | |
959 | case FROM_OBJECT: | |
960 | this->u_.from_object = from->u_.from_object; | |
961 | break; | |
962 | case IN_OUTPUT_DATA: | |
963 | this->u_.in_output_data = from->u_.in_output_data; | |
964 | break; | |
965 | case IN_OUTPUT_SEGMENT: | |
966 | this->u_.in_output_segment = from->u_.in_output_segment; | |
967 | break; | |
f3e9c5c5 ILT |
968 | case IS_CONSTANT: |
969 | case IS_UNDEFINED: | |
86f2e683 ILT |
970 | break; |
971 | default: | |
972 | gold_unreachable(); | |
973 | break; | |
974 | } | |
975 | ||
21131061 | 976 | if (same_name) |
24d47b34 ILT |
977 | { |
978 | // When overriding a versioned symbol with a special symbol, we | |
979 | // may be changing the version. This will happen if we see a | |
980 | // special symbol such as "_end" defined in a shared object with | |
981 | // one version (from a version script), but we want to define it | |
982 | // here with a different version (from a different version | |
983 | // script). | |
984 | this->version_ = from->version_; | |
985 | } | |
86f2e683 ILT |
986 | this->type_ = from->type_; |
987 | this->binding_ = from->binding_; | |
0602e05a | 988 | this->override_visibility(from->visibility_); |
86f2e683 ILT |
989 | this->nonvis_ = from->nonvis_; |
990 | ||
991 | // Special symbols are always considered to be regular symbols. | |
992 | this->in_reg_ = true; | |
46fe1623 ILT |
993 | |
994 | if (from->needs_dynsym_entry_) | |
995 | this->needs_dynsym_entry_ = true; | |
996 | if (from->needs_dynsym_value_) | |
997 | this->needs_dynsym_value_ = true; | |
998 | ||
5146f448 CC |
999 | this->is_predefined_ = from->is_predefined_; |
1000 | ||
46fe1623 ILT |
1001 | // We shouldn't see these flags. If we do, we need to handle them |
1002 | // somehow. | |
46fe1623 | 1003 | gold_assert(!from->is_forwarder_); |
880cd20d | 1004 | gold_assert(!from->has_plt_offset()); |
46fe1623 ILT |
1005 | gold_assert(!from->has_warning_); |
1006 | gold_assert(!from->is_copied_from_dynobj_); | |
55a93433 | 1007 | gold_assert(!from->is_forced_local_); |
86f2e683 ILT |
1008 | } |
1009 | ||
1010 | // Override a symbol with a special symbol. | |
1011 | ||
1012 | template<int size> | |
1013 | void | |
1014 | Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from) | |
1015 | { | |
1016 | this->override_base_with_special(from); | |
1017 | this->value_ = from->value_; | |
1018 | this->symsize_ = from->symsize_; | |
1019 | } | |
1020 | ||
aeddab66 ILT |
1021 | // Override TOSYM with the special symbol FROMSYM. This handles all |
1022 | // aliases of TOSYM. | |
1023 | ||
1024 | template<int size> | |
1025 | void | |
1026 | Symbol_table::override_with_special(Sized_symbol<size>* tosym, | |
1027 | const Sized_symbol<size>* fromsym) | |
1028 | { | |
1029 | tosym->override_with_special(fromsym); | |
1030 | if (tosym->has_alias()) | |
1031 | { | |
1032 | Symbol* sym = this->weak_aliases_[tosym]; | |
1033 | gold_assert(sym != NULL); | |
7d1a9ebb | 1034 | Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
1035 | do |
1036 | { | |
1037 | ssym->override_with_special(fromsym); | |
1038 | sym = this->weak_aliases_[ssym]; | |
1039 | gold_assert(sym != NULL); | |
7d1a9ebb | 1040 | ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
1041 | } |
1042 | while (ssym != tosym); | |
1043 | } | |
0602e05a ILT |
1044 | if (tosym->binding() == elfcpp::STB_LOCAL |
1045 | || ((tosym->visibility() == elfcpp::STV_HIDDEN | |
1046 | || tosym->visibility() == elfcpp::STV_INTERNAL) | |
1047 | && (tosym->binding() == elfcpp::STB_GLOBAL | |
adcf2816 | 1048 | || tosym->binding() == elfcpp::STB_GNU_UNIQUE |
0602e05a ILT |
1049 | || tosym->binding() == elfcpp::STB_WEAK) |
1050 | && !parameters->options().relocatable())) | |
55a93433 | 1051 | this->force_local(tosym); |
aeddab66 ILT |
1052 | } |
1053 | ||
14bfc3f5 ILT |
1054 | // Instantiate the templates we need. We could use the configure |
1055 | // script to restrict this to only the ones needed for implemented | |
1056 | // targets. | |
1057 | ||
6cfaf60b DK |
1058 | // We have to instantiate both big and little endian versions because |
1059 | // these are used by other templates that depends on size only. | |
1060 | ||
1061 | #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) | |
14bfc3f5 ILT |
1062 | template |
1063 | void | |
193a53d9 | 1064 | Symbol_table::resolve<32, false>( |
1564db8d | 1065 | Sized_symbol<32>* to, |
193a53d9 | 1066 | const elfcpp::Sym<32, false>& sym, |
d491d34e ILT |
1067 | unsigned int st_shndx, |
1068 | bool is_ordinary, | |
1069 | unsigned int orig_st_shndx, | |
14b31740 | 1070 | Object* object, |
b45e00b3 CC |
1071 | const char* version, |
1072 | bool is_default_version); | |
14bfc3f5 ILT |
1073 | |
1074 | template | |
1075 | void | |
193a53d9 | 1076 | Symbol_table::resolve<32, true>( |
1564db8d | 1077 | Sized_symbol<32>* to, |
193a53d9 | 1078 | const elfcpp::Sym<32, true>& sym, |
d491d34e ILT |
1079 | unsigned int st_shndx, |
1080 | bool is_ordinary, | |
1081 | unsigned int orig_st_shndx, | |
14b31740 | 1082 | Object* object, |
b45e00b3 CC |
1083 | const char* version, |
1084 | bool is_default_version); | |
193a53d9 | 1085 | #endif |
14bfc3f5 | 1086 | |
6cfaf60b | 1087 | #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) |
14bfc3f5 ILT |
1088 | template |
1089 | void | |
193a53d9 | 1090 | Symbol_table::resolve<64, false>( |
1564db8d | 1091 | Sized_symbol<64>* to, |
193a53d9 | 1092 | const elfcpp::Sym<64, false>& sym, |
d491d34e ILT |
1093 | unsigned int st_shndx, |
1094 | bool is_ordinary, | |
1095 | unsigned int orig_st_shndx, | |
14b31740 | 1096 | Object* object, |
b45e00b3 CC |
1097 | const char* version, |
1098 | bool is_default_version); | |
14bfc3f5 ILT |
1099 | |
1100 | template | |
1101 | void | |
193a53d9 | 1102 | Symbol_table::resolve<64, true>( |
1564db8d | 1103 | Sized_symbol<64>* to, |
193a53d9 | 1104 | const elfcpp::Sym<64, true>& sym, |
d491d34e ILT |
1105 | unsigned int st_shndx, |
1106 | bool is_ordinary, | |
1107 | unsigned int orig_st_shndx, | |
14b31740 | 1108 | Object* object, |
b45e00b3 CC |
1109 | const char* version, |
1110 | bool is_default_version); | |
193a53d9 | 1111 | #endif |
14bfc3f5 | 1112 | |
86f2e683 ILT |
1113 | #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) |
1114 | template | |
1115 | void | |
aeddab66 ILT |
1116 | Symbol_table::override_with_special<32>(Sized_symbol<32>*, |
1117 | const Sized_symbol<32>*); | |
86f2e683 ILT |
1118 | #endif |
1119 | ||
1120 | #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) | |
1121 | template | |
1122 | void | |
aeddab66 ILT |
1123 | Symbol_table::override_with_special<64>(Sized_symbol<64>*, |
1124 | const Sized_symbol<64>*); | |
86f2e683 ILT |
1125 | #endif |
1126 | ||
14bfc3f5 | 1127 | } // End namespace gold. |