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