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