* object.cc (Xindex::initialize_symtab_xindex): New function.
[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::FROM_OBJECT)
285 tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false,
286 to->type());
287 else
288 {
289 bool is_ordinary;
290 unsigned int shndx = to->shndx(&is_ordinary);
291 tobits = symbol_to_bits(to->binding(),
292 to->object()->is_dynamic(),
293 shndx,
294 is_ordinary,
295 to->type());
296 }
297
298 // FIXME: Warn if either but not both of TO and SYM are STT_TLS.
299
300 // We use a giant switch table for symbol resolution. This code is
301 // unwieldy, but: 1) it is efficient; 2) we definitely handle all
302 // cases; 3) it is easy to change the handling of a particular case.
303 // The alternative would be a series of conditionals, but it is easy
304 // to get the ordering wrong. This could also be done as a table,
305 // but that is no easier to understand than this large switch
306 // statement.
307
308 // These are the values generated by the bit codes.
309 enum
310 {
311 DEF = global_flag | regular_flag | def_flag,
312 WEAK_DEF = weak_flag | regular_flag | def_flag,
313 DYN_DEF = global_flag | dynamic_flag | def_flag,
314 DYN_WEAK_DEF = weak_flag | dynamic_flag | def_flag,
315 UNDEF = global_flag | regular_flag | undef_flag,
316 WEAK_UNDEF = weak_flag | regular_flag | undef_flag,
317 DYN_UNDEF = global_flag | dynamic_flag | undef_flag,
318 DYN_WEAK_UNDEF = weak_flag | dynamic_flag | undef_flag,
319 COMMON = global_flag | regular_flag | common_flag,
320 WEAK_COMMON = weak_flag | regular_flag | common_flag,
321 DYN_COMMON = global_flag | dynamic_flag | common_flag,
322 DYN_WEAK_COMMON = weak_flag | dynamic_flag | common_flag
323 };
324
325 switch (tobits * 16 + frombits)
326 {
327 case DEF * 16 + DEF:
328 // Two definitions of the same symbol.
329
330 // If either symbol is defined by an object included using
331 // --just-symbols, then don't warn. This is for compatibility
332 // with the GNU linker. FIXME: This is a hack.
333 if ((to->source() == Symbol::FROM_OBJECT && to->object()->just_symbols())
334 || object->just_symbols())
335 return false;
336
337 // FIXME: Do a better job of reporting locations.
338 gold_error(_("%s: multiple definition of %s"),
339 object != NULL ? object->name().c_str() : _("command line"),
340 to->demangled_name().c_str());
341 gold_error(_("%s: previous definition here"),
342 (to->source() == Symbol::FROM_OBJECT
343 ? to->object()->name().c_str()
344 : _("command line")));
345 return false;
346
347 case WEAK_DEF * 16 + DEF:
348 // We've seen a weak definition, and now we see a strong
349 // definition. In the original SVR4 linker, this was treated as
350 // a multiple definition error. In the Solaris linker and the
351 // GNU linker, a weak definition followed by a regular
352 // definition causes the weak definition to be overridden. We
353 // are currently compatible with the GNU linker. In the future
354 // we should add a target specific option to change this.
355 // FIXME.
356 return true;
357
358 case DYN_DEF * 16 + DEF:
359 case DYN_WEAK_DEF * 16 + DEF:
360 // We've seen a definition in a dynamic object, and now we see a
361 // definition in a regular object. The definition in the
362 // regular object overrides the definition in the dynamic
363 // object.
364 return true;
365
366 case UNDEF * 16 + DEF:
367 case WEAK_UNDEF * 16 + DEF:
368 case DYN_UNDEF * 16 + DEF:
369 case DYN_WEAK_UNDEF * 16 + DEF:
370 // We've seen an undefined reference, and now we see a
371 // definition. We use the definition.
372 return true;
373
374 case COMMON * 16 + DEF:
375 case WEAK_COMMON * 16 + DEF:
376 case DYN_COMMON * 16 + DEF:
377 case DYN_WEAK_COMMON * 16 + DEF:
378 // We've seen a common symbol and now we see a definition. The
379 // definition overrides. FIXME: We should optionally issue, version a
380 // warning.
381 return true;
382
383 case DEF * 16 + WEAK_DEF:
384 case WEAK_DEF * 16 + WEAK_DEF:
385 // We've seen a definition and now we see a weak definition. We
386 // ignore the new weak definition.
387 return false;
388
389 case DYN_DEF * 16 + WEAK_DEF:
390 case DYN_WEAK_DEF * 16 + WEAK_DEF:
391 // We've seen a dynamic definition and now we see a regular weak
392 // definition. The regular weak definition overrides.
393 return true;
394
395 case UNDEF * 16 + WEAK_DEF:
396 case WEAK_UNDEF * 16 + WEAK_DEF:
397 case DYN_UNDEF * 16 + WEAK_DEF:
398 case DYN_WEAK_UNDEF * 16 + WEAK_DEF:
399 // A weak definition of a currently undefined symbol.
400 return true;
401
402 case COMMON * 16 + WEAK_DEF:
403 case WEAK_COMMON * 16 + WEAK_DEF:
404 // A weak definition does not override a common definition.
405 return false;
406
407 case DYN_COMMON * 16 + WEAK_DEF:
408 case DYN_WEAK_COMMON * 16 + WEAK_DEF:
409 // A weak definition does override a definition in a dynamic
410 // object. FIXME: We should optionally issue a warning.
411 return true;
412
413 case DEF * 16 + DYN_DEF:
414 case WEAK_DEF * 16 + DYN_DEF:
415 case DYN_DEF * 16 + DYN_DEF:
416 case DYN_WEAK_DEF * 16 + DYN_DEF:
417 // Ignore a dynamic definition if we already have a definition.
418 return false;
419
420 case UNDEF * 16 + DYN_DEF:
421 case WEAK_UNDEF * 16 + DYN_DEF:
422 case DYN_UNDEF * 16 + DYN_DEF:
423 case DYN_WEAK_UNDEF * 16 + DYN_DEF:
424 // Use a dynamic definition if we have a reference.
425 return true;
426
427 case COMMON * 16 + DYN_DEF:
428 case WEAK_COMMON * 16 + DYN_DEF:
429 case DYN_COMMON * 16 + DYN_DEF:
430 case DYN_WEAK_COMMON * 16 + DYN_DEF:
431 // Ignore a dynamic definition if we already have a common
432 // definition.
433 return false;
434
435 case DEF * 16 + DYN_WEAK_DEF:
436 case WEAK_DEF * 16 + DYN_WEAK_DEF:
437 case DYN_DEF * 16 + DYN_WEAK_DEF:
438 case DYN_WEAK_DEF * 16 + DYN_WEAK_DEF:
439 // Ignore a weak dynamic definition if we already have a
440 // definition.
441 return false;
442
443 case UNDEF * 16 + DYN_WEAK_DEF:
444 case WEAK_UNDEF * 16 + DYN_WEAK_DEF:
445 case DYN_UNDEF * 16 + DYN_WEAK_DEF:
446 case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF:
447 // Use a weak dynamic definition if we have a reference.
448 return true;
449
450 case COMMON * 16 + DYN_WEAK_DEF:
451 case WEAK_COMMON * 16 + DYN_WEAK_DEF:
452 case DYN_COMMON * 16 + DYN_WEAK_DEF:
453 case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF:
454 // Ignore a weak dynamic definition if we already have a common
455 // definition.
456 return false;
457
458 case DEF * 16 + UNDEF:
459 case WEAK_DEF * 16 + UNDEF:
460 case DYN_DEF * 16 + UNDEF:
461 case DYN_WEAK_DEF * 16 + UNDEF:
462 case UNDEF * 16 + UNDEF:
463 // A new undefined reference tells us nothing.
464 return false;
465
466 case WEAK_UNDEF * 16 + UNDEF:
467 case DYN_UNDEF * 16 + UNDEF:
468 case DYN_WEAK_UNDEF * 16 + UNDEF:
469 // A strong undef overrides a dynamic or weak undef.
470 return true;
471
472 case COMMON * 16 + UNDEF:
473 case WEAK_COMMON * 16 + UNDEF:
474 case DYN_COMMON * 16 + UNDEF:
475 case DYN_WEAK_COMMON * 16 + UNDEF:
476 // A new undefined reference tells us nothing.
477 return false;
478
479 case DEF * 16 + WEAK_UNDEF:
480 case WEAK_DEF * 16 + WEAK_UNDEF:
481 case DYN_DEF * 16 + WEAK_UNDEF:
482 case DYN_WEAK_DEF * 16 + WEAK_UNDEF:
483 case UNDEF * 16 + WEAK_UNDEF:
484 case WEAK_UNDEF * 16 + WEAK_UNDEF:
485 case DYN_UNDEF * 16 + WEAK_UNDEF:
486 case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF:
487 case COMMON * 16 + WEAK_UNDEF:
488 case WEAK_COMMON * 16 + WEAK_UNDEF:
489 case DYN_COMMON * 16 + WEAK_UNDEF:
490 case DYN_WEAK_COMMON * 16 + WEAK_UNDEF:
491 // A new weak undefined reference tells us nothing.
492 return false;
493
494 case DEF * 16 + DYN_UNDEF:
495 case WEAK_DEF * 16 + DYN_UNDEF:
496 case DYN_DEF * 16 + DYN_UNDEF:
497 case DYN_WEAK_DEF * 16 + DYN_UNDEF:
498 case UNDEF * 16 + DYN_UNDEF:
499 case WEAK_UNDEF * 16 + DYN_UNDEF:
500 case DYN_UNDEF * 16 + DYN_UNDEF:
501 case DYN_WEAK_UNDEF * 16 + DYN_UNDEF:
502 case COMMON * 16 + DYN_UNDEF:
503 case WEAK_COMMON * 16 + DYN_UNDEF:
504 case DYN_COMMON * 16 + DYN_UNDEF:
505 case DYN_WEAK_COMMON * 16 + DYN_UNDEF:
506 // A new dynamic undefined reference tells us nothing.
507 return false;
508
509 case DEF * 16 + DYN_WEAK_UNDEF:
510 case WEAK_DEF * 16 + DYN_WEAK_UNDEF:
511 case DYN_DEF * 16 + DYN_WEAK_UNDEF:
512 case DYN_WEAK_DEF * 16 + DYN_WEAK_UNDEF:
513 case UNDEF * 16 + DYN_WEAK_UNDEF:
514 case WEAK_UNDEF * 16 + DYN_WEAK_UNDEF:
515 case DYN_UNDEF * 16 + DYN_WEAK_UNDEF:
516 case DYN_WEAK_UNDEF * 16 + DYN_WEAK_UNDEF:
517 case COMMON * 16 + DYN_WEAK_UNDEF:
518 case WEAK_COMMON * 16 + DYN_WEAK_UNDEF:
519 case DYN_COMMON * 16 + DYN_WEAK_UNDEF:
520 case DYN_WEAK_COMMON * 16 + DYN_WEAK_UNDEF:
521 // A new weak dynamic undefined reference tells us nothing.
522 return false;
523
524 case DEF * 16 + COMMON:
525 // A common symbol does not override a definition.
526 return false;
527
528 case WEAK_DEF * 16 + COMMON:
529 case DYN_DEF * 16 + COMMON:
530 case DYN_WEAK_DEF * 16 + COMMON:
531 // A common symbol does override a weak definition or a dynamic
532 // definition.
533 return true;
534
535 case UNDEF * 16 + COMMON:
536 case WEAK_UNDEF * 16 + COMMON:
537 case DYN_UNDEF * 16 + COMMON:
538 case DYN_WEAK_UNDEF * 16 + COMMON:
539 // A common symbol is a definition for a reference.
540 return true;
541
542 case COMMON * 16 + COMMON:
543 // Set the size to the maximum.
544 *adjust_common_sizes = true;
545 return false;
546
547 case WEAK_COMMON * 16 + COMMON:
548 // I'm not sure just what a weak common symbol means, but
549 // presumably it can be overridden by a regular common symbol.
550 return true;
551
552 case DYN_COMMON * 16 + COMMON:
553 case DYN_WEAK_COMMON * 16 + COMMON:
554 // Use the real common symbol, but adjust the size if necessary.
555 *adjust_common_sizes = true;
556 return true;
557
558 case DEF * 16 + WEAK_COMMON:
559 case WEAK_DEF * 16 + WEAK_COMMON:
560 case DYN_DEF * 16 + WEAK_COMMON:
561 case DYN_WEAK_DEF * 16 + WEAK_COMMON:
562 // Whatever a weak common symbol is, it won't override a
563 // definition.
564 return false;
565
566 case UNDEF * 16 + WEAK_COMMON:
567 case WEAK_UNDEF * 16 + WEAK_COMMON:
568 case DYN_UNDEF * 16 + WEAK_COMMON:
569 case DYN_WEAK_UNDEF * 16 + WEAK_COMMON:
570 // A weak common symbol is better than an undefined symbol.
571 return true;
572
573 case COMMON * 16 + WEAK_COMMON:
574 case WEAK_COMMON * 16 + WEAK_COMMON:
575 case DYN_COMMON * 16 + WEAK_COMMON:
576 case DYN_WEAK_COMMON * 16 + WEAK_COMMON:
577 // Ignore a weak common symbol in the presence of a real common
578 // symbol.
579 return false;
580
581 case DEF * 16 + DYN_COMMON:
582 case WEAK_DEF * 16 + DYN_COMMON:
583 case DYN_DEF * 16 + DYN_COMMON:
584 case DYN_WEAK_DEF * 16 + DYN_COMMON:
585 // Ignore a dynamic common symbol in the presence of a
586 // definition.
587 return false;
588
589 case UNDEF * 16 + DYN_COMMON:
590 case WEAK_UNDEF * 16 + DYN_COMMON:
591 case DYN_UNDEF * 16 + DYN_COMMON:
592 case DYN_WEAK_UNDEF * 16 + DYN_COMMON:
593 // A dynamic common symbol is a definition of sorts.
594 return true;
595
596 case COMMON * 16 + DYN_COMMON:
597 case WEAK_COMMON * 16 + DYN_COMMON:
598 case DYN_COMMON * 16 + DYN_COMMON:
599 case DYN_WEAK_COMMON * 16 + DYN_COMMON:
600 // Set the size to the maximum.
601 *adjust_common_sizes = true;
602 return false;
603
604 case DEF * 16 + DYN_WEAK_COMMON:
605 case WEAK_DEF * 16 + DYN_WEAK_COMMON:
606 case DYN_DEF * 16 + DYN_WEAK_COMMON:
607 case DYN_WEAK_DEF * 16 + DYN_WEAK_COMMON:
608 // A common symbol is ignored in the face of a definition.
609 return false;
610
611 case UNDEF * 16 + DYN_WEAK_COMMON:
612 case WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
613 case DYN_UNDEF * 16 + DYN_WEAK_COMMON:
614 case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
615 // I guess a weak common symbol is better than a definition.
616 return true;
617
618 case COMMON * 16 + DYN_WEAK_COMMON:
619 case WEAK_COMMON * 16 + DYN_WEAK_COMMON:
620 case DYN_COMMON * 16 + DYN_WEAK_COMMON:
621 case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON:
622 // Set the size to the maximum.
623 *adjust_common_sizes = true;
624 return false;
625
626 default:
627 gold_unreachable();
628 }
629 }
630
631 // A special case of should_override which is only called for a strong
632 // defined symbol from a regular object file. This is used when
633 // defining special symbols.
634
635 bool
636 Symbol_table::should_override_with_special(const Symbol* to)
637 {
638 bool adjust_common_sizes;
639 unsigned int frombits = global_flag | regular_flag | def_flag;
640 bool ret = Symbol_table::should_override(to, frombits, NULL,
641 &adjust_common_sizes);
642 gold_assert(!adjust_common_sizes);
643 return ret;
644 }
645
646 // Override symbol base with a special symbol.
647
648 void
649 Symbol::override_base_with_special(const Symbol* from)
650 {
651 gold_assert(this->name_ == from->name_ || this->has_alias());
652
653 this->source_ = from->source_;
654 switch (from->source_)
655 {
656 case FROM_OBJECT:
657 this->u_.from_object = from->u_.from_object;
658 break;
659 case IN_OUTPUT_DATA:
660 this->u_.in_output_data = from->u_.in_output_data;
661 break;
662 case IN_OUTPUT_SEGMENT:
663 this->u_.in_output_segment = from->u_.in_output_segment;
664 break;
665 case CONSTANT:
666 break;
667 default:
668 gold_unreachable();
669 break;
670 }
671
672 if (from->version_ != NULL && this->version_ != from->version_)
673 {
674 gold_assert(this->version_ == NULL);
675 this->version_ = from->version_;
676 }
677
678 this->type_ = from->type_;
679 this->binding_ = from->binding_;
680 this->visibility_ = from->visibility_;
681 this->nonvis_ = from->nonvis_;
682
683 // Special symbols are always considered to be regular symbols.
684 this->in_reg_ = true;
685
686 if (from->needs_dynsym_entry_)
687 this->needs_dynsym_entry_ = true;
688 if (from->needs_dynsym_value_)
689 this->needs_dynsym_value_ = true;
690
691 // We shouldn't see these flags. If we do, we need to handle them
692 // somehow.
693 gold_assert(!from->is_target_special_ || this->is_target_special_);
694 gold_assert(!from->is_forwarder_);
695 gold_assert(!from->has_plt_offset_);
696 gold_assert(!from->has_warning_);
697 gold_assert(!from->is_copied_from_dynobj_);
698 gold_assert(!from->is_forced_local_);
699 }
700
701 // Override a symbol with a special symbol.
702
703 template<int size>
704 void
705 Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from)
706 {
707 this->override_base_with_special(from);
708 this->value_ = from->value_;
709 this->symsize_ = from->symsize_;
710 }
711
712 // Override TOSYM with the special symbol FROMSYM. This handles all
713 // aliases of TOSYM.
714
715 template<int size>
716 void
717 Symbol_table::override_with_special(Sized_symbol<size>* tosym,
718 const Sized_symbol<size>* fromsym)
719 {
720 tosym->override_with_special(fromsym);
721 if (tosym->has_alias())
722 {
723 Symbol* sym = this->weak_aliases_[tosym];
724 gold_assert(sym != NULL);
725 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
726 do
727 {
728 ssym->override_with_special(fromsym);
729 sym = this->weak_aliases_[ssym];
730 gold_assert(sym != NULL);
731 ssym = this->get_sized_symbol<size>(sym);
732 }
733 while (ssym != tosym);
734 }
735 if (tosym->binding() == elfcpp::STB_LOCAL)
736 this->force_local(tosym);
737 }
738
739 // Instantiate the templates we need. We could use the configure
740 // script to restrict this to only the ones needed for implemented
741 // targets.
742
743 #ifdef HAVE_TARGET_32_LITTLE
744 template
745 void
746 Symbol_table::resolve<32, false>(
747 Sized_symbol<32>* to,
748 const elfcpp::Sym<32, false>& sym,
749 unsigned int st_shndx,
750 bool is_ordinary,
751 unsigned int orig_st_shndx,
752 Object* object,
753 const char* version);
754 #endif
755
756 #ifdef HAVE_TARGET_32_BIG
757 template
758 void
759 Symbol_table::resolve<32, true>(
760 Sized_symbol<32>* to,
761 const elfcpp::Sym<32, true>& sym,
762 unsigned int st_shndx,
763 bool is_ordinary,
764 unsigned int orig_st_shndx,
765 Object* object,
766 const char* version);
767 #endif
768
769 #ifdef HAVE_TARGET_64_LITTLE
770 template
771 void
772 Symbol_table::resolve<64, false>(
773 Sized_symbol<64>* to,
774 const elfcpp::Sym<64, false>& sym,
775 unsigned int st_shndx,
776 bool is_ordinary,
777 unsigned int orig_st_shndx,
778 Object* object,
779 const char* version);
780 #endif
781
782 #ifdef HAVE_TARGET_64_BIG
783 template
784 void
785 Symbol_table::resolve<64, true>(
786 Sized_symbol<64>* to,
787 const elfcpp::Sym<64, true>& sym,
788 unsigned int st_shndx,
789 bool is_ordinary,
790 unsigned int orig_st_shndx,
791 Object* object,
792 const char* version);
793 #endif
794
795 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
796 template
797 void
798 Symbol_table::override_with_special<32>(Sized_symbol<32>*,
799 const Sized_symbol<32>*);
800 #endif
801
802 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
803 template
804 void
805 Symbol_table::override_with_special<64>(Sized_symbol<64>*,
806 const Sized_symbol<64>*);
807 #endif
808
809 } // End namespace gold.
This page took 0.06209 seconds and 5 git commands to generate.