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 | ||
86f2e683 ILT |
74 | // The resolve functions build a little code for each symbol. |
75 | // Bit 0: 0 for global, 1 for weak. | |
76 | // Bit 1: 0 for regular object, 1 for shared object | |
77 | // Bits 2-3: 0 for normal, 1 for undefined, 2 for common | |
78 | // This gives us values from 0 to 11. | |
79 | ||
80 | static const int global_or_weak_shift = 0; | |
81 | static const unsigned int global_flag = 0 << global_or_weak_shift; | |
82 | static const unsigned int weak_flag = 1 << global_or_weak_shift; | |
83 | ||
84 | static const int regular_or_dynamic_shift = 1; | |
85 | static const unsigned int regular_flag = 0 << regular_or_dynamic_shift; | |
86 | static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift; | |
87 | ||
88 | static const int def_undef_or_common_shift = 2; | |
89 | static const unsigned int def_flag = 0 << def_undef_or_common_shift; | |
90 | static const unsigned int undef_flag = 1 << def_undef_or_common_shift; | |
91 | static const unsigned int common_flag = 2 << def_undef_or_common_shift; | |
92 | ||
14bfc3f5 ILT |
93 | // Resolve a symbol. This is called the second and subsequent times |
94 | // we see a symbol. TO is the pre-existing symbol. SYM is the new | |
14b31740 | 95 | // symbol, seen in OBJECT. VERSION of the version of SYM. |
14bfc3f5 ILT |
96 | |
97 | template<int size, bool big_endian> | |
98 | void | |
1564db8d | 99 | Symbol_table::resolve(Sized_symbol<size>* to, |
14bfc3f5 | 100 | const elfcpp::Sym<size, big_endian>& sym, |
14b31740 | 101 | Object* object, const char* version) |
14bfc3f5 ILT |
102 | { |
103 | if (object->target()->has_resolve()) | |
104 | { | |
274e99f9 | 105 | Sized_target<size, big_endian>* sized_target; |
593f47df ILT |
106 | sized_target = object->sized_target |
107 | SELECT_SIZE_ENDIAN_NAME(size, big_endian) ( | |
108 | SELECT_SIZE_ENDIAN_ONLY(size, big_endian)); | |
14b31740 | 109 | sized_target->resolve(to, sym, object, version); |
14bfc3f5 ILT |
110 | return; |
111 | } | |
112 | ||
86f2e683 ILT |
113 | if (!object->is_dynamic()) |
114 | { | |
115 | // Record that we've seen this symbol in a regular object. | |
116 | to->set_in_reg(); | |
117 | } | |
118 | else | |
119 | { | |
120 | // Record that we've seen this symbol in a dynamic object. | |
121 | to->set_in_dyn(); | |
122 | } | |
14bfc3f5 | 123 | |
86f2e683 ILT |
124 | unsigned int frombits; |
125 | switch (sym.get_st_bind()) | |
14bfc3f5 ILT |
126 | { |
127 | case elfcpp::STB_GLOBAL: | |
86f2e683 | 128 | frombits = global_flag; |
14bfc3f5 ILT |
129 | break; |
130 | ||
131 | case elfcpp::STB_WEAK: | |
86f2e683 | 132 | frombits = weak_flag; |
14bfc3f5 ILT |
133 | break; |
134 | ||
135 | case elfcpp::STB_LOCAL: | |
86f2e683 ILT |
136 | fprintf(stderr, |
137 | _("%s: %s: invalid STB_LOCAL symbol %s in external symbols\n"), | |
138 | program_name, object->name().c_str(), to->name()); | |
139 | gold_exit(false); | |
14bfc3f5 ILT |
140 | |
141 | default: | |
86f2e683 ILT |
142 | fprintf(stderr, |
143 | _("%s: %s: unsupported symbol binding %d for symbol %s\n"), | |
144 | program_name, object->name().c_str(), | |
145 | static_cast<int>(sym.get_st_bind()), to->name()); | |
146 | gold_exit(false); | |
14bfc3f5 ILT |
147 | } |
148 | ||
86f2e683 ILT |
149 | if (!object->is_dynamic()) |
150 | frombits |= regular_flag; | |
151 | else | |
152 | frombits |= dynamic_flag; | |
14bfc3f5 | 153 | |
86f2e683 | 154 | switch (sym.get_st_shndx()) |
14bfc3f5 ILT |
155 | { |
156 | case elfcpp::SHN_UNDEF: | |
86f2e683 | 157 | frombits |= undef_flag; |
14bfc3f5 ILT |
158 | break; |
159 | ||
160 | case elfcpp::SHN_COMMON: | |
86f2e683 | 161 | frombits |= common_flag; |
14bfc3f5 ILT |
162 | break; |
163 | ||
164 | default: | |
86f2e683 ILT |
165 | if (sym.get_st_type() == elfcpp::STT_COMMON) |
166 | frombits |= common_flag; | |
167 | else | |
168 | frombits |= def_flag; | |
14bfc3f5 ILT |
169 | break; |
170 | } | |
171 | ||
86f2e683 ILT |
172 | bool adjust_common_sizes; |
173 | if (Symbol_table::should_override(to, frombits, &adjust_common_sizes)) | |
174 | { | |
175 | typename Sized_symbol<size>::Size_type tosize = to->symsize(); | |
176 | ||
177 | to->override(sym, object, version); | |
178 | ||
179 | if (adjust_common_sizes && tosize > to->symsize()) | |
180 | to->set_symsize(tosize); | |
181 | } | |
182 | else | |
183 | { | |
184 | if (adjust_common_sizes && sym.get_st_size() > to->symsize()) | |
185 | to->set_symsize(sym.get_st_size()); | |
186 | } | |
187 | } | |
188 | ||
189 | // Handle the core of symbol resolution. This is called with the | |
190 | // existing symbol, TO, and a bitflag describing the new symbol. This | |
191 | // returns true if we should override the existing symbol with the new | |
192 | // one, and returns false otherwise. It sets *ADJUST_COMMON_SIZES to | |
193 | // true if we should set the symbol size to the maximum of the TO and | |
194 | // FROM sizes. It handles error conditions. | |
195 | ||
196 | bool | |
197 | Symbol_table::should_override(const Symbol* to, unsigned int frombits, | |
198 | bool* adjust_common_sizes) | |
199 | { | |
200 | *adjust_common_sizes = false; | |
201 | ||
202 | unsigned int tobits; | |
203 | switch (to->binding()) | |
14bfc3f5 ILT |
204 | { |
205 | case elfcpp::STB_GLOBAL: | |
86f2e683 | 206 | tobits = global_flag; |
14bfc3f5 ILT |
207 | break; |
208 | ||
209 | case elfcpp::STB_WEAK: | |
86f2e683 | 210 | tobits = weak_flag; |
14bfc3f5 ILT |
211 | break; |
212 | ||
213 | case elfcpp::STB_LOCAL: | |
86f2e683 ILT |
214 | // We should only see externally visible symbols in the symbol |
215 | // table. | |
216 | gold_unreachable(); | |
14bfc3f5 ILT |
217 | |
218 | default: | |
86f2e683 ILT |
219 | // Any target which wants to handle STB_LOOS, etc., needs to |
220 | // define a resolve method. | |
221 | gold_unreachable(); | |
14bfc3f5 ILT |
222 | } |
223 | ||
86f2e683 ILT |
224 | if (to->source() == Symbol::FROM_OBJECT |
225 | && to->object()->is_dynamic()) | |
226 | tobits |= dynamic_flag; | |
008db82e | 227 | else |
86f2e683 | 228 | tobits |= regular_flag; |
1564db8d | 229 | |
86f2e683 | 230 | switch (to->shndx()) |
14bfc3f5 ILT |
231 | { |
232 | case elfcpp::SHN_UNDEF: | |
86f2e683 | 233 | tobits |= undef_flag; |
14bfc3f5 ILT |
234 | break; |
235 | ||
236 | case elfcpp::SHN_COMMON: | |
86f2e683 | 237 | tobits |= common_flag; |
14bfc3f5 ILT |
238 | break; |
239 | ||
240 | default: | |
86f2e683 ILT |
241 | if (to->type() == elfcpp::STT_COMMON) |
242 | tobits |= common_flag; | |
243 | else | |
244 | tobits |= def_flag; | |
14bfc3f5 ILT |
245 | break; |
246 | } | |
247 | ||
1564db8d ILT |
248 | // FIXME: Warn if either but not both of TO and SYM are STT_TLS. |
249 | ||
14bfc3f5 ILT |
250 | // We use a giant switch table for symbol resolution. This code is |
251 | // unwieldy, but: 1) it is efficient; 2) we definitely handle all | |
252 | // cases; 3) it is easy to change the handling of a particular case. | |
253 | // The alternative would be a series of conditionals, but it is easy | |
254 | // to get the ordering wrong. This could also be done as a table, | |
255 | // but that is no easier to understand than this large switch | |
256 | // statement. | |
257 | ||
86f2e683 ILT |
258 | // These are the values generated by the bit codes. |
259 | enum | |
260 | { | |
261 | DEF = global_flag | regular_flag | def_flag, | |
262 | WEAK_DEF = weak_flag | regular_flag | def_flag, | |
263 | DYN_DEF = global_flag | dynamic_flag | def_flag, | |
264 | DYN_WEAK_DEF = weak_flag | dynamic_flag | def_flag, | |
265 | UNDEF = global_flag | regular_flag | undef_flag, | |
266 | WEAK_UNDEF = weak_flag | regular_flag | undef_flag, | |
267 | DYN_UNDEF = global_flag | dynamic_flag | undef_flag, | |
268 | DYN_WEAK_UNDEF = weak_flag | dynamic_flag | undef_flag, | |
269 | COMMON = global_flag | regular_flag | common_flag, | |
270 | WEAK_COMMON = weak_flag | regular_flag | common_flag, | |
271 | DYN_COMMON = global_flag | dynamic_flag | common_flag, | |
272 | DYN_WEAK_COMMON = weak_flag | dynamic_flag | common_flag | |
273 | }; | |
274 | ||
14bfc3f5 ILT |
275 | switch (tobits * 16 + frombits) |
276 | { | |
277 | case DEF * 16 + DEF: | |
12e14209 | 278 | // Two definitions of the same symbol. |
86f2e683 ILT |
279 | fprintf(stderr, "%s: multiple definition of %s\n", |
280 | program_name, to->name()); | |
12e14209 | 281 | // FIXME: Report locations. Record that we have seen an error. |
86f2e683 | 282 | return false; |
14bfc3f5 ILT |
283 | |
284 | case WEAK_DEF * 16 + DEF: | |
1564db8d ILT |
285 | // We've seen a weak definition, and now we see a strong |
286 | // definition. In the original SVR4 linker, this was treated as | |
287 | // a multiple definition error. In the Solaris linker and the | |
288 | // GNU linker, a weak definition followed by a regular | |
289 | // definition causes the weak definition to be overridden. We | |
290 | // are currently compatible with the GNU linker. In the future | |
291 | // we should add a target specific option to change this. | |
292 | // FIXME. | |
86f2e683 | 293 | return true; |
14bfc3f5 ILT |
294 | |
295 | case DYN_DEF * 16 + DEF: | |
296 | case DYN_WEAK_DEF * 16 + DEF: | |
1564db8d ILT |
297 | // We've seen a definition in a dynamic object, and now we see a |
298 | // definition in a regular object. The definition in the | |
299 | // regular object overrides the definition in the dynamic | |
300 | // object. | |
86f2e683 | 301 | return true; |
1564db8d | 302 | |
14bfc3f5 ILT |
303 | case UNDEF * 16 + DEF: |
304 | case WEAK_UNDEF * 16 + DEF: | |
305 | case DYN_UNDEF * 16 + DEF: | |
306 | case DYN_WEAK_UNDEF * 16 + DEF: | |
1564db8d ILT |
307 | // We've seen an undefined reference, and now we see a |
308 | // definition. We use the definition. | |
86f2e683 | 309 | return true; |
1564db8d | 310 | |
14bfc3f5 ILT |
311 | case COMMON * 16 + DEF: |
312 | case WEAK_COMMON * 16 + DEF: | |
313 | case DYN_COMMON * 16 + DEF: | |
314 | case DYN_WEAK_COMMON * 16 + DEF: | |
1564db8d | 315 | // We've seen a common symbol and now we see a definition. The |
14b31740 | 316 | // definition overrides. FIXME: We should optionally issue, version a |
1564db8d | 317 | // warning. |
86f2e683 | 318 | return true; |
14bfc3f5 ILT |
319 | |
320 | case DEF * 16 + WEAK_DEF: | |
321 | case WEAK_DEF * 16 + WEAK_DEF: | |
1564db8d ILT |
322 | // We've seen a definition and now we see a weak definition. We |
323 | // ignore the new weak definition. | |
86f2e683 | 324 | return false; |
1564db8d | 325 | |
14bfc3f5 ILT |
326 | case DYN_DEF * 16 + WEAK_DEF: |
327 | case DYN_WEAK_DEF * 16 + WEAK_DEF: | |
1564db8d ILT |
328 | // We've seen a dynamic definition and now we see a regular weak |
329 | // definition. The regular weak definition overrides. | |
86f2e683 | 330 | return true; |
1564db8d | 331 | |
14bfc3f5 ILT |
332 | case UNDEF * 16 + WEAK_DEF: |
333 | case WEAK_UNDEF * 16 + WEAK_DEF: | |
334 | case DYN_UNDEF * 16 + WEAK_DEF: | |
335 | case DYN_WEAK_UNDEF * 16 + WEAK_DEF: | |
1564db8d | 336 | // A weak definition of a currently undefined symbol. |
86f2e683 | 337 | return true; |
1564db8d | 338 | |
14bfc3f5 ILT |
339 | case COMMON * 16 + WEAK_DEF: |
340 | case WEAK_COMMON * 16 + WEAK_DEF: | |
1564db8d | 341 | // A weak definition does not override a common definition. |
86f2e683 | 342 | return false; |
1564db8d | 343 | |
14bfc3f5 ILT |
344 | case DYN_COMMON * 16 + WEAK_DEF: |
345 | case DYN_WEAK_COMMON * 16 + WEAK_DEF: | |
1564db8d ILT |
346 | // A weak definition does override a definition in a dynamic |
347 | // object. FIXME: We should optionally issue a warning. | |
86f2e683 | 348 | return true; |
14bfc3f5 ILT |
349 | |
350 | case DEF * 16 + DYN_DEF: | |
351 | case WEAK_DEF * 16 + DYN_DEF: | |
352 | case DYN_DEF * 16 + DYN_DEF: | |
353 | case DYN_WEAK_DEF * 16 + DYN_DEF: | |
1564db8d | 354 | // Ignore a dynamic definition if we already have a definition. |
86f2e683 | 355 | return false; |
1564db8d | 356 | |
14bfc3f5 ILT |
357 | case UNDEF * 16 + DYN_DEF: |
358 | case WEAK_UNDEF * 16 + DYN_DEF: | |
359 | case DYN_UNDEF * 16 + DYN_DEF: | |
360 | case DYN_WEAK_UNDEF * 16 + DYN_DEF: | |
1564db8d | 361 | // Use a dynamic definition if we have a reference. |
86f2e683 | 362 | return true; |
1564db8d | 363 | |
14bfc3f5 ILT |
364 | case COMMON * 16 + DYN_DEF: |
365 | case WEAK_COMMON * 16 + DYN_DEF: | |
366 | case DYN_COMMON * 16 + DYN_DEF: | |
367 | case DYN_WEAK_COMMON * 16 + DYN_DEF: | |
1564db8d ILT |
368 | // Ignore a dynamic definition if we already have a common |
369 | // definition. | |
86f2e683 | 370 | return false; |
14bfc3f5 ILT |
371 | |
372 | case DEF * 16 + DYN_WEAK_DEF: | |
373 | case WEAK_DEF * 16 + DYN_WEAK_DEF: | |
374 | case DYN_DEF * 16 + DYN_WEAK_DEF: | |
375 | case DYN_WEAK_DEF * 16 + DYN_WEAK_DEF: | |
1564db8d ILT |
376 | // Ignore a weak dynamic definition if we already have a |
377 | // definition. | |
86f2e683 | 378 | return false; |
1564db8d | 379 | |
14bfc3f5 ILT |
380 | case UNDEF * 16 + DYN_WEAK_DEF: |
381 | case WEAK_UNDEF * 16 + DYN_WEAK_DEF: | |
382 | case DYN_UNDEF * 16 + DYN_WEAK_DEF: | |
383 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF: | |
1564db8d | 384 | // Use a weak dynamic definition if we have a reference. |
86f2e683 | 385 | return true; |
1564db8d | 386 | |
14bfc3f5 ILT |
387 | case COMMON * 16 + DYN_WEAK_DEF: |
388 | case WEAK_COMMON * 16 + DYN_WEAK_DEF: | |
389 | case DYN_COMMON * 16 + DYN_WEAK_DEF: | |
390 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF: | |
1564db8d ILT |
391 | // Ignore a weak dynamic definition if we already have a common |
392 | // definition. | |
86f2e683 | 393 | return false; |
14bfc3f5 ILT |
394 | |
395 | case DEF * 16 + UNDEF: | |
396 | case WEAK_DEF * 16 + UNDEF: | |
397 | case DYN_DEF * 16 + UNDEF: | |
398 | case DYN_WEAK_DEF * 16 + UNDEF: | |
399 | case UNDEF * 16 + UNDEF: | |
ead1e424 | 400 | // A new undefined reference tells us nothing. |
86f2e683 | 401 | return false; |
ead1e424 | 402 | |
14bfc3f5 ILT |
403 | case WEAK_UNDEF * 16 + UNDEF: |
404 | case DYN_UNDEF * 16 + UNDEF: | |
405 | case DYN_WEAK_UNDEF * 16 + UNDEF: | |
ead1e424 | 406 | // A strong undef overrides a dynamic or weak undef. |
86f2e683 | 407 | return true; |
ead1e424 | 408 | |
14bfc3f5 ILT |
409 | case COMMON * 16 + UNDEF: |
410 | case WEAK_COMMON * 16 + UNDEF: | |
411 | case DYN_COMMON * 16 + UNDEF: | |
412 | case DYN_WEAK_COMMON * 16 + UNDEF: | |
1564db8d | 413 | // A new undefined reference tells us nothing. |
86f2e683 | 414 | return false; |
14bfc3f5 ILT |
415 | |
416 | case DEF * 16 + WEAK_UNDEF: | |
417 | case WEAK_DEF * 16 + WEAK_UNDEF: | |
418 | case DYN_DEF * 16 + WEAK_UNDEF: | |
419 | case DYN_WEAK_DEF * 16 + WEAK_UNDEF: | |
420 | case UNDEF * 16 + WEAK_UNDEF: | |
421 | case WEAK_UNDEF * 16 + WEAK_UNDEF: | |
422 | case DYN_UNDEF * 16 + WEAK_UNDEF: | |
423 | case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF: | |
424 | case COMMON * 16 + WEAK_UNDEF: | |
425 | case WEAK_COMMON * 16 + WEAK_UNDEF: | |
426 | case DYN_COMMON * 16 + WEAK_UNDEF: | |
427 | case DYN_WEAK_COMMON * 16 + WEAK_UNDEF: | |
1564db8d | 428 | // A new weak undefined reference tells us nothing. |
86f2e683 | 429 | return false; |
14bfc3f5 ILT |
430 | |
431 | case DEF * 16 + DYN_UNDEF: | |
432 | case WEAK_DEF * 16 + DYN_UNDEF: | |
433 | case DYN_DEF * 16 + DYN_UNDEF: | |
434 | case DYN_WEAK_DEF * 16 + DYN_UNDEF: | |
435 | case UNDEF * 16 + DYN_UNDEF: | |
436 | case WEAK_UNDEF * 16 + DYN_UNDEF: | |
437 | case DYN_UNDEF * 16 + DYN_UNDEF: | |
438 | case DYN_WEAK_UNDEF * 16 + DYN_UNDEF: | |
439 | case COMMON * 16 + DYN_UNDEF: | |
440 | case WEAK_COMMON * 16 + DYN_UNDEF: | |
441 | case DYN_COMMON * 16 + DYN_UNDEF: | |
442 | case DYN_WEAK_COMMON * 16 + DYN_UNDEF: | |
1564db8d | 443 | // A new dynamic undefined reference tells us nothing. |
86f2e683 | 444 | return false; |
14bfc3f5 ILT |
445 | |
446 | case DEF * 16 + DYN_WEAK_UNDEF: | |
447 | case WEAK_DEF * 16 + DYN_WEAK_UNDEF: | |
448 | case DYN_DEF * 16 + DYN_WEAK_UNDEF: | |
449 | case DYN_WEAK_DEF * 16 + DYN_WEAK_UNDEF: | |
450 | case UNDEF * 16 + DYN_WEAK_UNDEF: | |
451 | case WEAK_UNDEF * 16 + DYN_WEAK_UNDEF: | |
452 | case DYN_UNDEF * 16 + DYN_WEAK_UNDEF: | |
453 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_UNDEF: | |
454 | case COMMON * 16 + DYN_WEAK_UNDEF: | |
455 | case WEAK_COMMON * 16 + DYN_WEAK_UNDEF: | |
456 | case DYN_COMMON * 16 + DYN_WEAK_UNDEF: | |
457 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_UNDEF: | |
1564db8d | 458 | // A new weak dynamic undefined reference tells us nothing. |
86f2e683 | 459 | return false; |
14bfc3f5 ILT |
460 | |
461 | case DEF * 16 + COMMON: | |
1564db8d | 462 | // A common symbol does not override a definition. |
86f2e683 | 463 | return false; |
1564db8d | 464 | |
14bfc3f5 ILT |
465 | case WEAK_DEF * 16 + COMMON: |
466 | case DYN_DEF * 16 + COMMON: | |
467 | case DYN_WEAK_DEF * 16 + COMMON: | |
1564db8d ILT |
468 | // A common symbol does override a weak definition or a dynamic |
469 | // definition. | |
86f2e683 | 470 | return true; |
1564db8d | 471 | |
14bfc3f5 ILT |
472 | case UNDEF * 16 + COMMON: |
473 | case WEAK_UNDEF * 16 + COMMON: | |
474 | case DYN_UNDEF * 16 + COMMON: | |
475 | case DYN_WEAK_UNDEF * 16 + COMMON: | |
1564db8d | 476 | // A common symbol is a definition for a reference. |
86f2e683 | 477 | return true; |
1564db8d | 478 | |
14bfc3f5 | 479 | case COMMON * 16 + COMMON: |
ead1e424 | 480 | // Set the size to the maximum. |
86f2e683 ILT |
481 | *adjust_common_sizes = true; |
482 | return false; | |
ead1e424 | 483 | |
14bfc3f5 | 484 | case WEAK_COMMON * 16 + COMMON: |
ead1e424 ILT |
485 | // I'm not sure just what a weak common symbol means, but |
486 | // presumably it can be overridden by a regular common symbol. | |
86f2e683 | 487 | return true; |
ead1e424 | 488 | |
14bfc3f5 ILT |
489 | case DYN_COMMON * 16 + COMMON: |
490 | case DYN_WEAK_COMMON * 16 + COMMON: | |
86f2e683 ILT |
491 | // Use the real common symbol, but adjust the size if necessary. |
492 | *adjust_common_sizes = true; | |
493 | return true; | |
14bfc3f5 ILT |
494 | |
495 | case DEF * 16 + WEAK_COMMON: | |
496 | case WEAK_DEF * 16 + WEAK_COMMON: | |
497 | case DYN_DEF * 16 + WEAK_COMMON: | |
498 | case DYN_WEAK_DEF * 16 + WEAK_COMMON: | |
ead1e424 ILT |
499 | // Whatever a weak common symbol is, it won't override a |
500 | // definition. | |
86f2e683 | 501 | return false; |
ead1e424 | 502 | |
14bfc3f5 ILT |
503 | case UNDEF * 16 + WEAK_COMMON: |
504 | case WEAK_UNDEF * 16 + WEAK_COMMON: | |
505 | case DYN_UNDEF * 16 + WEAK_COMMON: | |
506 | case DYN_WEAK_UNDEF * 16 + WEAK_COMMON: | |
ead1e424 | 507 | // A weak common symbol is better than an undefined symbol. |
86f2e683 | 508 | return true; |
ead1e424 | 509 | |
14bfc3f5 ILT |
510 | case COMMON * 16 + WEAK_COMMON: |
511 | case WEAK_COMMON * 16 + WEAK_COMMON: | |
512 | case DYN_COMMON * 16 + WEAK_COMMON: | |
513 | case DYN_WEAK_COMMON * 16 + WEAK_COMMON: | |
ead1e424 ILT |
514 | // Ignore a weak common symbol in the presence of a real common |
515 | // symbol. | |
86f2e683 | 516 | return false; |
14bfc3f5 ILT |
517 | |
518 | case DEF * 16 + DYN_COMMON: | |
519 | case WEAK_DEF * 16 + DYN_COMMON: | |
520 | case DYN_DEF * 16 + DYN_COMMON: | |
521 | case DYN_WEAK_DEF * 16 + DYN_COMMON: | |
ead1e424 ILT |
522 | // Ignore a dynamic common symbol in the presence of a |
523 | // definition. | |
86f2e683 | 524 | return false; |
ead1e424 | 525 | |
14bfc3f5 ILT |
526 | case UNDEF * 16 + DYN_COMMON: |
527 | case WEAK_UNDEF * 16 + DYN_COMMON: | |
528 | case DYN_UNDEF * 16 + DYN_COMMON: | |
529 | case DYN_WEAK_UNDEF * 16 + DYN_COMMON: | |
ead1e424 | 530 | // A dynamic common symbol is a definition of sorts. |
86f2e683 | 531 | return true; |
ead1e424 | 532 | |
14bfc3f5 ILT |
533 | case COMMON * 16 + DYN_COMMON: |
534 | case WEAK_COMMON * 16 + DYN_COMMON: | |
535 | case DYN_COMMON * 16 + DYN_COMMON: | |
536 | case DYN_WEAK_COMMON * 16 + DYN_COMMON: | |
ead1e424 | 537 | // Set the size to the maximum. |
86f2e683 ILT |
538 | *adjust_common_sizes = true; |
539 | return false; | |
14bfc3f5 ILT |
540 | |
541 | case DEF * 16 + DYN_WEAK_COMMON: | |
542 | case WEAK_DEF * 16 + DYN_WEAK_COMMON: | |
543 | case DYN_DEF * 16 + DYN_WEAK_COMMON: | |
544 | case DYN_WEAK_DEF * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 545 | // A common symbol is ignored in the face of a definition. |
86f2e683 | 546 | return false; |
ead1e424 | 547 | |
14bfc3f5 ILT |
548 | case UNDEF * 16 + DYN_WEAK_COMMON: |
549 | case WEAK_UNDEF * 16 + DYN_WEAK_COMMON: | |
550 | case DYN_UNDEF * 16 + DYN_WEAK_COMMON: | |
551 | case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 552 | // I guess a weak common symbol is better than a definition. |
86f2e683 | 553 | return true; |
ead1e424 | 554 | |
14bfc3f5 ILT |
555 | case COMMON * 16 + DYN_WEAK_COMMON: |
556 | case WEAK_COMMON * 16 + DYN_WEAK_COMMON: | |
557 | case DYN_COMMON * 16 + DYN_WEAK_COMMON: | |
558 | case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON: | |
ead1e424 | 559 | // Set the size to the maximum. |
86f2e683 ILT |
560 | *adjust_common_sizes = true; |
561 | return false; | |
1564db8d ILT |
562 | |
563 | default: | |
a3ad94ed | 564 | gold_unreachable(); |
14bfc3f5 ILT |
565 | } |
566 | } | |
567 | ||
86f2e683 ILT |
568 | // A special case of should_override which is only called for a strong |
569 | // defined symbol from a regular object file. This is used when | |
570 | // defining special symbols. | |
571 | ||
572 | bool | |
573 | Symbol_table::should_override_with_special(const Symbol* to) | |
574 | { | |
575 | bool adjust_common_sizes; | |
576 | unsigned int frombits = global_flag | regular_flag | def_flag; | |
577 | bool ret = Symbol_table::should_override(to, frombits, &adjust_common_sizes); | |
578 | gold_assert(!adjust_common_sizes); | |
579 | return ret; | |
580 | } | |
581 | ||
582 | // Override symbol base with a special symbol. | |
583 | ||
584 | void | |
585 | Symbol::override_base_with_special(const Symbol* from) | |
586 | { | |
587 | this->source_ = from->source_; | |
588 | switch (from->source_) | |
589 | { | |
590 | case FROM_OBJECT: | |
591 | this->u_.from_object = from->u_.from_object; | |
592 | break; | |
593 | case IN_OUTPUT_DATA: | |
594 | this->u_.in_output_data = from->u_.in_output_data; | |
595 | break; | |
596 | case IN_OUTPUT_SEGMENT: | |
597 | this->u_.in_output_segment = from->u_.in_output_segment; | |
598 | break; | |
599 | case CONSTANT: | |
600 | break; | |
601 | default: | |
602 | gold_unreachable(); | |
603 | break; | |
604 | } | |
605 | ||
606 | if (from->version_ != NULL && this->version_ != from->version_) | |
607 | { | |
608 | gold_assert(this->version_ == NULL); | |
609 | this->version_ = from->version_; | |
610 | } | |
611 | ||
612 | this->type_ = from->type_; | |
613 | this->binding_ = from->binding_; | |
614 | this->visibility_ = from->visibility_; | |
615 | this->nonvis_ = from->nonvis_; | |
616 | ||
617 | // Special symbols are always considered to be regular symbols. | |
618 | this->in_reg_ = true; | |
619 | } | |
620 | ||
621 | // Override a symbol with a special symbol. | |
622 | ||
623 | template<int size> | |
624 | void | |
625 | Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from) | |
626 | { | |
627 | this->override_base_with_special(from); | |
628 | this->value_ = from->value_; | |
629 | this->symsize_ = from->symsize_; | |
630 | } | |
631 | ||
14bfc3f5 ILT |
632 | // Instantiate the templates we need. We could use the configure |
633 | // script to restrict this to only the ones needed for implemented | |
634 | // targets. | |
635 | ||
193a53d9 | 636 | #ifdef HAVE_TARGET_32_LITTLE |
14bfc3f5 ILT |
637 | template |
638 | void | |
193a53d9 | 639 | Symbol_table::resolve<32, false>( |
1564db8d | 640 | Sized_symbol<32>* to, |
193a53d9 | 641 | const elfcpp::Sym<32, false>& sym, |
14b31740 ILT |
642 | Object* object, |
643 | const char* version); | |
193a53d9 | 644 | #endif |
14bfc3f5 | 645 | |
193a53d9 | 646 | #ifdef HAVE_TARGET_32_BIG |
14bfc3f5 ILT |
647 | template |
648 | void | |
193a53d9 | 649 | Symbol_table::resolve<32, true>( |
1564db8d | 650 | Sized_symbol<32>* to, |
193a53d9 | 651 | const elfcpp::Sym<32, true>& sym, |
14b31740 ILT |
652 | Object* object, |
653 | const char* version); | |
193a53d9 | 654 | #endif |
14bfc3f5 | 655 | |
193a53d9 | 656 | #ifdef HAVE_TARGET_64_LITTLE |
14bfc3f5 ILT |
657 | template |
658 | void | |
193a53d9 | 659 | Symbol_table::resolve<64, false>( |
1564db8d | 660 | Sized_symbol<64>* to, |
193a53d9 | 661 | const elfcpp::Sym<64, false>& sym, |
14b31740 ILT |
662 | Object* object, |
663 | const char* version); | |
193a53d9 | 664 | #endif |
14bfc3f5 | 665 | |
193a53d9 | 666 | #ifdef HAVE_TARGET_64_BIG |
14bfc3f5 ILT |
667 | template |
668 | void | |
193a53d9 | 669 | Symbol_table::resolve<64, true>( |
1564db8d | 670 | Sized_symbol<64>* to, |
193a53d9 | 671 | const elfcpp::Sym<64, true>& sym, |
14b31740 ILT |
672 | Object* object, |
673 | const char* version); | |
193a53d9 | 674 | #endif |
14bfc3f5 | 675 | |
86f2e683 ILT |
676 | #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) |
677 | template | |
678 | void | |
679 | Sized_symbol<32>::override_with_special(const Sized_symbol<32>*); | |
680 | #endif | |
681 | ||
682 | #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) | |
683 | template | |
684 | void | |
685 | Sized_symbol<64>::override_with_special(const Sized_symbol<64>*); | |
686 | #endif | |
687 | ||
14bfc3f5 | 688 | } // End namespace gold. |