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