1 // resolve.cc -- symbol resolution for gold
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
33 // Symbol methods used in this file.
35 // This symbol is being overridden by another symbol whose version is
36 // VERSION. Update the VERSION_ field accordingly.
39 Symbol::override_version(const char* version
)
43 // This is the case where this symbol is NAME/VERSION, and the
44 // version was not marked as hidden. That makes it the default
45 // version, so we create NAME/NULL. Later we see another symbol
46 // NAME/NULL, and that symbol is overriding this one. In this
47 // case, since NAME/VERSION is the default, we make NAME/NULL
48 // override NAME/VERSION as well. They are already the same
49 // Symbol structure. Setting the VERSION_ field to NULL ensures
50 // that it will be output with the correct, empty, version.
51 this->version_
= version
;
55 // This is the case where this symbol is NAME/VERSION_ONE, and
56 // now we see NAME/VERSION_TWO, and NAME/VERSION_TWO is
57 // overriding NAME. If VERSION_ONE and VERSION_TWO are
58 // different, then this can only happen when VERSION_ONE is NULL
59 // and VERSION_TWO is not hidden.
60 gold_assert(this->version_
== version
|| this->version_
== NULL
);
61 this->version_
= version
;
65 // Override the fields in Symbol.
67 template<int size
, bool big_endian
>
69 Symbol::override_base(const elfcpp::Sym
<size
, big_endian
>& sym
,
70 unsigned int st_shndx
, bool is_ordinary
,
71 Object
* object
, const char* version
)
73 gold_assert(this->source_
== FROM_OBJECT
);
74 this->u_
.from_object
.object
= object
;
75 this->override_version(version
);
76 this->u_
.from_object
.shndx
= st_shndx
;
77 this->is_ordinary_shndx_
= is_ordinary
;
78 this->type_
= sym
.get_st_type();
79 this->binding_
= sym
.get_st_bind();
80 this->visibility_
= sym
.get_st_visibility();
81 this->nonvis_
= sym
.get_st_nonvis();
82 if (object
->is_dynamic())
88 // Override the fields in Sized_symbol.
91 template<bool big_endian
>
93 Sized_symbol
<size
>::override(const elfcpp::Sym
<size
, big_endian
>& sym
,
94 unsigned st_shndx
, bool is_ordinary
,
95 Object
* object
, const char* version
)
97 this->override_base(sym
, st_shndx
, is_ordinary
, object
, version
);
98 this->value_
= sym
.get_st_value();
99 this->symsize_
= sym
.get_st_size();
102 // Override TOSYM with symbol FROMSYM, defined in OBJECT, with version
103 // VERSION. This handles all aliases of TOSYM.
105 template<int size
, bool big_endian
>
107 Symbol_table::override(Sized_symbol
<size
>* tosym
,
108 const elfcpp::Sym
<size
, big_endian
>& fromsym
,
109 unsigned int st_shndx
, bool is_ordinary
,
110 Object
* object
, const char* version
)
112 tosym
->override(fromsym
, st_shndx
, is_ordinary
, object
, version
);
113 if (tosym
->has_alias())
115 Symbol
* sym
= this->weak_aliases_
[tosym
];
116 gold_assert(sym
!= NULL
);
117 Sized_symbol
<size
>* ssym
= this->get_sized_symbol
<size
>(sym
);
120 ssym
->override(fromsym
, st_shndx
, is_ordinary
, object
, version
);
121 sym
= this->weak_aliases_
[ssym
];
122 gold_assert(sym
!= NULL
);
123 ssym
= this->get_sized_symbol
<size
>(sym
);
125 while (ssym
!= tosym
);
129 // The resolve functions build a little code for each symbol.
130 // Bit 0: 0 for global, 1 for weak.
131 // Bit 1: 0 for regular object, 1 for shared object
132 // Bits 2-3: 0 for normal, 1 for undefined, 2 for common
133 // This gives us values from 0 to 11.
135 static const int global_or_weak_shift
= 0;
136 static const unsigned int global_flag
= 0 << global_or_weak_shift
;
137 static const unsigned int weak_flag
= 1 << global_or_weak_shift
;
139 static const int regular_or_dynamic_shift
= 1;
140 static const unsigned int regular_flag
= 0 << regular_or_dynamic_shift
;
141 static const unsigned int dynamic_flag
= 1 << regular_or_dynamic_shift
;
143 static const int def_undef_or_common_shift
= 2;
144 static const unsigned int def_flag
= 0 << def_undef_or_common_shift
;
145 static const unsigned int undef_flag
= 1 << def_undef_or_common_shift
;
146 static const unsigned int common_flag
= 2 << def_undef_or_common_shift
;
148 // This convenience function combines all the flags based on facts
152 symbol_to_bits(elfcpp::STB binding
, bool is_dynamic
,
153 unsigned int shndx
, bool is_ordinary
, elfcpp::STT type
)
159 case elfcpp::STB_GLOBAL
:
163 case elfcpp::STB_WEAK
:
167 case elfcpp::STB_LOCAL
:
168 // We should only see externally visible symbols in the symbol
170 gold_error(_("invalid STB_LOCAL symbol in external symbols"));
174 // Any target which wants to handle STB_LOOS, etc., needs to
175 // define a resolve method.
176 gold_error(_("unsupported symbol binding"));
181 bits
|= dynamic_flag
;
183 bits
|= regular_flag
;
187 case elfcpp::SHN_UNDEF
:
191 case elfcpp::SHN_COMMON
:
197 if (type
== elfcpp::STT_COMMON
)
207 // Resolve a symbol. This is called the second and subsequent times
208 // we see a symbol. TO is the pre-existing symbol. ST_SHNDX is the
209 // section index for SYM, possibly adjusted for many sections.
210 // IS_ORDINARY is whether ST_SHNDX is a normal section index rather
211 // than a special code. ORIG_ST_SHNDX is the original section index,
212 // before any munging because of discarded sections, except that all
213 // non-ordinary section indexes are mapped to SHN_UNDEF. VERSION is
214 // the version of SYM.
216 template<int size
, bool big_endian
>
218 Symbol_table::resolve(Sized_symbol
<size
>* to
,
219 const elfcpp::Sym
<size
, big_endian
>& sym
,
220 unsigned int st_shndx
, bool is_ordinary
,
221 unsigned int orig_st_shndx
,
222 Object
* object
, const char* version
)
224 if (object
->target()->has_resolve())
226 Sized_target
<size
, big_endian
>* sized_target
;
227 sized_target
= object
->sized_target
<size
, big_endian
>();
228 sized_target
->resolve(to
, sym
, object
, version
);
232 if (!object
->is_dynamic())
234 // Record that we've seen this symbol in a regular object.
239 // Record that we've seen this symbol in a dynamic object.
243 unsigned int frombits
= symbol_to_bits(sym
.get_st_bind(),
244 object
->is_dynamic(),
245 st_shndx
, is_ordinary
,
248 bool adjust_common_sizes
;
249 if (Symbol_table::should_override(to
, frombits
, object
,
250 &adjust_common_sizes
))
252 typename Sized_symbol
<size
>::Size_type tosize
= to
->symsize();
254 this->override(to
, sym
, st_shndx
, is_ordinary
, object
, version
);
256 if (adjust_common_sizes
&& tosize
> to
->symsize())
257 to
->set_symsize(tosize
);
261 if (adjust_common_sizes
&& sym
.get_st_size() > to
->symsize())
262 to
->set_symsize(sym
.get_st_size());
265 // A new weak undefined reference, merging with an old weak
266 // reference, could be a One Definition Rule (ODR) violation --
267 // especially if the types or sizes of the references differ. We'll
268 // store such pairs and look them up later to make sure they
269 // actually refer to the same lines of code. (Note: not all ODR
270 // violations can be found this way, and not everything this finds
271 // is an ODR violation. But it's helpful to warn about.)
273 if (parameters
->options().detect_odr_violations()
274 && sym
.get_st_bind() == elfcpp::STB_WEAK
275 && to
->binding() == elfcpp::STB_WEAK
276 && orig_st_shndx
!= elfcpp::SHN_UNDEF
277 && to
->shndx(&to_is_ordinary
) != elfcpp::SHN_UNDEF
279 && sym
.get_st_size() != 0 // Ignore weird 0-sized symbols.
280 && to
->symsize() != 0
281 && (sym
.get_st_type() != to
->type()
282 || sym
.get_st_size() != to
->symsize())
283 // C does not have a concept of ODR, so we only need to do this
284 // on C++ symbols. These have (mangled) names starting with _Z.
285 && to
->name()[0] == '_' && to
->name()[1] == 'Z')
287 Symbol_location fromloc
288 = { object
, orig_st_shndx
, sym
.get_st_value() };
289 Symbol_location toloc
= { to
->object(), to
->shndx(&to_is_ordinary
),
291 this->candidate_odr_violations_
[to
->name()].insert(fromloc
);
292 this->candidate_odr_violations_
[to
->name()].insert(toloc
);
296 // Handle the core of symbol resolution. This is called with the
297 // existing symbol, TO, and a bitflag describing the new symbol. This
298 // returns true if we should override the existing symbol with the new
299 // one, and returns false otherwise. It sets *ADJUST_COMMON_SIZES to
300 // true if we should set the symbol size to the maximum of the TO and
301 // FROM sizes. It handles error conditions.
304 Symbol_table::should_override(const Symbol
* to
, unsigned int frombits
,
305 Object
* object
, bool* adjust_common_sizes
)
307 *adjust_common_sizes
= false;
310 if (to
->source() == Symbol::IS_UNDEFINED
)
311 tobits
= symbol_to_bits(to
->binding(), false, elfcpp::SHN_UNDEF
, true,
313 else if (to
->source() != Symbol::FROM_OBJECT
)
314 tobits
= symbol_to_bits(to
->binding(), false, elfcpp::SHN_ABS
, false,
319 unsigned int shndx
= to
->shndx(&is_ordinary
);
320 tobits
= symbol_to_bits(to
->binding(),
321 to
->object()->is_dynamic(),
327 // FIXME: Warn if either but not both of TO and SYM are STT_TLS.
329 // We use a giant switch table for symbol resolution. This code is
330 // unwieldy, but: 1) it is efficient; 2) we definitely handle all
331 // cases; 3) it is easy to change the handling of a particular case.
332 // The alternative would be a series of conditionals, but it is easy
333 // to get the ordering wrong. This could also be done as a table,
334 // but that is no easier to understand than this large switch
337 // These are the values generated by the bit codes.
340 DEF
= global_flag
| regular_flag
| def_flag
,
341 WEAK_DEF
= weak_flag
| regular_flag
| def_flag
,
342 DYN_DEF
= global_flag
| dynamic_flag
| def_flag
,
343 DYN_WEAK_DEF
= weak_flag
| dynamic_flag
| def_flag
,
344 UNDEF
= global_flag
| regular_flag
| undef_flag
,
345 WEAK_UNDEF
= weak_flag
| regular_flag
| undef_flag
,
346 DYN_UNDEF
= global_flag
| dynamic_flag
| undef_flag
,
347 DYN_WEAK_UNDEF
= weak_flag
| dynamic_flag
| undef_flag
,
348 COMMON
= global_flag
| regular_flag
| common_flag
,
349 WEAK_COMMON
= weak_flag
| regular_flag
| common_flag
,
350 DYN_COMMON
= global_flag
| dynamic_flag
| common_flag
,
351 DYN_WEAK_COMMON
= weak_flag
| dynamic_flag
| common_flag
354 switch (tobits
* 16 + frombits
)
357 // Two definitions of the same symbol.
359 // If either symbol is defined by an object included using
360 // --just-symbols, then don't warn. This is for compatibility
361 // with the GNU linker. FIXME: This is a hack.
362 if ((to
->source() == Symbol::FROM_OBJECT
&& to
->object()->just_symbols())
363 || object
->just_symbols())
366 // FIXME: Do a better job of reporting locations.
367 gold_error(_("%s: multiple definition of %s"),
368 object
!= NULL
? object
->name().c_str() : _("command line"),
369 to
->demangled_name().c_str());
370 gold_error(_("%s: previous definition here"),
371 (to
->source() == Symbol::FROM_OBJECT
372 ? to
->object()->name().c_str()
373 : _("command line")));
376 case WEAK_DEF
* 16 + DEF
:
377 // We've seen a weak definition, and now we see a strong
378 // definition. In the original SVR4 linker, this was treated as
379 // a multiple definition error. In the Solaris linker and the
380 // GNU linker, a weak definition followed by a regular
381 // definition causes the weak definition to be overridden. We
382 // are currently compatible with the GNU linker. In the future
383 // we should add a target specific option to change this.
387 case DYN_DEF
* 16 + DEF
:
388 case DYN_WEAK_DEF
* 16 + DEF
:
389 // We've seen a definition in a dynamic object, and now we see a
390 // definition in a regular object. The definition in the
391 // regular object overrides the definition in the dynamic
395 case UNDEF
* 16 + DEF
:
396 case WEAK_UNDEF
* 16 + DEF
:
397 case DYN_UNDEF
* 16 + DEF
:
398 case DYN_WEAK_UNDEF
* 16 + DEF
:
399 // We've seen an undefined reference, and now we see a
400 // definition. We use the definition.
403 case COMMON
* 16 + DEF
:
404 case WEAK_COMMON
* 16 + DEF
:
405 case DYN_COMMON
* 16 + DEF
:
406 case DYN_WEAK_COMMON
* 16 + DEF
:
407 // We've seen a common symbol and now we see a definition. The
408 // definition overrides. FIXME: We should optionally issue, version a
412 case DEF
* 16 + WEAK_DEF
:
413 case WEAK_DEF
* 16 + WEAK_DEF
:
414 // We've seen a definition and now we see a weak definition. We
415 // ignore the new weak definition.
418 case DYN_DEF
* 16 + WEAK_DEF
:
419 case DYN_WEAK_DEF
* 16 + WEAK_DEF
:
420 // We've seen a dynamic definition and now we see a regular weak
421 // definition. The regular weak definition overrides.
424 case UNDEF
* 16 + WEAK_DEF
:
425 case WEAK_UNDEF
* 16 + WEAK_DEF
:
426 case DYN_UNDEF
* 16 + WEAK_DEF
:
427 case DYN_WEAK_UNDEF
* 16 + WEAK_DEF
:
428 // A weak definition of a currently undefined symbol.
431 case COMMON
* 16 + WEAK_DEF
:
432 case WEAK_COMMON
* 16 + WEAK_DEF
:
433 // A weak definition does not override a common definition.
436 case DYN_COMMON
* 16 + WEAK_DEF
:
437 case DYN_WEAK_COMMON
* 16 + WEAK_DEF
:
438 // A weak definition does override a definition in a dynamic
439 // object. FIXME: We should optionally issue a warning.
442 case DEF
* 16 + DYN_DEF
:
443 case WEAK_DEF
* 16 + DYN_DEF
:
444 case DYN_DEF
* 16 + DYN_DEF
:
445 case DYN_WEAK_DEF
* 16 + DYN_DEF
:
446 // Ignore a dynamic definition if we already have a definition.
449 case UNDEF
* 16 + DYN_DEF
:
450 case WEAK_UNDEF
* 16 + DYN_DEF
:
451 case DYN_UNDEF
* 16 + DYN_DEF
:
452 case DYN_WEAK_UNDEF
* 16 + DYN_DEF
:
453 // Use a dynamic definition if we have a reference.
456 case COMMON
* 16 + DYN_DEF
:
457 case WEAK_COMMON
* 16 + DYN_DEF
:
458 case DYN_COMMON
* 16 + DYN_DEF
:
459 case DYN_WEAK_COMMON
* 16 + DYN_DEF
:
460 // Ignore a dynamic definition if we already have a common
464 case DEF
* 16 + DYN_WEAK_DEF
:
465 case WEAK_DEF
* 16 + DYN_WEAK_DEF
:
466 case DYN_DEF
* 16 + DYN_WEAK_DEF
:
467 case DYN_WEAK_DEF
* 16 + DYN_WEAK_DEF
:
468 // Ignore a weak dynamic definition if we already have a
472 case UNDEF
* 16 + DYN_WEAK_DEF
:
473 case WEAK_UNDEF
* 16 + DYN_WEAK_DEF
:
474 case DYN_UNDEF
* 16 + DYN_WEAK_DEF
:
475 case DYN_WEAK_UNDEF
* 16 + DYN_WEAK_DEF
:
476 // Use a weak dynamic definition if we have a reference.
479 case COMMON
* 16 + DYN_WEAK_DEF
:
480 case WEAK_COMMON
* 16 + DYN_WEAK_DEF
:
481 case DYN_COMMON
* 16 + DYN_WEAK_DEF
:
482 case DYN_WEAK_COMMON
* 16 + DYN_WEAK_DEF
:
483 // Ignore a weak dynamic definition if we already have a common
487 case DEF
* 16 + UNDEF
:
488 case WEAK_DEF
* 16 + UNDEF
:
489 case DYN_DEF
* 16 + UNDEF
:
490 case DYN_WEAK_DEF
* 16 + UNDEF
:
491 case UNDEF
* 16 + UNDEF
:
492 // A new undefined reference tells us nothing.
495 case WEAK_UNDEF
* 16 + UNDEF
:
496 case DYN_UNDEF
* 16 + UNDEF
:
497 case DYN_WEAK_UNDEF
* 16 + UNDEF
:
498 // A strong undef overrides a dynamic or weak undef.
501 case COMMON
* 16 + UNDEF
:
502 case WEAK_COMMON
* 16 + UNDEF
:
503 case DYN_COMMON
* 16 + UNDEF
:
504 case DYN_WEAK_COMMON
* 16 + UNDEF
:
505 // A new undefined reference tells us nothing.
508 case DEF
* 16 + WEAK_UNDEF
:
509 case WEAK_DEF
* 16 + WEAK_UNDEF
:
510 case DYN_DEF
* 16 + WEAK_UNDEF
:
511 case DYN_WEAK_DEF
* 16 + WEAK_UNDEF
:
512 case UNDEF
* 16 + WEAK_UNDEF
:
513 case WEAK_UNDEF
* 16 + WEAK_UNDEF
:
514 case DYN_UNDEF
* 16 + WEAK_UNDEF
:
515 case DYN_WEAK_UNDEF
* 16 + WEAK_UNDEF
:
516 case COMMON
* 16 + WEAK_UNDEF
:
517 case WEAK_COMMON
* 16 + WEAK_UNDEF
:
518 case DYN_COMMON
* 16 + WEAK_UNDEF
:
519 case DYN_WEAK_COMMON
* 16 + WEAK_UNDEF
:
520 // A new weak undefined reference tells us nothing.
523 case DEF
* 16 + DYN_UNDEF
:
524 case WEAK_DEF
* 16 + DYN_UNDEF
:
525 case DYN_DEF
* 16 + DYN_UNDEF
:
526 case DYN_WEAK_DEF
* 16 + DYN_UNDEF
:
527 case UNDEF
* 16 + DYN_UNDEF
:
528 case WEAK_UNDEF
* 16 + DYN_UNDEF
:
529 case DYN_UNDEF
* 16 + DYN_UNDEF
:
530 case DYN_WEAK_UNDEF
* 16 + DYN_UNDEF
:
531 case COMMON
* 16 + DYN_UNDEF
:
532 case WEAK_COMMON
* 16 + DYN_UNDEF
:
533 case DYN_COMMON
* 16 + DYN_UNDEF
:
534 case DYN_WEAK_COMMON
* 16 + DYN_UNDEF
:
535 // A new dynamic undefined reference tells us nothing.
538 case DEF
* 16 + DYN_WEAK_UNDEF
:
539 case WEAK_DEF
* 16 + DYN_WEAK_UNDEF
:
540 case DYN_DEF
* 16 + DYN_WEAK_UNDEF
:
541 case DYN_WEAK_DEF
* 16 + DYN_WEAK_UNDEF
:
542 case UNDEF
* 16 + DYN_WEAK_UNDEF
:
543 case WEAK_UNDEF
* 16 + DYN_WEAK_UNDEF
:
544 case DYN_UNDEF
* 16 + DYN_WEAK_UNDEF
:
545 case DYN_WEAK_UNDEF
* 16 + DYN_WEAK_UNDEF
:
546 case COMMON
* 16 + DYN_WEAK_UNDEF
:
547 case WEAK_COMMON
* 16 + DYN_WEAK_UNDEF
:
548 case DYN_COMMON
* 16 + DYN_WEAK_UNDEF
:
549 case DYN_WEAK_COMMON
* 16 + DYN_WEAK_UNDEF
:
550 // A new weak dynamic undefined reference tells us nothing.
553 case DEF
* 16 + COMMON
:
554 // A common symbol does not override a definition.
557 case WEAK_DEF
* 16 + COMMON
:
558 case DYN_DEF
* 16 + COMMON
:
559 case DYN_WEAK_DEF
* 16 + COMMON
:
560 // A common symbol does override a weak definition or a dynamic
564 case UNDEF
* 16 + COMMON
:
565 case WEAK_UNDEF
* 16 + COMMON
:
566 case DYN_UNDEF
* 16 + COMMON
:
567 case DYN_WEAK_UNDEF
* 16 + COMMON
:
568 // A common symbol is a definition for a reference.
571 case COMMON
* 16 + COMMON
:
572 // Set the size to the maximum.
573 *adjust_common_sizes
= true;
576 case WEAK_COMMON
* 16 + COMMON
:
577 // I'm not sure just what a weak common symbol means, but
578 // presumably it can be overridden by a regular common symbol.
581 case DYN_COMMON
* 16 + COMMON
:
582 case DYN_WEAK_COMMON
* 16 + COMMON
:
583 // Use the real common symbol, but adjust the size if necessary.
584 *adjust_common_sizes
= true;
587 case DEF
* 16 + WEAK_COMMON
:
588 case WEAK_DEF
* 16 + WEAK_COMMON
:
589 case DYN_DEF
* 16 + WEAK_COMMON
:
590 case DYN_WEAK_DEF
* 16 + WEAK_COMMON
:
591 // Whatever a weak common symbol is, it won't override a
595 case UNDEF
* 16 + WEAK_COMMON
:
596 case WEAK_UNDEF
* 16 + WEAK_COMMON
:
597 case DYN_UNDEF
* 16 + WEAK_COMMON
:
598 case DYN_WEAK_UNDEF
* 16 + WEAK_COMMON
:
599 // A weak common symbol is better than an undefined symbol.
602 case COMMON
* 16 + WEAK_COMMON
:
603 case WEAK_COMMON
* 16 + WEAK_COMMON
:
604 case DYN_COMMON
* 16 + WEAK_COMMON
:
605 case DYN_WEAK_COMMON
* 16 + WEAK_COMMON
:
606 // Ignore a weak common symbol in the presence of a real common
610 case DEF
* 16 + DYN_COMMON
:
611 case WEAK_DEF
* 16 + DYN_COMMON
:
612 case DYN_DEF
* 16 + DYN_COMMON
:
613 case DYN_WEAK_DEF
* 16 + DYN_COMMON
:
614 // Ignore a dynamic common symbol in the presence of a
618 case UNDEF
* 16 + DYN_COMMON
:
619 case WEAK_UNDEF
* 16 + DYN_COMMON
:
620 case DYN_UNDEF
* 16 + DYN_COMMON
:
621 case DYN_WEAK_UNDEF
* 16 + DYN_COMMON
:
622 // A dynamic common symbol is a definition of sorts.
625 case COMMON
* 16 + DYN_COMMON
:
626 case WEAK_COMMON
* 16 + DYN_COMMON
:
627 case DYN_COMMON
* 16 + DYN_COMMON
:
628 case DYN_WEAK_COMMON
* 16 + DYN_COMMON
:
629 // Set the size to the maximum.
630 *adjust_common_sizes
= true;
633 case DEF
* 16 + DYN_WEAK_COMMON
:
634 case WEAK_DEF
* 16 + DYN_WEAK_COMMON
:
635 case DYN_DEF
* 16 + DYN_WEAK_COMMON
:
636 case DYN_WEAK_DEF
* 16 + DYN_WEAK_COMMON
:
637 // A common symbol is ignored in the face of a definition.
640 case UNDEF
* 16 + DYN_WEAK_COMMON
:
641 case WEAK_UNDEF
* 16 + DYN_WEAK_COMMON
:
642 case DYN_UNDEF
* 16 + DYN_WEAK_COMMON
:
643 case DYN_WEAK_UNDEF
* 16 + DYN_WEAK_COMMON
:
644 // I guess a weak common symbol is better than a definition.
647 case COMMON
* 16 + DYN_WEAK_COMMON
:
648 case WEAK_COMMON
* 16 + DYN_WEAK_COMMON
:
649 case DYN_COMMON
* 16 + DYN_WEAK_COMMON
:
650 case DYN_WEAK_COMMON
* 16 + DYN_WEAK_COMMON
:
651 // Set the size to the maximum.
652 *adjust_common_sizes
= true;
660 // A special case of should_override which is only called for a strong
661 // defined symbol from a regular object file. This is used when
662 // defining special symbols.
665 Symbol_table::should_override_with_special(const Symbol
* to
)
667 bool adjust_common_sizes
;
668 unsigned int frombits
= global_flag
| regular_flag
| def_flag
;
669 bool ret
= Symbol_table::should_override(to
, frombits
, NULL
,
670 &adjust_common_sizes
);
671 gold_assert(!adjust_common_sizes
);
675 // Override symbol base with a special symbol.
678 Symbol::override_base_with_special(const Symbol
* from
)
680 gold_assert(this->name_
== from
->name_
|| this->has_alias());
682 this->source_
= from
->source_
;
683 switch (from
->source_
)
686 this->u_
.from_object
= from
->u_
.from_object
;
689 this->u_
.in_output_data
= from
->u_
.in_output_data
;
691 case IN_OUTPUT_SEGMENT
:
692 this->u_
.in_output_segment
= from
->u_
.in_output_segment
;
702 this->override_version(from
->version_
);
703 this->type_
= from
->type_
;
704 this->binding_
= from
->binding_
;
705 this->visibility_
= from
->visibility_
;
706 this->nonvis_
= from
->nonvis_
;
708 // Special symbols are always considered to be regular symbols.
709 this->in_reg_
= true;
711 if (from
->needs_dynsym_entry_
)
712 this->needs_dynsym_entry_
= true;
713 if (from
->needs_dynsym_value_
)
714 this->needs_dynsym_value_
= true;
716 // We shouldn't see these flags. If we do, we need to handle them
718 gold_assert(!from
->is_target_special_
|| this->is_target_special_
);
719 gold_assert(!from
->is_forwarder_
);
720 gold_assert(!from
->has_plt_offset_
);
721 gold_assert(!from
->has_warning_
);
722 gold_assert(!from
->is_copied_from_dynobj_
);
723 gold_assert(!from
->is_forced_local_
);
726 // Override a symbol with a special symbol.
730 Sized_symbol
<size
>::override_with_special(const Sized_symbol
<size
>* from
)
732 this->override_base_with_special(from
);
733 this->value_
= from
->value_
;
734 this->symsize_
= from
->symsize_
;
737 // Override TOSYM with the special symbol FROMSYM. This handles all
742 Symbol_table::override_with_special(Sized_symbol
<size
>* tosym
,
743 const Sized_symbol
<size
>* fromsym
)
745 tosym
->override_with_special(fromsym
);
746 if (tosym
->has_alias())
748 Symbol
* sym
= this->weak_aliases_
[tosym
];
749 gold_assert(sym
!= NULL
);
750 Sized_symbol
<size
>* ssym
= this->get_sized_symbol
<size
>(sym
);
753 ssym
->override_with_special(fromsym
);
754 sym
= this->weak_aliases_
[ssym
];
755 gold_assert(sym
!= NULL
);
756 ssym
= this->get_sized_symbol
<size
>(sym
);
758 while (ssym
!= tosym
);
760 if (tosym
->binding() == elfcpp::STB_LOCAL
)
761 this->force_local(tosym
);
764 // Instantiate the templates we need. We could use the configure
765 // script to restrict this to only the ones needed for implemented
768 #ifdef HAVE_TARGET_32_LITTLE
771 Symbol_table::resolve
<32, false>(
772 Sized_symbol
<32>* to
,
773 const elfcpp::Sym
<32, false>& sym
,
774 unsigned int st_shndx
,
776 unsigned int orig_st_shndx
,
778 const char* version
);
781 #ifdef HAVE_TARGET_32_BIG
784 Symbol_table::resolve
<32, true>(
785 Sized_symbol
<32>* to
,
786 const elfcpp::Sym
<32, true>& sym
,
787 unsigned int st_shndx
,
789 unsigned int orig_st_shndx
,
791 const char* version
);
794 #ifdef HAVE_TARGET_64_LITTLE
797 Symbol_table::resolve
<64, false>(
798 Sized_symbol
<64>* to
,
799 const elfcpp::Sym
<64, false>& sym
,
800 unsigned int st_shndx
,
802 unsigned int orig_st_shndx
,
804 const char* version
);
807 #ifdef HAVE_TARGET_64_BIG
810 Symbol_table::resolve
<64, true>(
811 Sized_symbol
<64>* to
,
812 const elfcpp::Sym
<64, true>& sym
,
813 unsigned int st_shndx
,
815 unsigned int orig_st_shndx
,
817 const char* version
);
820 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
823 Symbol_table::override_with_special
<32>(Sized_symbol
<32>*,
824 const Sized_symbol
<32>*);
827 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
830 Symbol_table::override_with_special
<64>(Sized_symbol
<64>*,
831 const Sized_symbol
<64>*);
834 } // End namespace gold.