* ld.texinfo (PowerPC64 ELF64): Fix typo.
[deliverable/binutils-gdb.git] / gold / resolve.cc
CommitLineData
14bfc3f5
ILT
1// resolve.cc -- symbol resolution for gold
2
e5756efb 3// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
14bfc3f5
ILT
23#include "gold.h"
24
25#include "elfcpp.h"
26#include "target.h"
27#include "object.h"
28#include "symtab.h"
29
30namespace gold
31{
32
1564db8d
ILT
33// Symbol methods used in this file.
34
35// Override the fields in Symbol.
36
37template<int size, bool big_endian>
38void
39Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym,
d491d34e 40 unsigned int st_shndx, bool is_ordinary,
14b31740 41 Object* object, const char* version)
1564db8d 42{
a3ad94ed 43 gold_assert(this->source_ == FROM_OBJECT);
ead1e424 44 this->u_.from_object.object = object;
14b31740
ILT
45 if (version != NULL && this->version() != version)
46 {
47 gold_assert(this->version() == NULL);
48 this->version_ = version;
49 }
d491d34e
ILT
50 this->u_.from_object.shndx = st_shndx;
51 this->is_ordinary_shndx_ = is_ordinary;
1564db8d
ILT
52 this->type_ = sym.get_st_type();
53 this->binding_ = sym.get_st_bind();
54 this->visibility_ = sym.get_st_visibility();
ead1e424 55 this->nonvis_ = sym.get_st_nonvis();
0d4f1889
ILT
56 if (object->is_dynamic())
57 this->in_dyn_ = true;
58 else
59 this->in_reg_ = true;
1564db8d
ILT
60}
61
62// Override the fields in Sized_symbol.
63
64template<int size>
65template<bool big_endian>
66void
67Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym,
d491d34e 68 unsigned st_shndx, bool is_ordinary,
14b31740 69 Object* object, const char* version)
1564db8d 70{
d491d34e 71 this->override_base(sym, st_shndx, is_ordinary, object, version);
1564db8d 72 this->value_ = sym.get_st_value();
ead1e424 73 this->symsize_ = sym.get_st_size();
1564db8d
ILT
74}
75
aeddab66
ILT
76// Override TOSYM with symbol FROMSYM, defined in OBJECT, with version
77// VERSION. This handles all aliases of TOSYM.
78
79template<int size, bool big_endian>
80void
81Symbol_table::override(Sized_symbol<size>* tosym,
82 const elfcpp::Sym<size, big_endian>& fromsym,
d491d34e 83 unsigned int st_shndx, bool is_ordinary,
aeddab66
ILT
84 Object* object, const char* version)
85{
d491d34e 86 tosym->override(fromsym, st_shndx, is_ordinary, object, version);
aeddab66
ILT
87 if (tosym->has_alias())
88 {
89 Symbol* sym = this->weak_aliases_[tosym];
90 gold_assert(sym != NULL);
7d1a9ebb 91 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
92 do
93 {
d491d34e 94 ssym->override(fromsym, st_shndx, is_ordinary, object, version);
aeddab66
ILT
95 sym = this->weak_aliases_[ssym];
96 gold_assert(sym != NULL);
7d1a9ebb 97 ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
98 }
99 while (ssym != tosym);
100 }
101}
102
86f2e683
ILT
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
109static const int global_or_weak_shift = 0;
110static const unsigned int global_flag = 0 << global_or_weak_shift;
111static const unsigned int weak_flag = 1 << global_or_weak_shift;
112
113static const int regular_or_dynamic_shift = 1;
114static const unsigned int regular_flag = 0 << regular_or_dynamic_shift;
115static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift;
116
117static const int def_undef_or_common_shift = 2;
118static const unsigned int def_flag = 0 << def_undef_or_common_shift;
119static const unsigned int undef_flag = 1 << def_undef_or_common_shift;
120static const unsigned int common_flag = 2 << def_undef_or_common_shift;
121
70e654ba
ILT
122// This convenience function combines all the flags based on facts
123// about the symbol.
124
125static unsigned int
126symbol_to_bits(elfcpp::STB binding, bool is_dynamic,
d491d34e 127 unsigned int shndx, bool is_ordinary, elfcpp::STT type)
70e654ba
ILT
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:
d491d34e
ILT
166 if (!is_ordinary)
167 bits |= common_flag;
70e654ba
ILT
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
14bfc3f5 181// Resolve a symbol. This is called the second and subsequent times
d491d34e
ILT
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.
14bfc3f5
ILT
189
190template<int size, bool big_endian>
191void
1564db8d 192Symbol_table::resolve(Sized_symbol<size>* to,
14bfc3f5 193 const elfcpp::Sym<size, big_endian>& sym,
d491d34e
ILT
194 unsigned int st_shndx, bool is_ordinary,
195 unsigned int orig_st_shndx,
14b31740 196 Object* object, const char* version)
14bfc3f5
ILT
197{
198 if (object->target()->has_resolve())
199 {
274e99f9 200 Sized_target<size, big_endian>* sized_target;
7d1a9ebb 201 sized_target = object->sized_target<size, big_endian>();
14b31740 202 sized_target->resolve(to, sym, object, version);
14bfc3f5
ILT
203 return;
204 }
205
86f2e683
ILT
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 }
14bfc3f5 216
70e654ba
ILT
217 unsigned int frombits = symbol_to_bits(sym.get_st_bind(),
218 object->is_dynamic(),
d491d34e 219 st_shndx, is_ordinary,
70e654ba 220 sym.get_st_type());
14bfc3f5 221
86f2e683 222 bool adjust_common_sizes;
d20222a1
ILT
223 if (Symbol_table::should_override(to, frombits, object,
224 &adjust_common_sizes))
86f2e683
ILT
225 {
226 typename Sized_symbol<size>::Size_type tosize = to->symsize();
227
d491d34e 228 this->override(to, sym, st_shndx, is_ordinary, object, version);
86f2e683
ILT
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 }
70e654ba
ILT
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.)
d491d34e 246 bool to_is_ordinary;
8851ecca 247 if (parameters->options().detect_odr_violations()
d491d34e 248 && sym.get_st_bind() == elfcpp::STB_WEAK
70e654ba 249 && to->binding() == elfcpp::STB_WEAK
d491d34e
ILT
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.
70e654ba 254 && to->symsize() != 0
d491d34e
ILT
255 && (sym.get_st_type() != to->type()
256 || sym.get_st_size() != to->symsize())
70e654ba
ILT
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 {
a2b1aa12 261 Symbol_location fromloc
d491d34e
ILT
262 = { object, orig_st_shndx, sym.get_st_value() };
263 Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary),
264 to->value() };
a2b1aa12
ILT
265 this->candidate_odr_violations_[to->name()].insert(fromloc);
266 this->candidate_odr_violations_[to->name()].insert(toloc);
70e654ba 267 }
86f2e683
ILT
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
277bool
278Symbol_table::should_override(const Symbol* to, unsigned int frombits,
d20222a1 279 Object* object, bool* adjust_common_sizes)
86f2e683
ILT
280{
281 *adjust_common_sizes = false;
282
e5756efb 283 unsigned int tobits;
f3e9c5c5
ILT
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)
d491d34e 288 tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false,
e5756efb
ILT
289 to->type());
290 else
d491d34e
ILT
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 }
14bfc3f5 300
1564db8d
ILT
301 // FIXME: Warn if either but not both of TO and SYM are STT_TLS.
302
14bfc3f5
ILT
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
86f2e683
ILT
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
14bfc3f5
ILT
328 switch (tobits * 16 + frombits)
329 {
330 case DEF * 16 + DEF:
12e14209 331 // Two definitions of the same symbol.
878405a8
ILT
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
d20222a1
ILT
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"),
a2b1aa12 343 to->demangled_name().c_str());
d20222a1
ILT
344 gold_error(_("%s: previous definition here"),
345 (to->source() == Symbol::FROM_OBJECT
346 ? to->object()->name().c_str()
347 : _("command line")));
86f2e683 348 return false;
14bfc3f5
ILT
349
350 case WEAK_DEF * 16 + DEF:
1564db8d
ILT
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.
86f2e683 359 return true;
14bfc3f5
ILT
360
361 case DYN_DEF * 16 + DEF:
362 case DYN_WEAK_DEF * 16 + DEF:
1564db8d
ILT
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.
86f2e683 367 return true;
1564db8d 368
14bfc3f5
ILT
369 case UNDEF * 16 + DEF:
370 case WEAK_UNDEF * 16 + DEF:
371 case DYN_UNDEF * 16 + DEF:
372 case DYN_WEAK_UNDEF * 16 + DEF:
1564db8d
ILT
373 // We've seen an undefined reference, and now we see a
374 // definition. We use the definition.
86f2e683 375 return true;
1564db8d 376
14bfc3f5
ILT
377 case COMMON * 16 + DEF:
378 case WEAK_COMMON * 16 + DEF:
379 case DYN_COMMON * 16 + DEF:
380 case DYN_WEAK_COMMON * 16 + DEF:
1564db8d 381 // We've seen a common symbol and now we see a definition. The
14b31740 382 // definition overrides. FIXME: We should optionally issue, version a
1564db8d 383 // warning.
86f2e683 384 return true;
14bfc3f5
ILT
385
386 case DEF * 16 + WEAK_DEF:
387 case WEAK_DEF * 16 + WEAK_DEF:
1564db8d
ILT
388 // We've seen a definition and now we see a weak definition. We
389 // ignore the new weak definition.
86f2e683 390 return false;
1564db8d 391
14bfc3f5
ILT
392 case DYN_DEF * 16 + WEAK_DEF:
393 case DYN_WEAK_DEF * 16 + WEAK_DEF:
1564db8d
ILT
394 // We've seen a dynamic definition and now we see a regular weak
395 // definition. The regular weak definition overrides.
86f2e683 396 return true;
1564db8d 397
14bfc3f5
ILT
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:
1564db8d 402 // A weak definition of a currently undefined symbol.
86f2e683 403 return true;
1564db8d 404
14bfc3f5
ILT
405 case COMMON * 16 + WEAK_DEF:
406 case WEAK_COMMON * 16 + WEAK_DEF:
1564db8d 407 // A weak definition does not override a common definition.
86f2e683 408 return false;
1564db8d 409
14bfc3f5
ILT
410 case DYN_COMMON * 16 + WEAK_DEF:
411 case DYN_WEAK_COMMON * 16 + WEAK_DEF:
1564db8d
ILT
412 // A weak definition does override a definition in a dynamic
413 // object. FIXME: We should optionally issue a warning.
86f2e683 414 return true;
14bfc3f5
ILT
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:
1564db8d 420 // Ignore a dynamic definition if we already have a definition.
86f2e683 421 return false;
1564db8d 422
14bfc3f5
ILT
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:
1564db8d 427 // Use a dynamic definition if we have a reference.
86f2e683 428 return true;
1564db8d 429
14bfc3f5
ILT
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:
1564db8d
ILT
434 // Ignore a dynamic definition if we already have a common
435 // definition.
86f2e683 436 return false;
14bfc3f5
ILT
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:
1564db8d
ILT
442 // Ignore a weak dynamic definition if we already have a
443 // definition.
86f2e683 444 return false;
1564db8d 445
14bfc3f5
ILT
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:
1564db8d 450 // Use a weak dynamic definition if we have a reference.
86f2e683 451 return true;
1564db8d 452
14bfc3f5
ILT
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:
1564db8d
ILT
457 // Ignore a weak dynamic definition if we already have a common
458 // definition.
86f2e683 459 return false;
14bfc3f5
ILT
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:
ead1e424 466 // A new undefined reference tells us nothing.
86f2e683 467 return false;
ead1e424 468
14bfc3f5
ILT
469 case WEAK_UNDEF * 16 + UNDEF:
470 case DYN_UNDEF * 16 + UNDEF:
471 case DYN_WEAK_UNDEF * 16 + UNDEF:
ead1e424 472 // A strong undef overrides a dynamic or weak undef.
86f2e683 473 return true;
ead1e424 474
14bfc3f5
ILT
475 case COMMON * 16 + UNDEF:
476 case WEAK_COMMON * 16 + UNDEF:
477 case DYN_COMMON * 16 + UNDEF:
478 case DYN_WEAK_COMMON * 16 + UNDEF:
1564db8d 479 // A new undefined reference tells us nothing.
86f2e683 480 return false;
14bfc3f5
ILT
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:
1564db8d 494 // A new weak undefined reference tells us nothing.
86f2e683 495 return false;
14bfc3f5
ILT
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:
1564db8d 509 // A new dynamic undefined reference tells us nothing.
86f2e683 510 return false;
14bfc3f5
ILT
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:
1564db8d 524 // A new weak dynamic undefined reference tells us nothing.
86f2e683 525 return false;
14bfc3f5
ILT
526
527 case DEF * 16 + COMMON:
1564db8d 528 // A common symbol does not override a definition.
86f2e683 529 return false;
1564db8d 530
14bfc3f5
ILT
531 case WEAK_DEF * 16 + COMMON:
532 case DYN_DEF * 16 + COMMON:
533 case DYN_WEAK_DEF * 16 + COMMON:
1564db8d
ILT
534 // A common symbol does override a weak definition or a dynamic
535 // definition.
86f2e683 536 return true;
1564db8d 537
14bfc3f5
ILT
538 case UNDEF * 16 + COMMON:
539 case WEAK_UNDEF * 16 + COMMON:
540 case DYN_UNDEF * 16 + COMMON:
541 case DYN_WEAK_UNDEF * 16 + COMMON:
1564db8d 542 // A common symbol is a definition for a reference.
86f2e683 543 return true;
1564db8d 544
14bfc3f5 545 case COMMON * 16 + COMMON:
ead1e424 546 // Set the size to the maximum.
86f2e683
ILT
547 *adjust_common_sizes = true;
548 return false;
ead1e424 549
14bfc3f5 550 case WEAK_COMMON * 16 + COMMON:
ead1e424
ILT
551 // I'm not sure just what a weak common symbol means, but
552 // presumably it can be overridden by a regular common symbol.
86f2e683 553 return true;
ead1e424 554
14bfc3f5
ILT
555 case DYN_COMMON * 16 + COMMON:
556 case DYN_WEAK_COMMON * 16 + COMMON:
86f2e683
ILT
557 // Use the real common symbol, but adjust the size if necessary.
558 *adjust_common_sizes = true;
559 return true;
14bfc3f5
ILT
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:
ead1e424
ILT
565 // Whatever a weak common symbol is, it won't override a
566 // definition.
86f2e683 567 return false;
ead1e424 568
14bfc3f5
ILT
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:
ead1e424 573 // A weak common symbol is better than an undefined symbol.
86f2e683 574 return true;
ead1e424 575
14bfc3f5
ILT
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:
ead1e424
ILT
580 // Ignore a weak common symbol in the presence of a real common
581 // symbol.
86f2e683 582 return false;
14bfc3f5
ILT
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:
ead1e424
ILT
588 // Ignore a dynamic common symbol in the presence of a
589 // definition.
86f2e683 590 return false;
ead1e424 591
14bfc3f5
ILT
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:
ead1e424 596 // A dynamic common symbol is a definition of sorts.
86f2e683 597 return true;
ead1e424 598
14bfc3f5
ILT
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:
ead1e424 603 // Set the size to the maximum.
86f2e683
ILT
604 *adjust_common_sizes = true;
605 return false;
14bfc3f5
ILT
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:
ead1e424 611 // A common symbol is ignored in the face of a definition.
86f2e683 612 return false;
ead1e424 613
14bfc3f5
ILT
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:
ead1e424 618 // I guess a weak common symbol is better than a definition.
86f2e683 619 return true;
ead1e424 620
14bfc3f5
ILT
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:
ead1e424 625 // Set the size to the maximum.
86f2e683
ILT
626 *adjust_common_sizes = true;
627 return false;
1564db8d
ILT
628
629 default:
a3ad94ed 630 gold_unreachable();
14bfc3f5
ILT
631 }
632}
633
86f2e683
ILT
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
638bool
639Symbol_table::should_override_with_special(const Symbol* to)
640{
641 bool adjust_common_sizes;
642 unsigned int frombits = global_flag | regular_flag | def_flag;
d20222a1
ILT
643 bool ret = Symbol_table::should_override(to, frombits, NULL,
644 &adjust_common_sizes);
86f2e683
ILT
645 gold_assert(!adjust_common_sizes);
646 return ret;
647}
648
649// Override symbol base with a special symbol.
650
651void
652Symbol::override_base_with_special(const Symbol* from)
653{
46fe1623
ILT
654 gold_assert(this->name_ == from->name_ || this->has_alias());
655
86f2e683
ILT
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;
f3e9c5c5
ILT
668 case IS_CONSTANT:
669 case IS_UNDEFINED:
86f2e683
ILT
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;
46fe1623
ILT
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_);
46fe1623
ILT
699 gold_assert(!from->has_plt_offset_);
700 gold_assert(!from->has_warning_);
701 gold_assert(!from->is_copied_from_dynobj_);
55a93433 702 gold_assert(!from->is_forced_local_);
86f2e683
ILT
703}
704
705// Override a symbol with a special symbol.
706
707template<int size>
708void
709Sized_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
aeddab66
ILT
716// Override TOSYM with the special symbol FROMSYM. This handles all
717// aliases of TOSYM.
718
719template<int size>
720void
721Symbol_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);
7d1a9ebb 729 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
730 do
731 {
732 ssym->override_with_special(fromsym);
733 sym = this->weak_aliases_[ssym];
734 gold_assert(sym != NULL);
7d1a9ebb 735 ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
736 }
737 while (ssym != tosym);
738 }
55a93433
ILT
739 if (tosym->binding() == elfcpp::STB_LOCAL)
740 this->force_local(tosym);
aeddab66
ILT
741}
742
14bfc3f5
ILT
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
193a53d9 747#ifdef HAVE_TARGET_32_LITTLE
14bfc3f5
ILT
748template
749void
193a53d9 750Symbol_table::resolve<32, false>(
1564db8d 751 Sized_symbol<32>* to,
193a53d9 752 const elfcpp::Sym<32, false>& sym,
d491d34e
ILT
753 unsigned int st_shndx,
754 bool is_ordinary,
755 unsigned int orig_st_shndx,
14b31740
ILT
756 Object* object,
757 const char* version);
193a53d9 758#endif
14bfc3f5 759
193a53d9 760#ifdef HAVE_TARGET_32_BIG
14bfc3f5
ILT
761template
762void
193a53d9 763Symbol_table::resolve<32, true>(
1564db8d 764 Sized_symbol<32>* to,
193a53d9 765 const elfcpp::Sym<32, true>& sym,
d491d34e
ILT
766 unsigned int st_shndx,
767 bool is_ordinary,
768 unsigned int orig_st_shndx,
14b31740
ILT
769 Object* object,
770 const char* version);
193a53d9 771#endif
14bfc3f5 772
193a53d9 773#ifdef HAVE_TARGET_64_LITTLE
14bfc3f5
ILT
774template
775void
193a53d9 776Symbol_table::resolve<64, false>(
1564db8d 777 Sized_symbol<64>* to,
193a53d9 778 const elfcpp::Sym<64, false>& sym,
d491d34e
ILT
779 unsigned int st_shndx,
780 bool is_ordinary,
781 unsigned int orig_st_shndx,
14b31740
ILT
782 Object* object,
783 const char* version);
193a53d9 784#endif
14bfc3f5 785
193a53d9 786#ifdef HAVE_TARGET_64_BIG
14bfc3f5
ILT
787template
788void
193a53d9 789Symbol_table::resolve<64, true>(
1564db8d 790 Sized_symbol<64>* to,
193a53d9 791 const elfcpp::Sym<64, true>& sym,
d491d34e
ILT
792 unsigned int st_shndx,
793 bool is_ordinary,
794 unsigned int orig_st_shndx,
14b31740
ILT
795 Object* object,
796 const char* version);
193a53d9 797#endif
14bfc3f5 798
86f2e683
ILT
799#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
800template
801void
aeddab66
ILT
802Symbol_table::override_with_special<32>(Sized_symbol<32>*,
803 const Sized_symbol<32>*);
86f2e683
ILT
804#endif
805
806#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
807template
808void
aeddab66
ILT
809Symbol_table::override_with_special<64>(Sized_symbol<64>*,
810 const Sized_symbol<64>*);
86f2e683
ILT
811#endif
812
14bfc3f5 813} // End namespace gold.
This page took 0.124974 seconds and 4 git commands to generate.