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