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 | ||
7223e9ca ILT |
249 | // Return the PLT section to use for a global symbol. This is used |
250 | // for STT_GNU_IFUNC symbols. | |
251 | Output_data* | |
252 | plt_section_for_global(const Symbol* sym) const | |
253 | { return this->do_plt_section_for_global(sym); } | |
254 | ||
255 | // Return the PLT section to use for a local symbol. This is used | |
256 | // for STT_GNU_IFUNC symbols. | |
257 | Output_data* | |
258 | plt_section_for_local(const Relobj* object, unsigned int symndx) const | |
259 | { return this->do_plt_section_for_local(object, symndx); } | |
260 | ||
b3ce541e ILT |
261 | // Return whether this target can use relocation types to determine |
262 | // if a function's address is taken. | |
263 | bool | |
264 | can_check_for_function_pointers() const | |
265 | { return this->do_can_check_for_function_pointers(); } | |
266 | ||
267 | // Return whether a relocation to a merged section can be processed | |
268 | // to retrieve the contents. | |
269 | bool | |
270 | can_icf_inline_merge_sections () const | |
271 | { return this->pti_->can_icf_inline_merge_sections; } | |
272 | ||
273 | // Whether a section called SECTION_NAME may have function pointers to | |
274 | // sections not eligible for safe ICF folding. | |
275 | virtual bool | |
276 | section_may_have_icf_unsafe_pointers(const char* section_name) const | |
277 | { return this->do_section_may_have_icf_unsafe_pointers(section_name); } | |
278 | ||
b6848d3c ILT |
279 | // Return true if a reference to SYM from a reloc of type R_TYPE |
280 | // means that the current function may call an object compiled | |
281 | // without -fsplit-stack. SYM is known to be defined in an object | |
282 | // compiled without -fsplit-stack. | |
283 | bool | |
284 | is_call_to_non_split(const Symbol* sym, unsigned int r_type) const | |
285 | { return this->do_is_call_to_non_split(sym, r_type); } | |
286 | ||
364c7fa5 ILT |
287 | // A function starts at OFFSET in section SHNDX in OBJECT. That |
288 | // function was compiled with -fsplit-stack, but it refers to a | |
289 | // function which was compiled without -fsplit-stack. VIEW is a | |
290 | // modifiable view of the section; VIEW_SIZE is the size of the | |
291 | // view. The target has to adjust the function so that it allocates | |
292 | // enough stack. | |
293 | void | |
294 | calls_non_split(Relobj* object, unsigned int shndx, | |
295 | section_offset_type fnoffset, section_size_type fnsize, | |
296 | unsigned char* view, section_size_type view_size, | |
297 | std::string* from, std::string* to) const | |
298 | { | |
299 | this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size, | |
300 | from, to); | |
301 | } | |
302 | ||
f733487b DK |
303 | // Make an ELF object. |
304 | template<int size, bool big_endian> | |
305 | Object* | |
306 | make_elf_object(const std::string& name, Input_file* input_file, | |
307 | off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr) | |
308 | { return this->do_make_elf_object(name, input_file, offset, ehdr); } | |
309 | ||
c0a62865 DK |
310 | // Make an output section. |
311 | Output_section* | |
312 | make_output_section(const char* name, elfcpp::Elf_Word type, | |
313 | elfcpp::Elf_Xword flags) | |
314 | { return this->do_make_output_section(name, type, flags); } | |
315 | ||
20e6d0d6 DK |
316 | // Return true if target wants to perform relaxation. |
317 | bool | |
318 | may_relax() const | |
319 | { | |
320 | // Run the dummy relaxation pass twice if relaxation debugging is enabled. | |
321 | if (is_debugging_enabled(DEBUG_RELAXATION)) | |
322 | return true; | |
323 | ||
324 | return this->do_may_relax(); | |
325 | } | |
326 | ||
327 | // Perform a relaxation pass. Return true if layout may be changed. | |
328 | bool | |
c0a62865 | 329 | relax(int pass, const Input_objects* input_objects, Symbol_table* symtab, |
f625ae50 | 330 | Layout* layout, const Task* task) |
20e6d0d6 DK |
331 | { |
332 | // Run the dummy relaxation pass twice if relaxation debugging is enabled. | |
333 | if (is_debugging_enabled(DEBUG_RELAXATION)) | |
334 | return pass < 2; | |
335 | ||
f625ae50 | 336 | return this->do_relax(pass, input_objects, symtab, layout, task); |
c0a62865 | 337 | } |
20e6d0d6 | 338 | |
05a352e6 DK |
339 | // Return the target-specific name of attributes section. This is |
340 | // NULL if a target does not use attributes section or if it uses | |
341 | // the default section name ".gnu.attributes". | |
342 | const char* | |
343 | attributes_section() const | |
344 | { return this->pti_->attributes_section; } | |
345 | ||
346 | // Return the vendor name of vendor attributes. | |
347 | const char* | |
348 | attributes_vendor() const | |
349 | { return this->pti_->attributes_vendor; } | |
350 | ||
351 | // Whether a section called NAME is an attribute section. | |
352 | bool | |
353 | is_attributes_section(const char* name) const | |
354 | { | |
355 | return ((this->pti_->attributes_section != NULL | |
356 | && strcmp(name, this->pti_->attributes_section) == 0) | |
357 | || strcmp(name, ".gnu.attributes") == 0); | |
358 | } | |
359 | ||
360 | // Return a bit mask of argument types for attribute with TAG. | |
361 | int | |
362 | attribute_arg_type(int tag) const | |
363 | { return this->do_attribute_arg_type(tag); } | |
364 | ||
365 | // Return the attribute tag of the position NUM in the list of fixed | |
366 | // attributes. Normally there is no reordering and | |
367 | // attributes_order(NUM) == NUM. | |
368 | int | |
369 | attributes_order(int num) const | |
370 | { return this->do_attributes_order(num); } | |
371 | ||
0d31c79d DK |
372 | // When a target is selected as the default target, we call this method, |
373 | // which may be used for expensive, target-specific initialization. | |
374 | void | |
375 | select_as_default_target() | |
376 | { this->do_select_as_default_target(); } | |
377 | ||
14bfc3f5 | 378 | protected: |
75f65a3e ILT |
379 | // This struct holds the constant information for a child class. We |
380 | // use a struct to avoid the overhead of virtual function calls for | |
381 | // simple information. | |
382 | struct Target_info | |
383 | { | |
384 | // Address size (32 or 64). | |
385 | int size; | |
386 | // Whether the target is big endian. | |
387 | bool is_big_endian; | |
61ba1cf9 ILT |
388 | // The code to store in the e_machine field of the ELF header. |
389 | elfcpp::EM machine_code; | |
75f65a3e ILT |
390 | // Whether this target has a specific make_symbol function. |
391 | bool has_make_symbol; | |
392 | // Whether this target has a specific resolve function. | |
393 | bool has_resolve; | |
c51e6221 ILT |
394 | // Whether this target has a specific code fill function. |
395 | bool has_code_fill; | |
35cdfc9a ILT |
396 | // Whether an object file with no .note.GNU-stack sections implies |
397 | // that the stack should be executable. | |
398 | bool is_default_stack_executable; | |
b3ce541e ILT |
399 | // Whether a relocation to a merged section can be processed to |
400 | // retrieve the contents. | |
401 | bool can_icf_inline_merge_sections; | |
0864d551 ILT |
402 | // Prefix character to strip when checking for wrapping. |
403 | char wrap_char; | |
dbe717ef ILT |
404 | // The default dynamic linker name. |
405 | const char* dynamic_linker; | |
75f65a3e | 406 | // The default text segment address. |
0c5e9c22 | 407 | uint64_t default_text_segment_address; |
75f65a3e ILT |
408 | // The ABI specified page size. |
409 | uint64_t abi_pagesize; | |
410 | // The common page size used by actual implementations. | |
411 | uint64_t common_pagesize; | |
8a5e3e08 ILT |
412 | // The special section index for small common symbols; SHN_UNDEF |
413 | // if none. | |
414 | elfcpp::Elf_Half small_common_shndx; | |
415 | // The special section index for large common symbols; SHN_UNDEF | |
416 | // if none. | |
417 | elfcpp::Elf_Half large_common_shndx; | |
418 | // Section flags for small common section. | |
419 | elfcpp::Elf_Xword small_common_section_flags; | |
420 | // Section flags for large common section. | |
421 | elfcpp::Elf_Xword large_common_section_flags; | |
05a352e6 DK |
422 | // Name of attributes section if it is not ".gnu.attributes". |
423 | const char* attributes_section; | |
424 | // Vendor name of vendor attributes. | |
425 | const char* attributes_vendor; | |
75f65a3e ILT |
426 | }; |
427 | ||
428 | Target(const Target_info* pti) | |
d5b40221 DK |
429 | : pti_(pti), processor_specific_flags_(0), |
430 | are_processor_specific_flags_set_(false) | |
14bfc3f5 ILT |
431 | { } |
432 | ||
8a5e3e08 ILT |
433 | // Virtual function which may be implemented by the child class. |
434 | virtual void | |
435 | do_new_output_section(Output_section*) const | |
436 | { } | |
437 | ||
5a6f7e2d ILT |
438 | // Virtual function which may be implemented by the child class. |
439 | virtual void | |
f59f41f3 | 440 | do_finalize_sections(Layout*, const Input_objects*, Symbol_table*) |
5a6f7e2d ILT |
441 | { } |
442 | ||
ab5c9e90 ILT |
443 | // Virtual function which may be implemented by the child class. |
444 | virtual uint64_t | |
445 | do_dynsym_value(const Symbol*) const | |
446 | { gold_unreachable(); } | |
447 | ||
c51e6221 ILT |
448 | // Virtual function which must be implemented by the child class if |
449 | // needed. | |
450 | virtual std::string | |
8851ecca | 451 | do_code_fill(section_size_type) const |
c51e6221 ILT |
452 | { gold_unreachable(); } |
453 | ||
9a2d6984 ILT |
454 | // Virtual function which may be implemented by the child class. |
455 | virtual bool | |
9c2d0ef9 | 456 | do_is_defined_by_abi(const Symbol*) const |
9a2d6984 ILT |
457 | { return false; } |
458 | ||
36959681 ILT |
459 | // Adjust the output file header before it is written out. VIEW |
460 | // points to the header in external form. LEN is the length, and | |
461 | // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size. | |
462 | // By default, we do nothing. | |
463 | virtual void | |
464 | do_adjust_elf_header(unsigned char*, int) const | |
465 | { } | |
466 | ||
9b547ce6 | 467 | // Virtual function which may be overridden by the child class. |
bb04269c DK |
468 | virtual bool |
469 | do_is_local_label_name(const char*) const; | |
470 | ||
e291e7b9 ILT |
471 | // Virtual function that must be overridden by a target which uses |
472 | // target specific relocations. | |
473 | virtual unsigned int | |
474 | do_reloc_symbol_index(void*, unsigned int) const | |
475 | { gold_unreachable(); } | |
476 | ||
9b547ce6 | 477 | // Virtual function that must be overridden by a target which uses |
e291e7b9 ILT |
478 | // target specific relocations. |
479 | virtual uint64_t | |
480 | do_reloc_addend(void*, unsigned int, uint64_t) const | |
481 | { gold_unreachable(); } | |
482 | ||
7223e9ca ILT |
483 | // Virtual functions that must be overridden by a target that uses |
484 | // STT_GNU_IFUNC symbols. | |
485 | virtual Output_data* | |
486 | do_plt_section_for_global(const Symbol*) const | |
487 | { gold_unreachable(); } | |
488 | ||
489 | virtual Output_data* | |
490 | do_plt_section_for_local(const Relobj*, unsigned int) const | |
491 | { gold_unreachable(); } | |
492 | ||
b3ce541e ILT |
493 | // Virtual function which may be overriden by the child class. |
494 | virtual bool | |
495 | do_can_check_for_function_pointers() const | |
496 | { return false; } | |
497 | ||
498 | // Virtual function which may be overridden by the child class. We | |
499 | // recognize some default sections for which we don't care whether | |
500 | // they have function pointers. | |
501 | virtual bool | |
502 | do_section_may_have_icf_unsafe_pointers(const char* section_name) const | |
503 | { | |
504 | // We recognize sections for normal vtables, construction vtables and | |
505 | // EH frames. | |
506 | return (!is_prefix_of(".rodata._ZTV", section_name) | |
507 | && !is_prefix_of(".data.rel.ro._ZTV", section_name) | |
508 | && !is_prefix_of(".rodata._ZTC", section_name) | |
509 | && !is_prefix_of(".data.rel.ro._ZTC", section_name) | |
510 | && !is_prefix_of(".eh_frame", section_name)); | |
511 | } | |
512 | ||
b6848d3c ILT |
513 | // Virtual function which may be overridden by the child class. The |
514 | // default implementation is that any function not defined by the | |
515 | // ABI is a call to a non-split function. | |
516 | virtual bool | |
517 | do_is_call_to_non_split(const Symbol* sym, unsigned int) const; | |
518 | ||
364c7fa5 ILT |
519 | // Virtual function which may be overridden by the child class. |
520 | virtual void | |
521 | do_calls_non_split(Relobj* object, unsigned int, section_offset_type, | |
522 | section_size_type, unsigned char*, section_size_type, | |
523 | std::string*, std::string*) const; | |
524 | ||
f733487b | 525 | // make_elf_object hooks. There are four versions of these for |
7296d933 | 526 | // different address sizes and endianness. |
364c7fa5 | 527 | |
d5b40221 DK |
528 | // Set processor specific flags. |
529 | void | |
530 | set_processor_specific_flags(elfcpp::Elf_Word flags) | |
531 | { | |
532 | this->processor_specific_flags_ = flags; | |
533 | this->are_processor_specific_flags_set_ = true; | |
534 | } | |
535 | ||
f733487b | 536 | #ifdef HAVE_TARGET_32_LITTLE |
9b547ce6 | 537 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
538 | virtual Object* |
539 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
540 | const elfcpp::Ehdr<32, false>&); | |
541 | #endif | |
542 | ||
543 | #ifdef HAVE_TARGET_32_BIG | |
9b547ce6 | 544 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
545 | virtual Object* |
546 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
547 | const elfcpp::Ehdr<32, true>&); | |
548 | #endif | |
549 | ||
550 | #ifdef HAVE_TARGET_64_LITTLE | |
9b547ce6 | 551 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
552 | virtual Object* |
553 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
554 | const elfcpp::Ehdr<64, false>& ehdr); | |
555 | #endif | |
556 | ||
557 | #ifdef HAVE_TARGET_64_BIG | |
9b547ce6 | 558 | // Virtual functions which may be overridden by the child class. |
f733487b DK |
559 | virtual Object* |
560 | do_make_elf_object(const std::string& name, Input_file* input_file, | |
561 | off_t offset, const elfcpp::Ehdr<64, true>& ehdr); | |
562 | #endif | |
563 | ||
9b547ce6 | 564 | // Virtual functions which may be overridden by the child class. |
c0a62865 DK |
565 | virtual Output_section* |
566 | do_make_output_section(const char* name, elfcpp::Elf_Word type, | |
567 | elfcpp::Elf_Xword flags); | |
568 | ||
9b547ce6 | 569 | // Virtual function which may be overridden by the child class. |
20e6d0d6 DK |
570 | virtual bool |
571 | do_may_relax() const | |
572 | { return parameters->options().relax(); } | |
573 | ||
9b547ce6 | 574 | // Virtual function which may be overridden by the child class. |
20e6d0d6 | 575 | virtual bool |
f625ae50 | 576 | do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*) |
20e6d0d6 DK |
577 | { return false; } |
578 | ||
364c7fa5 ILT |
579 | // A function for targets to call. Return whether BYTES/LEN matches |
580 | // VIEW/VIEW_SIZE at OFFSET. | |
581 | bool | |
582 | match_view(const unsigned char* view, section_size_type view_size, | |
583 | section_offset_type offset, const char* bytes, size_t len) const; | |
584 | ||
585 | // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET | |
586 | // for LEN bytes. | |
587 | void | |
588 | set_view_to_nop(unsigned char* view, section_size_type view_size, | |
589 | section_offset_type offset, size_t len) const; | |
590 | ||
9b547ce6 | 591 | // This must be overridden by the child class if it has target-specific |
05a352e6 DK |
592 | // attributes subsection in the attribute section. |
593 | virtual int | |
594 | do_attribute_arg_type(int) const | |
595 | { gold_unreachable(); } | |
596 | ||
597 | // This may be overridden by the child class. | |
598 | virtual int | |
599 | do_attributes_order(int num) const | |
600 | { return num; } | |
601 | ||
0d31c79d DK |
602 | // This may be overridden by the child class. |
603 | virtual void | |
604 | do_select_as_default_target() | |
605 | { } | |
606 | ||
14bfc3f5 | 607 | private: |
f733487b | 608 | // The implementations of the four do_make_elf_object virtual functions are |
7296d933 | 609 | // almost identical except for their sizes and endianness. We use a template. |
f733487b DK |
610 | // for their implementations. |
611 | template<int size, bool big_endian> | |
612 | inline Object* | |
613 | do_make_elf_object_implementation(const std::string&, Input_file*, off_t, | |
614 | const elfcpp::Ehdr<size, big_endian>&); | |
615 | ||
14bfc3f5 ILT |
616 | Target(const Target&); |
617 | Target& operator=(const Target&); | |
618 | ||
75f65a3e ILT |
619 | // The target information. |
620 | const Target_info* pti_; | |
d5b40221 DK |
621 | // Processor-specific flags. |
622 | elfcpp::Elf_Word processor_specific_flags_; | |
623 | // Whether the processor-specific flags are set at least once. | |
624 | bool are_processor_specific_flags_set_; | |
bae7f79e ILT |
625 | }; |
626 | ||
14bfc3f5 ILT |
627 | // The abstract class for a specific size and endianness of target. |
628 | // Each actual target implementation class should derive from an | |
629 | // instantiation of Sized_target. | |
630 | ||
631 | template<int size, bool big_endian> | |
632 | class Sized_target : public Target | |
633 | { | |
634 | public: | |
635 | // Make a new symbol table entry for the target. This should be | |
636 | // overridden by a target which needs additional information in the | |
637 | // symbol table. This will only be called if has_make_symbol() | |
638 | // returns true. | |
639 | virtual Sized_symbol<size>* | |
14b31740 | 640 | make_symbol() const |
a3ad94ed | 641 | { gold_unreachable(); } |
14bfc3f5 ILT |
642 | |
643 | // Resolve a symbol for the target. This should be overridden by a | |
644 | // target which needs to take special action. TO is the | |
645 | // pre-existing symbol. SYM is the new symbol, seen in OBJECT. | |
14b31740 ILT |
646 | // VERSION is the version of SYM. This will only be called if |
647 | // has_resolve() returns true. | |
14bfc3f5 | 648 | virtual void |
14b31740 ILT |
649 | resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*, |
650 | const char*) | |
a3ad94ed | 651 | { gold_unreachable(); } |
14bfc3f5 | 652 | |
6d03d481 ST |
653 | // Process the relocs for a section, and record information of the |
654 | // mapping from source to destination sections. This mapping is later | |
655 | // used to determine unreferenced garbage sections. This procedure is | |
656 | // only called during garbage collection. | |
657 | virtual void | |
ad0f2072 ILT |
658 | gc_process_relocs(Symbol_table* symtab, |
659 | Layout* layout, | |
6fa2a40b | 660 | Sized_relobj_file<size, big_endian>* object, |
ad0f2072 ILT |
661 | unsigned int data_shndx, |
662 | unsigned int sh_type, | |
663 | const unsigned char* prelocs, | |
664 | size_t reloc_count, | |
665 | Output_section* output_section, | |
666 | bool needs_special_offset_handling, | |
667 | size_t local_symbol_count, | |
668 | const unsigned char* plocal_symbols) = 0; | |
6d03d481 | 669 | |
92e059d8 | 670 | // Scan the relocs for a section, and record any information |
ad0f2072 ILT |
671 | // required for the symbol. SYMTAB is the symbol table. OBJECT is |
672 | // the object in which the section appears. DATA_SHNDX is the | |
673 | // section index that these relocs apply to. SH_TYPE is the type of | |
674 | // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to | |
675 | // the relocation data. RELOC_COUNT is the number of relocs. | |
676 | // LOCAL_SYMBOL_COUNT is the number of local symbols. | |
677 | // OUTPUT_SECTION is the output section. | |
730cdc88 ILT |
678 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output |
679 | // sections are not mapped as usual. PLOCAL_SYMBOLS points to the | |
680 | // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of | |
681 | // pointers to the global symbol table from OBJECT. | |
61ba1cf9 | 682 | virtual void |
ad0f2072 | 683 | scan_relocs(Symbol_table* symtab, |
ead1e424 | 684 | Layout* layout, |
6fa2a40b | 685 | Sized_relobj_file<size, big_endian>* object, |
a3ad94ed | 686 | unsigned int data_shndx, |
92e059d8 ILT |
687 | unsigned int sh_type, |
688 | const unsigned char* prelocs, | |
689 | size_t reloc_count, | |
730cdc88 ILT |
690 | Output_section* output_section, |
691 | bool needs_special_offset_handling, | |
92e059d8 | 692 | size_t local_symbol_count, |
730cdc88 | 693 | const unsigned char* plocal_symbols) = 0; |
92e059d8 ILT |
694 | |
695 | // Relocate section data. SH_TYPE is the type of the relocation | |
696 | // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation | |
730cdc88 ILT |
697 | // information. RELOC_COUNT is the number of relocs. |
698 | // OUTPUT_SECTION is the output section. | |
699 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped | |
700 | // to correspond to the output section. VIEW is a view into the | |
701 | // output file holding the section contents, VIEW_ADDRESS is the | |
702 | // virtual address of the view, and VIEW_SIZE is the size of the | |
703 | // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx | |
704 | // parameters refer to the complete output section data, not just | |
705 | // the input section data. | |
92e059d8 ILT |
706 | virtual void |
707 | relocate_section(const Relocate_info<size, big_endian>*, | |
708 | unsigned int sh_type, | |
709 | const unsigned char* prelocs, | |
710 | size_t reloc_count, | |
730cdc88 ILT |
711 | Output_section* output_section, |
712 | bool needs_special_offset_handling, | |
92e059d8 ILT |
713 | unsigned char* view, |
714 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
364c7fa5 ILT |
715 | section_size_type view_size, |
716 | const Reloc_symbol_changes*) = 0; | |
61ba1cf9 | 717 | |
6a74a719 ILT |
718 | // Scan the relocs during a relocatable link. The parameters are |
719 | // like scan_relocs, with an additional Relocatable_relocs | |
720 | // parameter, used to record the disposition of the relocs. | |
721 | virtual void | |
ad0f2072 | 722 | scan_relocatable_relocs(Symbol_table* symtab, |
6a74a719 | 723 | Layout* layout, |
6fa2a40b | 724 | Sized_relobj_file<size, big_endian>* object, |
6a74a719 ILT |
725 | unsigned int data_shndx, |
726 | unsigned int sh_type, | |
727 | const unsigned char* prelocs, | |
728 | size_t reloc_count, | |
729 | Output_section* output_section, | |
730 | bool needs_special_offset_handling, | |
731 | size_t local_symbol_count, | |
732 | const unsigned char* plocal_symbols, | |
733 | Relocatable_relocs*) = 0; | |
734 | ||
735 | // Relocate a section during a relocatable link. The parameters are | |
736 | // like relocate_section, with additional parameters for the view of | |
737 | // the output reloc section. | |
738 | virtual void | |
739 | relocate_for_relocatable(const Relocate_info<size, big_endian>*, | |
740 | unsigned int sh_type, | |
741 | const unsigned char* prelocs, | |
742 | size_t reloc_count, | |
743 | Output_section* output_section, | |
744 | off_t offset_in_output_section, | |
745 | const Relocatable_relocs*, | |
746 | unsigned char* view, | |
747 | typename elfcpp::Elf_types<size>::Elf_Addr | |
748 | view_address, | |
749 | section_size_type view_size, | |
750 | unsigned char* reloc_view, | |
751 | section_size_type reloc_view_size) = 0; | |
5c388529 DK |
752 | |
753 | // Perform target-specific processing in a relocatable link. This is | |
754 | // only used if we use the relocation strategy RELOC_SPECIAL. | |
755 | // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation | |
756 | // section type. PRELOC_IN points to the original relocation. RELNUM is | |
757 | // the index number of the relocation in the relocation section. | |
758 | // OUTPUT_SECTION is the output section to which the relocation is applied. | |
759 | // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section | |
760 | // within the output section. VIEW points to the output view of the | |
761 | // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE | |
762 | // is the size of the output view and PRELOC_OUT points to the new | |
763 | // relocation in the output object. | |
764 | // | |
765 | // A target only needs to override this if the generic code in | |
766 | // target-reloc.h cannot handle some relocation types. | |
6a74a719 | 767 | |
5c388529 DK |
768 | virtual void |
769 | relocate_special_relocatable(const Relocate_info<size, big_endian>* | |
770 | /*relinfo */, | |
771 | unsigned int /* sh_type */, | |
772 | const unsigned char* /* preloc_in */, | |
773 | size_t /* relnum */, | |
774 | Output_section* /* output_section */, | |
775 | off_t /* offset_in_output_section */, | |
776 | unsigned char* /* view */, | |
777 | typename elfcpp::Elf_types<size>::Elf_Addr | |
778 | /* view_address */, | |
779 | section_size_type /* view_size */, | |
780 | unsigned char* /* preloc_out*/) | |
781 | { gold_unreachable(); } | |
782 | ||
0e70b911 CC |
783 | // Return the number of entries in the GOT. This is only used for |
784 | // laying out the incremental link info sections. A target needs | |
785 | // to implement this to support incremental linking. | |
786 | ||
787 | virtual unsigned int | |
788 | got_entry_count() const | |
789 | { gold_unreachable(); } | |
790 | ||
791 | // Return the number of entries in the PLT. This is only used for | |
792 | // laying out the incremental link info sections. A target needs | |
793 | // to implement this to support incremental linking. | |
794 | ||
795 | virtual unsigned int | |
796 | plt_entry_count() const | |
797 | { gold_unreachable(); } | |
798 | ||
799 | // Return the offset of the first non-reserved PLT entry. This is | |
800 | // only used for laying out the incremental link info sections. | |
801 | // A target needs to implement this to support incremental linking. | |
802 | ||
803 | virtual unsigned int | |
804 | first_plt_entry_offset() const | |
805 | { gold_unreachable(); } | |
806 | ||
807 | // Return the size of each PLT entry. This is only used for | |
808 | // laying out the incremental link info sections. A target needs | |
809 | // to implement this to support incremental linking. | |
810 | ||
811 | virtual unsigned int | |
812 | plt_entry_size() const | |
813 | { gold_unreachable(); } | |
814 | ||
4829d394 CC |
815 | // Create the GOT and PLT sections for an incremental update. |
816 | // A target needs to implement this to support incremental linking. | |
817 | ||
818 | virtual Output_data_got<size, big_endian>* | |
819 | init_got_plt_for_update(Symbol_table*, | |
820 | Layout*, | |
821 | unsigned int /* got_count */, | |
822 | unsigned int /* plt_count */) | |
823 | { gold_unreachable(); } | |
824 | ||
6fa2a40b CC |
825 | // Reserve a GOT entry for a local symbol, and regenerate any |
826 | // necessary dynamic relocations. | |
827 | virtual void | |
828 | reserve_local_got_entry(unsigned int /* got_index */, | |
829 | Sized_relobj<size, big_endian>* /* obj */, | |
830 | unsigned int /* r_sym */, | |
831 | unsigned int /* got_type */) | |
832 | { gold_unreachable(); } | |
833 | ||
834 | // Reserve a GOT entry for a global symbol, and regenerate any | |
835 | // necessary dynamic relocations. | |
836 | virtual void | |
837 | reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */, | |
838 | unsigned int /* got_type */) | |
839 | { gold_unreachable(); } | |
840 | ||
4829d394 CC |
841 | // Register an existing PLT entry for a global symbol. |
842 | // A target needs to implement this to support incremental linking. | |
843 | ||
844 | virtual void | |
845 | register_global_plt_entry(unsigned int /* plt_index */, | |
846 | Symbol*) | |
847 | { gold_unreachable(); } | |
848 | ||
26d3c67d CC |
849 | // Force a COPY relocation for a given symbol. |
850 | // A target needs to implement this to support incremental linking. | |
851 | ||
852 | virtual void | |
853 | emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t) | |
854 | { gold_unreachable(); } | |
855 | ||
94a3fc8b CC |
856 | // Apply an incremental relocation. |
857 | ||
858 | virtual void | |
859 | apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */, | |
860 | typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */, | |
861 | unsigned int /* r_type */, | |
862 | typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */, | |
863 | const Symbol* /* gsym */, | |
864 | unsigned char* /* view */, | |
865 | typename elfcpp::Elf_types<size>::Elf_Addr /* address */, | |
866 | section_size_type /* view_size */) | |
867 | { gold_unreachable(); } | |
868 | ||
14bfc3f5 | 869 | protected: |
75f65a3e ILT |
870 | Sized_target(const Target::Target_info* pti) |
871 | : Target(pti) | |
872 | { | |
a3ad94ed ILT |
873 | gold_assert(pti->size == size); |
874 | gold_assert(pti->is_big_endian ? big_endian : !big_endian); | |
75f65a3e | 875 | } |
14bfc3f5 | 876 | }; |
bae7f79e ILT |
877 | |
878 | } // End namespace gold. | |
879 | ||
880 | #endif // !defined(GOLD_TARGET_H) |