* gas/mmix/err-fb-2.s: New test.
[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
67181c72
ILT
259 // Return the PLT address to use for a global symbol. This is used
260 // for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative
261 // to this PLT address.
262 uint64_t
263 plt_address_for_global(const Symbol* sym) const
264 { return this->do_plt_address_for_global(sym); }
265
266 // Return the PLT address to use for a local symbol. This is used
267 // for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative
268 // to this PLT address.
269 uint64_t
270 plt_address_for_local(const Relobj* object, unsigned int symndx) const
271 { return this->do_plt_address_for_local(object, symndx); }
7223e9ca 272
b3ce541e
ILT
273 // Return whether this target can use relocation types to determine
274 // if a function's address is taken.
275 bool
276 can_check_for_function_pointers() const
277 { return this->do_can_check_for_function_pointers(); }
278
279 // Return whether a relocation to a merged section can be processed
280 // to retrieve the contents.
281 bool
282 can_icf_inline_merge_sections () const
283 { return this->pti_->can_icf_inline_merge_sections; }
284
285 // Whether a section called SECTION_NAME may have function pointers to
286 // sections not eligible for safe ICF folding.
287 virtual bool
288 section_may_have_icf_unsafe_pointers(const char* section_name) const
289 { return this->do_section_may_have_icf_unsafe_pointers(section_name); }
290
02d7cd44
ILT
291 // Return the base to use for the PC value in an FDE when it is
292 // encoded using DW_EH_PE_datarel. This does not appear to be
293 // documented anywhere, but it is target specific. Any use of
294 // DW_EH_PE_datarel in gcc requires defining a special macro
295 // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value.
296 uint64_t
297 ehframe_datarel_base() const
298 { return this->do_ehframe_datarel_base(); }
299
b6848d3c
ILT
300 // Return true if a reference to SYM from a reloc of type R_TYPE
301 // means that the current function may call an object compiled
302 // without -fsplit-stack. SYM is known to be defined in an object
303 // compiled without -fsplit-stack.
304 bool
305 is_call_to_non_split(const Symbol* sym, unsigned int r_type) const
306 { return this->do_is_call_to_non_split(sym, r_type); }
307
364c7fa5
ILT
308 // A function starts at OFFSET in section SHNDX in OBJECT. That
309 // function was compiled with -fsplit-stack, but it refers to a
310 // function which was compiled without -fsplit-stack. VIEW is a
311 // modifiable view of the section; VIEW_SIZE is the size of the
312 // view. The target has to adjust the function so that it allocates
313 // enough stack.
314 void
315 calls_non_split(Relobj* object, unsigned int shndx,
316 section_offset_type fnoffset, section_size_type fnsize,
317 unsigned char* view, section_size_type view_size,
318 std::string* from, std::string* to) const
319 {
320 this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size,
321 from, to);
322 }
323
f733487b
DK
324 // Make an ELF object.
325 template<int size, bool big_endian>
326 Object*
327 make_elf_object(const std::string& name, Input_file* input_file,
328 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
329 { return this->do_make_elf_object(name, input_file, offset, ehdr); }
330
c0a62865
DK
331 // Make an output section.
332 Output_section*
333 make_output_section(const char* name, elfcpp::Elf_Word type,
334 elfcpp::Elf_Xword flags)
335 { return this->do_make_output_section(name, type, flags); }
336
20e6d0d6
DK
337 // Return true if target wants to perform relaxation.
338 bool
339 may_relax() const
340 {
341 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
342 if (is_debugging_enabled(DEBUG_RELAXATION))
343 return true;
344
345 return this->do_may_relax();
346 }
347
348 // Perform a relaxation pass. Return true if layout may be changed.
349 bool
c0a62865 350 relax(int pass, const Input_objects* input_objects, Symbol_table* symtab,
f625ae50 351 Layout* layout, const Task* task)
20e6d0d6
DK
352 {
353 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
354 if (is_debugging_enabled(DEBUG_RELAXATION))
355 return pass < 2;
356
f625ae50 357 return this->do_relax(pass, input_objects, symtab, layout, task);
2e702c99 358 }
20e6d0d6 359
05a352e6
DK
360 // Return the target-specific name of attributes section. This is
361 // NULL if a target does not use attributes section or if it uses
362 // the default section name ".gnu.attributes".
363 const char*
364 attributes_section() const
365 { return this->pti_->attributes_section; }
366
367 // Return the vendor name of vendor attributes.
368 const char*
369 attributes_vendor() const
370 { return this->pti_->attributes_vendor; }
371
372 // Whether a section called NAME is an attribute section.
373 bool
374 is_attributes_section(const char* name) const
375 {
376 return ((this->pti_->attributes_section != NULL
377 && strcmp(name, this->pti_->attributes_section) == 0)
2e702c99 378 || strcmp(name, ".gnu.attributes") == 0);
05a352e6
DK
379 }
380
381 // Return a bit mask of argument types for attribute with TAG.
382 int
383 attribute_arg_type(int tag) const
384 { return this->do_attribute_arg_type(tag); }
385
386 // Return the attribute tag of the position NUM in the list of fixed
387 // attributes. Normally there is no reordering and
388 // attributes_order(NUM) == NUM.
389 int
390 attributes_order(int num) const
391 { return this->do_attributes_order(num); }
392
0d31c79d
DK
393 // When a target is selected as the default target, we call this method,
394 // which may be used for expensive, target-specific initialization.
395 void
396 select_as_default_target()
2e702c99 397 { this->do_select_as_default_target(); }
0d31c79d 398
200b2bb9
ILT
399 // Return the value to store in the EI_OSABI field in the ELF
400 // header.
401 elfcpp::ELFOSABI
402 osabi() const
403 { return this->osabi_; }
404
405 // Set the value to store in the EI_OSABI field in the ELF header.
406 void
407 set_osabi(elfcpp::ELFOSABI osabi)
408 { this->osabi_ = osabi; }
409
647f1574
DK
410 // Define target-specific standard symbols.
411 void
412 define_standard_symbols(Symbol_table* symtab, Layout* layout)
413 { this->do_define_standard_symbols(symtab, layout); }
414
14bfc3f5 415 protected:
75f65a3e
ILT
416 // This struct holds the constant information for a child class. We
417 // use a struct to avoid the overhead of virtual function calls for
418 // simple information.
419 struct Target_info
420 {
421 // Address size (32 or 64).
422 int size;
423 // Whether the target is big endian.
424 bool is_big_endian;
61ba1cf9
ILT
425 // The code to store in the e_machine field of the ELF header.
426 elfcpp::EM machine_code;
75f65a3e
ILT
427 // Whether this target has a specific make_symbol function.
428 bool has_make_symbol;
429 // Whether this target has a specific resolve function.
430 bool has_resolve;
c51e6221
ILT
431 // Whether this target has a specific code fill function.
432 bool has_code_fill;
35cdfc9a
ILT
433 // Whether an object file with no .note.GNU-stack sections implies
434 // that the stack should be executable.
435 bool is_default_stack_executable;
b3ce541e
ILT
436 // Whether a relocation to a merged section can be processed to
437 // retrieve the contents.
438 bool can_icf_inline_merge_sections;
0864d551
ILT
439 // Prefix character to strip when checking for wrapping.
440 char wrap_char;
dbe717ef
ILT
441 // The default dynamic linker name.
442 const char* dynamic_linker;
75f65a3e 443 // The default text segment address.
0c5e9c22 444 uint64_t default_text_segment_address;
75f65a3e
ILT
445 // The ABI specified page size.
446 uint64_t abi_pagesize;
447 // The common page size used by actual implementations.
448 uint64_t common_pagesize;
2e702c99
RM
449 // Whether PF_X segments must contain nothing but the contents of
450 // SHF_EXECINSTR sections (no non-executable data, no headers).
451 bool isolate_execinstr;
452 // If nonzero, distance from the text segment to the read-only segment.
453 uint64_t rosegment_gap;
8a5e3e08
ILT
454 // The special section index for small common symbols; SHN_UNDEF
455 // if none.
456 elfcpp::Elf_Half small_common_shndx;
457 // The special section index for large common symbols; SHN_UNDEF
458 // if none.
459 elfcpp::Elf_Half large_common_shndx;
460 // Section flags for small common section.
461 elfcpp::Elf_Xword small_common_section_flags;
462 // Section flags for large common section.
463 elfcpp::Elf_Xword large_common_section_flags;
05a352e6
DK
464 // Name of attributes section if it is not ".gnu.attributes".
465 const char* attributes_section;
466 // Vendor name of vendor attributes.
467 const char* attributes_vendor;
75f65a3e
ILT
468 };
469
470 Target(const Target_info* pti)
d5b40221 471 : pti_(pti), processor_specific_flags_(0),
200b2bb9 472 are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE)
14bfc3f5
ILT
473 { }
474
8a5e3e08
ILT
475 // Virtual function which may be implemented by the child class.
476 virtual void
477 do_new_output_section(Output_section*) const
478 { }
479
5a6f7e2d
ILT
480 // Virtual function which may be implemented by the child class.
481 virtual void
f59f41f3 482 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*)
5a6f7e2d
ILT
483 { }
484
ab5c9e90
ILT
485 // Virtual function which may be implemented by the child class.
486 virtual uint64_t
487 do_dynsym_value(const Symbol*) const
488 { gold_unreachable(); }
489
c51e6221
ILT
490 // Virtual function which must be implemented by the child class if
491 // needed.
492 virtual std::string
8851ecca 493 do_code_fill(section_size_type) const
c51e6221
ILT
494 { gold_unreachable(); }
495
9a2d6984
ILT
496 // Virtual function which may be implemented by the child class.
497 virtual bool
9c2d0ef9 498 do_is_defined_by_abi(const Symbol*) const
9a2d6984
ILT
499 { return false; }
500
36959681
ILT
501 // Adjust the output file header before it is written out. VIEW
502 // points to the header in external form. LEN is the length, and
503 // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
200b2bb9
ILT
504 // By default, we set the EI_OSABI field if requested (in
505 // Sized_target).
36959681 506 virtual void
200b2bb9 507 do_adjust_elf_header(unsigned char*, int) const = 0;
36959681 508
9b547ce6 509 // Virtual function which may be overridden by the child class.
bb04269c
DK
510 virtual bool
511 do_is_local_label_name(const char*) const;
512
e291e7b9
ILT
513 // Virtual function that must be overridden by a target which uses
514 // target specific relocations.
515 virtual unsigned int
516 do_reloc_symbol_index(void*, unsigned int) const
517 { gold_unreachable(); }
518
9b547ce6 519 // Virtual function that must be overridden by a target which uses
e291e7b9
ILT
520 // target specific relocations.
521 virtual uint64_t
522 do_reloc_addend(void*, unsigned int, uint64_t) const
523 { gold_unreachable(); }
524
7223e9ca
ILT
525 // Virtual functions that must be overridden by a target that uses
526 // STT_GNU_IFUNC symbols.
67181c72
ILT
527 virtual uint64_t
528 do_plt_address_for_global(const Symbol*) const
7223e9ca
ILT
529 { gold_unreachable(); }
530
67181c72
ILT
531 virtual uint64_t
532 do_plt_address_for_local(const Relobj*, unsigned int) const
7223e9ca
ILT
533 { gold_unreachable(); }
534
b3ce541e
ILT
535 // Virtual function which may be overriden by the child class.
536 virtual bool
537 do_can_check_for_function_pointers() const
538 { return false; }
539
540 // Virtual function which may be overridden by the child class. We
541 // recognize some default sections for which we don't care whether
542 // they have function pointers.
543 virtual bool
544 do_section_may_have_icf_unsafe_pointers(const char* section_name) const
545 {
546 // We recognize sections for normal vtables, construction vtables and
547 // EH frames.
548 return (!is_prefix_of(".rodata._ZTV", section_name)
549 && !is_prefix_of(".data.rel.ro._ZTV", section_name)
550 && !is_prefix_of(".rodata._ZTC", section_name)
551 && !is_prefix_of(".data.rel.ro._ZTC", section_name)
552 && !is_prefix_of(".eh_frame", section_name));
553 }
554
02d7cd44
ILT
555 virtual uint64_t
556 do_ehframe_datarel_base() const
557 { gold_unreachable(); }
558
b6848d3c
ILT
559 // Virtual function which may be overridden by the child class. The
560 // default implementation is that any function not defined by the
561 // ABI is a call to a non-split function.
562 virtual bool
563 do_is_call_to_non_split(const Symbol* sym, unsigned int) const;
564
364c7fa5
ILT
565 // Virtual function which may be overridden by the child class.
566 virtual void
567 do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
568 section_size_type, unsigned char*, section_size_type,
569 std::string*, std::string*) const;
570
f733487b 571 // make_elf_object hooks. There are four versions of these for
7296d933 572 // different address sizes and endianness.
364c7fa5 573
d5b40221
DK
574 // Set processor specific flags.
575 void
576 set_processor_specific_flags(elfcpp::Elf_Word flags)
577 {
578 this->processor_specific_flags_ = flags;
579 this->are_processor_specific_flags_set_ = true;
580 }
2e702c99 581
f733487b 582#ifdef HAVE_TARGET_32_LITTLE
9b547ce6 583 // Virtual functions which may be overridden by the child class.
f733487b
DK
584 virtual Object*
585 do_make_elf_object(const std::string&, Input_file*, off_t,
586 const elfcpp::Ehdr<32, false>&);
587#endif
588
589#ifdef HAVE_TARGET_32_BIG
9b547ce6 590 // Virtual functions which may be overridden by the child class.
f733487b
DK
591 virtual Object*
592 do_make_elf_object(const std::string&, Input_file*, off_t,
593 const elfcpp::Ehdr<32, true>&);
594#endif
595
596#ifdef HAVE_TARGET_64_LITTLE
9b547ce6 597 // Virtual functions which may be overridden by the child class.
f733487b
DK
598 virtual Object*
599 do_make_elf_object(const std::string&, Input_file*, off_t,
600 const elfcpp::Ehdr<64, false>& ehdr);
601#endif
602
603#ifdef HAVE_TARGET_64_BIG
9b547ce6 604 // Virtual functions which may be overridden by the child class.
f733487b
DK
605 virtual Object*
606 do_make_elf_object(const std::string& name, Input_file* input_file,
607 off_t offset, const elfcpp::Ehdr<64, true>& ehdr);
608#endif
609
9b547ce6 610 // Virtual functions which may be overridden by the child class.
c0a62865
DK
611 virtual Output_section*
612 do_make_output_section(const char* name, elfcpp::Elf_Word type,
613 elfcpp::Elf_Xword flags);
614
9b547ce6 615 // Virtual function which may be overridden by the child class.
20e6d0d6
DK
616 virtual bool
617 do_may_relax() const
618 { return parameters->options().relax(); }
619
9b547ce6 620 // Virtual function which may be overridden by the child class.
20e6d0d6 621 virtual bool
f625ae50 622 do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*)
20e6d0d6
DK
623 { return false; }
624
364c7fa5
ILT
625 // A function for targets to call. Return whether BYTES/LEN matches
626 // VIEW/VIEW_SIZE at OFFSET.
627 bool
628 match_view(const unsigned char* view, section_size_type view_size,
629 section_offset_type offset, const char* bytes, size_t len) const;
630
631 // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
632 // for LEN bytes.
633 void
634 set_view_to_nop(unsigned char* view, section_size_type view_size,
635 section_offset_type offset, size_t len) const;
636
9b547ce6 637 // This must be overridden by the child class if it has target-specific
2e702c99 638 // attributes subsection in the attribute section.
05a352e6
DK
639 virtual int
640 do_attribute_arg_type(int) const
641 { gold_unreachable(); }
642
643 // This may be overridden by the child class.
644 virtual int
645 do_attributes_order(int num) const
646 { return num; }
647
0d31c79d
DK
648 // This may be overridden by the child class.
649 virtual void
650 do_select_as_default_target()
651 { }
652
647f1574
DK
653 // This may be overridden by the child class.
654 virtual void
655 do_define_standard_symbols(Symbol_table*, Layout*)
656 { }
657
14bfc3f5 658 private:
f733487b 659 // The implementations of the four do_make_elf_object virtual functions are
7296d933 660 // almost identical except for their sizes and endianness. We use a template.
f733487b
DK
661 // for their implementations.
662 template<int size, bool big_endian>
663 inline Object*
664 do_make_elf_object_implementation(const std::string&, Input_file*, off_t,
665 const elfcpp::Ehdr<size, big_endian>&);
666
14bfc3f5
ILT
667 Target(const Target&);
668 Target& operator=(const Target&);
669
75f65a3e
ILT
670 // The target information.
671 const Target_info* pti_;
d5b40221
DK
672 // Processor-specific flags.
673 elfcpp::Elf_Word processor_specific_flags_;
674 // Whether the processor-specific flags are set at least once.
675 bool are_processor_specific_flags_set_;
200b2bb9
ILT
676 // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
677 // the ELF header. This is handled at this level because it is
678 // OS-specific rather than processor-specific.
679 elfcpp::ELFOSABI osabi_;
bae7f79e
ILT
680};
681
14bfc3f5
ILT
682// The abstract class for a specific size and endianness of target.
683// Each actual target implementation class should derive from an
684// instantiation of Sized_target.
685
686template<int size, bool big_endian>
687class Sized_target : public Target
688{
689 public:
690 // Make a new symbol table entry for the target. This should be
691 // overridden by a target which needs additional information in the
692 // symbol table. This will only be called if has_make_symbol()
693 // returns true.
694 virtual Sized_symbol<size>*
14b31740 695 make_symbol() const
a3ad94ed 696 { gold_unreachable(); }
14bfc3f5
ILT
697
698 // Resolve a symbol for the target. This should be overridden by a
699 // target which needs to take special action. TO is the
700 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
14b31740
ILT
701 // VERSION is the version of SYM. This will only be called if
702 // has_resolve() returns true.
14bfc3f5 703 virtual void
14b31740
ILT
704 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
705 const char*)
a3ad94ed 706 { gold_unreachable(); }
14bfc3f5 707
6d03d481
ST
708 // Process the relocs for a section, and record information of the
709 // mapping from source to destination sections. This mapping is later
710 // used to determine unreferenced garbage sections. This procedure is
711 // only called during garbage collection.
712 virtual void
ad0f2072
ILT
713 gc_process_relocs(Symbol_table* symtab,
714 Layout* layout,
6fa2a40b 715 Sized_relobj_file<size, big_endian>* object,
ad0f2072
ILT
716 unsigned int data_shndx,
717 unsigned int sh_type,
718 const unsigned char* prelocs,
719 size_t reloc_count,
720 Output_section* output_section,
721 bool needs_special_offset_handling,
722 size_t local_symbol_count,
723 const unsigned char* plocal_symbols) = 0;
6d03d481 724
92e059d8 725 // Scan the relocs for a section, and record any information
ad0f2072
ILT
726 // required for the symbol. SYMTAB is the symbol table. OBJECT is
727 // the object in which the section appears. DATA_SHNDX is the
728 // section index that these relocs apply to. SH_TYPE is the type of
729 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
730 // the relocation data. RELOC_COUNT is the number of relocs.
731 // LOCAL_SYMBOL_COUNT is the number of local symbols.
732 // OUTPUT_SECTION is the output section.
730cdc88
ILT
733 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
734 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
735 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
736 // pointers to the global symbol table from OBJECT.
61ba1cf9 737 virtual void
ad0f2072 738 scan_relocs(Symbol_table* symtab,
ead1e424 739 Layout* layout,
6fa2a40b 740 Sized_relobj_file<size, big_endian>* object,
a3ad94ed 741 unsigned int data_shndx,
92e059d8
ILT
742 unsigned int sh_type,
743 const unsigned char* prelocs,
744 size_t reloc_count,
730cdc88
ILT
745 Output_section* output_section,
746 bool needs_special_offset_handling,
92e059d8 747 size_t local_symbol_count,
730cdc88 748 const unsigned char* plocal_symbols) = 0;
92e059d8
ILT
749
750 // Relocate section data. SH_TYPE is the type of the relocation
751 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
730cdc88
ILT
752 // information. RELOC_COUNT is the number of relocs.
753 // OUTPUT_SECTION is the output section.
754 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
755 // to correspond to the output section. VIEW is a view into the
756 // output file holding the section contents, VIEW_ADDRESS is the
757 // virtual address of the view, and VIEW_SIZE is the size of the
758 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
759 // parameters refer to the complete output section data, not just
760 // the input section data.
92e059d8
ILT
761 virtual void
762 relocate_section(const Relocate_info<size, big_endian>*,
763 unsigned int sh_type,
764 const unsigned char* prelocs,
765 size_t reloc_count,
730cdc88
ILT
766 Output_section* output_section,
767 bool needs_special_offset_handling,
92e059d8
ILT
768 unsigned char* view,
769 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
364c7fa5
ILT
770 section_size_type view_size,
771 const Reloc_symbol_changes*) = 0;
61ba1cf9 772
6a74a719
ILT
773 // Scan the relocs during a relocatable link. The parameters are
774 // like scan_relocs, with an additional Relocatable_relocs
775 // parameter, used to record the disposition of the relocs.
776 virtual void
ad0f2072 777 scan_relocatable_relocs(Symbol_table* symtab,
6a74a719 778 Layout* layout,
6fa2a40b 779 Sized_relobj_file<size, big_endian>* object,
6a74a719
ILT
780 unsigned int data_shndx,
781 unsigned int sh_type,
782 const unsigned char* prelocs,
783 size_t reloc_count,
784 Output_section* output_section,
785 bool needs_special_offset_handling,
786 size_t local_symbol_count,
787 const unsigned char* plocal_symbols,
788 Relocatable_relocs*) = 0;
789
790 // Relocate a section during a relocatable link. The parameters are
791 // like relocate_section, with additional parameters for the view of
792 // the output reloc section.
793 virtual void
794 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
795 unsigned int sh_type,
796 const unsigned char* prelocs,
797 size_t reloc_count,
798 Output_section* output_section,
799 off_t offset_in_output_section,
800 const Relocatable_relocs*,
801 unsigned char* view,
802 typename elfcpp::Elf_types<size>::Elf_Addr
803 view_address,
804 section_size_type view_size,
805 unsigned char* reloc_view,
806 section_size_type reloc_view_size) = 0;
2e702c99 807
5c388529
DK
808 // Perform target-specific processing in a relocatable link. This is
809 // only used if we use the relocation strategy RELOC_SPECIAL.
810 // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
811 // section type. PRELOC_IN points to the original relocation. RELNUM is
812 // the index number of the relocation in the relocation section.
813 // OUTPUT_SECTION is the output section to which the relocation is applied.
814 // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
815 // within the output section. VIEW points to the output view of the
816 // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
817 // is the size of the output view and PRELOC_OUT points to the new
818 // relocation in the output object.
819 //
820 // A target only needs to override this if the generic code in
821 // target-reloc.h cannot handle some relocation types.
6a74a719 822
5c388529
DK
823 virtual void
824 relocate_special_relocatable(const Relocate_info<size, big_endian>*
825 /*relinfo */,
826 unsigned int /* sh_type */,
827 const unsigned char* /* preloc_in */,
828 size_t /* relnum */,
829 Output_section* /* output_section */,
830 off_t /* offset_in_output_section */,
831 unsigned char* /* view */,
832 typename elfcpp::Elf_types<size>::Elf_Addr
833 /* view_address */,
834 section_size_type /* view_size */,
835 unsigned char* /* preloc_out*/)
836 { gold_unreachable(); }
2e702c99 837
0e70b911
CC
838 // Return the number of entries in the GOT. This is only used for
839 // laying out the incremental link info sections. A target needs
840 // to implement this to support incremental linking.
841
842 virtual unsigned int
843 got_entry_count() const
844 { gold_unreachable(); }
845
846 // Return the number of entries in the PLT. This is only used for
847 // laying out the incremental link info sections. A target needs
848 // to implement this to support incremental linking.
849
850 virtual unsigned int
851 plt_entry_count() const
852 { gold_unreachable(); }
853
854 // Return the offset of the first non-reserved PLT entry. This is
855 // only used for laying out the incremental link info sections.
856 // A target needs to implement this to support incremental linking.
857
858 virtual unsigned int
859 first_plt_entry_offset() const
860 { gold_unreachable(); }
861
862 // Return the size of each PLT entry. This is only used for
863 // laying out the incremental link info sections. A target needs
864 // to implement this to support incremental linking.
865
866 virtual unsigned int
867 plt_entry_size() const
868 { gold_unreachable(); }
869
4829d394
CC
870 // Create the GOT and PLT sections for an incremental update.
871 // A target needs to implement this to support incremental linking.
872
dd74ae06 873 virtual Output_data_got_base*
4829d394
CC
874 init_got_plt_for_update(Symbol_table*,
875 Layout*,
876 unsigned int /* got_count */,
877 unsigned int /* plt_count */)
878 { gold_unreachable(); }
879
6fa2a40b
CC
880 // Reserve a GOT entry for a local symbol, and regenerate any
881 // necessary dynamic relocations.
882 virtual void
883 reserve_local_got_entry(unsigned int /* got_index */,
884 Sized_relobj<size, big_endian>* /* obj */,
885 unsigned int /* r_sym */,
886 unsigned int /* got_type */)
887 { gold_unreachable(); }
888
889 // Reserve a GOT entry for a global symbol, and regenerate any
890 // necessary dynamic relocations.
891 virtual void
892 reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */,
893 unsigned int /* got_type */)
894 { gold_unreachable(); }
895
4829d394
CC
896 // Register an existing PLT entry for a global symbol.
897 // A target needs to implement this to support incremental linking.
898
899 virtual void
67181c72
ILT
900 register_global_plt_entry(Symbol_table*, Layout*,
901 unsigned int /* plt_index */,
4829d394
CC
902 Symbol*)
903 { gold_unreachable(); }
904
26d3c67d
CC
905 // Force a COPY relocation for a given symbol.
906 // A target needs to implement this to support incremental linking.
907
908 virtual void
909 emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t)
910 { gold_unreachable(); }
911
94a3fc8b
CC
912 // Apply an incremental relocation.
913
914 virtual void
915 apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */,
916 typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */,
917 unsigned int /* r_type */,
918 typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */,
919 const Symbol* /* gsym */,
920 unsigned char* /* view */,
921 typename elfcpp::Elf_types<size>::Elf_Addr /* address */,
922 section_size_type /* view_size */)
923 { gold_unreachable(); }
924
14bfc3f5 925 protected:
75f65a3e
ILT
926 Sized_target(const Target::Target_info* pti)
927 : Target(pti)
928 {
a3ad94ed
ILT
929 gold_assert(pti->size == size);
930 gold_assert(pti->is_big_endian ? big_endian : !big_endian);
75f65a3e 931 }
200b2bb9
ILT
932
933 // Set the EI_OSABI field if requested.
934 virtual void
935 do_adjust_elf_header(unsigned char*, int) const;
14bfc3f5 936};
bae7f79e
ILT
937
938} // End namespace gold.
939
940#endif // !defined(GOLD_TARGET_H)
This page took 0.354864 seconds and 4 git commands to generate.