]>
Commit | Line | Data |
---|---|---|
14bfc3f5 | 1 | // target.h -- target support for gold -*- C++ -*- |
bae7f79e | 2 | |
b3ce541e | 3 | // Copyright 2006, 2007, 2008, 2009, 2010, 2011 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 | // The abstract class Target is the interface for target specific |
24 | // support. It defines abstract methods which each target must | |
25 | // implement. Typically there will be one target per processor, but | |
26 | // in some cases it may be necessary to have subclasses. | |
27 | ||
28 | // For speed and consistency we want to use inline functions to handle | |
29 | // relocation processing. So besides implementations of the abstract | |
30 | // methods, each target is expected to define a template | |
31 | // specialization of the relocation functions. | |
32 | ||
33 | #ifndef GOLD_TARGET_H | |
34 | #define GOLD_TARGET_H | |
35 | ||
14bfc3f5 | 36 | #include "elfcpp.h" |
8851ecca | 37 | #include "options.h" |
cd72c291 | 38 | #include "parameters.h" |
20e6d0d6 | 39 | #include "debug.h" |
14bfc3f5 | 40 | |
bae7f79e ILT |
41 | namespace gold |
42 | { | |
43 | ||
14bfc3f5 | 44 | class Object; |
364c7fa5 | 45 | class Relobj; |
61ba1cf9 | 46 | template<int size, bool big_endian> |
f6ce93d6 | 47 | class Sized_relobj; |
6fa2a40b CC |
48 | template<int size, bool big_endian> |
49 | class Sized_relobj_file; | |
6a74a719 | 50 | class Relocatable_relocs; |
92e059d8 | 51 | template<int size, bool big_endian> |
730cdc88 | 52 | class Relocate_info; |
364c7fa5 | 53 | class Reloc_symbol_changes; |
f6ce93d6 ILT |
54 | class Symbol; |
55 | template<int size> | |
56 | class Sized_symbol; | |
57 | class Symbol_table; | |
7223e9ca | 58 | class Output_data; |
4829d394 CC |
59 | template<int size, bool big_endian> |
60 | class Output_data_got; | |
730cdc88 | 61 | class Output_section; |
d5b40221 | 62 | class Input_objects; |
f625ae50 | 63 | class Task; |
14bfc3f5 ILT |
64 | |
65 | // The abstract class for target specific handling. | |
66 | ||
bae7f79e ILT |
67 | class Target |
68 | { | |
69 | public: | |
14bfc3f5 ILT |
70 | virtual ~Target() |
71 | { } | |
72 | ||
73 | // Return the bit size that this target implements. This should | |
74 | // return 32 or 64. | |
75 | int | |
76 | get_size() const | |
75f65a3e | 77 | { return this->pti_->size; } |
14bfc3f5 ILT |
78 | |
79 | // Return whether this target is big-endian. | |
80 | bool | |
81 | is_big_endian() const | |
75f65a3e | 82 | { return this->pti_->is_big_endian; } |
14bfc3f5 | 83 | |
61ba1cf9 ILT |
84 | // Machine code to store in e_machine field of ELF header. |
85 | elfcpp::EM | |
86 | machine_code() const | |
87 | { return this->pti_->machine_code; } | |
88 | ||
d5b40221 DK |
89 | // Processor specific flags to store in e_flags field of ELF header. |
90 | elfcpp::Elf_Word | |
91 | processor_specific_flags() const | |
92 | { return this->processor_specific_flags_; } | |
93 | ||
94 | // Whether processor specific flags are set at least once. | |
95 | bool | |
96 | are_processor_specific_flags_set() const | |
97 | { return this->are_processor_specific_flags_set_; } | |
98 | ||
14bfc3f5 ILT |
99 | // Whether this target has a specific make_symbol function. |
100 | bool | |
101 | has_make_symbol() const | |
75f65a3e | 102 | { return this->pti_->has_make_symbol; } |
14bfc3f5 ILT |
103 | |
104 | // Whether this target has a specific resolve function. | |
105 | bool | |
106 | has_resolve() const | |
75f65a3e ILT |
107 | { return this->pti_->has_resolve; } |
108 | ||
c51e6221 ILT |
109 | // Whether this target has a specific code fill function. |
110 | bool | |
111 | has_code_fill() const | |
112 | { return this->pti_->has_code_fill; } | |
113 | ||
dbe717ef ILT |
114 | // Return the default name of the dynamic linker. |
115 | const char* | |
116 | dynamic_linker() const | |
117 | { return this->pti_->dynamic_linker; } | |
118 | ||
75f65a3e ILT |
119 | // Return the default address to use for the text segment. |
120 | uint64_t | |
0c5e9c22 ILT |
121 | default_text_segment_address() const |
122 | { return this->pti_->default_text_segment_address; } | |
75f65a3e ILT |
123 | |
124 | // Return the ABI specified page size. | |
125 | uint64_t | |
126 | abi_pagesize() const | |
cd72c291 | 127 | { |
8851ecca ILT |
128 | if (parameters->options().max_page_size() > 0) |
129 | return parameters->options().max_page_size(); | |
cd72c291 ILT |
130 | else |
131 | return this->pti_->abi_pagesize; | |
132 | } | |
75f65a3e ILT |
133 | |
134 | // Return the common page size used on actual systems. | |
135 | uint64_t | |
136 | common_pagesize() const | |
cd72c291 | 137 | { |
8851ecca ILT |
138 | if (parameters->options().common_page_size() > 0) |
139 | return std::min(parameters->options().common_page_size(), | |
cd72c291 ILT |
140 | this->abi_pagesize()); |
141 | else | |
142 | return std::min(this->pti_->common_pagesize, | |
143 | this->abi_pagesize()); | |
144 | } | |
14bfc3f5 | 145 | |
35cdfc9a ILT |
146 | // If we see some object files with .note.GNU-stack sections, and |
147 | // some objects files without them, this returns whether we should | |
148 | // consider the object files without them to imply that the stack | |
149 | // should be executable. | |
150 | bool | |
151 | is_default_stack_executable() const | |
152 | { return this->pti_->is_default_stack_executable; } | |
153 | ||
0864d551 ILT |
154 | // Return a character which may appear as a prefix for a wrap |
155 | // symbol. If this character appears, we strip it when checking for | |
156 | // wrapping and add it back when forming the final symbol name. | |
157 | // This should be '\0' if not special prefix is required, which is | |
158 | // the normal case. | |
159 | char | |
160 | wrap_char() const | |
161 | { return this->pti_->wrap_char; } | |
162 | ||
8a5e3e08 ILT |
163 | // Return the special section index which indicates a small common |
164 | // symbol. This will return SHN_UNDEF if there are no small common | |
165 | // symbols. | |
166 | elfcpp::Elf_Half | |
167 | small_common_shndx() const | |
168 | { return this->pti_->small_common_shndx; } | |
169 | ||
170 | // Return values to add to the section flags for the section holding | |
171 | // small common symbols. | |
172 | elfcpp::Elf_Xword | |
173 | small_common_section_flags() const | |
174 | { | |
175 | gold_assert(this->pti_->small_common_shndx != elfcpp::SHN_UNDEF); | |
176 | return this->pti_->small_common_section_flags; | |
177 | } | |
178 | ||
179 | // Return the special section index which indicates a large common | |
180 | // symbol. This will return SHN_UNDEF if there are no large common | |
181 | // symbols. | |
182 | elfcpp::Elf_Half | |
183 | large_common_shndx() const | |
184 | { return this->pti_->large_common_shndx; } | |
185 | ||
186 | // Return values to add to the section flags for the section holding | |
187 | // large common symbols. | |
188 | elfcpp::Elf_Xword | |
189 | large_common_section_flags() const | |
190 | { | |
191 | gold_assert(this->pti_->large_common_shndx != elfcpp::SHN_UNDEF); | |
192 | return this->pti_->large_common_section_flags; | |
193 | } | |
194 | ||
195 | // This hook is called when an output section is created. | |
196 | void | |
197 | new_output_section(Output_section* os) const | |
198 | { this->do_new_output_section(os); } | |
199 | ||
5a6f7e2d ILT |
200 | // This is called to tell the target to complete any sections it is |
201 | // handling. After this all sections must have their final size. | |
202 | void | |
f59f41f3 DK |
203 | finalize_sections(Layout* layout, const Input_objects* input_objects, |
204 | Symbol_table* symtab) | |
205 | { return this->do_finalize_sections(layout, input_objects, symtab); } | |
5a6f7e2d | 206 | |
ab5c9e90 ILT |
207 | // Return the value to use for a global symbol which needs a special |
208 | // value in the dynamic symbol table. This will only be called if | |
209 | // the backend first calls symbol->set_needs_dynsym_value(). | |
210 | uint64_t | |
211 | dynsym_value(const Symbol* sym) const | |
212 | { return this->do_dynsym_value(sym); } | |
213 | ||
c51e6221 ILT |
214 | // Return a string to use to fill out a code section. This is |
215 | // basically one or more NOPS which must fill out the specified | |
216 | // length in bytes. | |
217 | std::string | |
8851ecca | 218 | code_fill(section_size_type length) const |
c51e6221 ILT |
219 | { return this->do_code_fill(length); } |
220 | ||
9a2d6984 ILT |
221 | // Return whether SYM is known to be defined by the ABI. This is |
222 | // used to avoid inappropriate warnings about undefined symbols. | |
223 | bool | |
9c2d0ef9 | 224 | is_defined_by_abi(const Symbol* sym) const |
9a2d6984 ILT |
225 | { return this->do_is_defined_by_abi(sym); } |
226 | ||
36959681 ILT |
227 | // Adjust the output file header before it is written out. VIEW |
228 | // points to the header in external form. LEN is the length. | |
229 | void | |
230 | adjust_elf_header(unsigned char* view, int len) const | |
231 | { return this->do_adjust_elf_header(view, len); } | |
232 | ||
bb04269c DK |
233 | // Return whether NAME is a local label name. This is used to implement the |
234 | // --discard-locals options. | |
235 | bool | |
236 | is_local_label_name(const char* name) const | |
237 | { return this->do_is_local_label_name(name); } | |
238 | ||
e291e7b9 ILT |
239 | // Get the symbol index to use for a target specific reloc. |
240 | unsigned int | |
241 | reloc_symbol_index(void* arg, unsigned int type) const | |
242 | { return this->do_reloc_symbol_index(arg, type); } | |
243 | ||
244 | // Get the addend to use for a target specific reloc. | |
245 | uint64_t | |
246 | reloc_addend(void* arg, unsigned int type, uint64_t addend) const | |
247 | { return this->do_reloc_addend(arg, type, addend); } | |
248 | ||
67181c72 ILT |
249 | // Return the PLT address to use for a global symbol. This is used |
250 | // for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative | |
251 | // to this PLT address. | |
252 | uint64_t | |
253 | plt_address_for_global(const Symbol* sym) const | |
254 | { return this->do_plt_address_for_global(sym); } | |
255 | ||
256 | // Return the PLT address to use for a local symbol. This is used | |
257 | // for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative | |
258 | // to this PLT address. | |
259 | uint64_t | |
260 | plt_address_for_local(const Relobj* object, unsigned int symndx) const | |
261 | { return this->do_plt_address_for_local(object, symndx); } | |
7223e9ca | 262 | |
b3ce541e ILT |
263 | // Return whether this target can use relocation types to determine |
264 | // if a function's address is taken. | |
265 | bool | |
266 | can_check_for_function_pointers() const | |
267 | { return this->do_can_check_for_function_pointers(); } | |
268 | ||
269 | // Return whether a relocation to a merged section can be processed | |
270 | // to retrieve the contents. | |
271 | bool | |
272 | can_icf_inline_merge_sections () const | |
273 | { return this->pti_->can_icf_inline_merge_sections; } | |
274 | ||
275 | // Whether a section called SECTION_NAME may have function pointers to | |
276 | // sections not eligible for safe ICF folding. | |
277 | virtual bool | |
278 | section_may_have_icf_unsafe_pointers(const char* section_name) const | |
279 | { return this->do_section_may_have_icf_unsafe_pointers(section_name); } | |
280 | ||
02d7cd44 ILT |
281 | // Return the base to use for the PC value in an FDE when it is |
282 | // encoded using DW_EH_PE_datarel. This does not appear to be | |
283 | // documented anywhere, but it is target specific. Any use of | |
284 | // DW_EH_PE_datarel in gcc requires defining a special macro | |
285 | // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value. | |
286 | uint64_t | |
287 | ehframe_datarel_base() const | |
288 | { return this->do_ehframe_datarel_base(); } | |
289 | ||
b6848d3c ILT |
290 | // Return true if a reference to SYM from a reloc of type R_TYPE |
291 | // means that the current function may call an object compiled | |
292 | // without -fsplit-stack. SYM is known to be defined in an object | |
293 | // compiled without -fsplit-stack. | |
294 | bool | |
295 | is_call_to_non_split(const Symbol* sym, unsigned int r_type) const | |
296 | { return this->do_is_call_to_non_split(sym, r_type); } | |
297 | ||
364c7fa5 ILT |
298 | // A function starts at OFFSET in section SHNDX in OBJECT. That |
299 | // function was compiled with -fsplit-stack, but it refers to a | |
300 | // function which was compiled without -fsplit-stack. VIEW is a | |
301 | // modifiable view of the section; VIEW_SIZE is the size of the | |
302 | // view. The target has to adjust the function so that it allocates | |
303 | // enough stack. | |
304 | void | |
305 | calls_non_split(Relobj* object, unsigned int shndx, | |
306 | section_offset_type fnoffset, section_size_type fnsize, | |
307 | unsigned char* view, section_size_type view_size, | |
308 | std::string* from, std::string* to) const | |
309 | { | |
310 | this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size, | |
311 | from, to); | |
312 | } | |
313 | ||
f733487b DK |
314 | // Make an ELF object. |
315 | template<int size, bool big_endian> | |
316 | Object* | |
317 | make_elf_object(const std::string& name, Input_file* input_file, | |
318 | off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr) | |
319 | { return this->do_make_elf_object(name, input_file, offset, ehdr); } | |
320 | ||
c0a62865 DK |
321 | // Make an output section. |
322 | Output_section* | |
323 | make_output_section(const char* name, elfcpp::Elf_Word type, | |
324 | elfcpp::Elf_Xword flags) | |
325 | { return this->do_make_output_section(name, type, flags); } | |
326 | ||
20e6d0d6 DK |
327 | // Return true if target wants to perform relaxation. |
328 | bool | |
329 | may_relax() const | |
330 | { | |
331 | // Run the dummy relaxation pass twice if relaxation debugging is enabled. | |
332 | if (is_debugging_enabled(DEBUG_RELAXATION)) | |
333 | return true; | |
334 | ||
335 | return this->do_may_relax(); | |
336 | } | |
337 | ||
338 | // Perform a relaxation pass. Return true if layout may be changed. | |
339 | bool | |
c0a62865 | 340 | relax(int pass, const Input_objects* input_objects, Symbol_table* symtab, |
f625ae50 | 341 | Layout* layout, const Task* task) |
20e6d0d6 DK |
342 | { |
343 | // Run the dummy relaxation pass twice if relaxation debugging is enabled. | |
344 | if (is_debugging_enabled(DEBUG_RELAXATION)) | |
345 | return pass < 2; | |
346 | ||
f625ae50 | 347 | return this->do_relax(pass, input_objects, symtab, layout, task); |
c0a62865 | 348 | } |
20e6d0d6 | 349 | |
05a352e6 DK |
350 | // Return the target-specific name of attributes section. This is |
351 | // NULL if a target does not use attributes section or if it uses | |
352 | // the default section name ".gnu.attributes". | |
353 | const char* | |
354 | attributes_section() const | |
355 | { return this->pti_->attributes_section; } | |
356 | ||
357 | // Return the vendor name of vendor attributes. | |
358 | const char* | |
359 | attributes_vendor() const | |
360 | { return this->pti_->attributes_vendor; } | |
361 | ||
362 | // Whether a section called NAME is an attribute section. | |
363 | bool | |
364 | is_attributes_section(const char* name) const | |
365 | { | |
366 | return ((this->pti_->attributes_section != NULL | |
367 | && strcmp(name, this->pti_->attributes_section) == 0) | |
368 | || strcmp(name, ".gnu.attributes") == 0); | |
369 | } | |
370 | ||
371 | // Return a bit mask of argument types for attribute with TAG. | |
372 | int | |
373 | attribute_arg_type(int tag) const | |
374 | { return this->do_attribute_arg_type(tag); } | |
375 | ||
376 | // Return the attribute tag of the position NUM in the list of fixed | |
377 | // attributes. Normally there is no reordering and | |
378 | // attributes_order(NUM) == NUM. | |
379 | int | |
380 | attributes_order(int num) const | |
381 | { return this->do_attributes_order(num); } | |
382 | ||
0d31c79d DK |
383 | // When a target is selected as the default target, we call this method, |
384 | // which may be used for expensive, target-specific initialization. | |
385 | void | |
386 | select_as_default_target() | |
387 | { this->do_select_as_default_target(); } | |
388 | ||
200b2bb9 ILT |
389 | // Return the value to store in the EI_OSABI field in the ELF |
390 | // header. | |
391 | elfcpp::ELFOSABI | |
392 | osabi() const | |
393 | { return this->osabi_; } | |
394 | ||
395 | // Set the value to store in the EI_OSABI field in the ELF header. | |
396 | void | |
397 | set_osabi(elfcpp::ELFOSABI osabi) | |
398 | { this->osabi_ = osabi; } | |
399 | ||
14bfc3f5 | 400 | protected: |
75f65a3e ILT |
401 | // This struct holds the constant information for a child class. We |
402 | // use a struct to avoid the overhead of virtual function calls for | |
403 | // simple information. | |
404 | struct Target_info | |
405 | { | |
406 | // Address size (32 or 64). | |
407 | int size; | |
408 | // Whether the target is big endian. | |
409 | bool is_big_endian; | |
61ba1cf9 ILT |
410 | // The code to store in the e_machine field of the ELF header. |
411 | elfcpp::EM machine_code; | |
75f65a3e ILT |
412 | // Whether this target has a specific make_symbol function. |
413 | bool has_make_symbol; | |
414 | // Whether this target has a specific resolve function. | |
415 | bool has_resolve; | |
c51e6221 ILT |
416 | // Whether this target has a specific code fill function. |
417 | bool has_code_fill; | |
35cdfc9a ILT |
418 | // Whether an object file with no .note.GNU-stack sections implies |
419 | // that the stack should be executable. | |
420 | bool is_default_stack_executable; | |
b3ce541e ILT |
421 | // Whether a relocation to a merged section can be processed to |
422 | // retrieve the contents. | |
423 | bool can_icf_inline_merge_sections; | |
0864d551 ILT |
424 | // Prefix character to strip when checking for wrapping. |
425 | char wrap_char; | |
dbe717ef ILT |
426 | // The default dynamic linker name. |
427 | const char* dynamic_linker; | |
75f65a3e | 428 | // The default text segment address. |
0c5e9c22 | 429 | uint64_t default_text_segment_address; |
75f65a3e ILT |
430 | // The ABI specified page size. |
431 | uint64_t abi_pagesize; | |
432 | // The common page size used by actual implementations. | |
433 | uint64_t common_pagesize; | |
8a5e3e08 ILT |
434 | // The special section index for small common symbols; SHN_UNDEF |
435 | // if none. | |
436 | elfcpp::Elf_Half small_common_shndx; | |
437 | // The special section index for large common symbols; SHN_UNDEF | |
438 | // if none. | |
439 | elfcpp::Elf_Half large_common_shndx; | |
440 | // Section flags for small common section. | |
441 | elfcpp::Elf_Xword small_common_section_flags; | |
442 | // Section flags for large common section. | |
443 | elfcpp::Elf_Xword large_common_section_flags; | |
05a352e6 DK |
444 | // Name of attributes section if it is not ".gnu.attributes". |
445 | const char* attributes_section; | |
446 | // Vendor name of vendor attributes. | |
447 | const char* attributes_vendor; | |
75f65a3e ILT |
448 | }; |
449 | ||
450 | Target(const Target_info* pti) | |
d5b40221 | 451 | : pti_(pti), processor_specific_flags_(0), |
200b2bb9 | 452 | are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE) |
14bfc3f5 ILT |
453 | { } |
454 | ||
8a5e3e08 ILT |
455 | // Virtual function which may be implemented by the child class. |
456 | virtual void | |
457 | do_new_output_section(Output_section*) const | |
458 | { } | |
459 | ||
5a6f7e2d ILT |
460 | // Virtual function which may be implemented by the child class. |
461 | virtual void | |
f59f41f3 | 462 | do_finalize_sections(Layout*, const Input_objects*, Symbol_table*) |
5a6f7e2d ILT |
463 | { } |
464 | ||
ab5c9e90 ILT |
465 | // Virtual function which may be implemented by the child class. |
466 | virtual uint64_t | |
467 | do_dynsym_value(const Symbol*) const | |
468 | { gold_unreachable(); } | |
469 | ||
c51e6221 ILT |
470 | // Virtual function which must be implemented by the child class if |
471 | // needed. | |
472 | virtual std::string | |
8851ecca | 473 | do_code_fill(section_size_type) const |
c51e6221 ILT |
474 | { gold_unreachable(); } |
475 | ||
9a2d6984 ILT |
476 | // Virtual function which may be implemented by the child class. |
477 | virtual bool | |
9c2d0ef9 | 478 | do_is_defined_by_abi(const Symbol*) const |
9a2d6984 ILT |
479 | { return false; } |
480 | ||
36959681 ILT |
481 | // Adjust the output file header before it is written out. VIEW |
482 | // points to the header in external form. LEN is the length, and | |
483 | // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size. | |
200b2bb9 ILT |
484 | // By default, we set the EI_OSABI field if requested (in |
485 | // Sized_target). | |
36959681 | 486 | virtual void |
200b2bb9 | 487 | do_adjust_elf_header(unsigned char*, int) const = 0; |
36959681 | 488 | |
9b547ce6 | 489 | // Virtual function which may be overridden by the child class. |
bb04269c DK |
490 | virtual bool |
491 | do_is_local_label_name(const char*) const; | |
492 | ||
e291e7b9 ILT |
493 | // Virtual function that must be overridden by a target which uses |
494 | // target specific relocations. | |
495 | virtual unsigned int | |
496 | do_reloc_symbol_index(void*, unsigned int) const | |
497 | { gold_unreachable(); } | |
498 | ||
9b547ce6 | 499 | // Virtual function that must be overridden by a target which uses |
e291e7b9 ILT |
500 | // target specific relocations. |
501 | virtual uint64_t | |
502 | do_reloc_addend(void*, unsigned int, uint64_t) const | |
503 | { gold_unreachable(); } | |
504 | ||
7223e9ca ILT |
505 | // Virtual functions that must be overridden by a target that uses |
506 | // STT_GNU_IFUNC symbols. | |
67181c72 ILT |
507 | virtual uint64_t |
508 | do_plt_address_for_global(const Symbol*) const | |
7223e9ca ILT |
509 | { gold_unreachable(); } |
510 | ||
67181c72 ILT |
511 | virtual uint64_t |
512 | do_plt_address_for_local(const Relobj*, unsigned int) const | |
7223e9ca ILT |
513 | { gold_unreachable(); } |
514 | ||
b3ce541e ILT |
515 | // Virtual function which may be overriden by the child class. |
516 | virtual bool | |
517 | do_can_check_for_function_pointers() const | |
518 | { return false; } | |
519 | ||
520 | // Virtual function which may be overridden by the child class. We | |
521 | // recognize some default sections for which we don't care whether | |
522 | // they have function pointers. | |
523 | virtual bool | |
524 | do_section_may_have_icf_unsafe_pointers(const char* section_name) const | |
525 | { | |
526 | // We recognize sections for normal vtables, construction vtables and | |
527 | // EH frames. | |
528 | return (!is_prefix_of(".rodata._ZTV", section_name) | |
529 | && !is_prefix_of(".data.rel.ro._ZTV", section_name) | |
530 | && !is_prefix_of(".rodata._ZTC", section_name) | |
531 | && !is_prefix_of(".data.rel.ro._ZTC", section_name) | |
532 | && !is_prefix_of(".eh_frame", section_name)); | |
533 | } | |
534 | ||
02d7cd44 ILT |
535 | virtual uint64_t |
536 | do_ehframe_datarel_base() const | |
537 | { gold_unreachable(); } | |
538 | ||
b6848d3c ILT |
539 | // Virtual function which may be overridden by the child class. The |
540 | // default implementation is that any function not defined by the | |
541 | // ABI is a call to a non-split function. | |
542 | virtual bool | |
543 | do_is_call_to_non_split(const Symbol* sym, unsigned int) const; | |
544 | ||
364c7fa5 ILT |
545 | // Virtual function which may be overridden by the child class. |
546 | virtual void | |
547 | do_calls_non_split(Relobj* object, unsigned int, section_offset_type, | |
548 | section_size_type, unsigned char*, section_size_type, | |
549 | std::string*, std::string*) const; | |
550 | ||
f733487b | 551 | // make_elf_object hooks. There are four versions of these for |
7296d933 | 552 | // different address sizes and endianness. |
364c7fa5 | 553 | |
d5b40221 DK |
554 | // Set processor specific flags. |
555 | void | |
556 | set_processor_specific_flags(elfcpp::Elf_Word flags) | |
557 | { | |
558 | this->processor_specific_flags_ = flags; | |
559 | this->are_processor_specific_flags_set_ = true; | |
560 | } | |
561 | ||
f733487b | 562 | #ifdef HAVE_TARGET_32_LITTLE |
9b547ce6 | 563 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
564 | virtual Object* |
565 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
566 | const elfcpp::Ehdr<32, false>&); | |
567 | #endif | |
568 | ||
569 | #ifdef HAVE_TARGET_32_BIG | |
9b547ce6 | 570 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
571 | virtual Object* |
572 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
573 | const elfcpp::Ehdr<32, true>&); | |
574 | #endif | |
575 | ||
576 | #ifdef HAVE_TARGET_64_LITTLE | |
9b547ce6 | 577 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
578 | virtual Object* |
579 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
580 | const elfcpp::Ehdr<64, false>& ehdr); | |
581 | #endif | |
582 | ||
583 | #ifdef HAVE_TARGET_64_BIG | |
9b547ce6 | 584 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
585 | virtual Object* |
586 | do_make_elf_object(const std::string& name, Input_file* input_file, | |
587 | off_t offset, const elfcpp::Ehdr<64, true>& ehdr); | |
588 | #endif | |
589 | ||
9b547ce6 | 590 | // Virtual functions which may be overridden by the child class. |
c0a62865 DK |
591 | virtual Output_section* |
592 | do_make_output_section(const char* name, elfcpp::Elf_Word type, | |
593 | elfcpp::Elf_Xword flags); | |
594 | ||
9b547ce6 | 595 | // Virtual function which may be overridden by the child class. |
20e6d0d6 DK |
596 | virtual bool |
597 | do_may_relax() const | |
598 | { return parameters->options().relax(); } | |
599 | ||
9b547ce6 | 600 | // Virtual function which may be overridden by the child class. |
20e6d0d6 | 601 | virtual bool |
f625ae50 | 602 | do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*) |
20e6d0d6 DK |
603 | { return false; } |
604 | ||
364c7fa5 ILT |
605 | // A function for targets to call. Return whether BYTES/LEN matches |
606 | // VIEW/VIEW_SIZE at OFFSET. | |
607 | bool | |
608 | match_view(const unsigned char* view, section_size_type view_size, | |
609 | section_offset_type offset, const char* bytes, size_t len) const; | |
610 | ||
611 | // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET | |
612 | // for LEN bytes. | |
613 | void | |
614 | set_view_to_nop(unsigned char* view, section_size_type view_size, | |
615 | section_offset_type offset, size_t len) const; | |
616 | ||
9b547ce6 | 617 | // This must be overridden by the child class if it has target-specific |
05a352e6 DK |
618 | // attributes subsection in the attribute section. |
619 | virtual int | |
620 | do_attribute_arg_type(int) const | |
621 | { gold_unreachable(); } | |
622 | ||
623 | // This may be overridden by the child class. | |
624 | virtual int | |
625 | do_attributes_order(int num) const | |
626 | { return num; } | |
627 | ||
0d31c79d DK |
628 | // This may be overridden by the child class. |
629 | virtual void | |
630 | do_select_as_default_target() | |
631 | { } | |
632 | ||
14bfc3f5 | 633 | private: |
f733487b | 634 | // The implementations of the four do_make_elf_object virtual functions are |
7296d933 | 635 | // almost identical except for their sizes and endianness. We use a template. |
f733487b DK |
636 | // for their implementations. |
637 | template<int size, bool big_endian> | |
638 | inline Object* | |
639 | do_make_elf_object_implementation(const std::string&, Input_file*, off_t, | |
640 | const elfcpp::Ehdr<size, big_endian>&); | |
641 | ||
14bfc3f5 ILT |
642 | Target(const Target&); |
643 | Target& operator=(const Target&); | |
644 | ||
75f65a3e ILT |
645 | // The target information. |
646 | const Target_info* pti_; | |
d5b40221 DK |
647 | // Processor-specific flags. |
648 | elfcpp::Elf_Word processor_specific_flags_; | |
649 | // Whether the processor-specific flags are set at least once. | |
650 | bool are_processor_specific_flags_set_; | |
200b2bb9 ILT |
651 | // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of |
652 | // the ELF header. This is handled at this level because it is | |
653 | // OS-specific rather than processor-specific. | |
654 | elfcpp::ELFOSABI osabi_; | |
bae7f79e ILT |
655 | }; |
656 | ||
14bfc3f5 ILT |
657 | // The abstract class for a specific size and endianness of target. |
658 | // Each actual target implementation class should derive from an | |
659 | // instantiation of Sized_target. | |
660 | ||
661 | template<int size, bool big_endian> | |
662 | class Sized_target : public Target | |
663 | { | |
664 | public: | |
665 | // Make a new symbol table entry for the target. This should be | |
666 | // overridden by a target which needs additional information in the | |
667 | // symbol table. This will only be called if has_make_symbol() | |
668 | // returns true. | |
669 | virtual Sized_symbol<size>* | |
14b31740 | 670 | make_symbol() const |
a3ad94ed | 671 | { gold_unreachable(); } |
14bfc3f5 ILT |
672 | |
673 | // Resolve a symbol for the target. This should be overridden by a | |
674 | // target which needs to take special action. TO is the | |
675 | // pre-existing symbol. SYM is the new symbol, seen in OBJECT. | |
14b31740 ILT |
676 | // VERSION is the version of SYM. This will only be called if |
677 | // has_resolve() returns true. | |
14bfc3f5 | 678 | virtual void |
14b31740 ILT |
679 | resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*, |
680 | const char*) | |
a3ad94ed | 681 | { gold_unreachable(); } |
14bfc3f5 | 682 | |
6d03d481 ST |
683 | // Process the relocs for a section, and record information of the |
684 | // mapping from source to destination sections. This mapping is later | |
685 | // used to determine unreferenced garbage sections. This procedure is | |
686 | // only called during garbage collection. | |
687 | virtual void | |
ad0f2072 ILT |
688 | gc_process_relocs(Symbol_table* symtab, |
689 | Layout* layout, | |
6fa2a40b | 690 | Sized_relobj_file<size, big_endian>* object, |
ad0f2072 ILT |
691 | unsigned int data_shndx, |
692 | unsigned int sh_type, | |
693 | const unsigned char* prelocs, | |
694 | size_t reloc_count, | |
695 | Output_section* output_section, | |
696 | bool needs_special_offset_handling, | |
697 | size_t local_symbol_count, | |
698 | const unsigned char* plocal_symbols) = 0; | |
6d03d481 | 699 | |
92e059d8 | 700 | // Scan the relocs for a section, and record any information |
ad0f2072 ILT |
701 | // required for the symbol. SYMTAB is the symbol table. OBJECT is |
702 | // the object in which the section appears. DATA_SHNDX is the | |
703 | // section index that these relocs apply to. SH_TYPE is the type of | |
704 | // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to | |
705 | // the relocation data. RELOC_COUNT is the number of relocs. | |
706 | // LOCAL_SYMBOL_COUNT is the number of local symbols. | |
707 | // OUTPUT_SECTION is the output section. | |
730cdc88 ILT |
708 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output |
709 | // sections are not mapped as usual. PLOCAL_SYMBOLS points to the | |
710 | // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of | |
711 | // pointers to the global symbol table from OBJECT. | |
61ba1cf9 | 712 | virtual void |
ad0f2072 | 713 | scan_relocs(Symbol_table* symtab, |
ead1e424 | 714 | Layout* layout, |
6fa2a40b | 715 | Sized_relobj_file<size, big_endian>* object, |
a3ad94ed | 716 | unsigned int data_shndx, |
92e059d8 ILT |
717 | unsigned int sh_type, |
718 | const unsigned char* prelocs, | |
719 | size_t reloc_count, | |
730cdc88 ILT |
720 | Output_section* output_section, |
721 | bool needs_special_offset_handling, | |
92e059d8 | 722 | size_t local_symbol_count, |
730cdc88 | 723 | const unsigned char* plocal_symbols) = 0; |
92e059d8 ILT |
724 | |
725 | // Relocate section data. SH_TYPE is the type of the relocation | |
726 | // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation | |
730cdc88 ILT |
727 | // information. RELOC_COUNT is the number of relocs. |
728 | // OUTPUT_SECTION is the output section. | |
729 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped | |
730 | // to correspond to the output section. VIEW is a view into the | |
731 | // output file holding the section contents, VIEW_ADDRESS is the | |
732 | // virtual address of the view, and VIEW_SIZE is the size of the | |
733 | // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx | |
734 | // parameters refer to the complete output section data, not just | |
735 | // the input section data. | |
92e059d8 ILT |
736 | virtual void |
737 | relocate_section(const Relocate_info<size, big_endian>*, | |
738 | unsigned int sh_type, | |
739 | const unsigned char* prelocs, | |
740 | size_t reloc_count, | |
730cdc88 ILT |
741 | Output_section* output_section, |
742 | bool needs_special_offset_handling, | |
92e059d8 ILT |
743 | unsigned char* view, |
744 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
364c7fa5 ILT |
745 | section_size_type view_size, |
746 | const Reloc_symbol_changes*) = 0; | |
61ba1cf9 | 747 | |
6a74a719 ILT |
748 | // Scan the relocs during a relocatable link. The parameters are |
749 | // like scan_relocs, with an additional Relocatable_relocs | |
750 | // parameter, used to record the disposition of the relocs. | |
751 | virtual void | |
ad0f2072 | 752 | scan_relocatable_relocs(Symbol_table* symtab, |
6a74a719 | 753 | Layout* layout, |
6fa2a40b | 754 | Sized_relobj_file<size, big_endian>* object, |
6a74a719 ILT |
755 | unsigned int data_shndx, |
756 | unsigned int sh_type, | |
757 | const unsigned char* prelocs, | |
758 | size_t reloc_count, | |
759 | Output_section* output_section, | |
760 | bool needs_special_offset_handling, | |
761 | size_t local_symbol_count, | |
762 | const unsigned char* plocal_symbols, | |
763 | Relocatable_relocs*) = 0; | |
764 | ||
765 | // Relocate a section during a relocatable link. The parameters are | |
766 | // like relocate_section, with additional parameters for the view of | |
767 | // the output reloc section. | |
768 | virtual void | |
769 | relocate_for_relocatable(const Relocate_info<size, big_endian>*, | |
770 | unsigned int sh_type, | |
771 | const unsigned char* prelocs, | |
772 | size_t reloc_count, | |
773 | Output_section* output_section, | |
774 | off_t offset_in_output_section, | |
775 | const Relocatable_relocs*, | |
776 | unsigned char* view, | |
777 | typename elfcpp::Elf_types<size>::Elf_Addr | |
778 | view_address, | |
779 | section_size_type view_size, | |
780 | unsigned char* reloc_view, | |
781 | section_size_type reloc_view_size) = 0; | |
5c388529 DK |
782 | |
783 | // Perform target-specific processing in a relocatable link. This is | |
784 | // only used if we use the relocation strategy RELOC_SPECIAL. | |
785 | // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation | |
786 | // section type. PRELOC_IN points to the original relocation. RELNUM is | |
787 | // the index number of the relocation in the relocation section. | |
788 | // OUTPUT_SECTION is the output section to which the relocation is applied. | |
789 | // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section | |
790 | // within the output section. VIEW points to the output view of the | |
791 | // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE | |
792 | // is the size of the output view and PRELOC_OUT points to the new | |
793 | // relocation in the output object. | |
794 | // | |
795 | // A target only needs to override this if the generic code in | |
796 | // target-reloc.h cannot handle some relocation types. | |
6a74a719 | 797 | |
5c388529 DK |
798 | virtual void |
799 | relocate_special_relocatable(const Relocate_info<size, big_endian>* | |
800 | /*relinfo */, | |
801 | unsigned int /* sh_type */, | |
802 | const unsigned char* /* preloc_in */, | |
803 | size_t /* relnum */, | |
804 | Output_section* /* output_section */, | |
805 | off_t /* offset_in_output_section */, | |
806 | unsigned char* /* view */, | |
807 | typename elfcpp::Elf_types<size>::Elf_Addr | |
808 | /* view_address */, | |
809 | section_size_type /* view_size */, | |
810 | unsigned char* /* preloc_out*/) | |
811 | { gold_unreachable(); } | |
812 | ||
0e70b911 CC |
813 | // Return the number of entries in the GOT. This is only used for |
814 | // laying out the incremental link info sections. A target needs | |
815 | // to implement this to support incremental linking. | |
816 | ||
817 | virtual unsigned int | |
818 | got_entry_count() const | |
819 | { gold_unreachable(); } | |
820 | ||
821 | // Return the number of entries in the PLT. This is only used for | |
822 | // laying out the incremental link info sections. A target needs | |
823 | // to implement this to support incremental linking. | |
824 | ||
825 | virtual unsigned int | |
826 | plt_entry_count() const | |
827 | { gold_unreachable(); } | |
828 | ||
829 | // Return the offset of the first non-reserved PLT entry. This is | |
830 | // only used for laying out the incremental link info sections. | |
831 | // A target needs to implement this to support incremental linking. | |
832 | ||
833 | virtual unsigned int | |
834 | first_plt_entry_offset() const | |
835 | { gold_unreachable(); } | |
836 | ||
837 | // Return the size of each PLT entry. This is only used for | |
838 | // laying out the incremental link info sections. A target needs | |
839 | // to implement this to support incremental linking. | |
840 | ||
841 | virtual unsigned int | |
842 | plt_entry_size() const | |
843 | { gold_unreachable(); } | |
844 | ||
4829d394 CC |
845 | // Create the GOT and PLT sections for an incremental update. |
846 | // A target needs to implement this to support incremental linking. | |
847 | ||
848 | virtual Output_data_got<size, big_endian>* | |
849 | init_got_plt_for_update(Symbol_table*, | |
850 | Layout*, | |
851 | unsigned int /* got_count */, | |
852 | unsigned int /* plt_count */) | |
853 | { gold_unreachable(); } | |
854 | ||
6fa2a40b CC |
855 | // Reserve a GOT entry for a local symbol, and regenerate any |
856 | // necessary dynamic relocations. | |
857 | virtual void | |
858 | reserve_local_got_entry(unsigned int /* got_index */, | |
859 | Sized_relobj<size, big_endian>* /* obj */, | |
860 | unsigned int /* r_sym */, | |
861 | unsigned int /* got_type */) | |
862 | { gold_unreachable(); } | |
863 | ||
864 | // Reserve a GOT entry for a global symbol, and regenerate any | |
865 | // necessary dynamic relocations. | |
866 | virtual void | |
867 | reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */, | |
868 | unsigned int /* got_type */) | |
869 | { gold_unreachable(); } | |
870 | ||
4829d394 CC |
871 | // Register an existing PLT entry for a global symbol. |
872 | // A target needs to implement this to support incremental linking. | |
873 | ||
874 | virtual void | |
67181c72 ILT |
875 | register_global_plt_entry(Symbol_table*, Layout*, |
876 | unsigned int /* plt_index */, | |
4829d394 CC |
877 | Symbol*) |
878 | { gold_unreachable(); } | |
879 | ||
26d3c67d CC |
880 | // Force a COPY relocation for a given symbol. |
881 | // A target needs to implement this to support incremental linking. | |
882 | ||
883 | virtual void | |
884 | emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t) | |
885 | { gold_unreachable(); } | |
886 | ||
94a3fc8b CC |
887 | // Apply an incremental relocation. |
888 | ||
889 | virtual void | |
890 | apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */, | |
891 | typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */, | |
892 | unsigned int /* r_type */, | |
893 | typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */, | |
894 | const Symbol* /* gsym */, | |
895 | unsigned char* /* view */, | |
896 | typename elfcpp::Elf_types<size>::Elf_Addr /* address */, | |
897 | section_size_type /* view_size */) | |
898 | { gold_unreachable(); } | |
899 | ||
14bfc3f5 | 900 | protected: |
75f65a3e ILT |
901 | Sized_target(const Target::Target_info* pti) |
902 | : Target(pti) | |
903 | { | |
a3ad94ed ILT |
904 | gold_assert(pti->size == size); |
905 | gold_assert(pti->is_big_endian ? big_endian : !big_endian); | |
75f65a3e | 906 | } |
200b2bb9 ILT |
907 | |
908 | // Set the EI_OSABI field if requested. | |
909 | virtual void | |
910 | do_adjust_elf_header(unsigned char*, int) const; | |
14bfc3f5 | 911 | }; |
bae7f79e ILT |
912 | |
913 | } // End namespace gold. | |
914 | ||
915 | #endif // !defined(GOLD_TARGET_H) |