Commit | Line | Data |
---|---|---|
14bfc3f5 | 1 | // target.h -- target support for gold -*- C++ -*- |
bae7f79e | 2 | |
82704155 | 3 | // Copyright (C) 2006-2019 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" |
98ff9231 | 39 | #include "stringpool.h" |
20e6d0d6 | 40 | #include "debug.h" |
14bfc3f5 | 41 | |
bae7f79e ILT |
42 | namespace gold |
43 | { | |
44 | ||
14bfc3f5 | 45 | class Object; |
364c7fa5 | 46 | class Relobj; |
61ba1cf9 | 47 | template<int size, bool big_endian> |
f6ce93d6 | 48 | class Sized_relobj; |
6fa2a40b CC |
49 | template<int size, bool big_endian> |
50 | class Sized_relobj_file; | |
6a74a719 | 51 | class Relocatable_relocs; |
92e059d8 | 52 | template<int size, bool big_endian> |
2c54b4f4 | 53 | struct Relocate_info; |
364c7fa5 | 54 | class Reloc_symbol_changes; |
f6ce93d6 ILT |
55 | class Symbol; |
56 | template<int size> | |
57 | class Sized_symbol; | |
58 | class Symbol_table; | |
7223e9ca | 59 | class Output_data; |
dd74ae06 | 60 | class Output_data_got_base; |
730cdc88 | 61 | class Output_section; |
d5b40221 | 62 | class Input_objects; |
f625ae50 | 63 | class Task; |
dc3714f3 | 64 | struct Symbol_location; |
98ff9231 | 65 | class Versions; |
14bfc3f5 ILT |
66 | |
67 | // The abstract class for target specific handling. | |
68 | ||
bae7f79e ILT |
69 | class Target |
70 | { | |
71 | public: | |
14bfc3f5 ILT |
72 | virtual ~Target() |
73 | { } | |
74 | ||
75 | // Return the bit size that this target implements. This should | |
76 | // return 32 or 64. | |
77 | int | |
78 | get_size() const | |
75f65a3e | 79 | { return this->pti_->size; } |
14bfc3f5 ILT |
80 | |
81 | // Return whether this target is big-endian. | |
82 | bool | |
83 | is_big_endian() const | |
75f65a3e | 84 | { return this->pti_->is_big_endian; } |
14bfc3f5 | 85 | |
61ba1cf9 ILT |
86 | // Machine code to store in e_machine field of ELF header. |
87 | elfcpp::EM | |
88 | machine_code() const | |
89 | { return this->pti_->machine_code; } | |
90 | ||
d5b40221 DK |
91 | // Processor specific flags to store in e_flags field of ELF header. |
92 | elfcpp::Elf_Word | |
93 | processor_specific_flags() const | |
94 | { return this->processor_specific_flags_; } | |
95 | ||
96 | // Whether processor specific flags are set at least once. | |
97 | bool | |
98 | are_processor_specific_flags_set() const | |
99 | { return this->are_processor_specific_flags_set_; } | |
100 | ||
14bfc3f5 ILT |
101 | // Whether this target has a specific make_symbol function. |
102 | bool | |
103 | has_make_symbol() const | |
75f65a3e | 104 | { return this->pti_->has_make_symbol; } |
14bfc3f5 ILT |
105 | |
106 | // Whether this target has a specific resolve function. | |
107 | bool | |
108 | has_resolve() const | |
75f65a3e ILT |
109 | { return this->pti_->has_resolve; } |
110 | ||
c51e6221 ILT |
111 | // Whether this target has a specific code fill function. |
112 | bool | |
113 | has_code_fill() const | |
114 | { return this->pti_->has_code_fill; } | |
115 | ||
dbe717ef ILT |
116 | // Return the default name of the dynamic linker. |
117 | const char* | |
118 | dynamic_linker() const | |
119 | { return this->pti_->dynamic_linker; } | |
120 | ||
75f65a3e | 121 | // Return the default address to use for the text segment. |
be2884c1 CC |
122 | // If a -z max-page-size argument has set the ABI page size |
123 | // to a value larger than the default starting address, | |
124 | // bump the starting address up to the page size, to avoid | |
125 | // misaligning the text segment in the file. | |
75f65a3e | 126 | uint64_t |
0c5e9c22 | 127 | default_text_segment_address() const |
be2884c1 CC |
128 | { |
129 | uint64_t addr = this->pti_->default_text_segment_address; | |
130 | uint64_t pagesize = this->abi_pagesize(); | |
131 | if (addr < pagesize) | |
132 | addr = pagesize; | |
133 | return addr; | |
134 | } | |
75f65a3e ILT |
135 | |
136 | // Return the ABI specified page size. | |
137 | uint64_t | |
138 | abi_pagesize() const | |
cd72c291 | 139 | { |
8851ecca ILT |
140 | if (parameters->options().max_page_size() > 0) |
141 | return parameters->options().max_page_size(); | |
cd72c291 ILT |
142 | else |
143 | return this->pti_->abi_pagesize; | |
144 | } | |
75f65a3e ILT |
145 | |
146 | // Return the common page size used on actual systems. | |
147 | uint64_t | |
148 | common_pagesize() const | |
cd72c291 | 149 | { |
8851ecca ILT |
150 | if (parameters->options().common_page_size() > 0) |
151 | return std::min(parameters->options().common_page_size(), | |
cd72c291 ILT |
152 | this->abi_pagesize()); |
153 | else | |
154 | return std::min(this->pti_->common_pagesize, | |
155 | this->abi_pagesize()); | |
156 | } | |
14bfc3f5 | 157 | |
2e702c99 RM |
158 | // Return whether PF_X segments must contain nothing but the contents of |
159 | // SHF_EXECINSTR sections (no non-executable data, no headers). | |
160 | bool | |
161 | isolate_execinstr() const | |
162 | { return this->pti_->isolate_execinstr; } | |
163 | ||
164 | uint64_t | |
165 | rosegment_gap() const | |
166 | { return this->pti_->rosegment_gap; } | |
167 | ||
35cdfc9a ILT |
168 | // If we see some object files with .note.GNU-stack sections, and |
169 | // some objects files without them, this returns whether we should | |
170 | // consider the object files without them to imply that the stack | |
171 | // should be executable. | |
172 | bool | |
173 | is_default_stack_executable() const | |
174 | { return this->pti_->is_default_stack_executable; } | |
175 | ||
0864d551 ILT |
176 | // Return a character which may appear as a prefix for a wrap |
177 | // symbol. If this character appears, we strip it when checking for | |
178 | // wrapping and add it back when forming the final symbol name. | |
179 | // This should be '\0' if not special prefix is required, which is | |
180 | // the normal case. | |
181 | char | |
182 | wrap_char() const | |
183 | { return this->pti_->wrap_char; } | |
184 | ||
8a5e3e08 ILT |
185 | // Return the special section index which indicates a small common |
186 | // symbol. This will return SHN_UNDEF if there are no small common | |
187 | // symbols. | |
188 | elfcpp::Elf_Half | |
189 | small_common_shndx() const | |
190 | { return this->pti_->small_common_shndx; } | |
191 | ||
192 | // Return values to add to the section flags for the section holding | |
193 | // small common symbols. | |
194 | elfcpp::Elf_Xword | |
195 | small_common_section_flags() const | |
196 | { | |
197 | gold_assert(this->pti_->small_common_shndx != elfcpp::SHN_UNDEF); | |
198 | return this->pti_->small_common_section_flags; | |
199 | } | |
200 | ||
201 | // Return the special section index which indicates a large common | |
202 | // symbol. This will return SHN_UNDEF if there are no large common | |
203 | // symbols. | |
204 | elfcpp::Elf_Half | |
205 | large_common_shndx() const | |
206 | { return this->pti_->large_common_shndx; } | |
207 | ||
208 | // Return values to add to the section flags for the section holding | |
209 | // large common symbols. | |
210 | elfcpp::Elf_Xword | |
211 | large_common_section_flags() const | |
212 | { | |
213 | gold_assert(this->pti_->large_common_shndx != elfcpp::SHN_UNDEF); | |
214 | return this->pti_->large_common_section_flags; | |
215 | } | |
216 | ||
217 | // This hook is called when an output section is created. | |
218 | void | |
219 | new_output_section(Output_section* os) const | |
220 | { this->do_new_output_section(os); } | |
221 | ||
5a6f7e2d ILT |
222 | // This is called to tell the target to complete any sections it is |
223 | // handling. After this all sections must have their final size. | |
224 | void | |
f59f41f3 DK |
225 | finalize_sections(Layout* layout, const Input_objects* input_objects, |
226 | Symbol_table* symtab) | |
227 | { return this->do_finalize_sections(layout, input_objects, symtab); } | |
5a6f7e2d | 228 | |
ab5c9e90 ILT |
229 | // Return the value to use for a global symbol which needs a special |
230 | // value in the dynamic symbol table. This will only be called if | |
231 | // the backend first calls symbol->set_needs_dynsym_value(). | |
232 | uint64_t | |
233 | dynsym_value(const Symbol* sym) const | |
234 | { return this->do_dynsym_value(sym); } | |
235 | ||
c51e6221 ILT |
236 | // Return a string to use to fill out a code section. This is |
237 | // basically one or more NOPS which must fill out the specified | |
238 | // length in bytes. | |
239 | std::string | |
8851ecca | 240 | code_fill(section_size_type length) const |
c51e6221 ILT |
241 | { return this->do_code_fill(length); } |
242 | ||
9a2d6984 ILT |
243 | // Return whether SYM is known to be defined by the ABI. This is |
244 | // used to avoid inappropriate warnings about undefined symbols. | |
245 | bool | |
9c2d0ef9 | 246 | is_defined_by_abi(const Symbol* sym) const |
9a2d6984 ILT |
247 | { return this->do_is_defined_by_abi(sym); } |
248 | ||
36959681 ILT |
249 | // Adjust the output file header before it is written out. VIEW |
250 | // points to the header in external form. LEN is the length. | |
251 | void | |
cc84c10b | 252 | adjust_elf_header(unsigned char* view, int len) |
36959681 ILT |
253 | { return this->do_adjust_elf_header(view, len); } |
254 | ||
9d5781f8 AM |
255 | // Return address and size to plug into eh_frame FDEs associated with a PLT. |
256 | void | |
257 | plt_fde_location(const Output_data* plt, unsigned char* oview, | |
258 | uint64_t* address, off_t* len) const | |
259 | { return this->do_plt_fde_location(plt, oview, address, len); } | |
260 | ||
bb04269c DK |
261 | // Return whether NAME is a local label name. This is used to implement the |
262 | // --discard-locals options. | |
263 | bool | |
264 | is_local_label_name(const char* name) const | |
265 | { return this->do_is_local_label_name(name); } | |
266 | ||
e291e7b9 ILT |
267 | // Get the symbol index to use for a target specific reloc. |
268 | unsigned int | |
269 | reloc_symbol_index(void* arg, unsigned int type) const | |
270 | { return this->do_reloc_symbol_index(arg, type); } | |
271 | ||
272 | // Get the addend to use for a target specific reloc. | |
273 | uint64_t | |
274 | reloc_addend(void* arg, unsigned int type, uint64_t addend) const | |
275 | { return this->do_reloc_addend(arg, type, addend); } | |
276 | ||
19fec8c1 | 277 | // Return the PLT address to use for a global symbol. |
67181c72 ILT |
278 | uint64_t |
279 | plt_address_for_global(const Symbol* sym) const | |
280 | { return this->do_plt_address_for_global(sym); } | |
281 | ||
19fec8c1 | 282 | // Return the PLT address to use for a local symbol. |
67181c72 ILT |
283 | uint64_t |
284 | plt_address_for_local(const Relobj* object, unsigned int symndx) const | |
285 | { return this->do_plt_address_for_local(object, symndx); } | |
7223e9ca | 286 | |
bd73a62d AM |
287 | // Return the offset to use for the GOT_INDX'th got entry which is |
288 | // for a local tls symbol specified by OBJECT, SYMNDX. | |
289 | int64_t | |
290 | tls_offset_for_local(const Relobj* object, | |
291 | unsigned int symndx, | |
292 | unsigned int got_indx) const | |
293 | { return do_tls_offset_for_local(object, symndx, got_indx); } | |
294 | ||
295 | // Return the offset to use for the GOT_INDX'th got entry which is | |
296 | // for global tls symbol GSYM. | |
297 | int64_t | |
298 | tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const | |
299 | { return do_tls_offset_for_global(gsym, got_indx); } | |
300 | ||
dc3714f3 AM |
301 | // For targets that use function descriptors, if LOC is the location |
302 | // of a function, modify it to point at the function entry location. | |
303 | void | |
304 | function_location(Symbol_location* loc) const | |
305 | { return do_function_location(loc); } | |
306 | ||
b3ce541e ILT |
307 | // Return whether this target can use relocation types to determine |
308 | // if a function's address is taken. | |
309 | bool | |
310 | can_check_for_function_pointers() const | |
311 | { return this->do_can_check_for_function_pointers(); } | |
312 | ||
313 | // Return whether a relocation to a merged section can be processed | |
314 | // to retrieve the contents. | |
315 | bool | |
316 | can_icf_inline_merge_sections () const | |
317 | { return this->pti_->can_icf_inline_merge_sections; } | |
318 | ||
319 | // Whether a section called SECTION_NAME may have function pointers to | |
320 | // sections not eligible for safe ICF folding. | |
321 | virtual bool | |
322 | section_may_have_icf_unsafe_pointers(const char* section_name) const | |
323 | { return this->do_section_may_have_icf_unsafe_pointers(section_name); } | |
324 | ||
02d7cd44 ILT |
325 | // Return the base to use for the PC value in an FDE when it is |
326 | // encoded using DW_EH_PE_datarel. This does not appear to be | |
327 | // documented anywhere, but it is target specific. Any use of | |
328 | // DW_EH_PE_datarel in gcc requires defining a special macro | |
329 | // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value. | |
330 | uint64_t | |
331 | ehframe_datarel_base() const | |
332 | { return this->do_ehframe_datarel_base(); } | |
333 | ||
4d625b70 | 334 | // Return true if a reference to SYM from a reloc at *PRELOC |
b6848d3c ILT |
335 | // means that the current function may call an object compiled |
336 | // without -fsplit-stack. SYM is known to be defined in an object | |
337 | // compiled without -fsplit-stack. | |
338 | bool | |
bd8d853f MK |
339 | is_call_to_non_split(const Symbol* sym, const unsigned char* preloc, |
340 | const unsigned char* view, | |
341 | section_size_type view_size) const | |
342 | { return this->do_is_call_to_non_split(sym, preloc, view, view_size); } | |
b6848d3c | 343 | |
364c7fa5 ILT |
344 | // A function starts at OFFSET in section SHNDX in OBJECT. That |
345 | // function was compiled with -fsplit-stack, but it refers to a | |
346 | // function which was compiled without -fsplit-stack. VIEW is a | |
347 | // modifiable view of the section; VIEW_SIZE is the size of the | |
348 | // view. The target has to adjust the function so that it allocates | |
349 | // enough stack. | |
350 | void | |
351 | calls_non_split(Relobj* object, unsigned int shndx, | |
352 | section_offset_type fnoffset, section_size_type fnsize, | |
6e0813d3 | 353 | const unsigned char* prelocs, size_t reloc_count, |
364c7fa5 ILT |
354 | unsigned char* view, section_size_type view_size, |
355 | std::string* from, std::string* to) const | |
356 | { | |
6e0813d3 CC |
357 | this->do_calls_non_split(object, shndx, fnoffset, fnsize, |
358 | prelocs, reloc_count, view, view_size, | |
364c7fa5 ILT |
359 | from, to); |
360 | } | |
361 | ||
f733487b DK |
362 | // Make an ELF object. |
363 | template<int size, bool big_endian> | |
364 | Object* | |
365 | make_elf_object(const std::string& name, Input_file* input_file, | |
366 | off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr) | |
367 | { return this->do_make_elf_object(name, input_file, offset, ehdr); } | |
368 | ||
c0a62865 DK |
369 | // Make an output section. |
370 | Output_section* | |
371 | make_output_section(const char* name, elfcpp::Elf_Word type, | |
372 | elfcpp::Elf_Xword flags) | |
373 | { return this->do_make_output_section(name, type, flags); } | |
374 | ||
20e6d0d6 DK |
375 | // Return true if target wants to perform relaxation. |
376 | bool | |
377 | may_relax() const | |
378 | { | |
379 | // Run the dummy relaxation pass twice if relaxation debugging is enabled. | |
380 | if (is_debugging_enabled(DEBUG_RELAXATION)) | |
381 | return true; | |
382 | ||
383 | return this->do_may_relax(); | |
384 | } | |
385 | ||
386 | // Perform a relaxation pass. Return true if layout may be changed. | |
387 | bool | |
c0a62865 | 388 | relax(int pass, const Input_objects* input_objects, Symbol_table* symtab, |
f625ae50 | 389 | Layout* layout, const Task* task) |
20e6d0d6 DK |
390 | { |
391 | // Run the dummy relaxation pass twice if relaxation debugging is enabled. | |
392 | if (is_debugging_enabled(DEBUG_RELAXATION)) | |
393 | return pass < 2; | |
394 | ||
f625ae50 | 395 | return this->do_relax(pass, input_objects, symtab, layout, task); |
2e702c99 | 396 | } |
20e6d0d6 | 397 | |
05a352e6 DK |
398 | // Return the target-specific name of attributes section. This is |
399 | // NULL if a target does not use attributes section or if it uses | |
400 | // the default section name ".gnu.attributes". | |
401 | const char* | |
402 | attributes_section() const | |
403 | { return this->pti_->attributes_section; } | |
404 | ||
405 | // Return the vendor name of vendor attributes. | |
406 | const char* | |
407 | attributes_vendor() const | |
408 | { return this->pti_->attributes_vendor; } | |
409 | ||
410 | // Whether a section called NAME is an attribute section. | |
411 | bool | |
412 | is_attributes_section(const char* name) const | |
413 | { | |
414 | return ((this->pti_->attributes_section != NULL | |
415 | && strcmp(name, this->pti_->attributes_section) == 0) | |
2e702c99 | 416 | || strcmp(name, ".gnu.attributes") == 0); |
05a352e6 DK |
417 | } |
418 | ||
419 | // Return a bit mask of argument types for attribute with TAG. | |
420 | int | |
421 | attribute_arg_type(int tag) const | |
422 | { return this->do_attribute_arg_type(tag); } | |
423 | ||
424 | // Return the attribute tag of the position NUM in the list of fixed | |
425 | // attributes. Normally there is no reordering and | |
426 | // attributes_order(NUM) == NUM. | |
427 | int | |
428 | attributes_order(int num) const | |
429 | { return this->do_attributes_order(num); } | |
430 | ||
0d31c79d DK |
431 | // When a target is selected as the default target, we call this method, |
432 | // which may be used for expensive, target-specific initialization. | |
433 | void | |
434 | select_as_default_target() | |
2e702c99 | 435 | { this->do_select_as_default_target(); } |
0d31c79d | 436 | |
200b2bb9 ILT |
437 | // Return the value to store in the EI_OSABI field in the ELF |
438 | // header. | |
439 | elfcpp::ELFOSABI | |
440 | osabi() const | |
441 | { return this->osabi_; } | |
442 | ||
443 | // Set the value to store in the EI_OSABI field in the ELF header. | |
444 | void | |
445 | set_osabi(elfcpp::ELFOSABI osabi) | |
446 | { this->osabi_ = osabi; } | |
447 | ||
647f1574 DK |
448 | // Define target-specific standard symbols. |
449 | void | |
450 | define_standard_symbols(Symbol_table* symtab, Layout* layout) | |
451 | { this->do_define_standard_symbols(symtab, layout); } | |
452 | ||
921b5322 AM |
453 | // Return the output section name to use given an input section |
454 | // name, or NULL if no target specific name mapping is required. | |
455 | // Set *PLEN to the length of the name if returning non-NULL. | |
456 | const char* | |
457 | output_section_name(const Relobj* relobj, | |
458 | const char* name, | |
459 | size_t* plen) const | |
460 | { return this->do_output_section_name(relobj, name, plen); } | |
461 | ||
e81fea4d AM |
462 | // Add any special sections for this symbol to the gc work list. |
463 | void | |
464 | gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const | |
465 | { this->do_gc_mark_symbol(symtab, sym); } | |
466 | ||
a67858e0 CC |
467 | // Return the name of the entry point symbol. |
468 | const char* | |
469 | entry_symbol_name() const | |
470 | { return this->pti_->entry_symbol_name; } | |
471 | ||
8d9743bd MK |
472 | // Return the size in bits of SHT_HASH entry. |
473 | int | |
474 | hash_entry_size() const | |
475 | { return this->pti_->hash_entry_size; } | |
476 | ||
bce5a025 CC |
477 | // Return the section type to use for unwind sections. |
478 | unsigned int | |
479 | unwind_section_type() const | |
480 | { return this->pti_->unwind_section_type; } | |
481 | ||
98ff9231 CC |
482 | // Whether the target has a custom set_dynsym_indexes method. |
483 | bool | |
484 | has_custom_set_dynsym_indexes() const | |
485 | { return this->do_has_custom_set_dynsym_indexes(); } | |
486 | ||
487 | // Custom set_dynsym_indexes method for a target. | |
488 | unsigned int | |
489 | set_dynsym_indexes(std::vector<Symbol*>* dyn_symbols, unsigned int index, | |
490 | std::vector<Symbol*>* syms, Stringpool* dynpool, | |
491 | Versions* versions, Symbol_table* symtab) const | |
492 | { | |
493 | return this->do_set_dynsym_indexes(dyn_symbols, index, syms, dynpool, | |
494 | versions, symtab); | |
495 | } | |
496 | ||
918fc1f8 CC |
497 | // Get the custom dynamic tag value. |
498 | unsigned int | |
499 | dynamic_tag_custom_value(elfcpp::DT tag) const | |
500 | { return this->do_dynamic_tag_custom_value(tag); } | |
501 | ||
800d9823 CC |
502 | // Adjust the value written to the dynamic symbol table. |
503 | void | |
504 | adjust_dyn_symbol(const Symbol* sym, unsigned char* view) const | |
505 | { this->do_adjust_dyn_symbol(sym, view); } | |
506 | ||
99fd8cff CC |
507 | // Return whether to include the section in the link. |
508 | bool | |
509 | should_include_section(elfcpp::Elf_Word sh_type) const | |
510 | { return this->do_should_include_section(sh_type); } | |
511 | ||
a2575bec | 512 | // Finalize the target-specific properties in the .note.gnu.property section. |
6c04fd9b | 513 | void |
a2575bec CC |
514 | finalize_gnu_properties(Layout* layout) const |
515 | { this->do_finalize_gnu_properties(layout); } | |
6c04fd9b | 516 | |
14bfc3f5 | 517 | protected: |
75f65a3e ILT |
518 | // This struct holds the constant information for a child class. We |
519 | // use a struct to avoid the overhead of virtual function calls for | |
520 | // simple information. | |
521 | struct Target_info | |
522 | { | |
523 | // Address size (32 or 64). | |
524 | int size; | |
525 | // Whether the target is big endian. | |
526 | bool is_big_endian; | |
61ba1cf9 ILT |
527 | // The code to store in the e_machine field of the ELF header. |
528 | elfcpp::EM machine_code; | |
75f65a3e ILT |
529 | // Whether this target has a specific make_symbol function. |
530 | bool has_make_symbol; | |
531 | // Whether this target has a specific resolve function. | |
532 | bool has_resolve; | |
c51e6221 ILT |
533 | // Whether this target has a specific code fill function. |
534 | bool has_code_fill; | |
35cdfc9a ILT |
535 | // Whether an object file with no .note.GNU-stack sections implies |
536 | // that the stack should be executable. | |
537 | bool is_default_stack_executable; | |
b3ce541e ILT |
538 | // Whether a relocation to a merged section can be processed to |
539 | // retrieve the contents. | |
540 | bool can_icf_inline_merge_sections; | |
0864d551 ILT |
541 | // Prefix character to strip when checking for wrapping. |
542 | char wrap_char; | |
dbe717ef ILT |
543 | // The default dynamic linker name. |
544 | const char* dynamic_linker; | |
75f65a3e | 545 | // The default text segment address. |
0c5e9c22 | 546 | uint64_t default_text_segment_address; |
75f65a3e ILT |
547 | // The ABI specified page size. |
548 | uint64_t abi_pagesize; | |
549 | // The common page size used by actual implementations. | |
550 | uint64_t common_pagesize; | |
2e702c99 RM |
551 | // Whether PF_X segments must contain nothing but the contents of |
552 | // SHF_EXECINSTR sections (no non-executable data, no headers). | |
553 | bool isolate_execinstr; | |
554 | // If nonzero, distance from the text segment to the read-only segment. | |
555 | uint64_t rosegment_gap; | |
8a5e3e08 ILT |
556 | // The special section index for small common symbols; SHN_UNDEF |
557 | // if none. | |
558 | elfcpp::Elf_Half small_common_shndx; | |
559 | // The special section index for large common symbols; SHN_UNDEF | |
560 | // if none. | |
561 | elfcpp::Elf_Half large_common_shndx; | |
562 | // Section flags for small common section. | |
563 | elfcpp::Elf_Xword small_common_section_flags; | |
564 | // Section flags for large common section. | |
565 | elfcpp::Elf_Xword large_common_section_flags; | |
05a352e6 DK |
566 | // Name of attributes section if it is not ".gnu.attributes". |
567 | const char* attributes_section; | |
568 | // Vendor name of vendor attributes. | |
569 | const char* attributes_vendor; | |
a67858e0 CC |
570 | // Name of the main entry point to the program. |
571 | const char* entry_symbol_name; | |
8d9743bd MK |
572 | // Size (in bits) of SHT_HASH entry. Always equal to 32, except for |
573 | // 64-bit S/390. | |
574 | const int hash_entry_size; | |
bce5a025 CC |
575 | // Processor-specific section type for ".eh_frame" (unwind) sections. |
576 | // SHT_PROGBITS if there is no special section type. | |
577 | const unsigned int unwind_section_type; | |
75f65a3e ILT |
578 | }; |
579 | ||
580 | Target(const Target_info* pti) | |
d5b40221 | 581 | : pti_(pti), processor_specific_flags_(0), |
200b2bb9 | 582 | are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE) |
14bfc3f5 ILT |
583 | { } |
584 | ||
8a5e3e08 ILT |
585 | // Virtual function which may be implemented by the child class. |
586 | virtual void | |
587 | do_new_output_section(Output_section*) const | |
588 | { } | |
589 | ||
5a6f7e2d ILT |
590 | // Virtual function which may be implemented by the child class. |
591 | virtual void | |
f59f41f3 | 592 | do_finalize_sections(Layout*, const Input_objects*, Symbol_table*) |
5a6f7e2d ILT |
593 | { } |
594 | ||
ab5c9e90 ILT |
595 | // Virtual function which may be implemented by the child class. |
596 | virtual uint64_t | |
597 | do_dynsym_value(const Symbol*) const | |
598 | { gold_unreachable(); } | |
599 | ||
c51e6221 ILT |
600 | // Virtual function which must be implemented by the child class if |
601 | // needed. | |
602 | virtual std::string | |
8851ecca | 603 | do_code_fill(section_size_type) const |
c51e6221 ILT |
604 | { gold_unreachable(); } |
605 | ||
9a2d6984 ILT |
606 | // Virtual function which may be implemented by the child class. |
607 | virtual bool | |
9c2d0ef9 | 608 | do_is_defined_by_abi(const Symbol*) const |
9a2d6984 ILT |
609 | { return false; } |
610 | ||
36959681 ILT |
611 | // Adjust the output file header before it is written out. VIEW |
612 | // points to the header in external form. LEN is the length, and | |
613 | // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size. | |
200b2bb9 ILT |
614 | // By default, we set the EI_OSABI field if requested (in |
615 | // Sized_target). | |
36959681 | 616 | virtual void |
cc84c10b | 617 | do_adjust_elf_header(unsigned char*, int) = 0; |
36959681 | 618 | |
9d5781f8 AM |
619 | // Return address and size to plug into eh_frame FDEs associated with a PLT. |
620 | virtual void | |
621 | do_plt_fde_location(const Output_data* plt, unsigned char* oview, | |
622 | uint64_t* address, off_t* len) const; | |
623 | ||
9b547ce6 | 624 | // Virtual function which may be overridden by the child class. |
bb04269c DK |
625 | virtual bool |
626 | do_is_local_label_name(const char*) const; | |
627 | ||
e291e7b9 ILT |
628 | // Virtual function that must be overridden by a target which uses |
629 | // target specific relocations. | |
630 | virtual unsigned int | |
631 | do_reloc_symbol_index(void*, unsigned int) const | |
632 | { gold_unreachable(); } | |
633 | ||
9b547ce6 | 634 | // Virtual function that must be overridden by a target which uses |
e291e7b9 ILT |
635 | // target specific relocations. |
636 | virtual uint64_t | |
637 | do_reloc_addend(void*, unsigned int, uint64_t) const | |
638 | { gold_unreachable(); } | |
639 | ||
7223e9ca ILT |
640 | // Virtual functions that must be overridden by a target that uses |
641 | // STT_GNU_IFUNC symbols. | |
67181c72 ILT |
642 | virtual uint64_t |
643 | do_plt_address_for_global(const Symbol*) const | |
7223e9ca ILT |
644 | { gold_unreachable(); } |
645 | ||
67181c72 ILT |
646 | virtual uint64_t |
647 | do_plt_address_for_local(const Relobj*, unsigned int) const | |
7223e9ca ILT |
648 | { gold_unreachable(); } |
649 | ||
bd73a62d AM |
650 | virtual int64_t |
651 | do_tls_offset_for_local(const Relobj*, unsigned int, unsigned int) const | |
652 | { gold_unreachable(); } | |
653 | ||
654 | virtual int64_t | |
655 | do_tls_offset_for_global(Symbol*, unsigned int) const | |
656 | { gold_unreachable(); } | |
657 | ||
dc3714f3 AM |
658 | virtual void |
659 | do_function_location(Symbol_location*) const = 0; | |
660 | ||
b3ce541e ILT |
661 | // Virtual function which may be overriden by the child class. |
662 | virtual bool | |
663 | do_can_check_for_function_pointers() const | |
664 | { return false; } | |
665 | ||
666 | // Virtual function which may be overridden by the child class. We | |
667 | // recognize some default sections for which we don't care whether | |
668 | // they have function pointers. | |
669 | virtual bool | |
670 | do_section_may_have_icf_unsafe_pointers(const char* section_name) const | |
671 | { | |
672 | // We recognize sections for normal vtables, construction vtables and | |
673 | // EH frames. | |
674 | return (!is_prefix_of(".rodata._ZTV", section_name) | |
675 | && !is_prefix_of(".data.rel.ro._ZTV", section_name) | |
676 | && !is_prefix_of(".rodata._ZTC", section_name) | |
677 | && !is_prefix_of(".data.rel.ro._ZTC", section_name) | |
678 | && !is_prefix_of(".eh_frame", section_name)); | |
679 | } | |
680 | ||
02d7cd44 ILT |
681 | virtual uint64_t |
682 | do_ehframe_datarel_base() const | |
683 | { gold_unreachable(); } | |
684 | ||
b6848d3c ILT |
685 | // Virtual function which may be overridden by the child class. The |
686 | // default implementation is that any function not defined by the | |
687 | // ABI is a call to a non-split function. | |
688 | virtual bool | |
bd8d853f MK |
689 | do_is_call_to_non_split(const Symbol* sym, const unsigned char*, |
690 | const unsigned char*, section_size_type) const; | |
b6848d3c | 691 | |
364c7fa5 ILT |
692 | // Virtual function which may be overridden by the child class. |
693 | virtual void | |
694 | do_calls_non_split(Relobj* object, unsigned int, section_offset_type, | |
6e0813d3 CC |
695 | section_size_type, const unsigned char*, size_t, |
696 | unsigned char*, section_size_type, | |
364c7fa5 ILT |
697 | std::string*, std::string*) const; |
698 | ||
f733487b | 699 | // make_elf_object hooks. There are four versions of these for |
7296d933 | 700 | // different address sizes and endianness. |
364c7fa5 | 701 | |
d5b40221 DK |
702 | // Set processor specific flags. |
703 | void | |
704 | set_processor_specific_flags(elfcpp::Elf_Word flags) | |
705 | { | |
706 | this->processor_specific_flags_ = flags; | |
707 | this->are_processor_specific_flags_set_ = true; | |
708 | } | |
2e702c99 | 709 | |
f733487b | 710 | #ifdef HAVE_TARGET_32_LITTLE |
9b547ce6 | 711 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
712 | virtual Object* |
713 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
714 | const elfcpp::Ehdr<32, false>&); | |
715 | #endif | |
716 | ||
717 | #ifdef HAVE_TARGET_32_BIG | |
9b547ce6 | 718 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
719 | virtual Object* |
720 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
721 | const elfcpp::Ehdr<32, true>&); | |
722 | #endif | |
723 | ||
724 | #ifdef HAVE_TARGET_64_LITTLE | |
9b547ce6 | 725 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
726 | virtual Object* |
727 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
728 | const elfcpp::Ehdr<64, false>& ehdr); | |
729 | #endif | |
730 | ||
731 | #ifdef HAVE_TARGET_64_BIG | |
9b547ce6 | 732 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
733 | virtual Object* |
734 | do_make_elf_object(const std::string& name, Input_file* input_file, | |
735 | off_t offset, const elfcpp::Ehdr<64, true>& ehdr); | |
736 | #endif | |
737 | ||
9b547ce6 | 738 | // Virtual functions which may be overridden by the child class. |
c0a62865 DK |
739 | virtual Output_section* |
740 | do_make_output_section(const char* name, elfcpp::Elf_Word type, | |
741 | elfcpp::Elf_Xword flags); | |
742 | ||
9b547ce6 | 743 | // Virtual function which may be overridden by the child class. |
20e6d0d6 DK |
744 | virtual bool |
745 | do_may_relax() const | |
746 | { return parameters->options().relax(); } | |
747 | ||
9b547ce6 | 748 | // Virtual function which may be overridden by the child class. |
20e6d0d6 | 749 | virtual bool |
f625ae50 | 750 | do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*) |
20e6d0d6 DK |
751 | { return false; } |
752 | ||
364c7fa5 ILT |
753 | // A function for targets to call. Return whether BYTES/LEN matches |
754 | // VIEW/VIEW_SIZE at OFFSET. | |
755 | bool | |
756 | match_view(const unsigned char* view, section_size_type view_size, | |
757 | section_offset_type offset, const char* bytes, size_t len) const; | |
758 | ||
759 | // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET | |
760 | // for LEN bytes. | |
761 | void | |
762 | set_view_to_nop(unsigned char* view, section_size_type view_size, | |
763 | section_offset_type offset, size_t len) const; | |
764 | ||
9b547ce6 | 765 | // This must be overridden by the child class if it has target-specific |
2e702c99 | 766 | // attributes subsection in the attribute section. |
05a352e6 DK |
767 | virtual int |
768 | do_attribute_arg_type(int) const | |
769 | { gold_unreachable(); } | |
770 | ||
771 | // This may be overridden by the child class. | |
772 | virtual int | |
773 | do_attributes_order(int num) const | |
774 | { return num; } | |
775 | ||
0d31c79d DK |
776 | // This may be overridden by the child class. |
777 | virtual void | |
778 | do_select_as_default_target() | |
779 | { } | |
780 | ||
647f1574 DK |
781 | // This may be overridden by the child class. |
782 | virtual void | |
783 | do_define_standard_symbols(Symbol_table*, Layout*) | |
784 | { } | |
785 | ||
921b5322 AM |
786 | // This may be overridden by the child class. |
787 | virtual const char* | |
788 | do_output_section_name(const Relobj*, const char*, size_t*) const | |
789 | { return NULL; } | |
790 | ||
e81fea4d AM |
791 | // This may be overridden by the child class. |
792 | virtual void | |
793 | do_gc_mark_symbol(Symbol_table*, Symbol*) const | |
794 | { } | |
795 | ||
98ff9231 CC |
796 | // This may be overridden by the child class. |
797 | virtual bool | |
798 | do_has_custom_set_dynsym_indexes() const | |
799 | { return false; } | |
800 | ||
801 | // This may be overridden by the child class. | |
802 | virtual unsigned int | |
803 | do_set_dynsym_indexes(std::vector<Symbol*>*, unsigned int, | |
804 | std::vector<Symbol*>*, Stringpool*, Versions*, | |
805 | Symbol_table*) const | |
806 | { gold_unreachable(); } | |
807 | ||
918fc1f8 CC |
808 | // This may be overridden by the child class. |
809 | virtual unsigned int | |
810 | do_dynamic_tag_custom_value(elfcpp::DT) const | |
811 | { gold_unreachable(); } | |
812 | ||
800d9823 CC |
813 | // This may be overridden by the child class. |
814 | virtual void | |
815 | do_adjust_dyn_symbol(const Symbol*, unsigned char*) const | |
816 | { } | |
817 | ||
99fd8cff CC |
818 | // This may be overridden by the child class. |
819 | virtual bool | |
820 | do_should_include_section(elfcpp::Elf_Word) const | |
821 | { return true; } | |
822 | ||
a2575bec | 823 | // Finalize the target-specific properties in the .note.gnu.property section. |
6c04fd9b | 824 | virtual void |
a2575bec | 825 | do_finalize_gnu_properties(Layout*) const |
6c04fd9b CC |
826 | { } |
827 | ||
14bfc3f5 | 828 | private: |
f733487b | 829 | // The implementations of the four do_make_elf_object virtual functions are |
7296d933 | 830 | // almost identical except for their sizes and endianness. We use a template. |
f733487b DK |
831 | // for their implementations. |
832 | template<int size, bool big_endian> | |
833 | inline Object* | |
834 | do_make_elf_object_implementation(const std::string&, Input_file*, off_t, | |
835 | const elfcpp::Ehdr<size, big_endian>&); | |
836 | ||
14bfc3f5 ILT |
837 | Target(const Target&); |
838 | Target& operator=(const Target&); | |
839 | ||
75f65a3e ILT |
840 | // The target information. |
841 | const Target_info* pti_; | |
d5b40221 DK |
842 | // Processor-specific flags. |
843 | elfcpp::Elf_Word processor_specific_flags_; | |
844 | // Whether the processor-specific flags are set at least once. | |
845 | bool are_processor_specific_flags_set_; | |
200b2bb9 ILT |
846 | // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of |
847 | // the ELF header. This is handled at this level because it is | |
848 | // OS-specific rather than processor-specific. | |
849 | elfcpp::ELFOSABI osabi_; | |
bae7f79e ILT |
850 | }; |
851 | ||
14bfc3f5 ILT |
852 | // The abstract class for a specific size and endianness of target. |
853 | // Each actual target implementation class should derive from an | |
854 | // instantiation of Sized_target. | |
855 | ||
856 | template<int size, bool big_endian> | |
857 | class Sized_target : public Target | |
858 | { | |
859 | public: | |
860 | // Make a new symbol table entry for the target. This should be | |
861 | // overridden by a target which needs additional information in the | |
862 | // symbol table. This will only be called if has_make_symbol() | |
863 | // returns true. | |
864 | virtual Sized_symbol<size>* | |
dc1c8a16 | 865 | make_symbol(const char*, elfcpp::STT, Object*, unsigned int, uint64_t) |
a3ad94ed | 866 | { gold_unreachable(); } |
14bfc3f5 ILT |
867 | |
868 | // Resolve a symbol for the target. This should be overridden by a | |
869 | // target which needs to take special action. TO is the | |
870 | // pre-existing symbol. SYM is the new symbol, seen in OBJECT. | |
14b31740 ILT |
871 | // VERSION is the version of SYM. This will only be called if |
872 | // has_resolve() returns true. | |
565ed01a | 873 | virtual bool |
14b31740 ILT |
874 | resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*, |
875 | const char*) | |
a3ad94ed | 876 | { gold_unreachable(); } |
14bfc3f5 | 877 | |
6d03d481 ST |
878 | // Process the relocs for a section, and record information of the |
879 | // mapping from source to destination sections. This mapping is later | |
880 | // used to determine unreferenced garbage sections. This procedure is | |
881 | // only called during garbage collection. | |
882 | virtual void | |
ad0f2072 ILT |
883 | gc_process_relocs(Symbol_table* symtab, |
884 | Layout* layout, | |
6fa2a40b | 885 | Sized_relobj_file<size, big_endian>* object, |
ad0f2072 ILT |
886 | unsigned int data_shndx, |
887 | unsigned int sh_type, | |
888 | const unsigned char* prelocs, | |
889 | size_t reloc_count, | |
890 | Output_section* output_section, | |
891 | bool needs_special_offset_handling, | |
892 | size_t local_symbol_count, | |
893 | const unsigned char* plocal_symbols) = 0; | |
6d03d481 | 894 | |
92e059d8 | 895 | // Scan the relocs for a section, and record any information |
ad0f2072 ILT |
896 | // required for the symbol. SYMTAB is the symbol table. OBJECT is |
897 | // the object in which the section appears. DATA_SHNDX is the | |
898 | // section index that these relocs apply to. SH_TYPE is the type of | |
899 | // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to | |
900 | // the relocation data. RELOC_COUNT is the number of relocs. | |
901 | // LOCAL_SYMBOL_COUNT is the number of local symbols. | |
902 | // OUTPUT_SECTION is the output section. | |
730cdc88 ILT |
903 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output |
904 | // sections are not mapped as usual. PLOCAL_SYMBOLS points to the | |
905 | // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of | |
906 | // pointers to the global symbol table from OBJECT. | |
61ba1cf9 | 907 | virtual void |
ad0f2072 | 908 | scan_relocs(Symbol_table* symtab, |
ead1e424 | 909 | Layout* layout, |
6fa2a40b | 910 | Sized_relobj_file<size, big_endian>* object, |
a3ad94ed | 911 | unsigned int data_shndx, |
92e059d8 ILT |
912 | unsigned int sh_type, |
913 | const unsigned char* prelocs, | |
914 | size_t reloc_count, | |
730cdc88 ILT |
915 | Output_section* output_section, |
916 | bool needs_special_offset_handling, | |
92e059d8 | 917 | size_t local_symbol_count, |
730cdc88 | 918 | const unsigned char* plocal_symbols) = 0; |
92e059d8 ILT |
919 | |
920 | // Relocate section data. SH_TYPE is the type of the relocation | |
921 | // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation | |
730cdc88 ILT |
922 | // information. RELOC_COUNT is the number of relocs. |
923 | // OUTPUT_SECTION is the output section. | |
924 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped | |
925 | // to correspond to the output section. VIEW is a view into the | |
926 | // output file holding the section contents, VIEW_ADDRESS is the | |
927 | // virtual address of the view, and VIEW_SIZE is the size of the | |
928 | // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx | |
929 | // parameters refer to the complete output section data, not just | |
930 | // the input section data. | |
92e059d8 ILT |
931 | virtual void |
932 | relocate_section(const Relocate_info<size, big_endian>*, | |
933 | unsigned int sh_type, | |
934 | const unsigned char* prelocs, | |
935 | size_t reloc_count, | |
730cdc88 ILT |
936 | Output_section* output_section, |
937 | bool needs_special_offset_handling, | |
92e059d8 ILT |
938 | unsigned char* view, |
939 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
364c7fa5 ILT |
940 | section_size_type view_size, |
941 | const Reloc_symbol_changes*) = 0; | |
61ba1cf9 | 942 | |
6a74a719 ILT |
943 | // Scan the relocs during a relocatable link. The parameters are |
944 | // like scan_relocs, with an additional Relocatable_relocs | |
945 | // parameter, used to record the disposition of the relocs. | |
946 | virtual void | |
ad0f2072 | 947 | scan_relocatable_relocs(Symbol_table* symtab, |
6a74a719 | 948 | Layout* layout, |
6fa2a40b | 949 | Sized_relobj_file<size, big_endian>* object, |
6a74a719 ILT |
950 | unsigned int data_shndx, |
951 | unsigned int sh_type, | |
952 | const unsigned char* prelocs, | |
953 | size_t reloc_count, | |
954 | Output_section* output_section, | |
955 | bool needs_special_offset_handling, | |
956 | size_t local_symbol_count, | |
957 | const unsigned char* plocal_symbols, | |
958 | Relocatable_relocs*) = 0; | |
959 | ||
4d625b70 CC |
960 | // Scan the relocs for --emit-relocs. The parameters are |
961 | // like scan_relocatable_relocs. | |
962 | virtual void | |
963 | emit_relocs_scan(Symbol_table* symtab, | |
964 | Layout* layout, | |
965 | Sized_relobj_file<size, big_endian>* object, | |
966 | unsigned int data_shndx, | |
967 | unsigned int sh_type, | |
968 | const unsigned char* prelocs, | |
969 | size_t reloc_count, | |
970 | Output_section* output_section, | |
971 | bool needs_special_offset_handling, | |
972 | size_t local_symbol_count, | |
973 | const unsigned char* plocal_syms, | |
974 | Relocatable_relocs* rr) = 0; | |
975 | ||
7404fe1b AM |
976 | // Emit relocations for a section during a relocatable link, and for |
977 | // --emit-relocs. The parameters are like relocate_section, with | |
978 | // additional parameters for the view of the output reloc section. | |
6a74a719 | 979 | virtual void |
7404fe1b AM |
980 | relocate_relocs(const Relocate_info<size, big_endian>*, |
981 | unsigned int sh_type, | |
982 | const unsigned char* prelocs, | |
983 | size_t reloc_count, | |
984 | Output_section* output_section, | |
62fe925a RM |
985 | typename elfcpp::Elf_types<size>::Elf_Off |
986 | offset_in_output_section, | |
7404fe1b AM |
987 | unsigned char* view, |
988 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
989 | section_size_type view_size, | |
990 | unsigned char* reloc_view, | |
991 | section_size_type reloc_view_size) = 0; | |
2e702c99 | 992 | |
5c388529 DK |
993 | // Perform target-specific processing in a relocatable link. This is |
994 | // only used if we use the relocation strategy RELOC_SPECIAL. | |
995 | // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation | |
996 | // section type. PRELOC_IN points to the original relocation. RELNUM is | |
997 | // the index number of the relocation in the relocation section. | |
998 | // OUTPUT_SECTION is the output section to which the relocation is applied. | |
999 | // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section | |
1000 | // within the output section. VIEW points to the output view of the | |
1001 | // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE | |
1002 | // is the size of the output view and PRELOC_OUT points to the new | |
1003 | // relocation in the output object. | |
1004 | // | |
1005 | // A target only needs to override this if the generic code in | |
1006 | // target-reloc.h cannot handle some relocation types. | |
6a74a719 | 1007 | |
5c388529 DK |
1008 | virtual void |
1009 | relocate_special_relocatable(const Relocate_info<size, big_endian>* | |
1010 | /*relinfo */, | |
1011 | unsigned int /* sh_type */, | |
1012 | const unsigned char* /* preloc_in */, | |
1013 | size_t /* relnum */, | |
1014 | Output_section* /* output_section */, | |
62fe925a RM |
1015 | typename elfcpp::Elf_types<size>::Elf_Off |
1016 | /* offset_in_output_section */, | |
5c388529 DK |
1017 | unsigned char* /* view */, |
1018 | typename elfcpp::Elf_types<size>::Elf_Addr | |
1019 | /* view_address */, | |
1020 | section_size_type /* view_size */, | |
1021 | unsigned char* /* preloc_out*/) | |
1022 | { gold_unreachable(); } | |
2e702c99 | 1023 | |
0e70b911 CC |
1024 | // Return the number of entries in the GOT. This is only used for |
1025 | // laying out the incremental link info sections. A target needs | |
1026 | // to implement this to support incremental linking. | |
1027 | ||
1028 | virtual unsigned int | |
1029 | got_entry_count() const | |
1030 | { gold_unreachable(); } | |
1031 | ||
1032 | // Return the number of entries in the PLT. This is only used for | |
1033 | // laying out the incremental link info sections. A target needs | |
1034 | // to implement this to support incremental linking. | |
1035 | ||
1036 | virtual unsigned int | |
1037 | plt_entry_count() const | |
1038 | { gold_unreachable(); } | |
1039 | ||
1040 | // Return the offset of the first non-reserved PLT entry. This is | |
1041 | // only used for laying out the incremental link info sections. | |
1042 | // A target needs to implement this to support incremental linking. | |
1043 | ||
1044 | virtual unsigned int | |
1045 | first_plt_entry_offset() const | |
1046 | { gold_unreachable(); } | |
1047 | ||
1048 | // Return the size of each PLT entry. This is only used for | |
1049 | // laying out the incremental link info sections. A target needs | |
1050 | // to implement this to support incremental linking. | |
1051 | ||
1052 | virtual unsigned int | |
1053 | plt_entry_size() const | |
1054 | { gold_unreachable(); } | |
1055 | ||
41e83f2b L |
1056 | // Return the size of each GOT entry. This is only used for |
1057 | // laying out the incremental link info sections. A target needs | |
1058 | // to implement this if its GOT size is different. | |
1059 | ||
1060 | virtual unsigned int | |
1061 | got_entry_size() const | |
1062 | { return size / 8; } | |
1063 | ||
4829d394 CC |
1064 | // Create the GOT and PLT sections for an incremental update. |
1065 | // A target needs to implement this to support incremental linking. | |
1066 | ||
dd74ae06 | 1067 | virtual Output_data_got_base* |
4829d394 CC |
1068 | init_got_plt_for_update(Symbol_table*, |
1069 | Layout*, | |
1070 | unsigned int /* got_count */, | |
1071 | unsigned int /* plt_count */) | |
1072 | { gold_unreachable(); } | |
1073 | ||
6fa2a40b CC |
1074 | // Reserve a GOT entry for a local symbol, and regenerate any |
1075 | // necessary dynamic relocations. | |
1076 | virtual void | |
1077 | reserve_local_got_entry(unsigned int /* got_index */, | |
1078 | Sized_relobj<size, big_endian>* /* obj */, | |
1079 | unsigned int /* r_sym */, | |
1080 | unsigned int /* got_type */) | |
1081 | { gold_unreachable(); } | |
1082 | ||
1083 | // Reserve a GOT entry for a global symbol, and regenerate any | |
1084 | // necessary dynamic relocations. | |
1085 | virtual void | |
1086 | reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */, | |
1087 | unsigned int /* got_type */) | |
1088 | { gold_unreachable(); } | |
1089 | ||
4829d394 CC |
1090 | // Register an existing PLT entry for a global symbol. |
1091 | // A target needs to implement this to support incremental linking. | |
1092 | ||
1093 | virtual void | |
67181c72 ILT |
1094 | register_global_plt_entry(Symbol_table*, Layout*, |
1095 | unsigned int /* plt_index */, | |
4829d394 CC |
1096 | Symbol*) |
1097 | { gold_unreachable(); } | |
1098 | ||
26d3c67d CC |
1099 | // Force a COPY relocation for a given symbol. |
1100 | // A target needs to implement this to support incremental linking. | |
1101 | ||
1102 | virtual void | |
1103 | emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t) | |
1104 | { gold_unreachable(); } | |
1105 | ||
94a3fc8b CC |
1106 | // Apply an incremental relocation. |
1107 | ||
1108 | virtual void | |
1109 | apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */, | |
1110 | typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */, | |
1111 | unsigned int /* r_type */, | |
1112 | typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */, | |
1113 | const Symbol* /* gsym */, | |
1114 | unsigned char* /* view */, | |
1115 | typename elfcpp::Elf_types<size>::Elf_Addr /* address */, | |
1116 | section_size_type /* view_size */) | |
1117 | { gold_unreachable(); } | |
1118 | ||
e81fea4d AM |
1119 | // Handle target specific gc actions when adding a gc reference from |
1120 | // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX | |
1121 | // and DST_OFF. | |
1122 | void | |
1123 | gc_add_reference(Symbol_table* symtab, | |
efc6fa12 | 1124 | Relobj* src_obj, |
e81fea4d | 1125 | unsigned int src_shndx, |
efc6fa12 | 1126 | Relobj* dst_obj, |
e81fea4d AM |
1127 | unsigned int dst_shndx, |
1128 | typename elfcpp::Elf_types<size>::Elf_Addr dst_off) const | |
1129 | { | |
1130 | this->do_gc_add_reference(symtab, src_obj, src_shndx, | |
1131 | dst_obj, dst_shndx, dst_off); | |
1132 | } | |
1133 | ||
4d625b70 CC |
1134 | // Return the r_sym field from a relocation. |
1135 | // Most targets can use the default version of this routine, | |
1136 | // but some targets have a non-standard r_info field, and will | |
1137 | // need to provide a target-specific version. | |
1138 | virtual unsigned int | |
1139 | get_r_sym(const unsigned char* preloc) const | |
1140 | { | |
1141 | // Since REL and RELA relocs share the same structure through | |
1142 | // the r_info field, we can just use REL here. | |
1143 | elfcpp::Rel<size, big_endian> rel(preloc); | |
1144 | return elfcpp::elf_r_sym<size>(rel.get_r_info()); | |
1145 | } | |
1146 | ||
a2575bec CC |
1147 | // Record a target-specific program property in the .note.gnu.property |
1148 | // section. | |
1149 | virtual void | |
dc1f2887 CC |
1150 | record_gnu_property(unsigned int, unsigned int, size_t, |
1151 | const unsigned char*, const Object*) | |
a2575bec CC |
1152 | { } |
1153 | ||
1154 | // Merge the target-specific program properties from the current object. | |
1155 | virtual void | |
1156 | merge_gnu_properties(const Object*) | |
1157 | { } | |
1158 | ||
14bfc3f5 | 1159 | protected: |
75f65a3e ILT |
1160 | Sized_target(const Target::Target_info* pti) |
1161 | : Target(pti) | |
1162 | { | |
a3ad94ed ILT |
1163 | gold_assert(pti->size == size); |
1164 | gold_assert(pti->is_big_endian ? big_endian : !big_endian); | |
75f65a3e | 1165 | } |
200b2bb9 ILT |
1166 | |
1167 | // Set the EI_OSABI field if requested. | |
1168 | virtual void | |
cc84c10b | 1169 | do_adjust_elf_header(unsigned char*, int); |
e81fea4d AM |
1170 | |
1171 | // Handle target specific gc actions when adding a gc reference. | |
1172 | virtual void | |
efc6fa12 CC |
1173 | do_gc_add_reference(Symbol_table*, Relobj*, unsigned int, |
1174 | Relobj*, unsigned int, | |
e81fea4d AM |
1175 | typename elfcpp::Elf_types<size>::Elf_Addr) const |
1176 | { } | |
dc3714f3 AM |
1177 | |
1178 | virtual void | |
1179 | do_function_location(Symbol_location*) const | |
1180 | { } | |
14bfc3f5 | 1181 | }; |
bae7f79e ILT |
1182 | |
1183 | } // End namespace gold. | |
1184 | ||
1185 | #endif // !defined(GOLD_TARGET_H) |