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