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