1 |
6 |
jlechner |
// 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 |
|
|
// This symbol is being overridden by another symbol whose version is
|
36 |
|
|
// VERSION. Update the VERSION_ field accordingly.
|
37 |
|
|
|
38 |
|
|
inline void
|
39 |
|
|
Symbol::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 |
|
|
|
65 |
|
|
// Override the fields in Symbol.
|
66 |
|
|
|
67 |
|
|
template<int size, bool big_endian>
|
68 |
|
|
void
|
69 |
|
|
Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym,
|
70 |
|
|
unsigned int st_shndx, bool is_ordinary,
|
71 |
|
|
Object* object, const char* version)
|
72 |
|
|
{
|
73 |
|
|
gold_assert(this->source_ == FROM_OBJECT);
|
74 |
|
|
this->u_.from_object.object = object;
|
75 |
|
|
this->override_version(version);
|
76 |
|
|
this->u_.from_object.shndx = st_shndx;
|
77 |
|
|
this->is_ordinary_shndx_ = is_ordinary;
|
78 |
|
|
this->type_ = sym.get_st_type();
|
79 |
|
|
this->binding_ = sym.get_st_bind();
|
80 |
|
|
this->visibility_ = sym.get_st_visibility();
|
81 |
|
|
this->nonvis_ = sym.get_st_nonvis();
|
82 |
|
|
if (object->is_dynamic())
|
83 |
|
|
this->in_dyn_ = true;
|
84 |
|
|
else
|
85 |
|
|
this->in_reg_ = true;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
// Override the fields in Sized_symbol.
|
89 |
|
|
|
90 |
|
|
template<int size>
|
91 |
|
|
template<bool big_endian>
|
92 |
|
|
void
|
93 |
|
|
Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym,
|
94 |
|
|
unsigned st_shndx, bool is_ordinary,
|
95 |
|
|
Object* object, const char* version)
|
96 |
|
|
{
|
97 |
|
|
this->override_base(sym, st_shndx, is_ordinary, object, version);
|
98 |
|
|
this->value_ = sym.get_st_value();
|
99 |
|
|
this->symsize_ = sym.get_st_size();
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
// Override TOSYM with symbol FROMSYM, defined in OBJECT, with version
|
103 |
|
|
// VERSION. This handles all aliases of TOSYM.
|
104 |
|
|
|
105 |
|
|
template<int size, bool big_endian>
|
106 |
|
|
void
|
107 |
|
|
Symbol_table::override(Sized_symbol<size>* tosym,
|
108 |
|
|
const elfcpp::Sym<size, big_endian>& fromsym,
|
109 |
|
|
unsigned int st_shndx, bool is_ordinary,
|
110 |
|
|
Object* object, const char* version)
|
111 |
|
|
{
|
112 |
|
|
tosym->override(fromsym, st_shndx, is_ordinary, object, version);
|
113 |
|
|
if (tosym->has_alias())
|
114 |
|
|
{
|
115 |
|
|
Symbol* sym = this->weak_aliases_[tosym];
|
116 |
|
|
gold_assert(sym != NULL);
|
117 |
|
|
Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
|
118 |
|
|
do
|
119 |
|
|
{
|
120 |
|
|
ssym->override(fromsym, st_shndx, is_ordinary, object, version);
|
121 |
|
|
sym = this->weak_aliases_[ssym];
|
122 |
|
|
gold_assert(sym != NULL);
|
123 |
|
|
ssym = this->get_sized_symbol<size>(sym);
|
124 |
|
|
}
|
125 |
|
|
while (ssym != tosym);
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
|
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 |
|
|
|
135 |
|
|
static const int global_or_weak_shift = 0;
|
136 |
|
|
static const unsigned int global_flag = 0 << global_or_weak_shift;
|
137 |
|
|
static const unsigned int weak_flag = 1 << global_or_weak_shift;
|
138 |
|
|
|
139 |
|
|
static const int regular_or_dynamic_shift = 1;
|
140 |
|
|
static const unsigned int regular_flag = 0 << regular_or_dynamic_shift;
|
141 |
|
|
static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift;
|
142 |
|
|
|
143 |
|
|
static const int def_undef_or_common_shift = 2;
|
144 |
|
|
static const unsigned int def_flag = 0 << def_undef_or_common_shift;
|
145 |
|
|
static const unsigned int undef_flag = 1 << def_undef_or_common_shift;
|
146 |
|
|
static const unsigned int common_flag = 2 << def_undef_or_common_shift;
|
147 |
|
|
|
148 |
|
|
// This convenience function combines all the flags based on facts
|
149 |
|
|
// about the symbol.
|
150 |
|
|
|
151 |
|
|
static unsigned int
|
152 |
|
|
symbol_to_bits(elfcpp::STB binding, bool is_dynamic,
|
153 |
|
|
unsigned int shndx, bool is_ordinary, elfcpp::STT type)
|
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:
|
192 |
|
|
if (!is_ordinary)
|
193 |
|
|
bits |= common_flag;
|
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 |
|
|
|
207 |
|
|
// Resolve a symbol. This is called the second and subsequent times
|
208 |
|
|
// we see a symbol. TO is the pre-existing symbol. ST_SHNDX is the
|
209 |
|
|
// section index for SYM, possibly adjusted for many sections.
|
210 |
|
|
// IS_ORDINARY is whether ST_SHNDX is a normal section index rather
|
211 |
|
|
// than a special code. ORIG_ST_SHNDX is the original section index,
|
212 |
|
|
// before any munging because of discarded sections, except that all
|
213 |
|
|
// non-ordinary section indexes are mapped to SHN_UNDEF. VERSION is
|
214 |
|
|
// the version of SYM.
|
215 |
|
|
|
216 |
|
|
template<int size, bool big_endian>
|
217 |
|
|
void
|
218 |
|
|
Symbol_table::resolve(Sized_symbol<size>* to,
|
219 |
|
|
const elfcpp::Sym<size, big_endian>& sym,
|
220 |
|
|
unsigned int st_shndx, bool is_ordinary,
|
221 |
|
|
unsigned int orig_st_shndx,
|
222 |
|
|
Object* object, const char* version)
|
223 |
|
|
{
|
224 |
|
|
if (object->target()->has_resolve())
|
225 |
|
|
{
|
226 |
|
|
Sized_target<size, big_endian>* sized_target;
|
227 |
|
|
sized_target = object->sized_target<size, big_endian>();
|
228 |
|
|
sized_target->resolve(to, sym, object, version);
|
229 |
|
|
return;
|
230 |
|
|
}
|
231 |
|
|
|
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 |
|
|
}
|
242 |
|
|
|
243 |
|
|
unsigned int frombits = symbol_to_bits(sym.get_st_bind(),
|
244 |
|
|
object->is_dynamic(),
|
245 |
|
|
st_shndx, is_ordinary,
|
246 |
|
|
sym.get_st_type());
|
247 |
|
|
|
248 |
|
|
bool adjust_common_sizes;
|
249 |
|
|
if (Symbol_table::should_override(to, frombits, object,
|
250 |
|
|
&adjust_common_sizes))
|
251 |
|
|
{
|
252 |
|
|
typename Sized_symbol<size>::Size_type tosize = to->symsize();
|
253 |
|
|
|
254 |
|
|
this->override(to, sym, st_shndx, is_ordinary, object, version);
|
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 |
|
|
}
|
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.)
|
272 |
|
|
bool to_is_ordinary;
|
273 |
|
|
if (parameters->options().detect_odr_violations()
|
274 |
|
|
&& sym.get_st_bind() == elfcpp::STB_WEAK
|
275 |
|
|
&& to->binding() == elfcpp::STB_WEAK
|
276 |
|
|
&& orig_st_shndx != elfcpp::SHN_UNDEF
|
277 |
|
|
&& to->shndx(&to_is_ordinary) != elfcpp::SHN_UNDEF
|
278 |
|
|
&& to_is_ordinary
|
279 |
|
|
&& sym.get_st_size() != 0 // Ignore weird 0-sized symbols.
|
280 |
|
|
&& to->symsize() != 0
|
281 |
|
|
&& (sym.get_st_type() != to->type()
|
282 |
|
|
|| sym.get_st_size() != to->symsize())
|
283 |
|
|
// C does not have a concept of ODR, so we only need to do this
|
284 |
|
|
// on C++ symbols. These have (mangled) names starting with _Z.
|
285 |
|
|
&& to->name()[0] == '_' && to->name()[1] == 'Z')
|
286 |
|
|
{
|
287 |
|
|
Symbol_location fromloc
|
288 |
|
|
= { object, orig_st_shndx, sym.get_st_value() };
|
289 |
|
|
Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary),
|
290 |
|
|
to->value() };
|
291 |
|
|
this->candidate_odr_violations_[to->name()].insert(fromloc);
|
292 |
|
|
this->candidate_odr_violations_[to->name()].insert(toloc);
|
293 |
|
|
}
|
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 |
|
|
|
303 |
|
|
bool
|
304 |
|
|
Symbol_table::should_override(const Symbol* to, unsigned int frombits,
|
305 |
|
|
Object* object, bool* adjust_common_sizes)
|
306 |
|
|
{
|
307 |
|
|
*adjust_common_sizes = false;
|
308 |
|
|
|
309 |
|
|
unsigned int tobits;
|
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)
|
314 |
|
|
tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false,
|
315 |
|
|
to->type());
|
316 |
|
|
else
|
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 |
|
|
}
|
326 |
|
|
|
327 |
|
|
// FIXME: Warn if either but not both of TO and SYM are STT_TLS.
|
328 |
|
|
|
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 |
|
|
|
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 |
|
|
|
354 |
|
|
switch (tobits * 16 + frombits)
|
355 |
|
|
{
|
356 |
|
|
case DEF * 16 + DEF:
|
357 |
|
|
// Two definitions of the same symbol.
|
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 |
|
|
|
366 |
|
|
// FIXME: Do a better job of reporting locations.
|
367 |
|
|
gold_error(_("%s: multiple definition of %s"),
|
368 |
|
|
object != NULL ? object->name().c_str() : _("command line"),
|
369 |
|
|
to->demangled_name().c_str());
|
370 |
|
|
gold_error(_("%s: previous definition here"),
|
371 |
|
|
(to->source() == Symbol::FROM_OBJECT
|
372 |
|
|
? to->object()->name().c_str()
|
373 |
|
|
: _("command line")));
|
374 |
|
|
return false;
|
375 |
|
|
|
376 |
|
|
case WEAK_DEF * 16 + DEF:
|
377 |
|
|
// We've seen a weak definition, and now we see a strong
|
378 |
|
|
// definition. In the original SVR4 linker, this was treated as
|
379 |
|
|
// a multiple definition error. In the Solaris linker and the
|
380 |
|
|
// GNU linker, a weak definition followed by a regular
|
381 |
|
|
// definition causes the weak definition to be overridden. We
|
382 |
|
|
// are currently compatible with the GNU linker. In the future
|
383 |
|
|
// we should add a target specific option to change this.
|
384 |
|
|
// FIXME.
|
385 |
|
|
return true;
|
386 |
|
|
|
387 |
|
|
case DYN_DEF * 16 + DEF:
|
388 |
|
|
case DYN_WEAK_DEF * 16 + DEF:
|
389 |
|
|
// We've seen a definition in a dynamic object, and now we see a
|
390 |
|
|
// definition in a regular object. The definition in the
|
391 |
|
|
// regular object overrides the definition in the dynamic
|
392 |
|
|
// object.
|
393 |
|
|
return true;
|
394 |
|
|
|
395 |
|
|
case UNDEF * 16 + DEF:
|
396 |
|
|
case WEAK_UNDEF * 16 + DEF:
|
397 |
|
|
case DYN_UNDEF * 16 + DEF:
|
398 |
|
|
case DYN_WEAK_UNDEF * 16 + DEF:
|
399 |
|
|
// We've seen an undefined reference, and now we see a
|
400 |
|
|
// definition. We use the definition.
|
401 |
|
|
return true;
|
402 |
|
|
|
403 |
|
|
case COMMON * 16 + DEF:
|
404 |
|
|
case WEAK_COMMON * 16 + DEF:
|
405 |
|
|
case DYN_COMMON * 16 + DEF:
|
406 |
|
|
case DYN_WEAK_COMMON * 16 + DEF:
|
407 |
|
|
// We've seen a common symbol and now we see a definition. The
|
408 |
|
|
// definition overrides. FIXME: We should optionally issue, version a
|
409 |
|
|
// warning.
|
410 |
|
|
return true;
|
411 |
|
|
|
412 |
|
|
case DEF * 16 + WEAK_DEF:
|
413 |
|
|
case WEAK_DEF * 16 + WEAK_DEF:
|
414 |
|
|
// We've seen a definition and now we see a weak definition. We
|
415 |
|
|
// ignore the new weak definition.
|
416 |
|
|
return false;
|
417 |
|
|
|
418 |
|
|
case DYN_DEF * 16 + WEAK_DEF:
|
419 |
|
|
case DYN_WEAK_DEF * 16 + WEAK_DEF:
|
420 |
|
|
// We've seen a dynamic definition and now we see a regular weak
|
421 |
|
|
// definition. The regular weak definition overrides.
|
422 |
|
|
return true;
|
423 |
|
|
|
424 |
|
|
case UNDEF * 16 + WEAK_DEF:
|
425 |
|
|
case WEAK_UNDEF * 16 + WEAK_DEF:
|
426 |
|
|
case DYN_UNDEF * 16 + WEAK_DEF:
|
427 |
|
|
case DYN_WEAK_UNDEF * 16 + WEAK_DEF:
|
428 |
|
|
// A weak definition of a currently undefined symbol.
|
429 |
|
|
return true;
|
430 |
|
|
|
431 |
|
|
case COMMON * 16 + WEAK_DEF:
|
432 |
|
|
case WEAK_COMMON * 16 + WEAK_DEF:
|
433 |
|
|
// A weak definition does not override a common definition.
|
434 |
|
|
return false;
|
435 |
|
|
|
436 |
|
|
case DYN_COMMON * 16 + WEAK_DEF:
|
437 |
|
|
case DYN_WEAK_COMMON * 16 + WEAK_DEF:
|
438 |
|
|
// A weak definition does override a definition in a dynamic
|
439 |
|
|
// object. FIXME: We should optionally issue a warning.
|
440 |
|
|
return true;
|
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:
|
446 |
|
|
// Ignore a dynamic definition if we already have a definition.
|
447 |
|
|
return false;
|
448 |
|
|
|
449 |
|
|
case UNDEF * 16 + DYN_DEF:
|
450 |
|
|
case WEAK_UNDEF * 16 + DYN_DEF:
|
451 |
|
|
case DYN_UNDEF * 16 + DYN_DEF:
|
452 |
|
|
case DYN_WEAK_UNDEF * 16 + DYN_DEF:
|
453 |
|
|
// Use a dynamic definition if we have a reference.
|
454 |
|
|
return true;
|
455 |
|
|
|
456 |
|
|
case COMMON * 16 + DYN_DEF:
|
457 |
|
|
case WEAK_COMMON * 16 + DYN_DEF:
|
458 |
|
|
case DYN_COMMON * 16 + DYN_DEF:
|
459 |
|
|
case DYN_WEAK_COMMON * 16 + DYN_DEF:
|
460 |
|
|
// Ignore a dynamic definition if we already have a common
|
461 |
|
|
// definition.
|
462 |
|
|
return false;
|
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:
|
468 |
|
|
// Ignore a weak dynamic definition if we already have a
|
469 |
|
|
// definition.
|
470 |
|
|
return false;
|
471 |
|
|
|
472 |
|
|
case UNDEF * 16 + DYN_WEAK_DEF:
|
473 |
|
|
case WEAK_UNDEF * 16 + DYN_WEAK_DEF:
|
474 |
|
|
case DYN_UNDEF * 16 + DYN_WEAK_DEF:
|
475 |
|
|
case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF:
|
476 |
|
|
// Use a weak dynamic definition if we have a reference.
|
477 |
|
|
return true;
|
478 |
|
|
|
479 |
|
|
case COMMON * 16 + DYN_WEAK_DEF:
|
480 |
|
|
case WEAK_COMMON * 16 + DYN_WEAK_DEF:
|
481 |
|
|
case DYN_COMMON * 16 + DYN_WEAK_DEF:
|
482 |
|
|
case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF:
|
483 |
|
|
// Ignore a weak dynamic definition if we already have a common
|
484 |
|
|
// definition.
|
485 |
|
|
return false;
|
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:
|
492 |
|
|
// A new undefined reference tells us nothing.
|
493 |
|
|
return false;
|
494 |
|
|
|
495 |
|
|
case WEAK_UNDEF * 16 + UNDEF:
|
496 |
|
|
case DYN_UNDEF * 16 + UNDEF:
|
497 |
|
|
case DYN_WEAK_UNDEF * 16 + UNDEF:
|
498 |
|
|
// A strong undef overrides a dynamic or weak undef.
|
499 |
|
|
return true;
|
500 |
|
|
|
501 |
|
|
case COMMON * 16 + UNDEF:
|
502 |
|
|
case WEAK_COMMON * 16 + UNDEF:
|
503 |
|
|
case DYN_COMMON * 16 + UNDEF:
|
504 |
|
|
case DYN_WEAK_COMMON * 16 + UNDEF:
|
505 |
|
|
// A new undefined reference tells us nothing.
|
506 |
|
|
return false;
|
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:
|
520 |
|
|
// A new weak undefined reference tells us nothing.
|
521 |
|
|
return false;
|
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:
|
535 |
|
|
// A new dynamic undefined reference tells us nothing.
|
536 |
|
|
return false;
|
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:
|
550 |
|
|
// A new weak dynamic undefined reference tells us nothing.
|
551 |
|
|
return false;
|
552 |
|
|
|
553 |
|
|
case DEF * 16 + COMMON:
|
554 |
|
|
// A common symbol does not override a definition.
|
555 |
|
|
return false;
|
556 |
|
|
|
557 |
|
|
case WEAK_DEF * 16 + COMMON:
|
558 |
|
|
case DYN_DEF * 16 + COMMON:
|
559 |
|
|
case DYN_WEAK_DEF * 16 + COMMON:
|
560 |
|
|
// A common symbol does override a weak definition or a dynamic
|
561 |
|
|
// definition.
|
562 |
|
|
return true;
|
563 |
|
|
|
564 |
|
|
case UNDEF * 16 + COMMON:
|
565 |
|
|
case WEAK_UNDEF * 16 + COMMON:
|
566 |
|
|
case DYN_UNDEF * 16 + COMMON:
|
567 |
|
|
case DYN_WEAK_UNDEF * 16 + COMMON:
|
568 |
|
|
// A common symbol is a definition for a reference.
|
569 |
|
|
return true;
|
570 |
|
|
|
571 |
|
|
case COMMON * 16 + COMMON:
|
572 |
|
|
// Set the size to the maximum.
|
573 |
|
|
*adjust_common_sizes = true;
|
574 |
|
|
return false;
|
575 |
|
|
|
576 |
|
|
case WEAK_COMMON * 16 + COMMON:
|
577 |
|
|
// I'm not sure just what a weak common symbol means, but
|
578 |
|
|
// presumably it can be overridden by a regular common symbol.
|
579 |
|
|
return true;
|
580 |
|
|
|
581 |
|
|
case DYN_COMMON * 16 + COMMON:
|
582 |
|
|
case DYN_WEAK_COMMON * 16 + COMMON:
|
583 |
|
|
// Use the real common symbol, but adjust the size if necessary.
|
584 |
|
|
*adjust_common_sizes = true;
|
585 |
|
|
return true;
|
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:
|
591 |
|
|
// Whatever a weak common symbol is, it won't override a
|
592 |
|
|
// definition.
|
593 |
|
|
return false;
|
594 |
|
|
|
595 |
|
|
case UNDEF * 16 + WEAK_COMMON:
|
596 |
|
|
case WEAK_UNDEF * 16 + WEAK_COMMON:
|
597 |
|
|
case DYN_UNDEF * 16 + WEAK_COMMON:
|
598 |
|
|
case DYN_WEAK_UNDEF * 16 + WEAK_COMMON:
|
599 |
|
|
// A weak common symbol is better than an undefined symbol.
|
600 |
|
|
return true;
|
601 |
|
|
|
602 |
|
|
case COMMON * 16 + WEAK_COMMON:
|
603 |
|
|
case WEAK_COMMON * 16 + WEAK_COMMON:
|
604 |
|
|
case DYN_COMMON * 16 + WEAK_COMMON:
|
605 |
|
|
case DYN_WEAK_COMMON * 16 + WEAK_COMMON:
|
606 |
|
|
// Ignore a weak common symbol in the presence of a real common
|
607 |
|
|
// symbol.
|
608 |
|
|
return false;
|
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:
|
614 |
|
|
// Ignore a dynamic common symbol in the presence of a
|
615 |
|
|
// definition.
|
616 |
|
|
return false;
|
617 |
|
|
|
618 |
|
|
case UNDEF * 16 + DYN_COMMON:
|
619 |
|
|
case WEAK_UNDEF * 16 + DYN_COMMON:
|
620 |
|
|
case DYN_UNDEF * 16 + DYN_COMMON:
|
621 |
|
|
case DYN_WEAK_UNDEF * 16 + DYN_COMMON:
|
622 |
|
|
// A dynamic common symbol is a definition of sorts.
|
623 |
|
|
return true;
|
624 |
|
|
|
625 |
|
|
case COMMON * 16 + DYN_COMMON:
|
626 |
|
|
case WEAK_COMMON * 16 + DYN_COMMON:
|
627 |
|
|
case DYN_COMMON * 16 + DYN_COMMON:
|
628 |
|
|
case DYN_WEAK_COMMON * 16 + DYN_COMMON:
|
629 |
|
|
// Set the size to the maximum.
|
630 |
|
|
*adjust_common_sizes = true;
|
631 |
|
|
return false;
|
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:
|
637 |
|
|
// A common symbol is ignored in the face of a definition.
|
638 |
|
|
return false;
|
639 |
|
|
|
640 |
|
|
case UNDEF * 16 + DYN_WEAK_COMMON:
|
641 |
|
|
case WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
|
642 |
|
|
case DYN_UNDEF * 16 + DYN_WEAK_COMMON:
|
643 |
|
|
case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
|
644 |
|
|
// I guess a weak common symbol is better than a definition.
|
645 |
|
|
return true;
|
646 |
|
|
|
647 |
|
|
case COMMON * 16 + DYN_WEAK_COMMON:
|
648 |
|
|
case WEAK_COMMON * 16 + DYN_WEAK_COMMON:
|
649 |
|
|
case DYN_COMMON * 16 + DYN_WEAK_COMMON:
|
650 |
|
|
case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON:
|
651 |
|
|
// Set the size to the maximum.
|
652 |
|
|
*adjust_common_sizes = true;
|
653 |
|
|
return false;
|
654 |
|
|
|
655 |
|
|
default:
|
656 |
|
|
gold_unreachable();
|
657 |
|
|
}
|
658 |
|
|
}
|
659 |
|
|
|
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 |
|
|
|
664 |
|
|
bool
|
665 |
|
|
Symbol_table::should_override_with_special(const Symbol* to)
|
666 |
|
|
{
|
667 |
|
|
bool adjust_common_sizes;
|
668 |
|
|
unsigned int frombits = global_flag | regular_flag | def_flag;
|
669 |
|
|
bool ret = Symbol_table::should_override(to, frombits, NULL,
|
670 |
|
|
&adjust_common_sizes);
|
671 |
|
|
gold_assert(!adjust_common_sizes);
|
672 |
|
|
return ret;
|
673 |
|
|
}
|
674 |
|
|
|
675 |
|
|
// Override symbol base with a special symbol.
|
676 |
|
|
|
677 |
|
|
void
|
678 |
|
|
Symbol::override_base_with_special(const Symbol* from)
|
679 |
|
|
{
|
680 |
|
|
gold_assert(this->name_ == from->name_ || this->has_alias());
|
681 |
|
|
|
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;
|
694 |
|
|
case IS_CONSTANT:
|
695 |
|
|
case IS_UNDEFINED:
|
696 |
|
|
break;
|
697 |
|
|
default:
|
698 |
|
|
gold_unreachable();
|
699 |
|
|
break;
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
this->override_version(from->version_);
|
703 |
|
|
this->type_ = from->type_;
|
704 |
|
|
this->binding_ = from->binding_;
|
705 |
|
|
this->visibility_ = from->visibility_;
|
706 |
|
|
this->nonvis_ = from->nonvis_;
|
707 |
|
|
|
708 |
|
|
// Special symbols are always considered to be regular symbols.
|
709 |
|
|
this->in_reg_ = true;
|
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_);
|
720 |
|
|
gold_assert(!from->has_plt_offset_);
|
721 |
|
|
gold_assert(!from->has_warning_);
|
722 |
|
|
gold_assert(!from->is_copied_from_dynobj_);
|
723 |
|
|
gold_assert(!from->is_forced_local_);
|
724 |
|
|
}
|
725 |
|
|
|
726 |
|
|
// Override a symbol with a special symbol.
|
727 |
|
|
|
728 |
|
|
template<int size>
|
729 |
|
|
void
|
730 |
|
|
Sized_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 |
|
|
|
737 |
|
|
// Override TOSYM with the special symbol FROMSYM. This handles all
|
738 |
|
|
// aliases of TOSYM.
|
739 |
|
|
|
740 |
|
|
template<int size>
|
741 |
|
|
void
|
742 |
|
|
Symbol_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);
|
750 |
|
|
Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
|
751 |
|
|
do
|
752 |
|
|
{
|
753 |
|
|
ssym->override_with_special(fromsym);
|
754 |
|
|
sym = this->weak_aliases_[ssym];
|
755 |
|
|
gold_assert(sym != NULL);
|
756 |
|
|
ssym = this->get_sized_symbol<size>(sym);
|
757 |
|
|
}
|
758 |
|
|
while (ssym != tosym);
|
759 |
|
|
}
|
760 |
|
|
if (tosym->binding() == elfcpp::STB_LOCAL)
|
761 |
|
|
this->force_local(tosym);
|
762 |
|
|
}
|
763 |
|
|
|
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 |
|
|
|
768 |
|
|
#ifdef HAVE_TARGET_32_LITTLE
|
769 |
|
|
template
|
770 |
|
|
void
|
771 |
|
|
Symbol_table::resolve<32, false>(
|
772 |
|
|
Sized_symbol<32>* to,
|
773 |
|
|
const elfcpp::Sym<32, false>& sym,
|
774 |
|
|
unsigned int st_shndx,
|
775 |
|
|
bool is_ordinary,
|
776 |
|
|
unsigned int orig_st_shndx,
|
777 |
|
|
Object* object,
|
778 |
|
|
const char* version);
|
779 |
|
|
#endif
|
780 |
|
|
|
781 |
|
|
#ifdef HAVE_TARGET_32_BIG
|
782 |
|
|
template
|
783 |
|
|
void
|
784 |
|
|
Symbol_table::resolve<32, true>(
|
785 |
|
|
Sized_symbol<32>* to,
|
786 |
|
|
const elfcpp::Sym<32, true>& sym,
|
787 |
|
|
unsigned int st_shndx,
|
788 |
|
|
bool is_ordinary,
|
789 |
|
|
unsigned int orig_st_shndx,
|
790 |
|
|
Object* object,
|
791 |
|
|
const char* version);
|
792 |
|
|
#endif
|
793 |
|
|
|
794 |
|
|
#ifdef HAVE_TARGET_64_LITTLE
|
795 |
|
|
template
|
796 |
|
|
void
|
797 |
|
|
Symbol_table::resolve<64, false>(
|
798 |
|
|
Sized_symbol<64>* to,
|
799 |
|
|
const elfcpp::Sym<64, false>& sym,
|
800 |
|
|
unsigned int st_shndx,
|
801 |
|
|
bool is_ordinary,
|
802 |
|
|
unsigned int orig_st_shndx,
|
803 |
|
|
Object* object,
|
804 |
|
|
const char* version);
|
805 |
|
|
#endif
|
806 |
|
|
|
807 |
|
|
#ifdef HAVE_TARGET_64_BIG
|
808 |
|
|
template
|
809 |
|
|
void
|
810 |
|
|
Symbol_table::resolve<64, true>(
|
811 |
|
|
Sized_symbol<64>* to,
|
812 |
|
|
const elfcpp::Sym<64, true>& sym,
|
813 |
|
|
unsigned int st_shndx,
|
814 |
|
|
bool is_ordinary,
|
815 |
|
|
unsigned int orig_st_shndx,
|
816 |
|
|
Object* object,
|
817 |
|
|
const char* version);
|
818 |
|
|
#endif
|
819 |
|
|
|
820 |
|
|
#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
|
821 |
|
|
template
|
822 |
|
|
void
|
823 |
|
|
Symbol_table::override_with_special<32>(Sized_symbol<32>*,
|
824 |
|
|
const Sized_symbol<32>*);
|
825 |
|
|
#endif
|
826 |
|
|
|
827 |
|
|
#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
|
828 |
|
|
template
|
829 |
|
|
void
|
830 |
|
|
Symbol_table::override_with_special<64>(Sized_symbol<64>*,
|
831 |
|
|
const Sized_symbol<64>*);
|
832 |
|
|
#endif
|
833 |
|
|
|
834 |
|
|
} // End namespace gold.
|