Commit | Line | Data |
---|---|---|
14bfc3f5 ILT |
1 | // resolve.cc -- symbol resolution for gold |
2 | ||
e5756efb | 3 | // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <iant@google.com>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
14bfc3f5 ILT |
23 | #include "gold.h" |
24 | ||
25 | #include "elfcpp.h" | |
26 | #include "target.h" | |
27 | #include "object.h" | |
28 | #include "symtab.h" | |
29 | ||
30 | namespace gold | |
31 | { | |
32 | ||
1564db8d ILT |
33 | // Symbol methods used in this file. |
34 | ||
35 | // Override the fields in Symbol. | |
36 | ||
37 | template<int size, bool big_endian> | |
38 | void | |
39 | Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym, | |
14b31740 | 40 | Object* object, const char* version) |
1564db8d | 41 | { |
a3ad94ed | 42 | gold_assert(this->source_ == FROM_OBJECT); |
ead1e424 | 43 | this->u_.from_object.object = object; |
14b31740 ILT |
44 | if (version != NULL && this->version() != version) |
45 | { | |
46 | gold_assert(this->version() == NULL); | |
47 | this->version_ = version; | |
48 | } | |
ead1e424 | 49 | // FIXME: Handle SHN_XINDEX. |
16649710 | 50 | this->u_.from_object.shndx = sym.get_st_shndx(); |
1564db8d ILT |
51 | this->type_ = sym.get_st_type(); |
52 | this->binding_ = sym.get_st_bind(); | |
53 | this->visibility_ = sym.get_st_visibility(); | |
ead1e424 | 54 | this->nonvis_ = sym.get_st_nonvis(); |
0d4f1889 ILT |
55 | if (object->is_dynamic()) |
56 | this->in_dyn_ = true; | |
57 | else | |
58 | this->in_reg_ = true; | |
1564db8d ILT |
59 | } |
60 | ||
61 | // Override the fields in Sized_symbol. | |
62 | ||
63 | template<int size> | |
64 | template<bool big_endian> | |
65 | void | |
66 | Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym, | |
14b31740 | 67 | Object* object, const char* version) |
1564db8d | 68 | { |
14b31740 | 69 | this->override_base(sym, object, version); |
1564db8d | 70 | this->value_ = sym.get_st_value(); |
ead1e424 | 71 | this->symsize_ = sym.get_st_size(); |
1564db8d ILT |
72 | } |
73 | ||
aeddab66 ILT |
74 | // Override TOSYM with symbol FROMSYM, defined in OBJECT, with version |
75 | // VERSION. This handles all aliases of TOSYM. | |
76 | ||
77 | template<int size, bool big_endian> | |
78 | void | |
79 | Symbol_table::override(Sized_symbol<size>* tosym, | |
80 | const elfcpp::Sym<size, big_endian>& fromsym, | |
81 | Object* object, const char* version) | |
82 | { | |
83 | tosym->override(fromsym, object, version); | |
84 | if (tosym->has_alias()) | |
85 | { | |
86 | Symbol* sym = this->weak_aliases_[tosym]; | |
87 | gold_assert(sym != NULL); | |
7d1a9ebb | 88 | Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
89 | do |
90 | { | |
91 | ssym->override(fromsym, object, version); | |
92 | sym = this->weak_aliases_[ssym]; | |
93 | gold_assert(sym != NULL); | |
7d1a9ebb | 94 | ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
95 | } |
96 | while (ssym != tosym); | |
97 | } | |
98 | } | |
99 | ||
86f2e683 ILT |
100 | // The resolve functions build a little code for each symbol. |
101 | // Bit 0: 0 for global, 1 for weak. | |
102 | // Bit 1: 0 for regular object, 1 for shared object | |
103 | // Bits 2-3: 0 for normal, 1 for undefined, 2 for common | |
104 | // This gives us values from 0 to 11. | |
105 | ||
106 | static const int global_or_weak_shift = 0; | |
107 | static const unsigned int global_flag = 0 << global_or_weak_shift; | |
108 | static const unsigned int weak_flag = 1 << global_or_weak_shift; | |
109 | ||
110 | static const int regular_or_dynamic_shift = 1; | |
111 | static const unsigned int regular_flag = 0 << regular_or_dynamic_shift; | |
112 | static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift; | |
113 | ||
114 | static const int def_undef_or_common_shift = 2; | |
115 | static const unsigned int def_flag = 0 << def_undef_or_common_shift; | |
116 | static const unsigned int undef_flag = 1 << def_undef_or_common_shift; | |
117 | static const unsigned int common_flag = 2 << def_undef_or_common_shift; | |
118 | ||
70e654ba ILT |
119 | // This convenience function combines all the flags based on facts |
120 | // about the symbol. | |
121 | ||
122 | static unsigned int | |
123 | symbol_to_bits(elfcpp::STB binding, bool is_dynamic, | |
124 | unsigned int shndx, elfcpp::STT type) | |
125 | { | |
126 | unsigned int bits; | |
127 | ||
128 | switch (binding) | |
129 | { | |
130 | case elfcpp::STB_GLOBAL: | |
131 | bits = global_flag; | |
132 | break; | |
133 | ||
134 | case elfcpp::STB_WEAK: | |
135 | bits = weak_flag; | |
136 | break; | |
137 | ||
138 | case elfcpp::STB_LOCAL: | |
139 | // We should only see externally visible symbols in the symbol | |
140 | // table. | |
141 | gold_error(_("invalid STB_LOCAL symbol in external symbols")); | |
142 | bits = global_flag; | |
143 | ||
144 | default: | |
145 | // Any target which wants to handle STB_LOOS, etc., needs to | |
146 | // define a resolve method. | |
147 | gold_error(_("unsupported symbol binding")); | |
148 | bits = global_flag; | |
149 | } | |
150 | ||
151 | if (is_dynamic) | |
152 | bits |= dynamic_flag; | |
153 | else | |
154 | bits |= regular_flag; | |
155 | ||
156 | switch (shndx) | |
157 | { | |
158 | case elfcpp::SHN_UNDEF: | |
159 | bits |= undef_flag; | |
160 | break; | |
161 | ||
162 | case elfcpp::SHN_COMMON: | |
163 | bits |= common_flag; | |
164 | break; | |
165 | ||
166 | default: | |
167 | if (type == elfcpp::STT_COMMON) | |
168 | bits |= common_flag; | |
169 | else | |
170 | bits |= def_flag; | |
171 | break; | |
172 | } | |
173 | ||
174 | return bits; | |
175 | } | |
176 | ||
14bfc3f5 | 177 | // Resolve a symbol. This is called the second and subsequent times |
70e654ba ILT |
178 | // we see a symbol. TO is the pre-existing symbol. ORIG_SYM is the |
179 | // new symbol, seen in OBJECT. SYM is almost always identical to | |
180 | // ORIG_SYM, but may be munged (for instance, if we determine the | |
181 | // symbol is in a to-be-discarded section, we'll set sym's shndx to | |
182 | // UNDEFINED). VERSION of the version of SYM. | |
14bfc3f5 ILT |
183 | |
184 | template<int size, bool big_endian> | |
185 | void | |
1564db8d | 186 | Symbol_table::resolve(Sized_symbol<size>* to, |
14bfc3f5 | 187 | const elfcpp::Sym<size, big_endian>& sym, |
70e654ba | 188 | const elfcpp::Sym<size, big_endian>& orig_sym, |
14b31740 | 189 | Object* object, const char* version) |
14bfc3f5 ILT |
190 | { |
191 | if (object->target()->has_resolve()) | |
192 | { | |
274e99f9 | 193 | Sized_target<size, big_endian>* sized_target; |
7d1a9ebb | 194 | sized_target = object->sized_target<size, big_endian>(); |
14b31740 | 195 | sized_target->resolve(to, sym, object, version); |
14bfc3f5 ILT |
196 | return; |
197 | } | |
198 | ||
86f2e683 ILT |
199 | if (!object->is_dynamic()) |
200 | { | |
201 | // Record that we've seen this symbol in a regular object. | |
202 | to->set_in_reg(); | |
203 | } | |
204 | else | |
205 | { | |
206 | // Record that we've seen this symbol in a dynamic object. | |
207 | to->set_in_dyn(); | |
208 | } | |
14bfc3f5 | 209 | |
70e654ba ILT |
210 | unsigned int frombits = symbol_to_bits(sym.get_st_bind(), |
211 | object->is_dynamic(), | |
212 | sym.get_st_shndx(), | |
213 | sym.get_st_type()); | |
14bfc3f5 | 214 | |
86f2e683 | 215 | bool adjust_common_sizes; |
d20222a1 ILT |
216 | if (Symbol_table::should_override(to, frombits, object, |
217 | &adjust_common_sizes)) | |
86f2e683 ILT |
218 | { |
219 | typename Sized_symbol<size>::Size_type tosize = to->symsize(); | |
220 | ||
aeddab66 | 221 | this->override(to, sym, object, version); |
86f2e683 ILT |
222 | |
223 | if (adjust_common_sizes && tosize > to->symsize()) | |
224 | to->set_symsize(tosize); | |
225 | } | |
226 | else | |
227 | { | |
228 | if (adjust_common_sizes && sym.get_st_size() > to->symsize()) | |
229 | to->set_symsize(sym.get_st_size()); | |
230 | } | |
70e654ba ILT |
231 | |
232 | // A new weak undefined reference, merging with an old weak | |
233 | // reference, could be a One Definition Rule (ODR) violation -- | |
234 | // especially if the types or sizes of the references differ. We'll | |
235 | // store such pairs and look them up later to make sure they | |
236 | // actually refer to the same lines of code. (Note: not all ODR | |
237 | // violations can be found this way, and not everything this finds | |
238 | // is an ODR violation. But it's helpful to warn about.) | |
239 | // We use orig_sym here because we want the symbol exactly as it | |
240 | // appears in the object file, not munged via our future processing. | |
8851ecca | 241 | if (parameters->options().detect_odr_violations() |
a55ce7fe | 242 | && orig_sym.get_st_bind() == elfcpp::STB_WEAK |
70e654ba ILT |
243 | && to->binding() == elfcpp::STB_WEAK |
244 | && orig_sym.get_st_shndx() != elfcpp::SHN_UNDEF | |
245 | && to->shndx() != elfcpp::SHN_UNDEF | |
246 | && orig_sym.get_st_size() != 0 // Ignore weird 0-sized symbols. | |
247 | && to->symsize() != 0 | |
248 | && (orig_sym.get_st_type() != to->type() | |
249 | || orig_sym.get_st_size() != to->symsize()) | |
250 | // C does not have a concept of ODR, so we only need to do this | |
251 | // on C++ symbols. These have (mangled) names starting with _Z. | |
252 | && to->name()[0] == '_' && to->name()[1] == 'Z') | |
253 | { | |
a2b1aa12 | 254 | Symbol_location fromloc |
70e654ba | 255 | = { object, orig_sym.get_st_shndx(), orig_sym.get_st_value() }; |
a2b1aa12 ILT |
256 | Symbol_location toloc = { to->object(), to->shndx(), to->value() }; |
257 | this->candidate_odr_violations_[to->name()].insert(fromloc); | |
258 | this->candidate_odr_violations_[to->name()].insert(toloc); | |
70e654ba | 259 | } |
86f2e683 ILT |
260 | } |
261 | ||
262 | // Handle the core of symbol resolution. This is called with the | |
263 | // existing symbol, TO, and a bitflag describing the new symbol. This | |
264 | // returns true if we should override the existing symbol with the new | |
265 | // one, and returns false otherwise. It sets *ADJUST_COMMON_SIZES to | |
266 | // true if we should set the symbol size to the maximum of the TO and | |
267 | // FROM sizes. It handles error conditions. | |
268 | ||
269 | bool | |
270 | Symbol_table::should_override(const Symbol* to, unsigned int frombits, | |
d20222a1 | 271 | Object* object, bool* adjust_common_sizes) |
86f2e683 ILT |
272 | { |
273 | *adjust_common_sizes = false; | |
274 | ||
e5756efb ILT |
275 | unsigned int tobits; |
276 | if (to->source() == Symbol::FROM_OBJECT) | |
277 | tobits = symbol_to_bits(to->binding(), | |
278 | to->object()->is_dynamic(), | |
279 | to->shndx(), | |
280 | to->type()); | |
281 | else | |
282 | tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, | |
283 | to->type()); | |
14bfc3f5 | 284 | |
1564db8d ILT |
285 | // FIXME: Warn if either but not both of TO and SYM are STT_TLS. |
286 | ||
14bfc3f5 ILT |
287 | // We use a giant switch table for symbol resolution. This code is |
288 | // unwieldy, but: 1) it is efficient; 2) we definitely handle all | |
289 | // cases; 3) it is easy to change the handling of a particular case. | |
290 | // The alternative would be a series of conditionals, but it is easy | |
291 | // to get the ordering wrong. This could also be done as a table, | |
292 | // but that is no easier to understand than this large switch | |
293 | // statement. | |
294 | ||
86f2e683 ILT |
295 | // These are the values generated by the bit codes. |
296 | enum | |
297 | { | |
298 | DEF = global_flag | regular_flag | def_flag, | |
299 | WEAK_DEF = weak_flag | regular_flag | def_flag, | |
300 | DYN_DEF = global_flag | dynamic_flag | def_flag, | |
301 | DYN_WEAK_DEF = weak_flag | dynamic_flag | def_flag, | |
302 | UNDEF = global_flag | regular_flag | undef_flag, | |
303 | WEAK_UNDEF = weak_flag | regular_flag | undef_flag, | |
304 | DYN_UNDEF = global_flag | dynamic_flag | undef_flag, | |
305 | DYN_WEAK_UNDEF = weak_flag | dynamic_flag | undef_flag, | |
306 | COMMON = global_flag | regular_flag | common_flag, | |
307 | WEAK_COMMON = weak_flag | regular_flag | common_flag, | |
308 | DYN_COMMON = global_flag | dynamic_flag | common_flag, | |
309 | DYN_WEAK_COMMON = weak_flag | dynamic_flag | common_flag | |
310 | }; | |
311 | ||
14bfc3f5 ILT |
312 | switch (tobits * 16 + frombits) |
313 | { | |
314 | case DEF * 16 + DEF: | |
12e14209 | 315 | // Two definitions of the same symbol. |
878405a8 ILT |
316 | |
317 | // If either symbol is defined by an object included using | |
318 | // --just-symbols, then don't warn. This is for compatibility | |
319 | // with the GNU linker. FIXME: This is a hack. | |
320 | if ((to->source() == Symbol::FROM_OBJECT && to->object()->just_symbols()) | |
321 | || object->just_symbols()) | |
322 | return false; | |
323 | ||
d20222a1 ILT |
324 | // FIXME: Do a better job of reporting locations. |
325 | gold_error(_("%s: multiple definition of %s"), | |
326 | object != NULL ? object->name().c_str() : _("command line"), | |
a2b1aa12 | 327 | to->demangled_name().c_str()); |
d20222a1 ILT |
328 | gold_error(_("%s: previous definition here"), |
329 | (to->source() == Symbol::FROM_OBJECT | |
330 | ? to->object()->name().c_str() | |
331 | : _("command line"))); | |
86f2e683 | 332 | return false; |
14bfc3f5 ILT |
333 | |
334 | case WEAK_DEF * 16 + DEF: | |
1564db8d ILT |
335 | // We've seen a weak definition, and now we see a strong |
336 | // definition. In the original SVR4 linker, this was treated as | |
337 | // a multiple definition error. In the Solaris linker and the | |
338 | // GNU linker, a weak definition followed by a regular | |
339 | // definition causes the weak definition to be overridden. We | |
340 | // are currently compatible with the GNU linker. In the future | |
341 | // we should add a target specific option to change this. | |
342 | // FIXME. | |
86f2e683 | 343 | return true; |
14bfc3f5 ILT |
344 | |
345 | case DYN_DEF * 16 + DEF: | |
346 | case DYN_WEAK_DEF * 16 + DEF: | |
1564db8d ILT |
347 | // We've seen a definition in a dynamic object, and now we see a |
348 | // definition in a regular object. The definition in the | |
349 | // regular object overrides the definition in the dynamic | |
350 | // object. | |
86f2e683 | 351 | return true; |
1564db8d | 352 | |
14bfc3f5 ILT |
353 | case UNDEF * 16 + DEF: |
354 | case WEAK_UNDEF * 16 + DEF: | |
355 | case DYN_UNDEF * 16 + DEF: | |
356 | case DYN_WEAK_UNDEF * 16 + DEF: | |
1564db8d ILT |
357 | // We've seen an undefined reference, and now we see a |
358 | // definition. We use the definition. | |
86f2e683 | 359 | return true; |
1564db8d | 360 | |
14bfc3f5 ILT |
361 | case COMMON * 16 + DEF: |
362 | case WEAK_COMMON * 16 + DEF: | |
363 | case DYN_COMMON * 16 + DEF: | |
364 | case DYN_WEAK_COMMON * 16 + DEF: | |
1564db8d | 365 | // We've seen a common symbol and now we see a definition. The |
14b31740 | 366 | // definition overrides. FIXME: We should optionally issue, version a |
1564db8d | 367 | // warning. |
86f2e683 | 368 | return true; |
14bfc3f5 ILT |
369 | |
370 | case DEF * 16 + WEAK_DEF: | |
371 | case WEAK_DEF * 16 + WEAK_DEF: | |
1564db8d ILT |
372 | // We've seen a definition and now we see a weak definition. We |
373 | // ignore the new weak definition. | |
86f2e683 | 374 | return false; |
1564db8d | 375 | |
14bfc3f5 ILT |
376 | case DYN_DEF * 16 + WEAK_DEF: |
377 | case DYN_WEAK_DEF * 16 + WEAK_DEF: | |
1564db8d ILT |
378 | // We've seen a dynamic definition and now we see a regular weak |
379 | // definition. The regular weak definition overrides. | |
86f2e683 | 380 | return true; |
1564db8d | 381 | |
14bfc3f5 ILT |
382 | case UNDEF * 16 + WEAK_DEF: |
383 | case WEAK_UNDEF * 16 + WEAK_DEF: | |
384 | case DYN_UNDEF * 16 + WEAK_DEF: | |
385 | case DYN_WEAK_UNDEF * 16 + WEAK_DEF: | |
1564db8d | 386 | // A weak definition of a currently undefined symbol. |
86f2e683 | 387 | return true; |
1564db8d | 388 | |
14bfc3f5 ILT |
389 | case COMMON * 16 + WEAK_DEF: |
390 | case WEAK_COMMON * 16 + WEAK_DEF: | |
1564db8d | 391 | // A weak definition does not override a common definition. |
86f2e683 | 392 | return false; |
1564db8d | 393 | |
14bfc3f5 ILT |
394 | case DYN_COMMON * 16 + WEAK_DEF: |
395 | case DYN_WEAK_COMMON * 16 + WEAK_DEF: | |
1564db8d ILT |
396 | // A weak definition does override a definition in a dynamic |
397 | // object. FIXME: We should optionally issue a warning. | |
86f2e683 | 398 | return true; |
14bfc3f5 ILT |
399 | |
400 | case DEF * 16 + DYN_DEF: | |
401 | case WEAK_DEF * 16 + DYN_DEF: | |
402 | case DYN_DEF * 16 + DYN_DEF: | |
403 | case DYN_WEAK_DEF * 16 + DYN_DEF: | |
1564db8d | 404 | // Ignore a dynamic definition if we already have a definition. |
86f2e683 | 405 | return false; |
1564db8d | 406 | |
14bfc3f5 ILT |
407 | case UNDEF * 16 + DYN_DEF: |
408 | case WEAK_UNDEF * 16 + DYN_DEF: | |
409 | case DYN_UNDEF * 16 + DYN_DEF: | |
410 | case DYN_WEAK_UNDEF * 16 + DYN_DEF: | |
1564db8d | 411 | // Use a dynamic definition if we have a reference. |
86f2e683 | 412 | return true; |
1564db8d | 413 | |
14bfc3f5 ILT |
414 | case COMMON * 16 + DYN_DEF: |
415 | case WEAK_COMMON * 16 + DYN_DEF: | |
416 | case DYN_COMMON * 16 + DYN_DEF: | |
417 | case DYN_WEAK_COMMON * 16 + DYN_DEF: | |
1564db8d ILT |
418 | // Ignore a dynamic definition if we already have a common |
419 | // definition. | |
86f2e683 | 420 | return false; |
14bfc3f5 ILT |
421 | |
422 | case DEF * 16 + DYN_WEAK_DEF: | |
423 | case WEAK_DEF * 16 + DYN_WEAK_DEF: | |
424 | case DYN_DEF * 16 + DYN_WEAK_DEF: | |
425 | case DYN_WEAK_DEF * 16 + DYN_WEAK_DEF: | |
1564db8d ILT |
426 | // Ignore a weak dynamic definition if we already have a |
427 | // definition. | |
86f2e683 | 428 | return false; |
1564db8d | 429 | |
14bfc3f5 ILT |
430 | case UNDEF * 16 + DYN_WEAK_DEF: |
431 | case WEAK_UNDEF * 16 + DYN_WEAK_DEF: | |
432 | case DYN_UNDEF * 16 + DYN_WEAK_DEF: | |
433 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF: | |
1564db8d | 434 | // Use a weak dynamic definition if we have a reference. |
86f2e683 | 435 | return true; |
1564db8d | 436 | |
14bfc3f5 ILT |
437 | case COMMON * 16 + DYN_WEAK_DEF: |
438 | case WEAK_COMMON * 16 + DYN_WEAK_DEF: | |
439 | case DYN_COMMON * 16 + DYN_WEAK_DEF: | |
440 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF: | |
1564db8d ILT |
441 | // Ignore a weak dynamic definition if we already have a common |
442 | // definition. | |
86f2e683 | 443 | return false; |
14bfc3f5 ILT |
444 | |
445 | case DEF * 16 + UNDEF: | |
446 | case WEAK_DEF * 16 + UNDEF: | |
447 | case DYN_DEF * 16 + UNDEF: | |
448 | case DYN_WEAK_DEF * 16 + UNDEF: | |
449 | case UNDEF * 16 + UNDEF: | |
ead1e424 | 450 | // A new undefined reference tells us nothing. |
86f2e683 | 451 | return false; |
ead1e424 | 452 | |
14bfc3f5 ILT |
453 | case WEAK_UNDEF * 16 + UNDEF: |
454 | case DYN_UNDEF * 16 + UNDEF: | |
455 | case DYN_WEAK_UNDEF * 16 + UNDEF: | |
ead1e424 | 456 | // A strong undef overrides a dynamic or weak undef. |
86f2e683 | 457 | return true; |
ead1e424 | 458 | |
14bfc3f5 ILT |
459 | case COMMON * 16 + UNDEF: |
460 | case WEAK_COMMON * 16 + UNDEF: | |
461 | case DYN_COMMON * 16 + UNDEF: | |
462 | case DYN_WEAK_COMMON * 16 + UNDEF: | |
1564db8d | 463 | // A new undefined reference tells us nothing. |
86f2e683 | 464 | return false; |
14bfc3f5 ILT |
465 | |
466 | case DEF * 16 + WEAK_UNDEF: | |
467 | case WEAK_DEF * 16 + WEAK_UNDEF: | |
468 | case DYN_DEF * 16 + WEAK_UNDEF: | |
469 | case DYN_WEAK_DEF * 16 + WEAK_UNDEF: | |
470 | case UNDEF * 16 + WEAK_UNDEF: | |
471 | case WEAK_UNDEF * 16 + WEAK_UNDEF: | |
472 | case DYN_UNDEF * 16 + WEAK_UNDEF: | |
473 | case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF: | |
474 | case COMMON * 16 + WEAK_UNDEF: | |
475 | case WEAK_COMMON * 16 + WEAK_UNDEF: | |
476 | case DYN_COMMON * 16 + WEAK_UNDEF: | |
477 | case DYN_WEAK_COMMON * 16 + WEAK_UNDEF: | |
1564db8d | 478 | // A new weak undefined reference tells us nothing. |
86f2e683 | 479 | return false; |
14bfc3f5 ILT |
480 | |
481 | case DEF * 16 + DYN_UNDEF: | |
482 | case WEAK_DEF * 16 + DYN_UNDEF: | |
483 | case DYN_DEF * 16 + DYN_UNDEF: | |
484 | case DYN_WEAK_DEF * 16 + DYN_UNDEF: | |
485 | case UNDEF * 16 + DYN_UNDEF: | |
486 | case WEAK_UNDEF * 16 + DYN_UNDEF: | |
487 | case DYN_UNDEF * 16 + DYN_UNDEF: | |
488 | case DYN_WEAK_UNDEF * 16 + DYN_UNDEF: | |
489 | case COMMON * 16 + DYN_UNDEF: | |
490 | case WEAK_COMMON * 16 + DYN_UNDEF: | |
491 | case DYN_COMMON * 16 + DYN_UNDEF: | |
492 | case DYN_WEAK_COMMON * 16 + DYN_UNDEF: | |
1564db8d | 493 | // A new dynamic undefined reference tells us nothing. |
86f2e683 | 494 | return false; |
14bfc3f5 ILT |
495 | |
496 | case DEF * 16 + DYN_WEAK_UNDEF: | |
497 | case WEAK_DEF * 16 + DYN_WEAK_UNDEF: | |
498 | case DYN_DEF * 16 + DYN_WEAK_UNDEF: | |
499 | case DYN_WEAK_DEF * 16 + DYN_WEAK_UNDEF: | |
500 | case UNDEF * 16 + DYN_WEAK_UNDEF: | |
501 | case WEAK_UNDEF * 16 + DYN_WEAK_UNDEF: | |
502 | case DYN_UNDEF * 16 + DYN_WEAK_UNDEF: | |
503 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_UNDEF: | |
504 | case COMMON * 16 + DYN_WEAK_UNDEF: | |
505 | case WEAK_COMMON * 16 + DYN_WEAK_UNDEF: | |
506 | case DYN_COMMON * 16 + DYN_WEAK_UNDEF: | |
507 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_UNDEF: | |
1564db8d | 508 | // A new weak dynamic undefined reference tells us nothing. |
86f2e683 | 509 | return false; |
14bfc3f5 ILT |
510 | |
511 | case DEF * 16 + COMMON: | |
1564db8d | 512 | // A common symbol does not override a definition. |
86f2e683 | 513 | return false; |
1564db8d | 514 | |
14bfc3f5 ILT |
515 | case WEAK_DEF * 16 + COMMON: |
516 | case DYN_DEF * 16 + COMMON: | |
517 | case DYN_WEAK_DEF * 16 + COMMON: | |
1564db8d ILT |
518 | // A common symbol does override a weak definition or a dynamic |
519 | // definition. | |
86f2e683 | 520 | return true; |
1564db8d | 521 | |
14bfc3f5 ILT |
522 | case UNDEF * 16 + COMMON: |
523 | case WEAK_UNDEF * 16 + COMMON: | |
524 | case DYN_UNDEF * 16 + COMMON: | |
525 | case DYN_WEAK_UNDEF * 16 + COMMON: | |
1564db8d | 526 | // A common symbol is a definition for a reference. |
86f2e683 | 527 | return true; |
1564db8d | 528 | |
14bfc3f5 | 529 | case COMMON * 16 + COMMON: |
ead1e424 | 530 | // Set the size to the maximum. |
86f2e683 ILT |
531 | *adjust_common_sizes = true; |
532 | return false; | |
ead1e424 | 533 | |
14bfc3f5 | 534 | case WEAK_COMMON * 16 + COMMON: |
ead1e424 ILT |
535 | // I'm not sure just what a weak common symbol means, but |
536 | // presumably it can be overridden by a regular common symbol. | |
86f2e683 | 537 | return true; |
ead1e424 | 538 | |
14bfc3f5 ILT |
539 | case DYN_COMMON * 16 + COMMON: |
540 | case DYN_WEAK_COMMON * 16 + COMMON: | |
86f2e683 ILT |
541 | // Use the real common symbol, but adjust the size if necessary. |
542 | *adjust_common_sizes = true; | |
543 | return true; | |
14bfc3f5 ILT |
544 | |
545 | case DEF * 16 + WEAK_COMMON: | |
546 | case WEAK_DEF * 16 + WEAK_COMMON: | |
547 | case DYN_DEF * 16 + WEAK_COMMON: | |
548 | case DYN_WEAK_DEF * 16 + WEAK_COMMON: | |
ead1e424 ILT |
549 | // Whatever a weak common symbol is, it won't override a |
550 | // definition. | |
86f2e683 | 551 | return false; |
ead1e424 | 552 | |
14bfc3f5 ILT |
553 | case UNDEF * 16 + WEAK_COMMON: |
554 | case WEAK_UNDEF * 16 + WEAK_COMMON: | |
555 | case DYN_UNDEF * 16 + WEAK_COMMON: | |
556 | case DYN_WEAK_UNDEF * 16 + WEAK_COMMON: | |
ead1e424 | 557 | // A weak common symbol is better than an undefined symbol. |
86f2e683 | 558 | return true; |
ead1e424 | 559 | |
14bfc3f5 ILT |
560 | case COMMON * 16 + WEAK_COMMON: |
561 | case WEAK_COMMON * 16 + WEAK_COMMON: | |
562 | case DYN_COMMON * 16 + WEAK_COMMON: | |
563 | case DYN_WEAK_COMMON * 16 + WEAK_COMMON: | |
ead1e424 ILT |
564 | // Ignore a weak common symbol in the presence of a real common |
565 | // symbol. | |
86f2e683 | 566 | return false; |
14bfc3f5 ILT |
567 | |
568 | case DEF * 16 + DYN_COMMON: | |
569 | case WEAK_DEF * 16 + DYN_COMMON: | |
570 | case DYN_DEF * 16 + DYN_COMMON: | |
571 | case DYN_WEAK_DEF * 16 + DYN_COMMON: | |
ead1e424 ILT |
572 | // Ignore a dynamic common symbol in the presence of a |
573 | // definition. | |
86f2e683 | 574 | return false; |
ead1e424 | 575 | |
14bfc3f5 ILT |
576 | case UNDEF * 16 + DYN_COMMON: |
577 | case WEAK_UNDEF * 16 + DYN_COMMON: | |
578 | case DYN_UNDEF * 16 + DYN_COMMON: | |
579 | case DYN_WEAK_UNDEF * 16 + DYN_COMMON: | |
ead1e424 | 580 | // A dynamic common symbol is a definition of sorts. |
86f2e683 | 581 | return true; |
ead1e424 | 582 | |
14bfc3f5 ILT |
583 | case COMMON * 16 + DYN_COMMON: |
584 | case WEAK_COMMON * 16 + DYN_COMMON: | |
585 | case DYN_COMMON * 16 + DYN_COMMON: | |
586 | case DYN_WEAK_COMMON * 16 + DYN_COMMON: | |
ead1e424 | 587 | // Set the size to the maximum. |
86f2e683 ILT |
588 | *adjust_common_sizes = true; |
589 | return false; | |
14bfc3f5 ILT |
590 | |
591 | case DEF * 16 + DYN_WEAK_COMMON: | |
592 | case WEAK_DEF * 16 + DYN_WEAK_COMMON: | |
593 | case DYN_DEF * 16 + DYN_WEAK_COMMON: | |
594 | case DYN_WEAK_DEF * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 595 | // A common symbol is ignored in the face of a definition. |
86f2e683 | 596 | return false; |
ead1e424 | 597 | |
14bfc3f5 ILT |
598 | case UNDEF * 16 + DYN_WEAK_COMMON: |
599 | case WEAK_UNDEF * 16 + DYN_WEAK_COMMON: | |
600 | case DYN_UNDEF * 16 + DYN_WEAK_COMMON: | |
601 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 602 | // I guess a weak common symbol is better than a definition. |
86f2e683 | 603 | return true; |
ead1e424 | 604 | |
14bfc3f5 ILT |
605 | case COMMON * 16 + DYN_WEAK_COMMON: |
606 | case WEAK_COMMON * 16 + DYN_WEAK_COMMON: | |
607 | case DYN_COMMON * 16 + DYN_WEAK_COMMON: | |
608 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 609 | // Set the size to the maximum. |
86f2e683 ILT |
610 | *adjust_common_sizes = true; |
611 | return false; | |
1564db8d ILT |
612 | |
613 | default: | |
a3ad94ed | 614 | gold_unreachable(); |
14bfc3f5 ILT |
615 | } |
616 | } | |
617 | ||
86f2e683 ILT |
618 | // A special case of should_override which is only called for a strong |
619 | // defined symbol from a regular object file. This is used when | |
620 | // defining special symbols. | |
621 | ||
622 | bool | |
623 | Symbol_table::should_override_with_special(const Symbol* to) | |
624 | { | |
625 | bool adjust_common_sizes; | |
626 | unsigned int frombits = global_flag | regular_flag | def_flag; | |
d20222a1 ILT |
627 | bool ret = Symbol_table::should_override(to, frombits, NULL, |
628 | &adjust_common_sizes); | |
86f2e683 ILT |
629 | gold_assert(!adjust_common_sizes); |
630 | return ret; | |
631 | } | |
632 | ||
633 | // Override symbol base with a special symbol. | |
634 | ||
635 | void | |
636 | Symbol::override_base_with_special(const Symbol* from) | |
637 | { | |
46fe1623 ILT |
638 | gold_assert(this->name_ == from->name_ || this->has_alias()); |
639 | ||
86f2e683 ILT |
640 | this->source_ = from->source_; |
641 | switch (from->source_) | |
642 | { | |
643 | case FROM_OBJECT: | |
644 | this->u_.from_object = from->u_.from_object; | |
645 | break; | |
646 | case IN_OUTPUT_DATA: | |
647 | this->u_.in_output_data = from->u_.in_output_data; | |
648 | break; | |
649 | case IN_OUTPUT_SEGMENT: | |
650 | this->u_.in_output_segment = from->u_.in_output_segment; | |
651 | break; | |
652 | case CONSTANT: | |
653 | break; | |
654 | default: | |
655 | gold_unreachable(); | |
656 | break; | |
657 | } | |
658 | ||
659 | if (from->version_ != NULL && this->version_ != from->version_) | |
660 | { | |
661 | gold_assert(this->version_ == NULL); | |
662 | this->version_ = from->version_; | |
663 | } | |
664 | ||
665 | this->type_ = from->type_; | |
666 | this->binding_ = from->binding_; | |
667 | this->visibility_ = from->visibility_; | |
668 | this->nonvis_ = from->nonvis_; | |
669 | ||
670 | // Special symbols are always considered to be regular symbols. | |
671 | this->in_reg_ = true; | |
46fe1623 ILT |
672 | |
673 | if (from->needs_dynsym_entry_) | |
674 | this->needs_dynsym_entry_ = true; | |
675 | if (from->needs_dynsym_value_) | |
676 | this->needs_dynsym_value_ = true; | |
677 | ||
678 | // We shouldn't see these flags. If we do, we need to handle them | |
679 | // somehow. | |
680 | gold_assert(!from->is_target_special_ || this->is_target_special_); | |
681 | gold_assert(!from->is_forwarder_); | |
682 | gold_assert(!from->has_got_offset_); | |
683 | gold_assert(!from->has_plt_offset_); | |
684 | gold_assert(!from->has_warning_); | |
685 | gold_assert(!from->is_copied_from_dynobj_); | |
55a93433 | 686 | gold_assert(!from->is_forced_local_); |
86f2e683 ILT |
687 | } |
688 | ||
689 | // Override a symbol with a special symbol. | |
690 | ||
691 | template<int size> | |
692 | void | |
693 | Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from) | |
694 | { | |
695 | this->override_base_with_special(from); | |
696 | this->value_ = from->value_; | |
697 | this->symsize_ = from->symsize_; | |
698 | } | |
699 | ||
aeddab66 ILT |
700 | // Override TOSYM with the special symbol FROMSYM. This handles all |
701 | // aliases of TOSYM. | |
702 | ||
703 | template<int size> | |
704 | void | |
705 | Symbol_table::override_with_special(Sized_symbol<size>* tosym, | |
706 | const Sized_symbol<size>* fromsym) | |
707 | { | |
708 | tosym->override_with_special(fromsym); | |
709 | if (tosym->has_alias()) | |
710 | { | |
711 | Symbol* sym = this->weak_aliases_[tosym]; | |
712 | gold_assert(sym != NULL); | |
7d1a9ebb | 713 | Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
714 | do |
715 | { | |
716 | ssym->override_with_special(fromsym); | |
717 | sym = this->weak_aliases_[ssym]; | |
718 | gold_assert(sym != NULL); | |
7d1a9ebb | 719 | ssym = this->get_sized_symbol<size>(sym); |
aeddab66 ILT |
720 | } |
721 | while (ssym != tosym); | |
722 | } | |
55a93433 ILT |
723 | if (tosym->binding() == elfcpp::STB_LOCAL) |
724 | this->force_local(tosym); | |
aeddab66 ILT |
725 | } |
726 | ||
14bfc3f5 ILT |
727 | // Instantiate the templates we need. We could use the configure |
728 | // script to restrict this to only the ones needed for implemented | |
729 | // targets. | |
730 | ||
193a53d9 | 731 | #ifdef HAVE_TARGET_32_LITTLE |
14bfc3f5 ILT |
732 | template |
733 | void | |
193a53d9 | 734 | Symbol_table::resolve<32, false>( |
1564db8d | 735 | Sized_symbol<32>* to, |
193a53d9 | 736 | const elfcpp::Sym<32, false>& sym, |
70e654ba | 737 | const elfcpp::Sym<32, false>& orig_sym, |
14b31740 ILT |
738 | Object* object, |
739 | const char* version); | |
193a53d9 | 740 | #endif |
14bfc3f5 | 741 | |
193a53d9 | 742 | #ifdef HAVE_TARGET_32_BIG |
14bfc3f5 ILT |
743 | template |
744 | void | |
193a53d9 | 745 | Symbol_table::resolve<32, true>( |
1564db8d | 746 | Sized_symbol<32>* to, |
193a53d9 | 747 | const elfcpp::Sym<32, true>& sym, |
70e654ba | 748 | const elfcpp::Sym<32, true>& orig_sym, |
14b31740 ILT |
749 | Object* object, |
750 | const char* version); | |
193a53d9 | 751 | #endif |
14bfc3f5 | 752 | |
193a53d9 | 753 | #ifdef HAVE_TARGET_64_LITTLE |
14bfc3f5 ILT |
754 | template |
755 | void | |
193a53d9 | 756 | Symbol_table::resolve<64, false>( |
1564db8d | 757 | Sized_symbol<64>* to, |
193a53d9 | 758 | const elfcpp::Sym<64, false>& sym, |
70e654ba | 759 | const elfcpp::Sym<64, false>& orig_sym, |
14b31740 ILT |
760 | Object* object, |
761 | const char* version); | |
193a53d9 | 762 | #endif |
14bfc3f5 | 763 | |
193a53d9 | 764 | #ifdef HAVE_TARGET_64_BIG |
14bfc3f5 ILT |
765 | template |
766 | void | |
193a53d9 | 767 | Symbol_table::resolve<64, true>( |
1564db8d | 768 | Sized_symbol<64>* to, |
193a53d9 | 769 | const elfcpp::Sym<64, true>& sym, |
70e654ba | 770 | const elfcpp::Sym<64, true>& orig_sym, |
14b31740 ILT |
771 | Object* object, |
772 | const char* version); | |
193a53d9 | 773 | #endif |
14bfc3f5 | 774 | |
86f2e683 ILT |
775 | #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) |
776 | template | |
777 | void | |
aeddab66 ILT |
778 | Symbol_table::override_with_special<32>(Sized_symbol<32>*, |
779 | const Sized_symbol<32>*); | |
86f2e683 ILT |
780 | #endif |
781 | ||
782 | #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) | |
783 | template | |
784 | void | |
aeddab66 ILT |
785 | Symbol_table::override_with_special<64>(Sized_symbol<64>*, |
786 | const Sized_symbol<64>*); | |
86f2e683 ILT |
787 | #endif |
788 | ||
14bfc3f5 | 789 | } // End namespace gold. |