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