291bca6967337a637fdd858e76019e87caa3afb0
[deliverable/binutils-gdb.git] / gold / resolve.cc
1 // resolve.cc -- symbol resolution for gold
2
3 // Copyright 2006, 2007, 2008 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
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
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,
40 unsigned int st_shndx, bool is_ordinary,
41 Object* object, const char* version)
42 {
43 gold_assert(this->source_ == FROM_OBJECT);
44 this->u_.from_object.object = object;
45 if (version != NULL && this->version() != version)
46 {
47 gold_assert(this->version() == NULL);
48 this->version_ = version;
49 }
50 this->u_.from_object.shndx = st_shndx;
51 this->is_ordinary_shndx_ = is_ordinary;
52 this->type_ = sym.get_st_type();
53 this->binding_ = sym.get_st_bind();
54 this->visibility_ = sym.get_st_visibility();
55 this->nonvis_ = sym.get_st_nonvis();
56 if (object->is_dynamic())
57 this->in_dyn_ = true;
58 else
59 this->in_reg_ = true;
60 }
61
62 // Override the fields in Sized_symbol.
63
64 template<int size>
65 template<bool big_endian>
66 void
67 Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym,
68 unsigned st_shndx, bool is_ordinary,
69 Object* object, const char* version)
70 {
71 this->override_base(sym, st_shndx, is_ordinary, object, version);
72 this->value_ = sym.get_st_value();
73 this->symsize_ = sym.get_st_size();
74 }
75
76 // Override TOSYM with symbol FROMSYM, defined in OBJECT, with version
77 // VERSION. This handles all aliases of TOSYM.
78
79 template<int size, bool big_endian>
80 void
81 Symbol_table::override(Sized_symbol<size>* tosym,
82 const elfcpp::Sym<size, big_endian>& fromsym,
83 unsigned int st_shndx, bool is_ordinary,
84 Object* object, const char* version)
85 {
86 tosym->override(fromsym, st_shndx, is_ordinary, object, version);
87 if (tosym->has_alias())
88 {
89 Symbol* sym = this->weak_aliases_[tosym];
90 gold_assert(sym != NULL);
91 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
92 do
93 {
94 ssym->override(fromsym, st_shndx, is_ordinary, object, version);
95 sym = this->weak_aliases_[ssym];
96 gold_assert(sym != NULL);
97 ssym = this->get_sized_symbol<size>(sym);
98 }
99 while (ssym != tosym);
100 }
101 }
102
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
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, bool is_ordinary, 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 if (!is_ordinary)
167 bits |= common_flag;
168 break;
169
170 default:
171 if (type == elfcpp::STT_COMMON)
172 bits |= common_flag;
173 else
174 bits |= def_flag;
175 break;
176 }
177
178 return bits;
179 }
180
181 // Resolve a symbol. This is called the second and subsequent times
182 // we see a symbol. TO is the pre-existing symbol. ST_SHNDX is the
183 // section index for SYM, possibly adjusted for many sections.
184 // IS_ORDINARY is whether ST_SHNDX is a normal section index rather
185 // than a special code. ORIG_ST_SHNDX is the original section index,
186 // before any munging because of discarded sections, except that all
187 // non-ordinary section indexes are mapped to SHN_UNDEF. VERSION of
188 // the version of SYM.
189
190 template<int size, bool big_endian>
191 void
192 Symbol_table::resolve(Sized_symbol<size>* to,
193 const elfcpp::Sym<size, big_endian>& sym,
194 unsigned int st_shndx, bool is_ordinary,
195 unsigned int orig_st_shndx,
196 Object* object, const char* version)
197 {
198 if (object->target()->has_resolve())
199 {
200 Sized_target<size, big_endian>* sized_target;
201 sized_target = object->sized_target<size, big_endian>();
202 sized_target->resolve(to, sym, object, version);
203 return;
204 }
205
206 if (!object->is_dynamic())
207 {
208 // Record that we've seen this symbol in a regular object.
209 to->set_in_reg();
210 }
211 else
212 {
213 // Record that we've seen this symbol in a dynamic object.
214 to->set_in_dyn();
215 }
216
217 unsigned int frombits = symbol_to_bits(sym.get_st_bind(),
218 object->is_dynamic(),
219 st_shndx, is_ordinary,
220 sym.get_st_type());
221
222 bool adjust_common_sizes;
223 if (Symbol_table::should_override(to, frombits, object,
224 &adjust_common_sizes))
225 {
226 typename Sized_symbol<size>::Size_type tosize = to->symsize();
227
228 this->override(to, sym, st_shndx, is_ordinary, object, version);
229
230 if (adjust_common_sizes && tosize > to->symsize())
231 to->set_symsize(tosize);
232 }
233 else
234 {
235 if (adjust_common_sizes && sym.get_st_size() > to->symsize())
236 to->set_symsize(sym.get_st_size());
237 }
238
239 // A new weak undefined reference, merging with an old weak
240 // reference, could be a One Definition Rule (ODR) violation --
241 // especially if the types or sizes of the references differ. We'll
242 // store such pairs and look them up later to make sure they
243 // actually refer to the same lines of code. (Note: not all ODR
244 // violations can be found this way, and not everything this finds
245 // is an ODR violation. But it's helpful to warn about.)
246 bool to_is_ordinary;
247 if (parameters->options().detect_odr_violations()
248 && sym.get_st_bind() == elfcpp::STB_WEAK
249 && to->binding() == elfcpp::STB_WEAK
250 && orig_st_shndx != elfcpp::SHN_UNDEF
251 && to->shndx(&to_is_ordinary) != elfcpp::SHN_UNDEF
252 && to_is_ordinary
253 && sym.get_st_size() != 0 // Ignore weird 0-sized symbols.
254 && to->symsize() != 0
255 && (sym.get_st_type() != to->type()
256 || sym.get_st_size() != to->symsize())
257 // C does not have a concept of ODR, so we only need to do this
258 // on C++ symbols. These have (mangled) names starting with _Z.
259 && to->name()[0] == '_' && to->name()[1] == 'Z')
260 {
261 Symbol_location fromloc
262 = { object, orig_st_shndx, sym.get_st_value() };
263 Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary),
264 to->value() };
265 this->candidate_odr_violations_[to->name()].insert(fromloc);
266 this->candidate_odr_violations_[to->name()].insert(toloc);
267 }
268 }
269
270 // Handle the core of symbol resolution. This is called with the
271 // existing symbol, TO, and a bitflag describing the new symbol. This
272 // returns true if we should override the existing symbol with the new
273 // one, and returns false otherwise. It sets *ADJUST_COMMON_SIZES to
274 // true if we should set the symbol size to the maximum of the TO and
275 // FROM sizes. It handles error conditions.
276
277 bool
278 Symbol_table::should_override(const Symbol* to, unsigned int frombits,
279 Object* object, bool* adjust_common_sizes)
280 {
281 *adjust_common_sizes = false;
282
283 unsigned int tobits;
284 if (to->source() == Symbol::IS_UNDEFINED)
285 tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_UNDEF, true,
286 to->type());
287 else if (to->source() != Symbol::FROM_OBJECT)
288 tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false,
289 to->type());
290 else
291 {
292 bool is_ordinary;
293 unsigned int shndx = to->shndx(&is_ordinary);
294 tobits = symbol_to_bits(to->binding(),
295 to->object()->is_dynamic(),
296 shndx,
297 is_ordinary,
298 to->type());
299 }
300
301 // FIXME: Warn if either but not both of TO and SYM are STT_TLS.
302
303 // We use a giant switch table for symbol resolution. This code is
304 // unwieldy, but: 1) it is efficient; 2) we definitely handle all
305 // cases; 3) it is easy to change the handling of a particular case.
306 // The alternative would be a series of conditionals, but it is easy
307 // to get the ordering wrong. This could also be done as a table,
308 // but that is no easier to understand than this large switch
309 // statement.
310
311 // These are the values generated by the bit codes.
312 enum
313 {
314 DEF = global_flag | regular_flag | def_flag,
315 WEAK_DEF = weak_flag | regular_flag | def_flag,
316 DYN_DEF = global_flag | dynamic_flag | def_flag,
317 DYN_WEAK_DEF = weak_flag | dynamic_flag | def_flag,
318 UNDEF = global_flag | regular_flag | undef_flag,
319 WEAK_UNDEF = weak_flag | regular_flag | undef_flag,
320 DYN_UNDEF = global_flag | dynamic_flag | undef_flag,
321 DYN_WEAK_UNDEF = weak_flag | dynamic_flag | undef_flag,
322 COMMON = global_flag | regular_flag | common_flag,
323 WEAK_COMMON = weak_flag | regular_flag | common_flag,
324 DYN_COMMON = global_flag | dynamic_flag | common_flag,
325 DYN_WEAK_COMMON = weak_flag | dynamic_flag | common_flag
326 };
327
328 switch (tobits * 16 + frombits)
329 {
330 case DEF * 16 + DEF:
331 // Two definitions of the same symbol.
332
333 // If either symbol is defined by an object included using
334 // --just-symbols, then don't warn. This is for compatibility
335 // with the GNU linker. FIXME: This is a hack.
336 if ((to->source() == Symbol::FROM_OBJECT && to->object()->just_symbols())
337 || object->just_symbols())
338 return false;
339
340 // FIXME: Do a better job of reporting locations.
341 gold_error(_("%s: multiple definition of %s"),
342 object != NULL ? object->name().c_str() : _("command line"),
343 to->demangled_name().c_str());
344 gold_error(_("%s: previous definition here"),
345 (to->source() == Symbol::FROM_OBJECT
346 ? to->object()->name().c_str()
347 : _("command line")));
348 return false;
349
350 case WEAK_DEF * 16 + DEF:
351 // We've seen a weak definition, and now we see a strong
352 // definition. In the original SVR4 linker, this was treated as
353 // a multiple definition error. In the Solaris linker and the
354 // GNU linker, a weak definition followed by a regular
355 // definition causes the weak definition to be overridden. We
356 // are currently compatible with the GNU linker. In the future
357 // we should add a target specific option to change this.
358 // FIXME.
359 return true;
360
361 case DYN_DEF * 16 + DEF:
362 case DYN_WEAK_DEF * 16 + DEF:
363 // We've seen a definition in a dynamic object, and now we see a
364 // definition in a regular object. The definition in the
365 // regular object overrides the definition in the dynamic
366 // object.
367 return true;
368
369 case UNDEF * 16 + DEF:
370 case WEAK_UNDEF * 16 + DEF:
371 case DYN_UNDEF * 16 + DEF:
372 case DYN_WEAK_UNDEF * 16 + DEF:
373 // We've seen an undefined reference, and now we see a
374 // definition. We use the definition.
375 return true;
376
377 case COMMON * 16 + DEF:
378 case WEAK_COMMON * 16 + DEF:
379 case DYN_COMMON * 16 + DEF:
380 case DYN_WEAK_COMMON * 16 + DEF:
381 // We've seen a common symbol and now we see a definition. The
382 // definition overrides. FIXME: We should optionally issue, version a
383 // warning.
384 return true;
385
386 case DEF * 16 + WEAK_DEF:
387 case WEAK_DEF * 16 + WEAK_DEF:
388 // We've seen a definition and now we see a weak definition. We
389 // ignore the new weak definition.
390 return false;
391
392 case DYN_DEF * 16 + WEAK_DEF:
393 case DYN_WEAK_DEF * 16 + WEAK_DEF:
394 // We've seen a dynamic definition and now we see a regular weak
395 // definition. The regular weak definition overrides.
396 return true;
397
398 case UNDEF * 16 + WEAK_DEF:
399 case WEAK_UNDEF * 16 + WEAK_DEF:
400 case DYN_UNDEF * 16 + WEAK_DEF:
401 case DYN_WEAK_UNDEF * 16 + WEAK_DEF:
402 // A weak definition of a currently undefined symbol.
403 return true;
404
405 case COMMON * 16 + WEAK_DEF:
406 case WEAK_COMMON * 16 + WEAK_DEF:
407 // A weak definition does not override a common definition.
408 return false;
409
410 case DYN_COMMON * 16 + WEAK_DEF:
411 case DYN_WEAK_COMMON * 16 + WEAK_DEF:
412 // A weak definition does override a definition in a dynamic
413 // object. FIXME: We should optionally issue a warning.
414 return true;
415
416 case DEF * 16 + DYN_DEF:
417 case WEAK_DEF * 16 + DYN_DEF:
418 case DYN_DEF * 16 + DYN_DEF:
419 case DYN_WEAK_DEF * 16 + DYN_DEF:
420 // Ignore a dynamic definition if we already have a definition.
421 return false;
422
423 case UNDEF * 16 + DYN_DEF:
424 case WEAK_UNDEF * 16 + DYN_DEF:
425 case DYN_UNDEF * 16 + DYN_DEF:
426 case DYN_WEAK_UNDEF * 16 + DYN_DEF:
427 // Use a dynamic definition if we have a reference.
428 return true;
429
430 case COMMON * 16 + DYN_DEF:
431 case WEAK_COMMON * 16 + DYN_DEF:
432 case DYN_COMMON * 16 + DYN_DEF:
433 case DYN_WEAK_COMMON * 16 + DYN_DEF:
434 // Ignore a dynamic definition if we already have a common
435 // definition.
436 return false;
437
438 case DEF * 16 + DYN_WEAK_DEF:
439 case WEAK_DEF * 16 + DYN_WEAK_DEF:
440 case DYN_DEF * 16 + DYN_WEAK_DEF:
441 case DYN_WEAK_DEF * 16 + DYN_WEAK_DEF:
442 // Ignore a weak dynamic definition if we already have a
443 // definition.
444 return false;
445
446 case UNDEF * 16 + DYN_WEAK_DEF:
447 case WEAK_UNDEF * 16 + DYN_WEAK_DEF:
448 case DYN_UNDEF * 16 + DYN_WEAK_DEF:
449 case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF:
450 // Use a weak dynamic definition if we have a reference.
451 return true;
452
453 case COMMON * 16 + DYN_WEAK_DEF:
454 case WEAK_COMMON * 16 + DYN_WEAK_DEF:
455 case DYN_COMMON * 16 + DYN_WEAK_DEF:
456 case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF:
457 // Ignore a weak dynamic definition if we already have a common
458 // definition.
459 return false;
460
461 case DEF * 16 + UNDEF:
462 case WEAK_DEF * 16 + UNDEF:
463 case DYN_DEF * 16 + UNDEF:
464 case DYN_WEAK_DEF * 16 + UNDEF:
465 case UNDEF * 16 + UNDEF:
466 // A new undefined reference tells us nothing.
467 return false;
468
469 case WEAK_UNDEF * 16 + UNDEF:
470 case DYN_UNDEF * 16 + UNDEF:
471 case DYN_WEAK_UNDEF * 16 + UNDEF:
472 // A strong undef overrides a dynamic or weak undef.
473 return true;
474
475 case COMMON * 16 + UNDEF:
476 case WEAK_COMMON * 16 + UNDEF:
477 case DYN_COMMON * 16 + UNDEF:
478 case DYN_WEAK_COMMON * 16 + UNDEF:
479 // A new undefined reference tells us nothing.
480 return false;
481
482 case DEF * 16 + WEAK_UNDEF:
483 case WEAK_DEF * 16 + WEAK_UNDEF:
484 case DYN_DEF * 16 + WEAK_UNDEF:
485 case DYN_WEAK_DEF * 16 + WEAK_UNDEF:
486 case UNDEF * 16 + WEAK_UNDEF:
487 case WEAK_UNDEF * 16 + WEAK_UNDEF:
488 case DYN_UNDEF * 16 + WEAK_UNDEF:
489 case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF:
490 case COMMON * 16 + WEAK_UNDEF:
491 case WEAK_COMMON * 16 + WEAK_UNDEF:
492 case DYN_COMMON * 16 + WEAK_UNDEF:
493 case DYN_WEAK_COMMON * 16 + WEAK_UNDEF:
494 // A new weak undefined reference tells us nothing.
495 return false;
496
497 case DEF * 16 + DYN_UNDEF:
498 case WEAK_DEF * 16 + DYN_UNDEF:
499 case DYN_DEF * 16 + DYN_UNDEF:
500 case DYN_WEAK_DEF * 16 + DYN_UNDEF:
501 case UNDEF * 16 + DYN_UNDEF:
502 case WEAK_UNDEF * 16 + DYN_UNDEF:
503 case DYN_UNDEF * 16 + DYN_UNDEF:
504 case DYN_WEAK_UNDEF * 16 + DYN_UNDEF:
505 case COMMON * 16 + DYN_UNDEF:
506 case WEAK_COMMON * 16 + DYN_UNDEF:
507 case DYN_COMMON * 16 + DYN_UNDEF:
508 case DYN_WEAK_COMMON * 16 + DYN_UNDEF:
509 // A new dynamic undefined reference tells us nothing.
510 return false;
511
512 case DEF * 16 + DYN_WEAK_UNDEF:
513 case WEAK_DEF * 16 + DYN_WEAK_UNDEF:
514 case DYN_DEF * 16 + DYN_WEAK_UNDEF:
515 case DYN_WEAK_DEF * 16 + DYN_WEAK_UNDEF:
516 case UNDEF * 16 + DYN_WEAK_UNDEF:
517 case WEAK_UNDEF * 16 + DYN_WEAK_UNDEF:
518 case DYN_UNDEF * 16 + DYN_WEAK_UNDEF:
519 case DYN_WEAK_UNDEF * 16 + DYN_WEAK_UNDEF:
520 case COMMON * 16 + DYN_WEAK_UNDEF:
521 case WEAK_COMMON * 16 + DYN_WEAK_UNDEF:
522 case DYN_COMMON * 16 + DYN_WEAK_UNDEF:
523 case DYN_WEAK_COMMON * 16 + DYN_WEAK_UNDEF:
524 // A new weak dynamic undefined reference tells us nothing.
525 return false;
526
527 case DEF * 16 + COMMON:
528 // A common symbol does not override a definition.
529 return false;
530
531 case WEAK_DEF * 16 + COMMON:
532 case DYN_DEF * 16 + COMMON:
533 case DYN_WEAK_DEF * 16 + COMMON:
534 // A common symbol does override a weak definition or a dynamic
535 // definition.
536 return true;
537
538 case UNDEF * 16 + COMMON:
539 case WEAK_UNDEF * 16 + COMMON:
540 case DYN_UNDEF * 16 + COMMON:
541 case DYN_WEAK_UNDEF * 16 + COMMON:
542 // A common symbol is a definition for a reference.
543 return true;
544
545 case COMMON * 16 + COMMON:
546 // Set the size to the maximum.
547 *adjust_common_sizes = true;
548 return false;
549
550 case WEAK_COMMON * 16 + COMMON:
551 // I'm not sure just what a weak common symbol means, but
552 // presumably it can be overridden by a regular common symbol.
553 return true;
554
555 case DYN_COMMON * 16 + COMMON:
556 case DYN_WEAK_COMMON * 16 + COMMON:
557 // Use the real common symbol, but adjust the size if necessary.
558 *adjust_common_sizes = true;
559 return true;
560
561 case DEF * 16 + WEAK_COMMON:
562 case WEAK_DEF * 16 + WEAK_COMMON:
563 case DYN_DEF * 16 + WEAK_COMMON:
564 case DYN_WEAK_DEF * 16 + WEAK_COMMON:
565 // Whatever a weak common symbol is, it won't override a
566 // definition.
567 return false;
568
569 case UNDEF * 16 + WEAK_COMMON:
570 case WEAK_UNDEF * 16 + WEAK_COMMON:
571 case DYN_UNDEF * 16 + WEAK_COMMON:
572 case DYN_WEAK_UNDEF * 16 + WEAK_COMMON:
573 // A weak common symbol is better than an undefined symbol.
574 return true;
575
576 case COMMON * 16 + WEAK_COMMON:
577 case WEAK_COMMON * 16 + WEAK_COMMON:
578 case DYN_COMMON * 16 + WEAK_COMMON:
579 case DYN_WEAK_COMMON * 16 + WEAK_COMMON:
580 // Ignore a weak common symbol in the presence of a real common
581 // symbol.
582 return false;
583
584 case DEF * 16 + DYN_COMMON:
585 case WEAK_DEF * 16 + DYN_COMMON:
586 case DYN_DEF * 16 + DYN_COMMON:
587 case DYN_WEAK_DEF * 16 + DYN_COMMON:
588 // Ignore a dynamic common symbol in the presence of a
589 // definition.
590 return false;
591
592 case UNDEF * 16 + DYN_COMMON:
593 case WEAK_UNDEF * 16 + DYN_COMMON:
594 case DYN_UNDEF * 16 + DYN_COMMON:
595 case DYN_WEAK_UNDEF * 16 + DYN_COMMON:
596 // A dynamic common symbol is a definition of sorts.
597 return true;
598
599 case COMMON * 16 + DYN_COMMON:
600 case WEAK_COMMON * 16 + DYN_COMMON:
601 case DYN_COMMON * 16 + DYN_COMMON:
602 case DYN_WEAK_COMMON * 16 + DYN_COMMON:
603 // Set the size to the maximum.
604 *adjust_common_sizes = true;
605 return false;
606
607 case DEF * 16 + DYN_WEAK_COMMON:
608 case WEAK_DEF * 16 + DYN_WEAK_COMMON:
609 case DYN_DEF * 16 + DYN_WEAK_COMMON:
610 case DYN_WEAK_DEF * 16 + DYN_WEAK_COMMON:
611 // A common symbol is ignored in the face of a definition.
612 return false;
613
614 case UNDEF * 16 + DYN_WEAK_COMMON:
615 case WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
616 case DYN_UNDEF * 16 + DYN_WEAK_COMMON:
617 case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
618 // I guess a weak common symbol is better than a definition.
619 return true;
620
621 case COMMON * 16 + DYN_WEAK_COMMON:
622 case WEAK_COMMON * 16 + DYN_WEAK_COMMON:
623 case DYN_COMMON * 16 + DYN_WEAK_COMMON:
624 case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON:
625 // Set the size to the maximum.
626 *adjust_common_sizes = true;
627 return false;
628
629 default:
630 gold_unreachable();
631 }
632 }
633
634 // A special case of should_override which is only called for a strong
635 // defined symbol from a regular object file. This is used when
636 // defining special symbols.
637
638 bool
639 Symbol_table::should_override_with_special(const Symbol* to)
640 {
641 bool adjust_common_sizes;
642 unsigned int frombits = global_flag | regular_flag | def_flag;
643 bool ret = Symbol_table::should_override(to, frombits, NULL,
644 &adjust_common_sizes);
645 gold_assert(!adjust_common_sizes);
646 return ret;
647 }
648
649 // Override symbol base with a special symbol.
650
651 void
652 Symbol::override_base_with_special(const Symbol* from)
653 {
654 gold_assert(this->name_ == from->name_ || this->has_alias());
655
656 this->source_ = from->source_;
657 switch (from->source_)
658 {
659 case FROM_OBJECT:
660 this->u_.from_object = from->u_.from_object;
661 break;
662 case IN_OUTPUT_DATA:
663 this->u_.in_output_data = from->u_.in_output_data;
664 break;
665 case IN_OUTPUT_SEGMENT:
666 this->u_.in_output_segment = from->u_.in_output_segment;
667 break;
668 case IS_CONSTANT:
669 case IS_UNDEFINED:
670 break;
671 default:
672 gold_unreachable();
673 break;
674 }
675
676 if (from->version_ != NULL && this->version_ != from->version_)
677 {
678 gold_assert(this->version_ == NULL);
679 this->version_ = from->version_;
680 }
681
682 this->type_ = from->type_;
683 this->binding_ = from->binding_;
684 this->visibility_ = from->visibility_;
685 this->nonvis_ = from->nonvis_;
686
687 // Special symbols are always considered to be regular symbols.
688 this->in_reg_ = true;
689
690 if (from->needs_dynsym_entry_)
691 this->needs_dynsym_entry_ = true;
692 if (from->needs_dynsym_value_)
693 this->needs_dynsym_value_ = true;
694
695 // We shouldn't see these flags. If we do, we need to handle them
696 // somehow.
697 gold_assert(!from->is_target_special_ || this->is_target_special_);
698 gold_assert(!from->is_forwarder_);
699 gold_assert(!from->has_plt_offset_);
700 gold_assert(!from->has_warning_);
701 gold_assert(!from->is_copied_from_dynobj_);
702 gold_assert(!from->is_forced_local_);
703 }
704
705 // Override a symbol with a special symbol.
706
707 template<int size>
708 void
709 Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from)
710 {
711 this->override_base_with_special(from);
712 this->value_ = from->value_;
713 this->symsize_ = from->symsize_;
714 }
715
716 // Override TOSYM with the special symbol FROMSYM. This handles all
717 // aliases of TOSYM.
718
719 template<int size>
720 void
721 Symbol_table::override_with_special(Sized_symbol<size>* tosym,
722 const Sized_symbol<size>* fromsym)
723 {
724 tosym->override_with_special(fromsym);
725 if (tosym->has_alias())
726 {
727 Symbol* sym = this->weak_aliases_[tosym];
728 gold_assert(sym != NULL);
729 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
730 do
731 {
732 ssym->override_with_special(fromsym);
733 sym = this->weak_aliases_[ssym];
734 gold_assert(sym != NULL);
735 ssym = this->get_sized_symbol<size>(sym);
736 }
737 while (ssym != tosym);
738 }
739 if (tosym->binding() == elfcpp::STB_LOCAL)
740 this->force_local(tosym);
741 }
742
743 // Instantiate the templates we need. We could use the configure
744 // script to restrict this to only the ones needed for implemented
745 // targets.
746
747 #ifdef HAVE_TARGET_32_LITTLE
748 template
749 void
750 Symbol_table::resolve<32, false>(
751 Sized_symbol<32>* to,
752 const elfcpp::Sym<32, false>& sym,
753 unsigned int st_shndx,
754 bool is_ordinary,
755 unsigned int orig_st_shndx,
756 Object* object,
757 const char* version);
758 #endif
759
760 #ifdef HAVE_TARGET_32_BIG
761 template
762 void
763 Symbol_table::resolve<32, true>(
764 Sized_symbol<32>* to,
765 const elfcpp::Sym<32, true>& sym,
766 unsigned int st_shndx,
767 bool is_ordinary,
768 unsigned int orig_st_shndx,
769 Object* object,
770 const char* version);
771 #endif
772
773 #ifdef HAVE_TARGET_64_LITTLE
774 template
775 void
776 Symbol_table::resolve<64, false>(
777 Sized_symbol<64>* to,
778 const elfcpp::Sym<64, false>& sym,
779 unsigned int st_shndx,
780 bool is_ordinary,
781 unsigned int orig_st_shndx,
782 Object* object,
783 const char* version);
784 #endif
785
786 #ifdef HAVE_TARGET_64_BIG
787 template
788 void
789 Symbol_table::resolve<64, true>(
790 Sized_symbol<64>* to,
791 const elfcpp::Sym<64, true>& sym,
792 unsigned int st_shndx,
793 bool is_ordinary,
794 unsigned int orig_st_shndx,
795 Object* object,
796 const char* version);
797 #endif
798
799 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
800 template
801 void
802 Symbol_table::override_with_special<32>(Sized_symbol<32>*,
803 const Sized_symbol<32>*);
804 #endif
805
806 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
807 template
808 void
809 Symbol_table::override_with_special<64>(Sized_symbol<64>*,
810 const Sized_symbol<64>*);
811 #endif
812
813 } // End namespace gold.
This page took 0.046143 seconds and 4 git commands to generate.