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