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