* nto-procfs.c (procfs_xfer_memory): Changed signature.
[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
75517b77
ILT
35// This symbol is being overridden by another symbol whose version is
36// VERSION. Update the VERSION_ field accordingly.
37
38inline void
39Symbol::override_version(const char* version)
40{
41 if (version == NULL)
42 {
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;
52 }
53 else
54 {
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;
62 }
63}
64
1564db8d
ILT
65// Override the fields in Symbol.
66
67template<int size, bool big_endian>
68void
69Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym,
d491d34e 70 unsigned int st_shndx, bool is_ordinary,
14b31740 71 Object* object, const char* version)
1564db8d 72{
a3ad94ed 73 gold_assert(this->source_ == FROM_OBJECT);
ead1e424 74 this->u_.from_object.object = object;
75517b77 75 this->override_version(version);
d491d34e
ILT
76 this->u_.from_object.shndx = st_shndx;
77 this->is_ordinary_shndx_ = is_ordinary;
1564db8d
ILT
78 this->type_ = sym.get_st_type();
79 this->binding_ = sym.get_st_bind();
80 this->visibility_ = sym.get_st_visibility();
ead1e424 81 this->nonvis_ = sym.get_st_nonvis();
0d4f1889
ILT
82 if (object->is_dynamic())
83 this->in_dyn_ = true;
84 else
85 this->in_reg_ = true;
1564db8d
ILT
86}
87
88// Override the fields in Sized_symbol.
89
90template<int size>
91template<bool big_endian>
92void
93Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym,
d491d34e 94 unsigned st_shndx, bool is_ordinary,
14b31740 95 Object* object, const char* version)
1564db8d 96{
d491d34e 97 this->override_base(sym, st_shndx, is_ordinary, object, version);
1564db8d 98 this->value_ = sym.get_st_value();
ead1e424 99 this->symsize_ = sym.get_st_size();
1564db8d
ILT
100}
101
aeddab66
ILT
102// Override TOSYM with symbol FROMSYM, defined in OBJECT, with version
103// VERSION. This handles all aliases of TOSYM.
104
105template<int size, bool big_endian>
106void
107Symbol_table::override(Sized_symbol<size>* tosym,
108 const elfcpp::Sym<size, big_endian>& fromsym,
d491d34e 109 unsigned int st_shndx, bool is_ordinary,
aeddab66
ILT
110 Object* object, const char* version)
111{
d491d34e 112 tosym->override(fromsym, st_shndx, is_ordinary, object, version);
aeddab66
ILT
113 if (tosym->has_alias())
114 {
115 Symbol* sym = this->weak_aliases_[tosym];
116 gold_assert(sym != NULL);
7d1a9ebb 117 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
118 do
119 {
d491d34e 120 ssym->override(fromsym, st_shndx, is_ordinary, object, version);
aeddab66
ILT
121 sym = this->weak_aliases_[ssym];
122 gold_assert(sym != NULL);
7d1a9ebb 123 ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
124 }
125 while (ssym != tosym);
126 }
127}
128
86f2e683
ILT
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.
134
135static const int global_or_weak_shift = 0;
136static const unsigned int global_flag = 0 << global_or_weak_shift;
137static const unsigned int weak_flag = 1 << global_or_weak_shift;
138
139static const int regular_or_dynamic_shift = 1;
140static const unsigned int regular_flag = 0 << regular_or_dynamic_shift;
141static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift;
142
143static const int def_undef_or_common_shift = 2;
144static const unsigned int def_flag = 0 << def_undef_or_common_shift;
145static const unsigned int undef_flag = 1 << def_undef_or_common_shift;
146static const unsigned int common_flag = 2 << def_undef_or_common_shift;
147
70e654ba
ILT
148// This convenience function combines all the flags based on facts
149// about the symbol.
150
151static unsigned int
152symbol_to_bits(elfcpp::STB binding, bool is_dynamic,
d491d34e 153 unsigned int shndx, bool is_ordinary, elfcpp::STT type)
70e654ba
ILT
154{
155 unsigned int bits;
156
157 switch (binding)
158 {
159 case elfcpp::STB_GLOBAL:
160 bits = global_flag;
161 break;
162
163 case elfcpp::STB_WEAK:
164 bits = weak_flag;
165 break;
166
167 case elfcpp::STB_LOCAL:
168 // We should only see externally visible symbols in the symbol
169 // table.
170 gold_error(_("invalid STB_LOCAL symbol in external symbols"));
171 bits = global_flag;
172
173 default:
174 // Any target which wants to handle STB_LOOS, etc., needs to
175 // define a resolve method.
176 gold_error(_("unsupported symbol binding"));
177 bits = global_flag;
178 }
179
180 if (is_dynamic)
181 bits |= dynamic_flag;
182 else
183 bits |= regular_flag;
184
185 switch (shndx)
186 {
187 case elfcpp::SHN_UNDEF:
188 bits |= undef_flag;
189 break;
190
191 case elfcpp::SHN_COMMON:
d491d34e
ILT
192 if (!is_ordinary)
193 bits |= common_flag;
70e654ba
ILT
194 break;
195
196 default:
197 if (type == elfcpp::STT_COMMON)
198 bits |= common_flag;
199 else
200 bits |= def_flag;
201 break;
202 }
203
204 return bits;
205}
206
14bfc3f5 207// Resolve a symbol. This is called the second and subsequent times
d491d34e
ILT
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 of
214// the version of SYM.
14bfc3f5
ILT
215
216template<int size, bool big_endian>
217void
1564db8d 218Symbol_table::resolve(Sized_symbol<size>* to,
14bfc3f5 219 const elfcpp::Sym<size, big_endian>& sym,
d491d34e
ILT
220 unsigned int st_shndx, bool is_ordinary,
221 unsigned int orig_st_shndx,
14b31740 222 Object* object, const char* version)
14bfc3f5
ILT
223{
224 if (object->target()->has_resolve())
225 {
274e99f9 226 Sized_target<size, big_endian>* sized_target;
7d1a9ebb 227 sized_target = object->sized_target<size, big_endian>();
14b31740 228 sized_target->resolve(to, sym, object, version);
14bfc3f5
ILT
229 return;
230 }
231
86f2e683
ILT
232 if (!object->is_dynamic())
233 {
234 // Record that we've seen this symbol in a regular object.
235 to->set_in_reg();
236 }
237 else
238 {
239 // Record that we've seen this symbol in a dynamic object.
240 to->set_in_dyn();
241 }
14bfc3f5 242
70e654ba
ILT
243 unsigned int frombits = symbol_to_bits(sym.get_st_bind(),
244 object->is_dynamic(),
d491d34e 245 st_shndx, is_ordinary,
70e654ba 246 sym.get_st_type());
14bfc3f5 247
86f2e683 248 bool adjust_common_sizes;
d20222a1
ILT
249 if (Symbol_table::should_override(to, frombits, object,
250 &adjust_common_sizes))
86f2e683
ILT
251 {
252 typename Sized_symbol<size>::Size_type tosize = to->symsize();
253
d491d34e 254 this->override(to, sym, st_shndx, is_ordinary, object, version);
86f2e683
ILT
255
256 if (adjust_common_sizes && tosize > to->symsize())
257 to->set_symsize(tosize);
258 }
259 else
260 {
261 if (adjust_common_sizes && sym.get_st_size() > to->symsize())
262 to->set_symsize(sym.get_st_size());
263 }
70e654ba
ILT
264
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.)
d491d34e 272 bool to_is_ordinary;
8851ecca 273 if (parameters->options().detect_odr_violations()
d491d34e 274 && sym.get_st_bind() == elfcpp::STB_WEAK
70e654ba 275 && to->binding() == elfcpp::STB_WEAK
d491d34e
ILT
276 && orig_st_shndx != elfcpp::SHN_UNDEF
277 && to->shndx(&to_is_ordinary) != elfcpp::SHN_UNDEF
278 && to_is_ordinary
279 && sym.get_st_size() != 0 // Ignore weird 0-sized symbols.
70e654ba 280 && to->symsize() != 0
d491d34e
ILT
281 && (sym.get_st_type() != to->type()
282 || sym.get_st_size() != to->symsize())
70e654ba
ILT
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')
286 {
a2b1aa12 287 Symbol_location fromloc
d491d34e
ILT
288 = { object, orig_st_shndx, sym.get_st_value() };
289 Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary),
290 to->value() };
a2b1aa12
ILT
291 this->candidate_odr_violations_[to->name()].insert(fromloc);
292 this->candidate_odr_violations_[to->name()].insert(toloc);
70e654ba 293 }
86f2e683
ILT
294}
295
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.
302
303bool
304Symbol_table::should_override(const Symbol* to, unsigned int frombits,
d20222a1 305 Object* object, bool* adjust_common_sizes)
86f2e683
ILT
306{
307 *adjust_common_sizes = false;
308
e5756efb 309 unsigned int tobits;
f3e9c5c5
ILT
310 if (to->source() == Symbol::IS_UNDEFINED)
311 tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_UNDEF, true,
312 to->type());
313 else if (to->source() != Symbol::FROM_OBJECT)
d491d34e 314 tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false,
e5756efb
ILT
315 to->type());
316 else
d491d34e
ILT
317 {
318 bool is_ordinary;
319 unsigned int shndx = to->shndx(&is_ordinary);
320 tobits = symbol_to_bits(to->binding(),
321 to->object()->is_dynamic(),
322 shndx,
323 is_ordinary,
324 to->type());
325 }
14bfc3f5 326
1564db8d
ILT
327 // FIXME: Warn if either but not both of TO and SYM are STT_TLS.
328
14bfc3f5
ILT
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
335 // statement.
336
86f2e683
ILT
337 // These are the values generated by the bit codes.
338 enum
339 {
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
352 };
353
14bfc3f5
ILT
354 switch (tobits * 16 + frombits)
355 {
356 case DEF * 16 + DEF:
12e14209 357 // Two definitions of the same symbol.
878405a8
ILT
358
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())
364 return false;
365
d20222a1
ILT
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"),
a2b1aa12 369 to->demangled_name().c_str());
d20222a1
ILT
370 gold_error(_("%s: previous definition here"),
371 (to->source() == Symbol::FROM_OBJECT
372 ? to->object()->name().c_str()
373 : _("command line")));
86f2e683 374 return false;
14bfc3f5
ILT
375
376 case WEAK_DEF * 16 + DEF:
1564db8d
ILT
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.
384 // FIXME.
86f2e683 385 return true;
14bfc3f5
ILT
386
387 case DYN_DEF * 16 + DEF:
388 case DYN_WEAK_DEF * 16 + DEF:
1564db8d
ILT
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
392 // object.
86f2e683 393 return true;
1564db8d 394
14bfc3f5
ILT
395 case UNDEF * 16 + DEF:
396 case WEAK_UNDEF * 16 + DEF:
397 case DYN_UNDEF * 16 + DEF:
398 case DYN_WEAK_UNDEF * 16 + DEF:
1564db8d
ILT
399 // We've seen an undefined reference, and now we see a
400 // definition. We use the definition.
86f2e683 401 return true;
1564db8d 402
14bfc3f5
ILT
403 case COMMON * 16 + DEF:
404 case WEAK_COMMON * 16 + DEF:
405 case DYN_COMMON * 16 + DEF:
406 case DYN_WEAK_COMMON * 16 + DEF:
1564db8d 407 // We've seen a common symbol and now we see a definition. The
14b31740 408 // definition overrides. FIXME: We should optionally issue, version a
1564db8d 409 // warning.
86f2e683 410 return true;
14bfc3f5
ILT
411
412 case DEF * 16 + WEAK_DEF:
413 case WEAK_DEF * 16 + WEAK_DEF:
1564db8d
ILT
414 // We've seen a definition and now we see a weak definition. We
415 // ignore the new weak definition.
86f2e683 416 return false;
1564db8d 417
14bfc3f5
ILT
418 case DYN_DEF * 16 + WEAK_DEF:
419 case DYN_WEAK_DEF * 16 + WEAK_DEF:
1564db8d
ILT
420 // We've seen a dynamic definition and now we see a regular weak
421 // definition. The regular weak definition overrides.
86f2e683 422 return true;
1564db8d 423
14bfc3f5
ILT
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:
1564db8d 428 // A weak definition of a currently undefined symbol.
86f2e683 429 return true;
1564db8d 430
14bfc3f5
ILT
431 case COMMON * 16 + WEAK_DEF:
432 case WEAK_COMMON * 16 + WEAK_DEF:
1564db8d 433 // A weak definition does not override a common definition.
86f2e683 434 return false;
1564db8d 435
14bfc3f5
ILT
436 case DYN_COMMON * 16 + WEAK_DEF:
437 case DYN_WEAK_COMMON * 16 + WEAK_DEF:
1564db8d
ILT
438 // A weak definition does override a definition in a dynamic
439 // object. FIXME: We should optionally issue a warning.
86f2e683 440 return true;
14bfc3f5
ILT
441
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:
1564db8d 446 // Ignore a dynamic definition if we already have a definition.
86f2e683 447 return false;
1564db8d 448
14bfc3f5
ILT
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:
1564db8d 453 // Use a dynamic definition if we have a reference.
86f2e683 454 return true;
1564db8d 455
14bfc3f5
ILT
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:
1564db8d
ILT
460 // Ignore a dynamic definition if we already have a common
461 // definition.
86f2e683 462 return false;
14bfc3f5
ILT
463
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:
1564db8d
ILT
468 // Ignore a weak dynamic definition if we already have a
469 // definition.
86f2e683 470 return false;
1564db8d 471
14bfc3f5
ILT
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:
1564db8d 476 // Use a weak dynamic definition if we have a reference.
86f2e683 477 return true;
1564db8d 478
14bfc3f5
ILT
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:
1564db8d
ILT
483 // Ignore a weak dynamic definition if we already have a common
484 // definition.
86f2e683 485 return false;
14bfc3f5
ILT
486
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:
ead1e424 492 // A new undefined reference tells us nothing.
86f2e683 493 return false;
ead1e424 494
14bfc3f5
ILT
495 case WEAK_UNDEF * 16 + UNDEF:
496 case DYN_UNDEF * 16 + UNDEF:
497 case DYN_WEAK_UNDEF * 16 + UNDEF:
ead1e424 498 // A strong undef overrides a dynamic or weak undef.
86f2e683 499 return true;
ead1e424 500
14bfc3f5
ILT
501 case COMMON * 16 + UNDEF:
502 case WEAK_COMMON * 16 + UNDEF:
503 case DYN_COMMON * 16 + UNDEF:
504 case DYN_WEAK_COMMON * 16 + UNDEF:
1564db8d 505 // A new undefined reference tells us nothing.
86f2e683 506 return false;
14bfc3f5
ILT
507
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:
1564db8d 520 // A new weak undefined reference tells us nothing.
86f2e683 521 return false;
14bfc3f5
ILT
522
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:
1564db8d 535 // A new dynamic undefined reference tells us nothing.
86f2e683 536 return false;
14bfc3f5
ILT
537
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:
1564db8d 550 // A new weak dynamic undefined reference tells us nothing.
86f2e683 551 return false;
14bfc3f5
ILT
552
553 case DEF * 16 + COMMON:
1564db8d 554 // A common symbol does not override a definition.
86f2e683 555 return false;
1564db8d 556
14bfc3f5
ILT
557 case WEAK_DEF * 16 + COMMON:
558 case DYN_DEF * 16 + COMMON:
559 case DYN_WEAK_DEF * 16 + COMMON:
1564db8d
ILT
560 // A common symbol does override a weak definition or a dynamic
561 // definition.
86f2e683 562 return true;
1564db8d 563
14bfc3f5
ILT
564 case UNDEF * 16 + COMMON:
565 case WEAK_UNDEF * 16 + COMMON:
566 case DYN_UNDEF * 16 + COMMON:
567 case DYN_WEAK_UNDEF * 16 + COMMON:
1564db8d 568 // A common symbol is a definition for a reference.
86f2e683 569 return true;
1564db8d 570
14bfc3f5 571 case COMMON * 16 + COMMON:
ead1e424 572 // Set the size to the maximum.
86f2e683
ILT
573 *adjust_common_sizes = true;
574 return false;
ead1e424 575
14bfc3f5 576 case WEAK_COMMON * 16 + COMMON:
ead1e424
ILT
577 // I'm not sure just what a weak common symbol means, but
578 // presumably it can be overridden by a regular common symbol.
86f2e683 579 return true;
ead1e424 580
14bfc3f5
ILT
581 case DYN_COMMON * 16 + COMMON:
582 case DYN_WEAK_COMMON * 16 + COMMON:
86f2e683
ILT
583 // Use the real common symbol, but adjust the size if necessary.
584 *adjust_common_sizes = true;
585 return true;
14bfc3f5
ILT
586
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:
ead1e424
ILT
591 // Whatever a weak common symbol is, it won't override a
592 // definition.
86f2e683 593 return false;
ead1e424 594
14bfc3f5
ILT
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:
ead1e424 599 // A weak common symbol is better than an undefined symbol.
86f2e683 600 return true;
ead1e424 601
14bfc3f5
ILT
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:
ead1e424
ILT
606 // Ignore a weak common symbol in the presence of a real common
607 // symbol.
86f2e683 608 return false;
14bfc3f5
ILT
609
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:
ead1e424
ILT
614 // Ignore a dynamic common symbol in the presence of a
615 // definition.
86f2e683 616 return false;
ead1e424 617
14bfc3f5
ILT
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:
ead1e424 622 // A dynamic common symbol is a definition of sorts.
86f2e683 623 return true;
ead1e424 624
14bfc3f5
ILT
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:
ead1e424 629 // Set the size to the maximum.
86f2e683
ILT
630 *adjust_common_sizes = true;
631 return false;
14bfc3f5
ILT
632
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:
ead1e424 637 // A common symbol is ignored in the face of a definition.
86f2e683 638 return false;
ead1e424 639
14bfc3f5
ILT
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:
ead1e424 644 // I guess a weak common symbol is better than a definition.
86f2e683 645 return true;
ead1e424 646
14bfc3f5
ILT
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:
ead1e424 651 // Set the size to the maximum.
86f2e683
ILT
652 *adjust_common_sizes = true;
653 return false;
1564db8d
ILT
654
655 default:
a3ad94ed 656 gold_unreachable();
14bfc3f5
ILT
657 }
658}
659
86f2e683
ILT
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.
663
664bool
665Symbol_table::should_override_with_special(const Symbol* to)
666{
667 bool adjust_common_sizes;
668 unsigned int frombits = global_flag | regular_flag | def_flag;
d20222a1
ILT
669 bool ret = Symbol_table::should_override(to, frombits, NULL,
670 &adjust_common_sizes);
86f2e683
ILT
671 gold_assert(!adjust_common_sizes);
672 return ret;
673}
674
675// Override symbol base with a special symbol.
676
677void
678Symbol::override_base_with_special(const Symbol* from)
679{
46fe1623
ILT
680 gold_assert(this->name_ == from->name_ || this->has_alias());
681
86f2e683
ILT
682 this->source_ = from->source_;
683 switch (from->source_)
684 {
685 case FROM_OBJECT:
686 this->u_.from_object = from->u_.from_object;
687 break;
688 case IN_OUTPUT_DATA:
689 this->u_.in_output_data = from->u_.in_output_data;
690 break;
691 case IN_OUTPUT_SEGMENT:
692 this->u_.in_output_segment = from->u_.in_output_segment;
693 break;
f3e9c5c5
ILT
694 case IS_CONSTANT:
695 case IS_UNDEFINED:
86f2e683
ILT
696 break;
697 default:
698 gold_unreachable();
699 break;
700 }
701
75517b77 702 this->override_version(from->version_);
86f2e683
ILT
703 this->type_ = from->type_;
704 this->binding_ = from->binding_;
705 this->visibility_ = from->visibility_;
706 this->nonvis_ = from->nonvis_;
707
708 // Special symbols are always considered to be regular symbols.
709 this->in_reg_ = true;
46fe1623
ILT
710
711 if (from->needs_dynsym_entry_)
712 this->needs_dynsym_entry_ = true;
713 if (from->needs_dynsym_value_)
714 this->needs_dynsym_value_ = true;
715
716 // We shouldn't see these flags. If we do, we need to handle them
717 // somehow.
718 gold_assert(!from->is_target_special_ || this->is_target_special_);
719 gold_assert(!from->is_forwarder_);
46fe1623
ILT
720 gold_assert(!from->has_plt_offset_);
721 gold_assert(!from->has_warning_);
722 gold_assert(!from->is_copied_from_dynobj_);
55a93433 723 gold_assert(!from->is_forced_local_);
86f2e683
ILT
724}
725
726// Override a symbol with a special symbol.
727
728template<int size>
729void
730Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from)
731{
732 this->override_base_with_special(from);
733 this->value_ = from->value_;
734 this->symsize_ = from->symsize_;
735}
736
aeddab66
ILT
737// Override TOSYM with the special symbol FROMSYM. This handles all
738// aliases of TOSYM.
739
740template<int size>
741void
742Symbol_table::override_with_special(Sized_symbol<size>* tosym,
743 const Sized_symbol<size>* fromsym)
744{
745 tosym->override_with_special(fromsym);
746 if (tosym->has_alias())
747 {
748 Symbol* sym = this->weak_aliases_[tosym];
749 gold_assert(sym != NULL);
7d1a9ebb 750 Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
751 do
752 {
753 ssym->override_with_special(fromsym);
754 sym = this->weak_aliases_[ssym];
755 gold_assert(sym != NULL);
7d1a9ebb 756 ssym = this->get_sized_symbol<size>(sym);
aeddab66
ILT
757 }
758 while (ssym != tosym);
759 }
55a93433
ILT
760 if (tosym->binding() == elfcpp::STB_LOCAL)
761 this->force_local(tosym);
aeddab66
ILT
762}
763
14bfc3f5
ILT
764// Instantiate the templates we need. We could use the configure
765// script to restrict this to only the ones needed for implemented
766// targets.
767
193a53d9 768#ifdef HAVE_TARGET_32_LITTLE
14bfc3f5
ILT
769template
770void
193a53d9 771Symbol_table::resolve<32, false>(
1564db8d 772 Sized_symbol<32>* to,
193a53d9 773 const elfcpp::Sym<32, false>& sym,
d491d34e
ILT
774 unsigned int st_shndx,
775 bool is_ordinary,
776 unsigned int orig_st_shndx,
14b31740
ILT
777 Object* object,
778 const char* version);
193a53d9 779#endif
14bfc3f5 780
193a53d9 781#ifdef HAVE_TARGET_32_BIG
14bfc3f5
ILT
782template
783void
193a53d9 784Symbol_table::resolve<32, true>(
1564db8d 785 Sized_symbol<32>* to,
193a53d9 786 const elfcpp::Sym<32, true>& sym,
d491d34e
ILT
787 unsigned int st_shndx,
788 bool is_ordinary,
789 unsigned int orig_st_shndx,
14b31740
ILT
790 Object* object,
791 const char* version);
193a53d9 792#endif
14bfc3f5 793
193a53d9 794#ifdef HAVE_TARGET_64_LITTLE
14bfc3f5
ILT
795template
796void
193a53d9 797Symbol_table::resolve<64, false>(
1564db8d 798 Sized_symbol<64>* to,
193a53d9 799 const elfcpp::Sym<64, false>& sym,
d491d34e
ILT
800 unsigned int st_shndx,
801 bool is_ordinary,
802 unsigned int orig_st_shndx,
14b31740
ILT
803 Object* object,
804 const char* version);
193a53d9 805#endif
14bfc3f5 806
193a53d9 807#ifdef HAVE_TARGET_64_BIG
14bfc3f5
ILT
808template
809void
193a53d9 810Symbol_table::resolve<64, true>(
1564db8d 811 Sized_symbol<64>* to,
193a53d9 812 const elfcpp::Sym<64, true>& sym,
d491d34e
ILT
813 unsigned int st_shndx,
814 bool is_ordinary,
815 unsigned int orig_st_shndx,
14b31740
ILT
816 Object* object,
817 const char* version);
193a53d9 818#endif
14bfc3f5 819
86f2e683
ILT
820#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
821template
822void
aeddab66
ILT
823Symbol_table::override_with_special<32>(Sized_symbol<32>*,
824 const Sized_symbol<32>*);
86f2e683
ILT
825#endif
826
827#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
828template
829void
aeddab66
ILT
830Symbol_table::override_with_special<64>(Sized_symbol<64>*,
831 const Sized_symbol<64>*);
86f2e683
ILT
832#endif
833
14bfc3f5 834} // End namespace gold.
This page took 0.138472 seconds and 4 git commands to generate.