1
// target.h -- target support for gold -*- C++ -*-
3
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
4
// Free Software Foundation, Inc.
5
// Written by Ian Lance Taylor <iant@google.com>.
7
// This file is part of gold.
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.
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.
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.
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.
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.
39
#include "parameters.h"
47
template<int size, bool big_endian>
49
template<int size, bool big_endian>
50
class Sized_relobj_file;
51
class Relocatable_relocs;
52
template<int size, bool big_endian>
54
class Reloc_symbol_changes;
60
class Output_data_got_base;
64
struct Symbol_location;
66
// The abstract class for target specific handling.
74
// Return the bit size that this target implements. This should
78
{ return this->pti_->size; }
80
// Return whether this target is big-endian.
83
{ return this->pti_->is_big_endian; }
85
// Machine code to store in e_machine field of ELF header.
88
{ return this->pti_->machine_code; }
90
// Processor specific flags to store in e_flags field of ELF header.
92
processor_specific_flags() const
93
{ return this->processor_specific_flags_; }
95
// Whether processor specific flags are set at least once.
97
are_processor_specific_flags_set() const
98
{ return this->are_processor_specific_flags_set_; }
100
// Whether this target has a specific make_symbol function.
102
has_make_symbol() const
103
{ return this->pti_->has_make_symbol; }
105
// Whether this target has a specific resolve function.
108
{ return this->pti_->has_resolve; }
110
// Whether this target has a specific code fill function.
112
has_code_fill() const
113
{ return this->pti_->has_code_fill; }
115
// Return the default name of the dynamic linker.
117
dynamic_linker() const
118
{ return this->pti_->dynamic_linker; }
120
// Return the default address to use for the text segment.
122
default_text_segment_address() const
123
{ return this->pti_->default_text_segment_address; }
125
// Return the ABI specified page size.
129
if (parameters->options().max_page_size() > 0)
130
return parameters->options().max_page_size();
132
return this->pti_->abi_pagesize;
135
// Return the common page size used on actual systems.
137
common_pagesize() const
139
if (parameters->options().common_page_size() > 0)
140
return std::min(parameters->options().common_page_size(),
141
this->abi_pagesize());
143
return std::min(this->pti_->common_pagesize,
144
this->abi_pagesize());
147
// Return whether PF_X segments must contain nothing but the contents of
148
// SHF_EXECINSTR sections (no non-executable data, no headers).
150
isolate_execinstr() const
151
{ return this->pti_->isolate_execinstr; }
154
rosegment_gap() const
155
{ return this->pti_->rosegment_gap; }
157
// If we see some object files with .note.GNU-stack sections, and
158
// some objects files without them, this returns whether we should
159
// consider the object files without them to imply that the stack
160
// should be executable.
162
is_default_stack_executable() const
163
{ return this->pti_->is_default_stack_executable; }
165
// Return a character which may appear as a prefix for a wrap
166
// symbol. If this character appears, we strip it when checking for
167
// wrapping and add it back when forming the final symbol name.
168
// This should be '\0' if not special prefix is required, which is
172
{ return this->pti_->wrap_char; }
174
// Return the special section index which indicates a small common
175
// symbol. This will return SHN_UNDEF if there are no small common
178
small_common_shndx() const
179
{ return this->pti_->small_common_shndx; }
181
// Return values to add to the section flags for the section holding
182
// small common symbols.
184
small_common_section_flags() const
186
gold_assert(this->pti_->small_common_shndx != elfcpp::SHN_UNDEF);
187
return this->pti_->small_common_section_flags;
190
// Return the special section index which indicates a large common
191
// symbol. This will return SHN_UNDEF if there are no large common
194
large_common_shndx() const
195
{ return this->pti_->large_common_shndx; }
197
// Return values to add to the section flags for the section holding
198
// large common symbols.
200
large_common_section_flags() const
202
gold_assert(this->pti_->large_common_shndx != elfcpp::SHN_UNDEF);
203
return this->pti_->large_common_section_flags;
206
// This hook is called when an output section is created.
208
new_output_section(Output_section* os) const
209
{ this->do_new_output_section(os); }
211
// This is called to tell the target to complete any sections it is
212
// handling. After this all sections must have their final size.
214
finalize_sections(Layout* layout, const Input_objects* input_objects,
215
Symbol_table* symtab)
216
{ return this->do_finalize_sections(layout, input_objects, symtab); }
218
// Return the value to use for a global symbol which needs a special
219
// value in the dynamic symbol table. This will only be called if
220
// the backend first calls symbol->set_needs_dynsym_value().
222
dynsym_value(const Symbol* sym) const
223
{ return this->do_dynsym_value(sym); }
225
// Return a string to use to fill out a code section. This is
226
// basically one or more NOPS which must fill out the specified
229
code_fill(section_size_type length) const
230
{ return this->do_code_fill(length); }
232
// Return whether SYM is known to be defined by the ABI. This is
233
// used to avoid inappropriate warnings about undefined symbols.
235
is_defined_by_abi(const Symbol* sym) const
236
{ return this->do_is_defined_by_abi(sym); }
238
// Adjust the output file header before it is written out. VIEW
239
// points to the header in external form. LEN is the length.
241
adjust_elf_header(unsigned char* view, int len) const
242
{ return this->do_adjust_elf_header(view, len); }
244
// Return address and size to plug into eh_frame FDEs associated with a PLT.
246
plt_fde_location(const Output_data* plt, unsigned char* oview,
247
uint64_t* address, off_t* len) const
248
{ return this->do_plt_fde_location(plt, oview, address, len); }
250
// Return whether NAME is a local label name. This is used to implement the
251
// --discard-locals options.
253
is_local_label_name(const char* name) const
254
{ return this->do_is_local_label_name(name); }
256
// Get the symbol index to use for a target specific reloc.
258
reloc_symbol_index(void* arg, unsigned int type) const
259
{ return this->do_reloc_symbol_index(arg, type); }
261
// Get the addend to use for a target specific reloc.
263
reloc_addend(void* arg, unsigned int type, uint64_t addend) const
264
{ return this->do_reloc_addend(arg, type, addend); }
266
// Return the PLT address to use for a global symbol.
268
plt_address_for_global(const Symbol* sym) const
269
{ return this->do_plt_address_for_global(sym); }
271
// Return the PLT address to use for a local symbol.
273
plt_address_for_local(const Relobj* object, unsigned int symndx) const
274
{ return this->do_plt_address_for_local(object, symndx); }
276
// Return the offset to use for the GOT_INDX'th got entry which is
277
// for a local tls symbol specified by OBJECT, SYMNDX.
279
tls_offset_for_local(const Relobj* object,
281
unsigned int got_indx) const
282
{ return do_tls_offset_for_local(object, symndx, got_indx); }
284
// Return the offset to use for the GOT_INDX'th got entry which is
285
// for global tls symbol GSYM.
287
tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const
288
{ return do_tls_offset_for_global(gsym, got_indx); }
290
// For targets that use function descriptors, if LOC is the location
291
// of a function, modify it to point at the function entry location.
293
function_location(Symbol_location* loc) const
294
{ return do_function_location(loc); }
296
// Return whether this target can use relocation types to determine
297
// if a function's address is taken.
299
can_check_for_function_pointers() const
300
{ return this->do_can_check_for_function_pointers(); }
302
// Return whether a relocation to a merged section can be processed
303
// to retrieve the contents.
305
can_icf_inline_merge_sections () const
306
{ return this->pti_->can_icf_inline_merge_sections; }
308
// Whether a section called SECTION_NAME may have function pointers to
309
// sections not eligible for safe ICF folding.
311
section_may_have_icf_unsafe_pointers(const char* section_name) const
312
{ return this->do_section_may_have_icf_unsafe_pointers(section_name); }
314
// Return the base to use for the PC value in an FDE when it is
315
// encoded using DW_EH_PE_datarel. This does not appear to be
316
// documented anywhere, but it is target specific. Any use of
317
// DW_EH_PE_datarel in gcc requires defining a special macro
318
// (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value.
320
ehframe_datarel_base() const
321
{ return this->do_ehframe_datarel_base(); }
323
// Return true if a reference to SYM from a reloc of type R_TYPE
324
// means that the current function may call an object compiled
325
// without -fsplit-stack. SYM is known to be defined in an object
326
// compiled without -fsplit-stack.
328
is_call_to_non_split(const Symbol* sym, unsigned int r_type) const
329
{ return this->do_is_call_to_non_split(sym, r_type); }
331
// A function starts at OFFSET in section SHNDX in OBJECT. That
332
// function was compiled with -fsplit-stack, but it refers to a
333
// function which was compiled without -fsplit-stack. VIEW is a
334
// modifiable view of the section; VIEW_SIZE is the size of the
335
// view. The target has to adjust the function so that it allocates
338
calls_non_split(Relobj* object, unsigned int shndx,
339
section_offset_type fnoffset, section_size_type fnsize,
340
unsigned char* view, section_size_type view_size,
341
std::string* from, std::string* to) const
343
this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size,
347
// Make an ELF object.
348
template<int size, bool big_endian>
350
make_elf_object(const std::string& name, Input_file* input_file,
351
off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
352
{ return this->do_make_elf_object(name, input_file, offset, ehdr); }
354
// Make an output section.
356
make_output_section(const char* name, elfcpp::Elf_Word type,
357
elfcpp::Elf_Xword flags)
358
{ return this->do_make_output_section(name, type, flags); }
360
// Return true if target wants to perform relaxation.
364
// Run the dummy relaxation pass twice if relaxation debugging is enabled.
365
if (is_debugging_enabled(DEBUG_RELAXATION))
368
return this->do_may_relax();
371
// Perform a relaxation pass. Return true if layout may be changed.
373
relax(int pass, const Input_objects* input_objects, Symbol_table* symtab,
374
Layout* layout, const Task* task)
376
// Run the dummy relaxation pass twice if relaxation debugging is enabled.
377
if (is_debugging_enabled(DEBUG_RELAXATION))
380
return this->do_relax(pass, input_objects, symtab, layout, task);
383
// Return the target-specific name of attributes section. This is
384
// NULL if a target does not use attributes section or if it uses
385
// the default section name ".gnu.attributes".
387
attributes_section() const
388
{ return this->pti_->attributes_section; }
390
// Return the vendor name of vendor attributes.
392
attributes_vendor() const
393
{ return this->pti_->attributes_vendor; }
395
// Whether a section called NAME is an attribute section.
397
is_attributes_section(const char* name) const
399
return ((this->pti_->attributes_section != NULL
400
&& strcmp(name, this->pti_->attributes_section) == 0)
401
|| strcmp(name, ".gnu.attributes") == 0);
404
// Return a bit mask of argument types for attribute with TAG.
406
attribute_arg_type(int tag) const
407
{ return this->do_attribute_arg_type(tag); }
409
// Return the attribute tag of the position NUM in the list of fixed
410
// attributes. Normally there is no reordering and
411
// attributes_order(NUM) == NUM.
413
attributes_order(int num) const
414
{ return this->do_attributes_order(num); }
416
// When a target is selected as the default target, we call this method,
417
// which may be used for expensive, target-specific initialization.
419
select_as_default_target()
420
{ this->do_select_as_default_target(); }
422
// Return the value to store in the EI_OSABI field in the ELF
426
{ return this->osabi_; }
428
// Set the value to store in the EI_OSABI field in the ELF header.
430
set_osabi(elfcpp::ELFOSABI osabi)
431
{ this->osabi_ = osabi; }
433
// Define target-specific standard symbols.
435
define_standard_symbols(Symbol_table* symtab, Layout* layout)
436
{ this->do_define_standard_symbols(symtab, layout); }
438
// Return the output section name to use given an input section
439
// name, or NULL if no target specific name mapping is required.
440
// Set *PLEN to the length of the name if returning non-NULL.
442
output_section_name(const Relobj* relobj,
445
{ return this->do_output_section_name(relobj, name, plen); }
447
// Add any special sections for this symbol to the gc work list.
449
gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const
450
{ this->do_gc_mark_symbol(symtab, sym); }
453
// This struct holds the constant information for a child class. We
454
// use a struct to avoid the overhead of virtual function calls for
455
// simple information.
458
// Address size (32 or 64).
460
// Whether the target is big endian.
462
// The code to store in the e_machine field of the ELF header.
463
elfcpp::EM machine_code;
464
// Whether this target has a specific make_symbol function.
465
bool has_make_symbol;
466
// Whether this target has a specific resolve function.
468
// Whether this target has a specific code fill function.
470
// Whether an object file with no .note.GNU-stack sections implies
471
// that the stack should be executable.
472
bool is_default_stack_executable;
473
// Whether a relocation to a merged section can be processed to
474
// retrieve the contents.
475
bool can_icf_inline_merge_sections;
476
// Prefix character to strip when checking for wrapping.
478
// The default dynamic linker name.
479
const char* dynamic_linker;
480
// The default text segment address.
481
uint64_t default_text_segment_address;
482
// The ABI specified page size.
483
uint64_t abi_pagesize;
484
// The common page size used by actual implementations.
485
uint64_t common_pagesize;
486
// Whether PF_X segments must contain nothing but the contents of
487
// SHF_EXECINSTR sections (no non-executable data, no headers).
488
bool isolate_execinstr;
489
// If nonzero, distance from the text segment to the read-only segment.
490
uint64_t rosegment_gap;
491
// The special section index for small common symbols; SHN_UNDEF
493
elfcpp::Elf_Half small_common_shndx;
494
// The special section index for large common symbols; SHN_UNDEF
496
elfcpp::Elf_Half large_common_shndx;
497
// Section flags for small common section.
498
elfcpp::Elf_Xword small_common_section_flags;
499
// Section flags for large common section.
500
elfcpp::Elf_Xword large_common_section_flags;
501
// Name of attributes section if it is not ".gnu.attributes".
502
const char* attributes_section;
503
// Vendor name of vendor attributes.
504
const char* attributes_vendor;
507
Target(const Target_info* pti)
508
: pti_(pti), processor_specific_flags_(0),
509
are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE)
512
// Virtual function which may be implemented by the child class.
514
do_new_output_section(Output_section*) const
517
// Virtual function which may be implemented by the child class.
519
do_finalize_sections(Layout*, const Input_objects*, Symbol_table*)
522
// Virtual function which may be implemented by the child class.
524
do_dynsym_value(const Symbol*) const
525
{ gold_unreachable(); }
527
// Virtual function which must be implemented by the child class if
530
do_code_fill(section_size_type) const
531
{ gold_unreachable(); }
533
// Virtual function which may be implemented by the child class.
535
do_is_defined_by_abi(const Symbol*) const
538
// Adjust the output file header before it is written out. VIEW
539
// points to the header in external form. LEN is the length, and
540
// will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
541
// By default, we set the EI_OSABI field if requested (in
544
do_adjust_elf_header(unsigned char*, int) const = 0;
546
// Return address and size to plug into eh_frame FDEs associated with a PLT.
548
do_plt_fde_location(const Output_data* plt, unsigned char* oview,
549
uint64_t* address, off_t* len) const;
551
// Virtual function which may be overridden by the child class.
553
do_is_local_label_name(const char*) const;
555
// Virtual function that must be overridden by a target which uses
556
// target specific relocations.
558
do_reloc_symbol_index(void*, unsigned int) const
559
{ gold_unreachable(); }
561
// Virtual function that must be overridden by a target which uses
562
// target specific relocations.
564
do_reloc_addend(void*, unsigned int, uint64_t) const
565
{ gold_unreachable(); }
567
// Virtual functions that must be overridden by a target that uses
568
// STT_GNU_IFUNC symbols.
570
do_plt_address_for_global(const Symbol*) const
571
{ gold_unreachable(); }
574
do_plt_address_for_local(const Relobj*, unsigned int) const
575
{ gold_unreachable(); }
578
do_tls_offset_for_local(const Relobj*, unsigned int, unsigned int) const
579
{ gold_unreachable(); }
582
do_tls_offset_for_global(Symbol*, unsigned int) const
583
{ gold_unreachable(); }
586
do_function_location(Symbol_location*) const = 0;
588
// Virtual function which may be overriden by the child class.
590
do_can_check_for_function_pointers() const
593
// Virtual function which may be overridden by the child class. We
594
// recognize some default sections for which we don't care whether
595
// they have function pointers.
597
do_section_may_have_icf_unsafe_pointers(const char* section_name) const
599
// We recognize sections for normal vtables, construction vtables and
601
return (!is_prefix_of(".rodata._ZTV", section_name)
602
&& !is_prefix_of(".data.rel.ro._ZTV", section_name)
603
&& !is_prefix_of(".rodata._ZTC", section_name)
604
&& !is_prefix_of(".data.rel.ro._ZTC", section_name)
605
&& !is_prefix_of(".eh_frame", section_name));
609
do_ehframe_datarel_base() const
610
{ gold_unreachable(); }
612
// Virtual function which may be overridden by the child class. The
613
// default implementation is that any function not defined by the
614
// ABI is a call to a non-split function.
616
do_is_call_to_non_split(const Symbol* sym, unsigned int) const;
618
// Virtual function which may be overridden by the child class.
620
do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
621
section_size_type, unsigned char*, section_size_type,
622
std::string*, std::string*) const;
624
// make_elf_object hooks. There are four versions of these for
625
// different address sizes and endianness.
627
// Set processor specific flags.
629
set_processor_specific_flags(elfcpp::Elf_Word flags)
631
this->processor_specific_flags_ = flags;
632
this->are_processor_specific_flags_set_ = true;
635
#ifdef HAVE_TARGET_32_LITTLE
636
// Virtual functions which may be overridden by the child class.
638
do_make_elf_object(const std::string&, Input_file*, off_t,
639
const elfcpp::Ehdr<32, false>&);
642
#ifdef HAVE_TARGET_32_BIG
643
// Virtual functions which may be overridden by the child class.
645
do_make_elf_object(const std::string&, Input_file*, off_t,
646
const elfcpp::Ehdr<32, true>&);
649
#ifdef HAVE_TARGET_64_LITTLE
650
// Virtual functions which may be overridden by the child class.
652
do_make_elf_object(const std::string&, Input_file*, off_t,
653
const elfcpp::Ehdr<64, false>& ehdr);
656
#ifdef HAVE_TARGET_64_BIG
657
// Virtual functions which may be overridden by the child class.
659
do_make_elf_object(const std::string& name, Input_file* input_file,
660
off_t offset, const elfcpp::Ehdr<64, true>& ehdr);
663
// Virtual functions which may be overridden by the child class.
664
virtual Output_section*
665
do_make_output_section(const char* name, elfcpp::Elf_Word type,
666
elfcpp::Elf_Xword flags);
668
// Virtual function which may be overridden by the child class.
671
{ return parameters->options().relax(); }
673
// Virtual function which may be overridden by the child class.
675
do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*)
678
// A function for targets to call. Return whether BYTES/LEN matches
679
// VIEW/VIEW_SIZE at OFFSET.
681
match_view(const unsigned char* view, section_size_type view_size,
682
section_offset_type offset, const char* bytes, size_t len) const;
684
// Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
687
set_view_to_nop(unsigned char* view, section_size_type view_size,
688
section_offset_type offset, size_t len) const;
690
// This must be overridden by the child class if it has target-specific
691
// attributes subsection in the attribute section.
693
do_attribute_arg_type(int) const
694
{ gold_unreachable(); }
696
// This may be overridden by the child class.
698
do_attributes_order(int num) const
701
// This may be overridden by the child class.
703
do_select_as_default_target()
706
// This may be overridden by the child class.
708
do_define_standard_symbols(Symbol_table*, Layout*)
711
// This may be overridden by the child class.
713
do_output_section_name(const Relobj*, const char*, size_t*) const
716
// This may be overridden by the child class.
718
do_gc_mark_symbol(Symbol_table*, Symbol*) const
722
// The implementations of the four do_make_elf_object virtual functions are
723
// almost identical except for their sizes and endianness. We use a template.
724
// for their implementations.
725
template<int size, bool big_endian>
727
do_make_elf_object_implementation(const std::string&, Input_file*, off_t,
728
const elfcpp::Ehdr<size, big_endian>&);
730
Target(const Target&);
731
Target& operator=(const Target&);
733
// The target information.
734
const Target_info* pti_;
735
// Processor-specific flags.
736
elfcpp::Elf_Word processor_specific_flags_;
737
// Whether the processor-specific flags are set at least once.
738
bool are_processor_specific_flags_set_;
739
// If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
740
// the ELF header. This is handled at this level because it is
741
// OS-specific rather than processor-specific.
742
elfcpp::ELFOSABI osabi_;
745
// The abstract class for a specific size and endianness of target.
746
// Each actual target implementation class should derive from an
747
// instantiation of Sized_target.
749
template<int size, bool big_endian>
750
class Sized_target : public Target
753
// Make a new symbol table entry for the target. This should be
754
// overridden by a target which needs additional information in the
755
// symbol table. This will only be called if has_make_symbol()
757
virtual Sized_symbol<size>*
759
{ gold_unreachable(); }
761
// Resolve a symbol for the target. This should be overridden by a
762
// target which needs to take special action. TO is the
763
// pre-existing symbol. SYM is the new symbol, seen in OBJECT.
764
// VERSION is the version of SYM. This will only be called if
765
// has_resolve() returns true.
767
resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
769
{ gold_unreachable(); }
771
// Process the relocs for a section, and record information of the
772
// mapping from source to destination sections. This mapping is later
773
// used to determine unreferenced garbage sections. This procedure is
774
// only called during garbage collection.
776
gc_process_relocs(Symbol_table* symtab,
778
Sized_relobj_file<size, big_endian>* object,
779
unsigned int data_shndx,
780
unsigned int sh_type,
781
const unsigned char* prelocs,
783
Output_section* output_section,
784
bool needs_special_offset_handling,
785
size_t local_symbol_count,
786
const unsigned char* plocal_symbols) = 0;
788
// Scan the relocs for a section, and record any information
789
// required for the symbol. SYMTAB is the symbol table. OBJECT is
790
// the object in which the section appears. DATA_SHNDX is the
791
// section index that these relocs apply to. SH_TYPE is the type of
792
// the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
793
// the relocation data. RELOC_COUNT is the number of relocs.
794
// LOCAL_SYMBOL_COUNT is the number of local symbols.
795
// OUTPUT_SECTION is the output section.
796
// NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
797
// sections are not mapped as usual. PLOCAL_SYMBOLS points to the
798
// local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
799
// pointers to the global symbol table from OBJECT.
801
scan_relocs(Symbol_table* symtab,
803
Sized_relobj_file<size, big_endian>* object,
804
unsigned int data_shndx,
805
unsigned int sh_type,
806
const unsigned char* prelocs,
808
Output_section* output_section,
809
bool needs_special_offset_handling,
810
size_t local_symbol_count,
811
const unsigned char* plocal_symbols) = 0;
813
// Relocate section data. SH_TYPE is the type of the relocation
814
// section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
815
// information. RELOC_COUNT is the number of relocs.
816
// OUTPUT_SECTION is the output section.
817
// NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
818
// to correspond to the output section. VIEW is a view into the
819
// output file holding the section contents, VIEW_ADDRESS is the
820
// virtual address of the view, and VIEW_SIZE is the size of the
821
// view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
822
// parameters refer to the complete output section data, not just
823
// the input section data.
825
relocate_section(const Relocate_info<size, big_endian>*,
826
unsigned int sh_type,
827
const unsigned char* prelocs,
829
Output_section* output_section,
830
bool needs_special_offset_handling,
832
typename elfcpp::Elf_types<size>::Elf_Addr view_address,
833
section_size_type view_size,
834
const Reloc_symbol_changes*) = 0;
836
// Scan the relocs during a relocatable link. The parameters are
837
// like scan_relocs, with an additional Relocatable_relocs
838
// parameter, used to record the disposition of the relocs.
840
scan_relocatable_relocs(Symbol_table* symtab,
842
Sized_relobj_file<size, big_endian>* object,
843
unsigned int data_shndx,
844
unsigned int sh_type,
845
const unsigned char* prelocs,
847
Output_section* output_section,
848
bool needs_special_offset_handling,
849
size_t local_symbol_count,
850
const unsigned char* plocal_symbols,
851
Relocatable_relocs*) = 0;
853
// Emit relocations for a section during a relocatable link, and for
854
// --emit-relocs. The parameters are like relocate_section, with
855
// additional parameters for the view of the output reloc section.
857
relocate_relocs(const Relocate_info<size, big_endian>*,
858
unsigned int sh_type,
859
const unsigned char* prelocs,
861
Output_section* output_section,
862
typename elfcpp::Elf_types<size>::Elf_Off
863
offset_in_output_section,
864
const Relocatable_relocs*,
866
typename elfcpp::Elf_types<size>::Elf_Addr view_address,
867
section_size_type view_size,
868
unsigned char* reloc_view,
869
section_size_type reloc_view_size) = 0;
871
// Perform target-specific processing in a relocatable link. This is
872
// only used if we use the relocation strategy RELOC_SPECIAL.
873
// RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
874
// section type. PRELOC_IN points to the original relocation. RELNUM is
875
// the index number of the relocation in the relocation section.
876
// OUTPUT_SECTION is the output section to which the relocation is applied.
877
// OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
878
// within the output section. VIEW points to the output view of the
879
// output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
880
// is the size of the output view and PRELOC_OUT points to the new
881
// relocation in the output object.
883
// A target only needs to override this if the generic code in
884
// target-reloc.h cannot handle some relocation types.
887
relocate_special_relocatable(const Relocate_info<size, big_endian>*
889
unsigned int /* sh_type */,
890
const unsigned char* /* preloc_in */,
892
Output_section* /* output_section */,
893
typename elfcpp::Elf_types<size>::Elf_Off
894
/* offset_in_output_section */,
895
unsigned char* /* view */,
896
typename elfcpp::Elf_types<size>::Elf_Addr
898
section_size_type /* view_size */,
899
unsigned char* /* preloc_out*/)
900
{ gold_unreachable(); }
902
// Return the number of entries in the GOT. This is only used for
903
// laying out the incremental link info sections. A target needs
904
// to implement this to support incremental linking.
907
got_entry_count() const
908
{ gold_unreachable(); }
910
// Return the number of entries in the PLT. This is only used for
911
// laying out the incremental link info sections. A target needs
912
// to implement this to support incremental linking.
915
plt_entry_count() const
916
{ gold_unreachable(); }
918
// Return the offset of the first non-reserved PLT entry. This is
919
// only used for laying out the incremental link info sections.
920
// A target needs to implement this to support incremental linking.
923
first_plt_entry_offset() const
924
{ gold_unreachable(); }
926
// Return the size of each PLT entry. This is only used for
927
// laying out the incremental link info sections. A target needs
928
// to implement this to support incremental linking.
931
plt_entry_size() const
932
{ gold_unreachable(); }
934
// Create the GOT and PLT sections for an incremental update.
935
// A target needs to implement this to support incremental linking.
937
virtual Output_data_got_base*
938
init_got_plt_for_update(Symbol_table*,
940
unsigned int /* got_count */,
941
unsigned int /* plt_count */)
942
{ gold_unreachable(); }
944
// Reserve a GOT entry for a local symbol, and regenerate any
945
// necessary dynamic relocations.
947
reserve_local_got_entry(unsigned int /* got_index */,
948
Sized_relobj<size, big_endian>* /* obj */,
949
unsigned int /* r_sym */,
950
unsigned int /* got_type */)
951
{ gold_unreachable(); }
953
// Reserve a GOT entry for a global symbol, and regenerate any
954
// necessary dynamic relocations.
956
reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */,
957
unsigned int /* got_type */)
958
{ gold_unreachable(); }
960
// Register an existing PLT entry for a global symbol.
961
// A target needs to implement this to support incremental linking.
964
register_global_plt_entry(Symbol_table*, Layout*,
965
unsigned int /* plt_index */,
967
{ gold_unreachable(); }
969
// Force a COPY relocation for a given symbol.
970
// A target needs to implement this to support incremental linking.
973
emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t)
974
{ gold_unreachable(); }
976
// Apply an incremental relocation.
979
apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */,
980
typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */,
981
unsigned int /* r_type */,
982
typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */,
983
const Symbol* /* gsym */,
984
unsigned char* /* view */,
985
typename elfcpp::Elf_types<size>::Elf_Addr /* address */,
986
section_size_type /* view_size */)
987
{ gold_unreachable(); }
989
// Handle target specific gc actions when adding a gc reference from
990
// SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
993
gc_add_reference(Symbol_table* symtab,
995
unsigned int src_shndx,
997
unsigned int dst_shndx,
998
typename elfcpp::Elf_types<size>::Elf_Addr dst_off) const
1000
this->do_gc_add_reference(symtab, src_obj, src_shndx,
1001
dst_obj, dst_shndx, dst_off);
1005
Sized_target(const Target::Target_info* pti)
1008
gold_assert(pti->size == size);
1009
gold_assert(pti->is_big_endian ? big_endian : !big_endian);
1012
// Set the EI_OSABI field if requested.
1014
do_adjust_elf_header(unsigned char*, int) const;
1016
// Handle target specific gc actions when adding a gc reference.
1018
do_gc_add_reference(Symbol_table*, Object*, unsigned int,
1019
Object*, unsigned int,
1020
typename elfcpp::Elf_types<size>::Elf_Addr) const
1024
do_function_location(Symbol_location*) const
1028
} // End namespace gold.
1030
#endif // !defined(GOLD_TARGET_H)