Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // symtab.h -- the gold symbol table -*- C++ -*- |
2 | ||
ebdbb458 | 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 | ||
bae7f79e ILT |
23 | // Symbol_table |
24 | // The symbol table. | |
25 | ||
bae7f79e ILT |
26 | #include <string> |
27 | #include <utility> | |
ead1e424 | 28 | #include <vector> |
bae7f79e ILT |
29 | |
30 | #include "elfcpp.h" | |
7e1edb90 | 31 | #include "parameters.h" |
14bfc3f5 | 32 | #include "stringpool.h" |
f6ce93d6 | 33 | #include "object.h" |
bae7f79e ILT |
34 | |
35 | #ifndef GOLD_SYMTAB_H | |
36 | #define GOLD_SYMTAB_H | |
37 | ||
38 | namespace gold | |
39 | { | |
40 | ||
14bfc3f5 | 41 | class Object; |
f6ce93d6 | 42 | class Relobj; |
dbe717ef ILT |
43 | template<int size, bool big_endian> |
44 | class Sized_relobj; | |
f6ce93d6 | 45 | class Dynobj; |
dbe717ef ILT |
46 | template<int size, bool big_endian> |
47 | class Sized_dynobj; | |
14b31740 | 48 | class Versions; |
09124467 | 49 | class Version_script_info; |
9a2d6984 | 50 | class Input_objects; |
ead1e424 | 51 | class Output_data; |
a3ad94ed | 52 | class Output_section; |
ead1e424 | 53 | class Output_segment; |
61ba1cf9 | 54 | class Output_file; |
d491d34e | 55 | class Output_symtab_xindex; |
14bfc3f5 | 56 | |
14bfc3f5 ILT |
57 | // The base class of an entry in the symbol table. The symbol table |
58 | // can have a lot of entries, so we don't want this class to big. | |
59 | // Size dependent fields can be found in the template class | |
60 | // Sized_symbol. Targets may support their own derived classes. | |
bae7f79e | 61 | |
bae7f79e ILT |
62 | class Symbol |
63 | { | |
64 | public: | |
ead1e424 ILT |
65 | // Because we want the class to be small, we don't use any virtual |
66 | // functions. But because symbols can be defined in different | |
67 | // places, we need to classify them. This enum is the different | |
68 | // sources of symbols we support. | |
69 | enum Source | |
70 | { | |
f6ce93d6 ILT |
71 | // Symbol defined in a relocatable or dynamic input file--this is |
72 | // the most common case. | |
ead1e424 ILT |
73 | FROM_OBJECT, |
74 | // Symbol defined in an Output_data, a special section created by | |
75 | // the target. | |
76 | IN_OUTPUT_DATA, | |
77 | // Symbol defined in an Output_segment, with no associated | |
78 | // section. | |
79 | IN_OUTPUT_SEGMENT, | |
80 | // Symbol value is constant. | |
f3e9c5c5 ILT |
81 | IS_CONSTANT, |
82 | // Symbol is undefined. | |
83 | IS_UNDEFINED | |
ead1e424 ILT |
84 | }; |
85 | ||
86 | // When the source is IN_OUTPUT_SEGMENT, we need to describe what | |
87 | // the offset means. | |
88 | enum Segment_offset_base | |
89 | { | |
90 | // From the start of the segment. | |
91 | SEGMENT_START, | |
92 | // From the end of the segment. | |
93 | SEGMENT_END, | |
94 | // From the filesz of the segment--i.e., after the loaded bytes | |
95 | // but before the bytes which are allocated but zeroed. | |
96 | SEGMENT_BSS | |
97 | }; | |
98 | ||
14bfc3f5 ILT |
99 | // Return the symbol name. |
100 | const char* | |
101 | name() const | |
102 | { return this->name_; } | |
103 | ||
a2b1aa12 ILT |
104 | // Return the (ANSI) demangled version of the name, if |
105 | // parameters.demangle() is true. Otherwise, return the name. This | |
106 | // is intended to be used only for logging errors, so it's not | |
107 | // super-efficient. | |
108 | std::string | |
109 | demangled_name() const; | |
110 | ||
14bfc3f5 ILT |
111 | // Return the symbol version. This will return NULL for an |
112 | // unversioned symbol. | |
113 | const char* | |
114 | version() const | |
115 | { return this->version_; } | |
116 | ||
09124467 ILT |
117 | // Return whether this version is the default for this symbol name |
118 | // (eg, "foo@@V2" is a default version; "foo@V1" is not). Only | |
119 | // meaningful for versioned symbols. | |
120 | bool | |
121 | is_default() const | |
122 | { | |
123 | gold_assert(this->version_ != NULL); | |
124 | return this->is_def_; | |
125 | } | |
126 | ||
be3e6201 | 127 | // Set that this version is the default for this symbol name. |
09124467 | 128 | void |
be3e6201 ILT |
129 | set_is_default() |
130 | { this->is_def_ = true; } | |
09124467 | 131 | |
ead1e424 ILT |
132 | // Return the symbol source. |
133 | Source | |
134 | source() const | |
135 | { return this->source_; } | |
136 | ||
14bfc3f5 ILT |
137 | // Return the object with which this symbol is associated. |
138 | Object* | |
139 | object() const | |
ead1e424 | 140 | { |
a3ad94ed | 141 | gold_assert(this->source_ == FROM_OBJECT); |
ead1e424 ILT |
142 | return this->u_.from_object.object; |
143 | } | |
144 | ||
f6ce93d6 ILT |
145 | // Return the index of the section in the input relocatable or |
146 | // dynamic object file. | |
ead1e424 | 147 | unsigned int |
d491d34e | 148 | shndx(bool* is_ordinary) const |
ead1e424 | 149 | { |
a3ad94ed | 150 | gold_assert(this->source_ == FROM_OBJECT); |
d491d34e | 151 | *is_ordinary = this->is_ordinary_shndx_; |
16649710 | 152 | return this->u_.from_object.shndx; |
ead1e424 ILT |
153 | } |
154 | ||
155 | // Return the output data section with which this symbol is | |
156 | // associated, if the symbol was specially defined with respect to | |
157 | // an output data section. | |
158 | Output_data* | |
159 | output_data() const | |
160 | { | |
a3ad94ed | 161 | gold_assert(this->source_ == IN_OUTPUT_DATA); |
ead1e424 ILT |
162 | return this->u_.in_output_data.output_data; |
163 | } | |
164 | ||
165 | // If this symbol was defined with respect to an output data | |
166 | // section, return whether the value is an offset from end. | |
167 | bool | |
168 | offset_is_from_end() const | |
169 | { | |
a3ad94ed | 170 | gold_assert(this->source_ == IN_OUTPUT_DATA); |
ead1e424 ILT |
171 | return this->u_.in_output_data.offset_is_from_end; |
172 | } | |
173 | ||
174 | // Return the output segment with which this symbol is associated, | |
175 | // if the symbol was specially defined with respect to an output | |
176 | // segment. | |
177 | Output_segment* | |
178 | output_segment() const | |
179 | { | |
a3ad94ed | 180 | gold_assert(this->source_ == IN_OUTPUT_SEGMENT); |
ead1e424 ILT |
181 | return this->u_.in_output_segment.output_segment; |
182 | } | |
183 | ||
184 | // If this symbol was defined with respect to an output segment, | |
185 | // return the offset base. | |
186 | Segment_offset_base | |
187 | offset_base() const | |
188 | { | |
a3ad94ed | 189 | gold_assert(this->source_ == IN_OUTPUT_SEGMENT); |
ead1e424 ILT |
190 | return this->u_.in_output_segment.offset_base; |
191 | } | |
14bfc3f5 ILT |
192 | |
193 | // Return the symbol binding. | |
194 | elfcpp::STB | |
195 | binding() const | |
196 | { return this->binding_; } | |
197 | ||
1564db8d ILT |
198 | // Return the symbol type. |
199 | elfcpp::STT | |
200 | type() const | |
201 | { return this->type_; } | |
202 | ||
203 | // Return the symbol visibility. | |
204 | elfcpp::STV | |
205 | visibility() const | |
206 | { return this->visibility_; } | |
207 | ||
208 | // Return the non-visibility part of the st_other field. | |
209 | unsigned char | |
ead1e424 ILT |
210 | nonvis() const |
211 | { return this->nonvis_; } | |
14bfc3f5 | 212 | |
1564db8d ILT |
213 | // Return whether this symbol is a forwarder. This will never be |
214 | // true of a symbol found in the hash table, but may be true of | |
215 | // symbol pointers attached to object files. | |
216 | bool | |
217 | is_forwarder() const | |
218 | { return this->is_forwarder_; } | |
219 | ||
220 | // Mark this symbol as a forwarder. | |
221 | void | |
222 | set_forwarder() | |
223 | { this->is_forwarder_ = true; } | |
224 | ||
aeddab66 ILT |
225 | // Return whether this symbol has an alias in the weak aliases table |
226 | // in Symbol_table. | |
227 | bool | |
228 | has_alias() const | |
229 | { return this->has_alias_; } | |
230 | ||
231 | // Mark this symbol as having an alias. | |
232 | void | |
233 | set_has_alias() | |
234 | { this->has_alias_ = true; } | |
235 | ||
c06b7b0b ILT |
236 | // Return whether this symbol needs an entry in the dynamic symbol |
237 | // table. | |
238 | bool | |
239 | needs_dynsym_entry() const | |
429c1569 ILT |
240 | { |
241 | return (this->needs_dynsym_entry_ | |
242 | || (this->in_reg() && this->in_dyn())); | |
243 | } | |
c06b7b0b ILT |
244 | |
245 | // Mark this symbol as needing an entry in the dynamic symbol table. | |
246 | void | |
247 | set_needs_dynsym_entry() | |
248 | { this->needs_dynsym_entry_ = true; } | |
249 | ||
436ca963 ILT |
250 | // Return whether this symbol should be added to the dynamic symbol |
251 | // table. | |
252 | bool | |
253 | should_add_dynsym_entry() const; | |
254 | ||
008db82e ILT |
255 | // Return whether this symbol has been seen in a regular object. |
256 | bool | |
257 | in_reg() const | |
258 | { return this->in_reg_; } | |
259 | ||
260 | // Mark this symbol as having been seen in a regular object. | |
261 | void | |
262 | set_in_reg() | |
263 | { this->in_reg_ = true; } | |
264 | ||
1ebd95fd ILT |
265 | // Return whether this symbol has been seen in a dynamic object. |
266 | bool | |
267 | in_dyn() const | |
268 | { return this->in_dyn_; } | |
269 | ||
f6ce93d6 | 270 | // Mark this symbol as having been seen in a dynamic object. |
1564db8d ILT |
271 | void |
272 | set_in_dyn() | |
273 | { this->in_dyn_ = true; } | |
274 | ||
c06b7b0b ILT |
275 | // Return the index of this symbol in the output file symbol table. |
276 | // A value of -1U means that this symbol is not going into the | |
277 | // output file. This starts out as zero, and is set to a non-zero | |
278 | // value by Symbol_table::finalize. It is an error to ask for the | |
279 | // symbol table index before it has been set. | |
280 | unsigned int | |
281 | symtab_index() const | |
282 | { | |
a3ad94ed | 283 | gold_assert(this->symtab_index_ != 0); |
c06b7b0b ILT |
284 | return this->symtab_index_; |
285 | } | |
286 | ||
287 | // Set the index of the symbol in the output file symbol table. | |
288 | void | |
289 | set_symtab_index(unsigned int index) | |
290 | { | |
a3ad94ed | 291 | gold_assert(index != 0); |
c06b7b0b ILT |
292 | this->symtab_index_ = index; |
293 | } | |
294 | ||
a3ad94ed ILT |
295 | // Return whether this symbol already has an index in the output |
296 | // file symbol table. | |
297 | bool | |
298 | has_symtab_index() const | |
299 | { return this->symtab_index_ != 0; } | |
300 | ||
c06b7b0b ILT |
301 | // Return the index of this symbol in the dynamic symbol table. A |
302 | // value of -1U means that this symbol is not going into the dynamic | |
303 | // symbol table. This starts out as zero, and is set to a non-zero | |
304 | // during Layout::finalize. It is an error to ask for the dynamic | |
305 | // symbol table index before it has been set. | |
306 | unsigned int | |
307 | dynsym_index() const | |
308 | { | |
a3ad94ed | 309 | gold_assert(this->dynsym_index_ != 0); |
c06b7b0b ILT |
310 | return this->dynsym_index_; |
311 | } | |
312 | ||
313 | // Set the index of the symbol in the dynamic symbol table. | |
314 | void | |
315 | set_dynsym_index(unsigned int index) | |
316 | { | |
a3ad94ed | 317 | gold_assert(index != 0); |
c06b7b0b ILT |
318 | this->dynsym_index_ = index; |
319 | } | |
320 | ||
16649710 ILT |
321 | // Return whether this symbol already has an index in the dynamic |
322 | // symbol table. | |
323 | bool | |
324 | has_dynsym_index() const | |
325 | { return this->dynsym_index_ != 0; } | |
326 | ||
ead1e424 | 327 | // Return whether this symbol has an entry in the GOT section. |
07f397ab | 328 | // For a TLS symbol, this GOT entry will hold its tp-relative offset. |
92e059d8 | 329 | bool |
0a65a3a7 CC |
330 | has_got_offset(unsigned int got_type) const |
331 | { return this->got_offsets_.get_offset(got_type) != -1U; } | |
ead1e424 ILT |
332 | |
333 | // Return the offset into the GOT section of this symbol. | |
334 | unsigned int | |
0a65a3a7 | 335 | got_offset(unsigned int got_type) const |
ead1e424 | 336 | { |
0a65a3a7 CC |
337 | unsigned int got_offset = this->got_offsets_.get_offset(got_type); |
338 | gold_assert(got_offset != -1U); | |
339 | return got_offset; | |
ead1e424 ILT |
340 | } |
341 | ||
342 | // Set the GOT offset of this symbol. | |
343 | void | |
0a65a3a7 CC |
344 | set_got_offset(unsigned int got_type, unsigned int got_offset) |
345 | { this->got_offsets_.set_offset(got_type, got_offset); } | |
07f397ab | 346 | |
a3ad94ed | 347 | // Return whether this symbol has an entry in the PLT section. |
ead1e424 | 348 | bool |
a3ad94ed ILT |
349 | has_plt_offset() const |
350 | { return this->has_plt_offset_; } | |
351 | ||
352 | // Return the offset into the PLT section of this symbol. | |
353 | unsigned int | |
354 | plt_offset() const | |
355 | { | |
356 | gold_assert(this->has_plt_offset()); | |
357 | return this->plt_offset_; | |
358 | } | |
359 | ||
360 | // Set the PLT offset of this symbol. | |
361 | void | |
362 | set_plt_offset(unsigned int plt_offset) | |
363 | { | |
364 | this->has_plt_offset_ = true; | |
365 | this->plt_offset_ = plt_offset; | |
366 | } | |
367 | ||
ab5c9e90 ILT |
368 | // Return whether this dynamic symbol needs a special value in the |
369 | // dynamic symbol table. | |
370 | bool | |
371 | needs_dynsym_value() const | |
372 | { return this->needs_dynsym_value_; } | |
373 | ||
374 | // Set that this dynamic symbol needs a special value in the dynamic | |
375 | // symbol table. | |
376 | void | |
377 | set_needs_dynsym_value() | |
378 | { | |
379 | gold_assert(this->object()->is_dynamic()); | |
380 | this->needs_dynsym_value_ = true; | |
381 | } | |
382 | ||
a3ad94ed ILT |
383 | // Return true if the final value of this symbol is known at link |
384 | // time. | |
385 | bool | |
b3b74ddc | 386 | final_value_is_known() const; |
ead1e424 | 387 | |
f6ce93d6 ILT |
388 | // Return whether this is a defined symbol (not undefined or |
389 | // common). | |
390 | bool | |
391 | is_defined() const | |
392 | { | |
d491d34e ILT |
393 | bool is_ordinary; |
394 | if (this->source_ != FROM_OBJECT) | |
f3e9c5c5 | 395 | return this->source_ != IS_UNDEFINED; |
d491d34e ILT |
396 | unsigned int shndx = this->shndx(&is_ordinary); |
397 | return (is_ordinary | |
398 | ? shndx != elfcpp::SHN_UNDEF | |
399 | : shndx != elfcpp::SHN_COMMON); | |
a3ad94ed ILT |
400 | } |
401 | ||
14b31740 | 402 | // Return true if this symbol is from a dynamic object. |
a3ad94ed | 403 | bool |
14b31740 | 404 | is_from_dynobj() const |
a3ad94ed | 405 | { |
14b31740 | 406 | return this->source_ == FROM_OBJECT && this->object()->is_dynamic(); |
f6ce93d6 ILT |
407 | } |
408 | ||
ead1e424 ILT |
409 | // Return whether this is an undefined symbol. |
410 | bool | |
411 | is_undefined() const | |
412 | { | |
d491d34e | 413 | bool is_ordinary; |
f3e9c5c5 ILT |
414 | return ((this->source_ == FROM_OBJECT |
415 | && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF | |
416 | && is_ordinary) | |
417 | || this->source_ == IS_UNDEFINED); | |
ead1e424 ILT |
418 | } |
419 | ||
86925eef CC |
420 | // Return whether this is a weak undefined symbol. |
421 | bool | |
422 | is_weak_undefined() const | |
f3e9c5c5 | 423 | { return this->is_undefined() && this->binding() == elfcpp::STB_WEAK; } |
86925eef | 424 | |
86925eef CC |
425 | // Return whether this is an absolute symbol. |
426 | bool | |
427 | is_absolute() const | |
428 | { | |
d491d34e | 429 | bool is_ordinary; |
f3e9c5c5 ILT |
430 | return ((this->source_ == FROM_OBJECT |
431 | && this->shndx(&is_ordinary) == elfcpp::SHN_ABS | |
432 | && !is_ordinary) | |
433 | || this->source_ == IS_CONSTANT); | |
86925eef CC |
434 | } |
435 | ||
ead1e424 ILT |
436 | // Return whether this is a common symbol. |
437 | bool | |
438 | is_common() const | |
439 | { | |
d491d34e | 440 | bool is_ordinary; |
f6ce93d6 | 441 | return (this->source_ == FROM_OBJECT |
d491d34e ILT |
442 | && ((this->shndx(&is_ordinary) == elfcpp::SHN_COMMON |
443 | && !is_ordinary) | |
f6ce93d6 | 444 | || this->type_ == elfcpp::STT_COMMON)); |
ead1e424 | 445 | } |
92e059d8 | 446 | |
a6badf5a ILT |
447 | // Return whether this symbol can be seen outside this object. |
448 | bool | |
449 | is_externally_visible() const | |
450 | { | |
451 | return (this->visibility_ == elfcpp::STV_DEFAULT | |
452 | || this->visibility_ == elfcpp::STV_PROTECTED); | |
453 | } | |
454 | ||
436ca963 ILT |
455 | // Return true if this symbol can be preempted by a definition in |
456 | // another link unit. | |
457 | bool | |
458 | is_preemptible() const | |
459 | { | |
386c048c ILT |
460 | // It doesn't make sense to ask whether a symbol defined in |
461 | // another object is preemptible. | |
462 | gold_assert(!this->is_from_dynobj()); | |
463 | ||
8fc19601 ILT |
464 | // It doesn't make sense to ask whether an undefined symbol |
465 | // is preemptible. | |
466 | gold_assert(!this->is_undefined()); | |
467 | ||
f1f70eae ILT |
468 | // If a symbol does not have default visibility, it can not be |
469 | // seen outside this link unit and therefore is not preemptible. | |
470 | if (this->visibility_ != elfcpp::STV_DEFAULT) | |
471 | return false; | |
472 | ||
473 | // If this symbol has been forced to be a local symbol by a | |
474 | // version script, then it is not visible outside this link unit | |
475 | // and is not preemptible. | |
476 | if (this->is_forced_local_) | |
477 | return false; | |
478 | ||
479 | // If we are not producing a shared library, then nothing is | |
480 | // preemptible. | |
481 | if (!parameters->options().shared()) | |
482 | return false; | |
483 | ||
484 | // If the user used -Bsymbolic, then nothing is preemptible. | |
485 | if (parameters->options().Bsymbolic()) | |
486 | return false; | |
487 | ||
488 | // If the user used -Bsymbolic-functions, then functions are not | |
489 | // preemptible. We explicitly check for not being STT_OBJECT, | |
490 | // rather than for being STT_FUNC, because that is what the GNU | |
491 | // linker does. | |
492 | if (this->type() != elfcpp::STT_OBJECT | |
493 | && parameters->options().Bsymbolic_functions()) | |
494 | return false; | |
495 | ||
496 | // Otherwise the symbol is preemptible. | |
497 | return true; | |
436ca963 ILT |
498 | } |
499 | ||
d61c6bd4 ILT |
500 | // Return true if this symbol is a function that needs a PLT entry. |
501 | // If the symbol is defined in a dynamic object or if it is subject | |
8fc19601 ILT |
502 | // to pre-emption, we need to make a PLT entry. If we're doing a |
503 | // static link, we don't create PLT entries. | |
d61c6bd4 ILT |
504 | bool |
505 | needs_plt_entry() const | |
506 | { | |
8fc19601 ILT |
507 | return (!parameters->doing_static_link() |
508 | && this->type() == elfcpp::STT_FUNC | |
509 | && (this->is_from_dynobj() | |
f3c69fca | 510 | || this->is_undefined() |
8fc19601 | 511 | || this->is_preemptible())); |
d61c6bd4 ILT |
512 | } |
513 | ||
0700cf32 ILT |
514 | // When determining whether a reference to a symbol needs a dynamic |
515 | // relocation, we need to know several things about the reference. | |
516 | // These flags may be or'ed together. | |
517 | enum Reference_flags | |
518 | { | |
519 | // Reference to the symbol's absolute address. | |
520 | ABSOLUTE_REF = 1, | |
521 | // A non-PIC reference. | |
522 | NON_PIC_REF = 2, | |
523 | // A function call. | |
524 | FUNCTION_CALL = 4 | |
525 | }; | |
526 | ||
d61c6bd4 ILT |
527 | // Given a direct absolute or pc-relative static relocation against |
528 | // the global symbol, this function returns whether a dynamic relocation | |
529 | // is needed. | |
530 | ||
531 | bool | |
0700cf32 | 532 | needs_dynamic_reloc(int flags) const |
d61c6bd4 | 533 | { |
8fc19601 ILT |
534 | // No dynamic relocations in a static link! |
535 | if (parameters->doing_static_link()) | |
536 | return false; | |
537 | ||
f3c69fca CC |
538 | // A reference to a weak undefined symbol from an executable should be |
539 | // statically resolved to 0, and does not need a dynamic relocation. | |
540 | // This matches gnu ld behavior. | |
541 | if (this->is_weak_undefined() && !parameters->options().shared()) | |
542 | return false; | |
543 | ||
544 | // A reference to an absolute symbol does not need a dynamic relocation. | |
545 | if (this->is_absolute()) | |
86925eef CC |
546 | return false; |
547 | ||
d61c6bd4 | 548 | // An absolute reference within a position-independent output file |
0700cf32 ILT |
549 | // will need a dynamic relocation. |
550 | if ((flags & ABSOLUTE_REF) | |
8851ecca | 551 | && parameters->options().output_is_position_independent()) |
d61c6bd4 ILT |
552 | return true; |
553 | ||
554 | // A function call that can branch to a local PLT entry does not need | |
5240d12a ILT |
555 | // a dynamic relocation. A non-pic pc-relative function call in a |
556 | // shared library cannot use a PLT entry. | |
0700cf32 | 557 | if ((flags & FUNCTION_CALL) |
5240d12a | 558 | && this->has_plt_offset() |
8851ecca | 559 | && !((flags & NON_PIC_REF) && parameters->options().shared())) |
d61c6bd4 ILT |
560 | return false; |
561 | ||
562 | // A reference to any PLT entry in a non-position-independent executable | |
563 | // does not need a dynamic relocation. | |
8851ecca | 564 | if (!parameters->options().output_is_position_independent() |
d61c6bd4 ILT |
565 | && this->has_plt_offset()) |
566 | return false; | |
567 | ||
568 | // A reference to a symbol defined in a dynamic object or to a | |
569 | // symbol that is preemptible will need a dynamic relocation. | |
8fc19601 ILT |
570 | if (this->is_from_dynobj() |
571 | || this->is_undefined() | |
572 | || this->is_preemptible()) | |
d61c6bd4 ILT |
573 | return true; |
574 | ||
575 | // For all other cases, return FALSE. | |
576 | return false; | |
577 | } | |
578 | ||
579 | // Given a direct absolute static relocation against | |
580 | // the global symbol, where a dynamic relocation is needed, this | |
581 | // function returns whether a relative dynamic relocation can be used. | |
582 | // The caller must determine separately whether the static relocation | |
583 | // is compatible with a relative relocation. | |
584 | ||
585 | bool | |
586 | can_use_relative_reloc(bool is_function_call) const | |
587 | { | |
588 | // A function call that can branch to a local PLT entry can | |
589 | // use a RELATIVE relocation. | |
590 | if (is_function_call && this->has_plt_offset()) | |
591 | return true; | |
592 | ||
593 | // A reference to a symbol defined in a dynamic object or to a | |
594 | // symbol that is preemptible can not use a RELATIVE relocaiton. | |
8fc19601 ILT |
595 | if (this->is_from_dynobj() |
596 | || this->is_undefined() | |
597 | || this->is_preemptible()) | |
d61c6bd4 ILT |
598 | return false; |
599 | ||
600 | // For all other cases, return TRUE. | |
601 | return true; | |
602 | } | |
603 | ||
77e65537 ILT |
604 | // Return the output section where this symbol is defined. Return |
605 | // NULL if the symbol has an absolute value. | |
606 | Output_section* | |
607 | output_section() const; | |
608 | ||
609 | // Set the symbol's output section. This is used for symbols | |
610 | // defined in scripts. This should only be called after the symbol | |
611 | // table has been finalized. | |
612 | void | |
613 | set_output_section(Output_section*); | |
a445fddf | 614 | |
f6ce93d6 ILT |
615 | // Return whether there should be a warning for references to this |
616 | // symbol. | |
617 | bool | |
618 | has_warning() const | |
619 | { return this->has_warning_; } | |
620 | ||
621 | // Mark this symbol as having a warning. | |
622 | void | |
623 | set_has_warning() | |
624 | { this->has_warning_ = true; } | |
625 | ||
46fe1623 ILT |
626 | // Return whether this symbol is defined by a COPY reloc from a |
627 | // dynamic object. | |
628 | bool | |
629 | is_copied_from_dynobj() const | |
630 | { return this->is_copied_from_dynobj_; } | |
631 | ||
632 | // Mark this symbol as defined by a COPY reloc. | |
633 | void | |
634 | set_is_copied_from_dynobj() | |
635 | { this->is_copied_from_dynobj_ = true; } | |
636 | ||
55a93433 ILT |
637 | // Return whether this symbol is forced to visibility STB_LOCAL |
638 | // by a "local:" entry in a version script. | |
639 | bool | |
640 | is_forced_local() const | |
641 | { return this->is_forced_local_; } | |
642 | ||
643 | // Mark this symbol as forced to STB_LOCAL visibility. | |
644 | void | |
645 | set_is_forced_local() | |
646 | { this->is_forced_local_ = true; } | |
647 | ||
14bfc3f5 ILT |
648 | protected: |
649 | // Instances of this class should always be created at a specific | |
650 | // size. | |
651 | Symbol() | |
f6ce93d6 | 652 | { memset(this, 0, sizeof *this); } |
14bfc3f5 | 653 | |
ead1e424 ILT |
654 | // Initialize the general fields. |
655 | void | |
656 | init_fields(const char* name, const char* version, | |
657 | elfcpp::STT type, elfcpp::STB binding, | |
658 | elfcpp::STV visibility, unsigned char nonvis); | |
659 | ||
d491d34e ILT |
660 | // Initialize fields from an ELF symbol in OBJECT. ST_SHNDX is the |
661 | // section index, IS_ORDINARY is whether it is a normal section | |
662 | // index rather than a special code. | |
14bfc3f5 ILT |
663 | template<int size, bool big_endian> |
664 | void | |
f3e9c5c5 ILT |
665 | init_base_object(const char *name, const char* version, Object* object, |
666 | const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx, | |
667 | bool is_ordinary); | |
bae7f79e | 668 | |
ead1e424 ILT |
669 | // Initialize fields for an Output_data. |
670 | void | |
75517b77 ILT |
671 | init_base_output_data(const char* name, const char* version, Output_data*, |
672 | elfcpp::STT, elfcpp::STB, elfcpp::STV, | |
673 | unsigned char nonvis, bool offset_is_from_end); | |
ead1e424 ILT |
674 | |
675 | // Initialize fields for an Output_segment. | |
676 | void | |
75517b77 ILT |
677 | init_base_output_segment(const char* name, const char* version, |
678 | Output_segment* os, elfcpp::STT type, | |
679 | elfcpp::STB binding, elfcpp::STV visibility, | |
680 | unsigned char nonvis, | |
f3e9c5c5 | 681 | Segment_offset_base offset_base); |
ead1e424 ILT |
682 | |
683 | // Initialize fields for a constant. | |
684 | void | |
75517b77 ILT |
685 | init_base_constant(const char* name, const char* version, elfcpp::STT type, |
686 | elfcpp::STB binding, elfcpp::STV visibility, | |
687 | unsigned char nonvis); | |
f3e9c5c5 ILT |
688 | |
689 | // Initialize fields for an undefined symbol. | |
690 | void | |
75517b77 ILT |
691 | init_base_undefined(const char* name, const char* version, elfcpp::STT type, |
692 | elfcpp::STB binding, elfcpp::STV visibility, | |
693 | unsigned char nonvis); | |
ead1e424 | 694 | |
1564db8d ILT |
695 | // Override existing symbol. |
696 | template<int size, bool big_endian> | |
697 | void | |
d491d34e ILT |
698 | override_base(const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx, |
699 | bool is_ordinary, Object* object, const char* version); | |
1564db8d | 700 | |
86f2e683 ILT |
701 | // Override existing symbol with a special symbol. |
702 | void | |
703 | override_base_with_special(const Symbol* from); | |
704 | ||
75517b77 ILT |
705 | // Override symbol version. |
706 | void | |
707 | override_version(const char* version); | |
708 | ||
c7912668 ILT |
709 | // Allocate a common symbol by giving it a location in the output |
710 | // file. | |
711 | void | |
712 | allocate_base_common(Output_data*); | |
713 | ||
bae7f79e | 714 | private: |
14bfc3f5 ILT |
715 | Symbol(const Symbol&); |
716 | Symbol& operator=(const Symbol&); | |
717 | ||
718 | // Symbol name (expected to point into a Stringpool). | |
719 | const char* name_; | |
720 | // Symbol version (expected to point into a Stringpool). This may | |
721 | // be NULL. | |
bae7f79e | 722 | const char* version_; |
ead1e424 ILT |
723 | |
724 | union | |
725 | { | |
726 | // This struct is used if SOURCE_ == FROM_OBJECT. | |
727 | struct | |
728 | { | |
729 | // Object in which symbol is defined, or in which it was first | |
730 | // seen. | |
731 | Object* object; | |
732 | // Section number in object_ in which symbol is defined. | |
16649710 | 733 | unsigned int shndx; |
ead1e424 ILT |
734 | } from_object; |
735 | ||
736 | // This struct is used if SOURCE_ == IN_OUTPUT_DATA. | |
737 | struct | |
738 | { | |
739 | // Output_data in which symbol is defined. Before | |
740 | // Layout::finalize the symbol's value is an offset within the | |
741 | // Output_data. | |
742 | Output_data* output_data; | |
743 | // True if the offset is from the end, false if the offset is | |
744 | // from the beginning. | |
745 | bool offset_is_from_end; | |
746 | } in_output_data; | |
747 | ||
748 | // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT. | |
749 | struct | |
750 | { | |
751 | // Output_segment in which the symbol is defined. Before | |
752 | // Layout::finalize the symbol's value is an offset. | |
753 | Output_segment* output_segment; | |
754 | // The base to use for the offset before Layout::finalize. | |
755 | Segment_offset_base offset_base; | |
756 | } in_output_segment; | |
757 | } u_; | |
758 | ||
c06b7b0b ILT |
759 | // The index of this symbol in the output file. If the symbol is |
760 | // not going into the output file, this value is -1U. This field | |
761 | // starts as always holding zero. It is set to a non-zero value by | |
762 | // Symbol_table::finalize. | |
763 | unsigned int symtab_index_; | |
764 | ||
765 | // The index of this symbol in the dynamic symbol table. If the | |
766 | // symbol is not going into the dynamic symbol table, this value is | |
767 | // -1U. This field starts as always holding zero. It is set to a | |
768 | // non-zero value during Layout::finalize. | |
769 | unsigned int dynsym_index_; | |
770 | ||
ead1e424 | 771 | // If this symbol has an entry in the GOT section (has_got_offset_ |
0a65a3a7 CC |
772 | // is true), this holds the offset from the start of the GOT section. |
773 | // A symbol may have more than one GOT offset (e.g., when mixing | |
774 | // modules compiled with two different TLS models), but will usually | |
775 | // have at most one. | |
776 | Got_offset_list got_offsets_; | |
07f397ab | 777 | |
a3ad94ed ILT |
778 | // If this symbol has an entry in the PLT section (has_plt_offset_ |
779 | // is true), then this is the offset from the start of the PLT | |
780 | // section. | |
781 | unsigned int plt_offset_; | |
782 | ||
d491d34e | 783 | // Symbol type (bits 0 to 3). |
bae7f79e | 784 | elfcpp::STT type_ : 4; |
d491d34e | 785 | // Symbol binding (bits 4 to 7). |
bae7f79e | 786 | elfcpp::STB binding_ : 4; |
d491d34e | 787 | // Symbol visibility (bits 8 to 9). |
14bfc3f5 | 788 | elfcpp::STV visibility_ : 2; |
d491d34e | 789 | // Rest of symbol st_other field (bits 10 to 15). |
ead1e424 | 790 | unsigned int nonvis_ : 6; |
d491d34e | 791 | // The type of symbol (bits 16 to 18). |
f6ce93d6 | 792 | Source source_ : 3; |
14bfc3f5 | 793 | // True if this symbol always requires special target-specific |
d491d34e | 794 | // handling (bit 19). |
ead1e424 | 795 | bool is_target_special_ : 1; |
d491d34e | 796 | // True if this is the default version of the symbol (bit 20). |
1564db8d | 797 | bool is_def_ : 1; |
14bfc3f5 ILT |
798 | // True if this symbol really forwards to another symbol. This is |
799 | // used when we discover after the fact that two different entries | |
800 | // in the hash table really refer to the same symbol. This will | |
801 | // never be set for a symbol found in the hash table, but may be set | |
802 | // for a symbol found in the list of symbols attached to an Object. | |
803 | // It forwards to the symbol found in the forwarders_ map of | |
d491d34e | 804 | // Symbol_table (bit 21). |
1564db8d | 805 | bool is_forwarder_ : 1; |
aeddab66 | 806 | // True if the symbol has an alias in the weak_aliases table in |
d491d34e | 807 | // Symbol_table (bit 22). |
aeddab66 | 808 | bool has_alias_ : 1; |
d491d34e ILT |
809 | // True if this symbol needs to be in the dynamic symbol table (bit |
810 | // 23). | |
c06b7b0b | 811 | bool needs_dynsym_entry_ : 1; |
d491d34e | 812 | // True if we've seen this symbol in a regular object (bit 24). |
008db82e | 813 | bool in_reg_ : 1; |
d491d34e | 814 | // True if we've seen this symbol in a dynamic object (bit 25). |
1564db8d | 815 | bool in_dyn_ : 1; |
d491d34e | 816 | // True if the symbol has an entry in the PLT section (bit 26). |
a3ad94ed | 817 | bool has_plt_offset_ : 1; |
ab5c9e90 | 818 | // True if this is a dynamic symbol which needs a special value in |
d491d34e | 819 | // the dynamic symbol table (bit 27). |
ab5c9e90 | 820 | bool needs_dynsym_value_ : 1; |
d491d34e | 821 | // True if there is a warning for this symbol (bit 28). |
f6ce93d6 | 822 | bool has_warning_ : 1; |
46fe1623 | 823 | // True if we are using a COPY reloc for this symbol, so that the |
d491d34e | 824 | // real definition lives in a dynamic object (bit 29). |
46fe1623 | 825 | bool is_copied_from_dynobj_ : 1; |
55a93433 | 826 | // True if this symbol was forced to local visibility by a version |
d491d34e | 827 | // script (bit 30). |
55a93433 | 828 | bool is_forced_local_ : 1; |
d491d34e ILT |
829 | // True if the field u_.from_object.shndx is an ordinary section |
830 | // index, not one of the special codes from SHN_LORESERVE to | |
831 | // SHN_HIRESERVE. | |
832 | bool is_ordinary_shndx_ : 1; | |
bae7f79e ILT |
833 | }; |
834 | ||
14bfc3f5 ILT |
835 | // The parts of a symbol which are size specific. Using a template |
836 | // derived class like this helps us use less space on a 32-bit system. | |
bae7f79e ILT |
837 | |
838 | template<int size> | |
14bfc3f5 ILT |
839 | class Sized_symbol : public Symbol |
840 | { | |
841 | public: | |
1564db8d ILT |
842 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Value_type; |
843 | typedef typename elfcpp::Elf_types<size>::Elf_WXword Size_type; | |
844 | ||
14bfc3f5 ILT |
845 | Sized_symbol() |
846 | { } | |
847 | ||
d491d34e ILT |
848 | // Initialize fields from an ELF symbol in OBJECT. ST_SHNDX is the |
849 | // section index, IS_ORDINARY is whether it is a normal section | |
850 | // index rather than a special code. | |
14bfc3f5 ILT |
851 | template<bool big_endian> |
852 | void | |
f3e9c5c5 ILT |
853 | init_object(const char *name, const char* version, Object* object, |
854 | const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx, | |
855 | bool is_ordinary); | |
14bfc3f5 | 856 | |
ead1e424 ILT |
857 | // Initialize fields for an Output_data. |
858 | void | |
75517b77 ILT |
859 | init_output_data(const char* name, const char* version, Output_data*, |
860 | Value_type value, Size_type symsize, elfcpp::STT, | |
861 | elfcpp::STB, elfcpp::STV, unsigned char nonvis, | |
862 | bool offset_is_from_end); | |
ead1e424 ILT |
863 | |
864 | // Initialize fields for an Output_segment. | |
865 | void | |
75517b77 ILT |
866 | init_output_segment(const char* name, const char* version, Output_segment*, |
867 | Value_type value, Size_type symsize, elfcpp::STT, | |
868 | elfcpp::STB, elfcpp::STV, unsigned char nonvis, | |
869 | Segment_offset_base offset_base); | |
ead1e424 ILT |
870 | |
871 | // Initialize fields for a constant. | |
872 | void | |
75517b77 ILT |
873 | init_constant(const char* name, const char* version, Value_type value, |
874 | Size_type symsize, elfcpp::STT, elfcpp::STB, elfcpp::STV, | |
875 | unsigned char nonvis); | |
f3e9c5c5 ILT |
876 | |
877 | // Initialize fields for an undefined symbol. | |
878 | void | |
75517b77 ILT |
879 | init_undefined(const char* name, const char* version, elfcpp::STT, |
880 | elfcpp::STB, elfcpp::STV, unsigned char nonvis); | |
ead1e424 | 881 | |
1564db8d ILT |
882 | // Override existing symbol. |
883 | template<bool big_endian> | |
884 | void | |
d491d34e ILT |
885 | override(const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx, |
886 | bool is_ordinary, Object* object, const char* version); | |
1564db8d | 887 | |
86f2e683 ILT |
888 | // Override existing symbol with a special symbol. |
889 | void | |
890 | override_with_special(const Sized_symbol<size>*); | |
891 | ||
1564db8d ILT |
892 | // Return the symbol's value. |
893 | Value_type | |
894 | value() const | |
895 | { return this->value_; } | |
896 | ||
897 | // Return the symbol's size (we can't call this 'size' because that | |
898 | // is a template parameter). | |
899 | Size_type | |
900 | symsize() const | |
ead1e424 ILT |
901 | { return this->symsize_; } |
902 | ||
903 | // Set the symbol size. This is used when resolving common symbols. | |
904 | void | |
905 | set_symsize(Size_type symsize) | |
906 | { this->symsize_ = symsize; } | |
1564db8d | 907 | |
75f65a3e ILT |
908 | // Set the symbol value. This is called when we store the final |
909 | // values of the symbols into the symbol table. | |
910 | void | |
911 | set_value(Value_type value) | |
912 | { this->value_ = value; } | |
913 | ||
c7912668 ILT |
914 | // Allocate a common symbol by giving it a location in the output |
915 | // file. | |
916 | void | |
917 | allocate_common(Output_data*, Value_type value); | |
918 | ||
14bfc3f5 ILT |
919 | private: |
920 | Sized_symbol(const Sized_symbol&); | |
921 | Sized_symbol& operator=(const Sized_symbol&); | |
922 | ||
ead1e424 ILT |
923 | // Symbol value. Before Layout::finalize this is the offset in the |
924 | // input section. This is set to the final value during | |
925 | // Layout::finalize. | |
1564db8d | 926 | Value_type value_; |
14bfc3f5 | 927 | // Symbol size. |
ead1e424 ILT |
928 | Size_type symsize_; |
929 | }; | |
930 | ||
931 | // A struct describing a symbol defined by the linker, where the value | |
932 | // of the symbol is defined based on an output section. This is used | |
933 | // for symbols defined by the linker, like "_init_array_start". | |
934 | ||
935 | struct Define_symbol_in_section | |
936 | { | |
937 | // The symbol name. | |
938 | const char* name; | |
939 | // The name of the output section with which this symbol should be | |
940 | // associated. If there is no output section with that name, the | |
941 | // symbol will be defined as zero. | |
942 | const char* output_section; | |
943 | // The offset of the symbol within the output section. This is an | |
944 | // offset from the start of the output section, unless start_at_end | |
945 | // is true, in which case this is an offset from the end of the | |
946 | // output section. | |
947 | uint64_t value; | |
948 | // The size of the symbol. | |
949 | uint64_t size; | |
950 | // The symbol type. | |
951 | elfcpp::STT type; | |
952 | // The symbol binding. | |
953 | elfcpp::STB binding; | |
954 | // The symbol visibility. | |
955 | elfcpp::STV visibility; | |
956 | // The rest of the st_other field. | |
957 | unsigned char nonvis; | |
958 | // If true, the value field is an offset from the end of the output | |
959 | // section. | |
960 | bool offset_is_from_end; | |
961 | // If true, this symbol is defined only if we see a reference to it. | |
962 | bool only_if_ref; | |
963 | }; | |
964 | ||
965 | // A struct describing a symbol defined by the linker, where the value | |
966 | // of the symbol is defined based on a segment. This is used for | |
967 | // symbols defined by the linker, like "_end". We describe the | |
968 | // segment with which the symbol should be associated by its | |
969 | // characteristics. If no segment meets these characteristics, the | |
970 | // symbol will be defined as zero. If there is more than one segment | |
971 | // which meets these characteristics, we will use the first one. | |
972 | ||
973 | struct Define_symbol_in_segment | |
974 | { | |
975 | // The symbol name. | |
976 | const char* name; | |
977 | // The segment type where the symbol should be defined, typically | |
978 | // PT_LOAD. | |
979 | elfcpp::PT segment_type; | |
980 | // Bitmask of segment flags which must be set. | |
981 | elfcpp::PF segment_flags_set; | |
982 | // Bitmask of segment flags which must be clear. | |
983 | elfcpp::PF segment_flags_clear; | |
984 | // The offset of the symbol within the segment. The offset is | |
985 | // calculated from the position set by offset_base. | |
986 | uint64_t value; | |
987 | // The size of the symbol. | |
988 | uint64_t size; | |
989 | // The symbol type. | |
990 | elfcpp::STT type; | |
991 | // The symbol binding. | |
992 | elfcpp::STB binding; | |
993 | // The symbol visibility. | |
994 | elfcpp::STV visibility; | |
995 | // The rest of the st_other field. | |
996 | unsigned char nonvis; | |
997 | // The base from which we compute the offset. | |
998 | Symbol::Segment_offset_base offset_base; | |
999 | // If true, this symbol is defined only if we see a reference to it. | |
1000 | bool only_if_ref; | |
14bfc3f5 ILT |
1001 | }; |
1002 | ||
f6ce93d6 ILT |
1003 | // This class manages warnings. Warnings are a GNU extension. When |
1004 | // we see a section named .gnu.warning.SYM in an object file, and if | |
1005 | // we wind using the definition of SYM from that object file, then we | |
1006 | // will issue a warning for any relocation against SYM from a | |
1007 | // different object file. The text of the warning is the contents of | |
1008 | // the section. This is not precisely the definition used by the old | |
1009 | // GNU linker; the old GNU linker treated an occurrence of | |
1010 | // .gnu.warning.SYM as defining a warning symbol. A warning symbol | |
1011 | // would trigger a warning on any reference. However, it was | |
1012 | // inconsistent in that a warning in a dynamic object only triggered | |
1013 | // if there was no definition in a regular object. This linker is | |
1014 | // different in that we only issue a warning if we use the symbol | |
1015 | // definition from the same object file as the warning section. | |
1016 | ||
1017 | class Warnings | |
1018 | { | |
1019 | public: | |
1020 | Warnings() | |
1021 | : warnings_() | |
1022 | { } | |
1023 | ||
cb295612 ILT |
1024 | // Add a warning for symbol NAME in object OBJ. WARNING is the text |
1025 | // of the warning. | |
f6ce93d6 ILT |
1026 | void |
1027 | add_warning(Symbol_table* symtab, const char* name, Object* obj, | |
cb295612 | 1028 | const std::string& warning); |
f6ce93d6 ILT |
1029 | |
1030 | // For each symbol for which we should give a warning, make a note | |
1031 | // on the symbol. | |
1032 | void | |
cb295612 | 1033 | note_warnings(Symbol_table* symtab); |
f6ce93d6 | 1034 | |
75f2446e ILT |
1035 | // Issue a warning for a reference to SYM at RELINFO's location. |
1036 | template<int size, bool big_endian> | |
f6ce93d6 | 1037 | void |
75f2446e ILT |
1038 | issue_warning(const Symbol* sym, const Relocate_info<size, big_endian>*, |
1039 | size_t relnum, off_t reloffset) const; | |
f6ce93d6 ILT |
1040 | |
1041 | private: | |
1042 | Warnings(const Warnings&); | |
1043 | Warnings& operator=(const Warnings&); | |
1044 | ||
1045 | // What we need to know to get the warning text. | |
1046 | struct Warning_location | |
1047 | { | |
1048 | // The object the warning is in. | |
1049 | Object* object; | |
cb295612 | 1050 | // The warning text. |
f6ce93d6 ILT |
1051 | std::string text; |
1052 | ||
1053 | Warning_location() | |
cb295612 | 1054 | : object(NULL), text() |
f6ce93d6 ILT |
1055 | { } |
1056 | ||
1057 | void | |
cb295612 | 1058 | set(Object* o, const std::string& t) |
f6ce93d6 ILT |
1059 | { |
1060 | this->object = o; | |
cb295612 | 1061 | this->text = t; |
f6ce93d6 | 1062 | } |
f6ce93d6 ILT |
1063 | }; |
1064 | ||
1065 | // A mapping from warning symbol names (canonicalized in | |
70e654ba | 1066 | // Symbol_table's namepool_ field) to warning information. |
f6ce93d6 ILT |
1067 | typedef Unordered_map<const char*, Warning_location> Warning_table; |
1068 | ||
1069 | Warning_table warnings_; | |
1070 | }; | |
1071 | ||
14bfc3f5 ILT |
1072 | // The main linker symbol table. |
1073 | ||
bae7f79e ILT |
1074 | class Symbol_table |
1075 | { | |
1076 | public: | |
6d013333 ILT |
1077 | // COUNT is an estimate of how many symbosl will be inserted in the |
1078 | // symbol table. It's ok to put 0 if you don't know; a correct | |
1079 | // guess will just save some CPU by reducing hashtable resizes. | |
09124467 | 1080 | Symbol_table(unsigned int count, const Version_script_info& version_script); |
bae7f79e | 1081 | |
1564db8d | 1082 | ~Symbol_table(); |
bae7f79e | 1083 | |
dbe717ef | 1084 | // Add COUNT external symbols from the relocatable object RELOBJ to |
d491d34e ILT |
1085 | // the symbol table. SYMS is the symbols, SYMNDX_OFFSET is the |
1086 | // offset in the symbol table of the first symbol, SYM_NAMES is | |
1087 | // their names, SYM_NAME_SIZE is the size of SYM_NAMES. This sets | |
1088 | // SYMPOINTERS to point to the symbols in the symbol table. | |
14bfc3f5 ILT |
1089 | template<int size, bool big_endian> |
1090 | void | |
dbe717ef ILT |
1091 | add_from_relobj(Sized_relobj<size, big_endian>* relobj, |
1092 | const unsigned char* syms, size_t count, | |
d491d34e ILT |
1093 | size_t symndx_offset, const char* sym_names, |
1094 | size_t sym_name_size, | |
730cdc88 | 1095 | typename Sized_relobj<size, big_endian>::Symbols*); |
14bfc3f5 | 1096 | |
dbe717ef ILT |
1097 | // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the |
1098 | // symbol table. SYMS is the symbols. SYM_NAMES is their names. | |
1099 | // SYM_NAME_SIZE is the size of SYM_NAMES. The other parameters are | |
1100 | // symbol version data. | |
1101 | template<int size, bool big_endian> | |
1102 | void | |
1103 | add_from_dynobj(Sized_dynobj<size, big_endian>* dynobj, | |
1104 | const unsigned char* syms, size_t count, | |
1105 | const char* sym_names, size_t sym_name_size, | |
1106 | const unsigned char* versym, size_t versym_size, | |
1107 | const std::vector<const char*>*); | |
1108 | ||
ead1e424 ILT |
1109 | // Define a special symbol based on an Output_data. It is a |
1110 | // multiple definition error if this symbol is already defined. | |
14b31740 | 1111 | Symbol* |
9b07f471 | 1112 | define_in_output_data(const char* name, const char* version, |
14b31740 | 1113 | Output_data*, uint64_t value, uint64_t symsize, |
ead1e424 ILT |
1114 | elfcpp::STT type, elfcpp::STB binding, |
1115 | elfcpp::STV visibility, unsigned char nonvis, | |
1116 | bool offset_is_from_end, bool only_if_ref); | |
1117 | ||
1118 | // Define a special symbol based on an Output_segment. It is a | |
1119 | // multiple definition error if this symbol is already defined. | |
14b31740 | 1120 | Symbol* |
9b07f471 ILT |
1121 | define_in_output_segment(const char* name, const char* version, |
1122 | Output_segment*, uint64_t value, uint64_t symsize, | |
ead1e424 ILT |
1123 | elfcpp::STT type, elfcpp::STB binding, |
1124 | elfcpp::STV visibility, unsigned char nonvis, | |
1125 | Symbol::Segment_offset_base, bool only_if_ref); | |
1126 | ||
1127 | // Define a special symbol with a constant value. It is a multiple | |
1128 | // definition error if this symbol is already defined. | |
14b31740 | 1129 | Symbol* |
9b07f471 | 1130 | define_as_constant(const char* name, const char* version, |
14b31740 ILT |
1131 | uint64_t value, uint64_t symsize, elfcpp::STT type, |
1132 | elfcpp::STB binding, elfcpp::STV visibility, | |
caa9d5d9 ILT |
1133 | unsigned char nonvis, bool only_if_ref, |
1134 | bool force_override); | |
ead1e424 | 1135 | |
a445fddf ILT |
1136 | // Define a set of symbols in output sections. If ONLY_IF_REF is |
1137 | // true, only define them if they are referenced. | |
ead1e424 | 1138 | void |
a445fddf ILT |
1139 | define_symbols(const Layout*, int count, const Define_symbol_in_section*, |
1140 | bool only_if_ref); | |
ead1e424 | 1141 | |
a445fddf ILT |
1142 | // Define a set of symbols in output segments. If ONLY_IF_REF is |
1143 | // true, only defined them if they are referenced. | |
ead1e424 | 1144 | void |
a445fddf ILT |
1145 | define_symbols(const Layout*, int count, const Define_symbol_in_segment*, |
1146 | bool only_if_ref); | |
ead1e424 | 1147 | |
46fe1623 ILT |
1148 | // Define SYM using a COPY reloc. POSD is the Output_data where the |
1149 | // symbol should be defined--typically a .dyn.bss section. VALUE is | |
1150 | // the offset within POSD. | |
1151 | template<int size> | |
1152 | void | |
9b07f471 | 1153 | define_with_copy_reloc(Sized_symbol<size>* sym, Output_data* posd, |
fe8718a4 | 1154 | typename elfcpp::Elf_types<size>::Elf_Addr); |
46fe1623 | 1155 | |
61ba1cf9 ILT |
1156 | // Look up a symbol. |
1157 | Symbol* | |
1158 | lookup(const char*, const char* version = NULL) const; | |
1159 | ||
14bfc3f5 | 1160 | // Return the real symbol associated with the forwarder symbol FROM. |
bae7f79e | 1161 | Symbol* |
c06b7b0b | 1162 | resolve_forwards(const Symbol* from) const; |
bae7f79e | 1163 | |
1564db8d ILT |
1164 | // Return the sized version of a symbol in this table. |
1165 | template<int size> | |
1166 | Sized_symbol<size>* | |
7d1a9ebb | 1167 | get_sized_symbol(Symbol*) const; |
1564db8d ILT |
1168 | |
1169 | template<int size> | |
1170 | const Sized_symbol<size>* | |
7d1a9ebb | 1171 | get_sized_symbol(const Symbol*) const; |
54dc6425 | 1172 | |
ead1e424 ILT |
1173 | // Return the count of undefined symbols seen. |
1174 | int | |
1175 | saw_undefined() const | |
1176 | { return this->saw_undefined_; } | |
1177 | ||
1178 | // Allocate the common symbols | |
1179 | void | |
155a0dd7 | 1180 | allocate_commons(Layout*); |
ead1e424 | 1181 | |
cb295612 ILT |
1182 | // Add a warning for symbol NAME in object OBJ. WARNING is the text |
1183 | // of the warning. | |
f6ce93d6 | 1184 | void |
cb295612 ILT |
1185 | add_warning(const char* name, Object* obj, const std::string& warning) |
1186 | { this->warnings_.add_warning(this, name, obj, warning); } | |
f6ce93d6 ILT |
1187 | |
1188 | // Canonicalize a symbol name for use in the hash table. | |
1189 | const char* | |
1190 | canonicalize_name(const char* name) | |
cfd73a4e | 1191 | { return this->namepool_.add(name, true, NULL); } |
f6ce93d6 ILT |
1192 | |
1193 | // Possibly issue a warning for a reference to SYM at LOCATION which | |
1194 | // is in OBJ. | |
75f2446e | 1195 | template<int size, bool big_endian> |
f6ce93d6 | 1196 | void |
75f2446e ILT |
1197 | issue_warning(const Symbol* sym, |
1198 | const Relocate_info<size, big_endian>* relinfo, | |
1199 | size_t relnum, off_t reloffset) const | |
1200 | { this->warnings_.issue_warning(sym, relinfo, relnum, reloffset); } | |
f6ce93d6 | 1201 | |
70e654ba ILT |
1202 | // Check candidate_odr_violations_ to find symbols with the same name |
1203 | // but apparently different definitions (different source-file/line-no). | |
1204 | void | |
17a1d0a9 | 1205 | detect_odr_violations(const Task*, const char* output_file_name) const; |
70e654ba | 1206 | |
f3e9c5c5 ILT |
1207 | // Add any undefined symbols named on the command line to the symbol |
1208 | // table. | |
1209 | void | |
1210 | add_undefined_symbols_from_command_line(); | |
1211 | ||
46fe1623 ILT |
1212 | // SYM is defined using a COPY reloc. Return the dynamic object |
1213 | // where the original definition was found. | |
1214 | Dynobj* | |
1215 | get_copy_source(const Symbol* sym) const; | |
1216 | ||
a3ad94ed ILT |
1217 | // Set the dynamic symbol indexes. INDEX is the index of the first |
1218 | // global dynamic symbol. Pointers to the symbols are stored into | |
1219 | // the vector. The names are stored into the Stringpool. This | |
1220 | // returns an updated dynamic symbol index. | |
1221 | unsigned int | |
9b07f471 ILT |
1222 | set_dynsym_indexes(unsigned int index, std::vector<Symbol*>*, |
1223 | Stringpool*, Versions*); | |
a3ad94ed | 1224 | |
75f65a3e | 1225 | // Finalize the symbol table after we have set the final addresses |
c06b7b0b | 1226 | // of all the input sections. This sets the final symbol indexes, |
55a93433 ILT |
1227 | // values and adds the names to *POOL. *PLOCAL_SYMCOUNT is the |
1228 | // index of the first global symbol. OFF is the file offset of the | |
1229 | // global symbol table, DYNOFF is the offset of the globals in the | |
1230 | // dynamic symbol table, DYN_GLOBAL_INDEX is the index of the first | |
1231 | // global dynamic symbol, and DYNCOUNT is the number of global | |
1232 | // dynamic symbols. This records the parameters, and returns the | |
1233 | // new file offset. It updates *PLOCAL_SYMCOUNT if it created any | |
1234 | // local symbols. | |
75f65a3e | 1235 | off_t |
55a93433 ILT |
1236 | finalize(off_t off, off_t dynoff, size_t dyn_global_index, size_t dyncount, |
1237 | Stringpool* pool, unsigned int *plocal_symcount); | |
1564db8d | 1238 | |
61ba1cf9 ILT |
1239 | // Write out the global symbols. |
1240 | void | |
9a2d6984 | 1241 | write_globals(const Input_objects*, const Stringpool*, const Stringpool*, |
d491d34e | 1242 | Output_symtab_xindex*, Output_symtab_xindex*, |
16649710 | 1243 | Output_file*) const; |
61ba1cf9 | 1244 | |
a3ad94ed ILT |
1245 | // Write out a section symbol. Return the updated offset. |
1246 | void | |
d491d34e ILT |
1247 | write_section_symbol(const Output_section*, Output_symtab_xindex*, |
1248 | Output_file*, off_t) const; | |
a3ad94ed | 1249 | |
abaa3995 ILT |
1250 | // Dump statistical information to stderr. |
1251 | void | |
1252 | print_stats() const; | |
1253 | ||
09124467 ILT |
1254 | // Return the version script information. |
1255 | const Version_script_info& | |
1256 | version_script() const | |
1257 | { return version_script_; } | |
1258 | ||
bae7f79e ILT |
1259 | private: |
1260 | Symbol_table(const Symbol_table&); | |
1261 | Symbol_table& operator=(const Symbol_table&); | |
1262 | ||
155a0dd7 ILT |
1263 | // The type of the list of common symbols. |
1264 | typedef std::vector<Symbol*> Commons_type; | |
1265 | ||
14bfc3f5 ILT |
1266 | // Make FROM a forwarder symbol to TO. |
1267 | void | |
1268 | make_forwarder(Symbol* from, Symbol* to); | |
1269 | ||
1270 | // Add a symbol. | |
1271 | template<int size, bool big_endian> | |
aeddab66 | 1272 | Sized_symbol<size>* |
f0641a0b ILT |
1273 | add_from_object(Object*, const char *name, Stringpool::Key name_key, |
1274 | const char *version, Stringpool::Key version_key, | |
70e654ba | 1275 | bool def, const elfcpp::Sym<size, big_endian>& sym, |
d491d34e ILT |
1276 | unsigned int st_shndx, bool is_ordinary, |
1277 | unsigned int orig_st_shndx); | |
14bfc3f5 ILT |
1278 | |
1279 | // Resolve symbols. | |
1280 | template<int size, bool big_endian> | |
aeddab66 | 1281 | void |
1564db8d ILT |
1282 | resolve(Sized_symbol<size>* to, |
1283 | const elfcpp::Sym<size, big_endian>& sym, | |
d491d34e ILT |
1284 | unsigned int st_shndx, bool is_ordinary, |
1285 | unsigned int orig_st_shndx, | |
14b31740 | 1286 | Object*, const char* version); |
14bfc3f5 | 1287 | |
1564db8d | 1288 | template<int size, bool big_endian> |
aeddab66 | 1289 | void |
14b31740 | 1290 | resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from, |
7d1a9ebb | 1291 | const char* version); |
14b31740 | 1292 | |
55a93433 ILT |
1293 | // Record that a symbol is forced to be local by a version script. |
1294 | void | |
1295 | force_local(Symbol*); | |
1296 | ||
0864d551 ILT |
1297 | // Adjust NAME and *NAME_KEY for wrapping. |
1298 | const char* | |
1299 | wrap_symbol(Object* object, const char*, Stringpool::Key* name_key); | |
1300 | ||
86f2e683 ILT |
1301 | // Whether we should override a symbol, based on flags in |
1302 | // resolve.cc. | |
1303 | static bool | |
d20222a1 | 1304 | should_override(const Symbol*, unsigned int, Object*, bool*); |
86f2e683 | 1305 | |
aeddab66 ILT |
1306 | // Override a symbol. |
1307 | template<int size, bool big_endian> | |
1308 | void | |
1309 | override(Sized_symbol<size>* tosym, | |
1310 | const elfcpp::Sym<size, big_endian>& fromsym, | |
d491d34e | 1311 | unsigned int st_shndx, bool is_ordinary, |
aeddab66 ILT |
1312 | Object* object, const char* version); |
1313 | ||
86f2e683 ILT |
1314 | // Whether we should override a symbol with a special symbol which |
1315 | // is automatically defined by the linker. | |
1316 | static bool | |
1317 | should_override_with_special(const Symbol*); | |
1318 | ||
aeddab66 ILT |
1319 | // Override a symbol with a special symbol. |
1320 | template<int size> | |
1321 | void | |
1322 | override_with_special(Sized_symbol<size>* tosym, | |
1323 | const Sized_symbol<size>* fromsym); | |
1324 | ||
1325 | // Record all weak alias sets for a dynamic object. | |
1326 | template<int size> | |
1327 | void | |
1328 | record_weak_aliases(std::vector<Sized_symbol<size>*>*); | |
1329 | ||
14b31740 ILT |
1330 | // Define a special symbol. |
1331 | template<int size, bool big_endian> | |
1332 | Sized_symbol<size>* | |
9b07f471 | 1333 | define_special_symbol(const char** pname, const char** pversion, |
7d1a9ebb | 1334 | bool only_if_ref, Sized_symbol<size>** poldsym); |
14bfc3f5 | 1335 | |
ead1e424 ILT |
1336 | // Define a symbol in an Output_data, sized version. |
1337 | template<int size> | |
14b31740 | 1338 | Sized_symbol<size>* |
9b07f471 | 1339 | do_define_in_output_data(const char* name, const char* version, Output_data*, |
ead1e424 ILT |
1340 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
1341 | typename elfcpp::Elf_types<size>::Elf_WXword ssize, | |
1342 | elfcpp::STT type, elfcpp::STB binding, | |
1343 | elfcpp::STV visibility, unsigned char nonvis, | |
1344 | bool offset_is_from_end, bool only_if_ref); | |
1345 | ||
1346 | // Define a symbol in an Output_segment, sized version. | |
1347 | template<int size> | |
14b31740 | 1348 | Sized_symbol<size>* |
ead1e424 | 1349 | do_define_in_output_segment( |
9b07f471 | 1350 | const char* name, const char* version, Output_segment* os, |
ead1e424 ILT |
1351 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
1352 | typename elfcpp::Elf_types<size>::Elf_WXword ssize, | |
1353 | elfcpp::STT type, elfcpp::STB binding, | |
1354 | elfcpp::STV visibility, unsigned char nonvis, | |
1355 | Symbol::Segment_offset_base offset_base, bool only_if_ref); | |
1356 | ||
1357 | // Define a symbol as a constant, sized version. | |
1358 | template<int size> | |
14b31740 | 1359 | Sized_symbol<size>* |
ead1e424 | 1360 | do_define_as_constant( |
9b07f471 | 1361 | const char* name, const char* version, |
ead1e424 ILT |
1362 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
1363 | typename elfcpp::Elf_types<size>::Elf_WXword ssize, | |
1364 | elfcpp::STT type, elfcpp::STB binding, | |
1365 | elfcpp::STV visibility, unsigned char nonvis, | |
caa9d5d9 | 1366 | bool only_if_ref, bool force_override); |
ead1e424 | 1367 | |
f3e9c5c5 ILT |
1368 | // Add any undefined symbols named on the command line to the symbol |
1369 | // table, sized version. | |
1370 | template<int size> | |
1371 | void | |
1372 | do_add_undefined_symbols_from_command_line(); | |
1373 | ||
ead1e424 ILT |
1374 | // Allocate the common symbols, sized version. |
1375 | template<int size> | |
1376 | void | |
155a0dd7 ILT |
1377 | do_allocate_commons(Layout*); |
1378 | ||
1379 | // Allocate the common symbols from one list. | |
1380 | template<int size> | |
1381 | void | |
1382 | do_allocate_commons_list(Layout*, bool is_tls, Commons_type*); | |
ead1e424 | 1383 | |
70e654ba ILT |
1384 | // Implement detect_odr_violations. |
1385 | template<int size, bool big_endian> | |
1386 | void | |
1387 | sized_detect_odr_violations() const; | |
1388 | ||
75f65a3e ILT |
1389 | // Finalize symbols specialized for size. |
1390 | template<int size> | |
1391 | off_t | |
55a93433 ILT |
1392 | sized_finalize(off_t, Stringpool*, unsigned int*); |
1393 | ||
1394 | // Finalize a symbol. Return whether it should be added to the | |
1395 | // symbol table. | |
1396 | template<int size> | |
1397 | bool | |
1398 | sized_finalize_symbol(Symbol*); | |
1399 | ||
1400 | // Add a symbol the final symtab by setting its index. | |
1401 | template<int size> | |
1402 | void | |
1403 | add_to_final_symtab(Symbol*, Stringpool*, unsigned int* pindex, off_t* poff); | |
75f65a3e | 1404 | |
61ba1cf9 ILT |
1405 | // Write globals specialized for size and endianness. |
1406 | template<int size, bool big_endian> | |
1407 | void | |
9a2d6984 | 1408 | sized_write_globals(const Input_objects*, const Stringpool*, |
d491d34e ILT |
1409 | const Stringpool*, Output_symtab_xindex*, |
1410 | Output_symtab_xindex*, Output_file*) const; | |
16649710 ILT |
1411 | |
1412 | // Write out a symbol to P. | |
1413 | template<int size, bool big_endian> | |
1414 | void | |
ab5c9e90 ILT |
1415 | sized_write_symbol(Sized_symbol<size>*, |
1416 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
1417 | unsigned int shndx, | |
7d1a9ebb | 1418 | const Stringpool*, unsigned char* p) const; |
61ba1cf9 | 1419 | |
9a2d6984 ILT |
1420 | // Possibly warn about an undefined symbol from a dynamic object. |
1421 | void | |
1422 | warn_about_undefined_dynobj_symbol(const Input_objects*, Symbol*) const; | |
1423 | ||
a3ad94ed ILT |
1424 | // Write out a section symbol, specialized for size and endianness. |
1425 | template<int size, bool big_endian> | |
1426 | void | |
d491d34e ILT |
1427 | sized_write_section_symbol(const Output_section*, Output_symtab_xindex*, |
1428 | Output_file*, off_t) const; | |
a3ad94ed | 1429 | |
54dc6425 ILT |
1430 | // The type of the symbol hash table. |
1431 | ||
f0641a0b | 1432 | typedef std::pair<Stringpool::Key, Stringpool::Key> Symbol_table_key; |
14bfc3f5 ILT |
1433 | |
1434 | struct Symbol_table_hash | |
1435 | { | |
1436 | size_t | |
1437 | operator()(const Symbol_table_key&) const; | |
1438 | }; | |
1439 | ||
1440 | struct Symbol_table_eq | |
1441 | { | |
1442 | bool | |
1443 | operator()(const Symbol_table_key&, const Symbol_table_key&) const; | |
1444 | }; | |
1445 | ||
1446 | typedef Unordered_map<Symbol_table_key, Symbol*, Symbol_table_hash, | |
1447 | Symbol_table_eq> Symbol_table_type; | |
1448 | ||
55a93433 ILT |
1449 | // The type of the list of symbols which have been forced local. |
1450 | typedef std::vector<Symbol*> Forced_locals; | |
1451 | ||
46fe1623 ILT |
1452 | // A map from symbols with COPY relocs to the dynamic objects where |
1453 | // they are defined. | |
1454 | typedef Unordered_map<const Symbol*, Dynobj*> Copied_symbol_dynobjs; | |
1455 | ||
70e654ba ILT |
1456 | // A map from symbol name (as a pointer into the namepool) to all |
1457 | // the locations the symbols is (weakly) defined (and certain other | |
1458 | // conditions are met). This map will be used later to detect | |
1459 | // possible One Definition Rule (ODR) violations. | |
1460 | struct Symbol_location | |
1461 | { | |
1462 | Object* object; // Object where the symbol is defined. | |
1463 | unsigned int shndx; // Section-in-object where the symbol is defined. | |
1464 | off_t offset; // Offset-in-section where the symbol is defined. | |
1465 | bool operator==(const Symbol_location& that) const | |
1466 | { | |
1467 | return (this->object == that.object | |
1468 | && this->shndx == that.shndx | |
1469 | && this->offset == that.offset); | |
1470 | } | |
1471 | }; | |
1472 | ||
1473 | struct Symbol_location_hash | |
1474 | { | |
1475 | size_t operator()(const Symbol_location& loc) const | |
1476 | { return reinterpret_cast<uintptr_t>(loc.object) ^ loc.offset ^ loc.shndx; } | |
1477 | }; | |
1478 | ||
1479 | typedef Unordered_map<const char*, | |
1480 | Unordered_set<Symbol_location, Symbol_location_hash> > | |
1481 | Odr_map; | |
1482 | ||
ead1e424 ILT |
1483 | // We increment this every time we see a new undefined symbol, for |
1484 | // use in archive groups. | |
1485 | int saw_undefined_; | |
c06b7b0b ILT |
1486 | // The index of the first global symbol in the output file. |
1487 | unsigned int first_global_index_; | |
75f65a3e ILT |
1488 | // The file offset within the output symtab section where we should |
1489 | // write the table. | |
1490 | off_t offset_; | |
61ba1cf9 | 1491 | // The number of global symbols we want to write out. |
55a93433 | 1492 | unsigned int output_count_; |
16649710 ILT |
1493 | // The file offset of the global dynamic symbols, or 0 if none. |
1494 | off_t dynamic_offset_; | |
16649710 ILT |
1495 | // The index of the first global dynamic symbol. |
1496 | unsigned int first_dynamic_global_index_; | |
16649710 | 1497 | // The number of global dynamic symbols, or 0 if none. |
55a93433 | 1498 | unsigned int dynamic_count_; |
54dc6425 | 1499 | // The symbol hash table. |
14bfc3f5 | 1500 | Symbol_table_type table_; |
54dc6425 ILT |
1501 | // A pool of symbol names. This is used for all global symbols. |
1502 | // Entries in the hash table point into this pool. | |
14bfc3f5 | 1503 | Stringpool namepool_; |
14bfc3f5 | 1504 | // Forwarding symbols. |
c06b7b0b | 1505 | Unordered_map<const Symbol*, Symbol*> forwarders_; |
aeddab66 ILT |
1506 | // Weak aliases. A symbol in this list points to the next alias. |
1507 | // The aliases point to each other in a circular list. | |
1508 | Unordered_map<Symbol*, Symbol*> weak_aliases_; | |
ead1e424 ILT |
1509 | // We don't expect there to be very many common symbols, so we keep |
1510 | // a list of them. When we find a common symbol we add it to this | |
1511 | // list. It is possible that by the time we process the list the | |
1512 | // symbol is no longer a common symbol. It may also have become a | |
1513 | // forwarder. | |
1514 | Commons_type commons_; | |
155a0dd7 ILT |
1515 | // This is like the commons_ field, except that it holds TLS common |
1516 | // symbols. | |
1517 | Commons_type tls_commons_; | |
55a93433 ILT |
1518 | // A list of symbols which have been forced to be local. We don't |
1519 | // expect there to be very many of them, so we keep a list of them | |
1520 | // rather than walking the whole table to find them. | |
1521 | Forced_locals forced_locals_; | |
f6ce93d6 ILT |
1522 | // Manage symbol warnings. |
1523 | Warnings warnings_; | |
70e654ba ILT |
1524 | // Manage potential One Definition Rule (ODR) violations. |
1525 | Odr_map candidate_odr_violations_; | |
1526 | ||
46fe1623 ILT |
1527 | // When we emit a COPY reloc for a symbol, we define it in an |
1528 | // Output_data. When it's time to emit version information for it, | |
1529 | // we need to know the dynamic object in which we found the original | |
1530 | // definition. This maps symbols with COPY relocs to the dynamic | |
1531 | // object where they were defined. | |
1532 | Copied_symbol_dynobjs copied_symbol_dynobjs_; | |
09124467 ILT |
1533 | // Information parsed from the version script, if any. |
1534 | const Version_script_info& version_script_; | |
bae7f79e ILT |
1535 | }; |
1536 | ||
1564db8d ILT |
1537 | // We inline get_sized_symbol for efficiency. |
1538 | ||
1539 | template<int size> | |
1540 | Sized_symbol<size>* | |
7d1a9ebb | 1541 | Symbol_table::get_sized_symbol(Symbol* sym) const |
1564db8d | 1542 | { |
8851ecca | 1543 | gold_assert(size == parameters->target().get_size()); |
1564db8d ILT |
1544 | return static_cast<Sized_symbol<size>*>(sym); |
1545 | } | |
1546 | ||
1547 | template<int size> | |
1548 | const Sized_symbol<size>* | |
7d1a9ebb | 1549 | Symbol_table::get_sized_symbol(const Symbol* sym) const |
1564db8d | 1550 | { |
8851ecca | 1551 | gold_assert(size == parameters->target().get_size()); |
1564db8d ILT |
1552 | return static_cast<const Sized_symbol<size>*>(sym); |
1553 | } | |
1554 | ||
bae7f79e ILT |
1555 | } // End namespace gold. |
1556 | ||
1557 | #endif // !defined(GOLD_SYMTAB_H) |