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
;
65 // The abstract class for target specific handling.
73 // Return the bit size that this target implements. This should
77 { return this->pti_
->size
; }
79 // Return whether this target is big-endian.
82 { return this->pti_
->is_big_endian
; }
84 // Machine code to store in e_machine field of ELF header.
87 { return this->pti_
->machine_code
; }
89 // Processor specific flags to store in e_flags field of ELF header.
91 processor_specific_flags() const
92 { return this->processor_specific_flags_
; }
94 // Whether processor specific flags are set at least once.
96 are_processor_specific_flags_set() const
97 { return this->are_processor_specific_flags_set_
; }
99 // Whether this target has a specific make_symbol function.
101 has_make_symbol() const
102 { return this->pti_
->has_make_symbol
; }
104 // Whether this target has a specific resolve function.
107 { return this->pti_
->has_resolve
; }
109 // Whether this target has a specific code fill function.
111 has_code_fill() const
112 { return this->pti_
->has_code_fill
; }
114 // Return the default name of the dynamic linker.
116 dynamic_linker() const
117 { return this->pti_
->dynamic_linker
; }
119 // Return the default address to use for the text segment.
121 default_text_segment_address() const
122 { return this->pti_
->default_text_segment_address
; }
124 // Return the ABI specified page size.
128 if (parameters
->options().max_page_size() > 0)
129 return parameters
->options().max_page_size();
131 return this->pti_
->abi_pagesize
;
134 // Return the common page size used on actual systems.
136 common_pagesize() const
138 if (parameters
->options().common_page_size() > 0)
139 return std::min(parameters
->options().common_page_size(),
140 this->abi_pagesize());
142 return std::min(this->pti_
->common_pagesize
,
143 this->abi_pagesize());
146 // Return whether PF_X segments must contain nothing but the contents of
147 // SHF_EXECINSTR sections (no non-executable data, no headers).
149 isolate_execinstr() const
150 { return this->pti_
->isolate_execinstr
; }
153 rosegment_gap() const
154 { return this->pti_
->rosegment_gap
; }
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.
161 is_default_stack_executable() const
162 { return this->pti_
->is_default_stack_executable
; }
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
171 { return this->pti_
->wrap_char
; }
173 // Return the special section index which indicates a small common
174 // symbol. This will return SHN_UNDEF if there are no small common
177 small_common_shndx() const
178 { return this->pti_
->small_common_shndx
; }
180 // Return values to add to the section flags for the section holding
181 // small common symbols.
183 small_common_section_flags() const
185 gold_assert(this->pti_
->small_common_shndx
!= elfcpp::SHN_UNDEF
);
186 return this->pti_
->small_common_section_flags
;
189 // Return the special section index which indicates a large common
190 // symbol. This will return SHN_UNDEF if there are no large common
193 large_common_shndx() const
194 { return this->pti_
->large_common_shndx
; }
196 // Return values to add to the section flags for the section holding
197 // large common symbols.
199 large_common_section_flags() const
201 gold_assert(this->pti_
->large_common_shndx
!= elfcpp::SHN_UNDEF
);
202 return this->pti_
->large_common_section_flags
;
205 // This hook is called when an output section is created.
207 new_output_section(Output_section
* os
) const
208 { this->do_new_output_section(os
); }
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.
213 finalize_sections(Layout
* layout
, const Input_objects
* input_objects
,
214 Symbol_table
* symtab
)
215 { return this->do_finalize_sections(layout
, input_objects
, symtab
); }
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().
221 dynsym_value(const Symbol
* sym
) const
222 { return this->do_dynsym_value(sym
); }
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
228 code_fill(section_size_type length
) const
229 { return this->do_code_fill(length
); }
231 // Return whether SYM is known to be defined by the ABI. This is
232 // used to avoid inappropriate warnings about undefined symbols.
234 is_defined_by_abi(const Symbol
* sym
) const
235 { return this->do_is_defined_by_abi(sym
); }
237 // Adjust the output file header before it is written out. VIEW
238 // points to the header in external form. LEN is the length.
240 adjust_elf_header(unsigned char* view
, int len
) const
241 { return this->do_adjust_elf_header(view
, len
); }
243 // Return whether NAME is a local label name. This is used to implement the
244 // --discard-locals options.
246 is_local_label_name(const char* name
) const
247 { return this->do_is_local_label_name(name
); }
249 // Get the symbol index to use for a target specific reloc.
251 reloc_symbol_index(void* arg
, unsigned int type
) const
252 { return this->do_reloc_symbol_index(arg
, type
); }
254 // Get the addend to use for a target specific reloc.
256 reloc_addend(void* arg
, unsigned int type
, uint64_t addend
) const
257 { return this->do_reloc_addend(arg
, type
, addend
); }
259 // Return the PLT address to use for a global symbol.
261 plt_address_for_global(const Symbol
* sym
) const
262 { return this->do_plt_address_for_global(sym
); }
264 // Return the PLT address to use for a local symbol.
266 plt_address_for_local(const Relobj
* object
, unsigned int symndx
) const
267 { return this->do_plt_address_for_local(object
, symndx
); }
269 // Return the offset to use for the GOT_INDX'th got entry which is
270 // for a local tls symbol specified by OBJECT, SYMNDX.
272 tls_offset_for_local(const Relobj
* object
,
274 unsigned int got_indx
) const
275 { return do_tls_offset_for_local(object
, symndx
, got_indx
); }
277 // Return the offset to use for the GOT_INDX'th got entry which is
278 // for global tls symbol GSYM.
280 tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const
281 { return do_tls_offset_for_global(gsym
, got_indx
); }
283 // Return whether this target can use relocation types to determine
284 // if a function's address is taken.
286 can_check_for_function_pointers() const
287 { return this->do_can_check_for_function_pointers(); }
289 // Return whether a relocation to a merged section can be processed
290 // to retrieve the contents.
292 can_icf_inline_merge_sections () const
293 { return this->pti_
->can_icf_inline_merge_sections
; }
295 // Whether a section called SECTION_NAME may have function pointers to
296 // sections not eligible for safe ICF folding.
298 section_may_have_icf_unsafe_pointers(const char* section_name
) const
299 { return this->do_section_may_have_icf_unsafe_pointers(section_name
); }
301 // Return the base to use for the PC value in an FDE when it is
302 // encoded using DW_EH_PE_datarel. This does not appear to be
303 // documented anywhere, but it is target specific. Any use of
304 // DW_EH_PE_datarel in gcc requires defining a special macro
305 // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value.
307 ehframe_datarel_base() const
308 { return this->do_ehframe_datarel_base(); }
310 // Return true if a reference to SYM from a reloc of type R_TYPE
311 // means that the current function may call an object compiled
312 // without -fsplit-stack. SYM is known to be defined in an object
313 // compiled without -fsplit-stack.
315 is_call_to_non_split(const Symbol
* sym
, unsigned int r_type
) const
316 { return this->do_is_call_to_non_split(sym
, r_type
); }
318 // A function starts at OFFSET in section SHNDX in OBJECT. That
319 // function was compiled with -fsplit-stack, but it refers to a
320 // function which was compiled without -fsplit-stack. VIEW is a
321 // modifiable view of the section; VIEW_SIZE is the size of the
322 // view. The target has to adjust the function so that it allocates
325 calls_non_split(Relobj
* object
, unsigned int shndx
,
326 section_offset_type fnoffset
, section_size_type fnsize
,
327 unsigned char* view
, section_size_type view_size
,
328 std::string
* from
, std::string
* to
) const
330 this->do_calls_non_split(object
, shndx
, fnoffset
, fnsize
, view
, view_size
,
334 // Make an ELF object.
335 template<int size
, bool big_endian
>
337 make_elf_object(const std::string
& name
, Input_file
* input_file
,
338 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
339 { return this->do_make_elf_object(name
, input_file
, offset
, ehdr
); }
341 // Make an output section.
343 make_output_section(const char* name
, elfcpp::Elf_Word type
,
344 elfcpp::Elf_Xword flags
)
345 { return this->do_make_output_section(name
, type
, flags
); }
347 // Return true if target wants to perform relaxation.
351 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
352 if (is_debugging_enabled(DEBUG_RELAXATION
))
355 return this->do_may_relax();
358 // Perform a relaxation pass. Return true if layout may be changed.
360 relax(int pass
, const Input_objects
* input_objects
, Symbol_table
* symtab
,
361 Layout
* layout
, const Task
* task
)
363 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
364 if (is_debugging_enabled(DEBUG_RELAXATION
))
367 return this->do_relax(pass
, input_objects
, symtab
, layout
, task
);
370 // Return the target-specific name of attributes section. This is
371 // NULL if a target does not use attributes section or if it uses
372 // the default section name ".gnu.attributes".
374 attributes_section() const
375 { return this->pti_
->attributes_section
; }
377 // Return the vendor name of vendor attributes.
379 attributes_vendor() const
380 { return this->pti_
->attributes_vendor
; }
382 // Whether a section called NAME is an attribute section.
384 is_attributes_section(const char* name
) const
386 return ((this->pti_
->attributes_section
!= NULL
387 && strcmp(name
, this->pti_
->attributes_section
) == 0)
388 || strcmp(name
, ".gnu.attributes") == 0);
391 // Return a bit mask of argument types for attribute with TAG.
393 attribute_arg_type(int tag
) const
394 { return this->do_attribute_arg_type(tag
); }
396 // Return the attribute tag of the position NUM in the list of fixed
397 // attributes. Normally there is no reordering and
398 // attributes_order(NUM) == NUM.
400 attributes_order(int num
) const
401 { return this->do_attributes_order(num
); }
403 // When a target is selected as the default target, we call this method,
404 // which may be used for expensive, target-specific initialization.
406 select_as_default_target()
407 { this->do_select_as_default_target(); }
409 // Return the value to store in the EI_OSABI field in the ELF
413 { return this->osabi_
; }
415 // Set the value to store in the EI_OSABI field in the ELF header.
417 set_osabi(elfcpp::ELFOSABI osabi
)
418 { this->osabi_
= osabi
; }
420 // Define target-specific standard symbols.
422 define_standard_symbols(Symbol_table
* symtab
, Layout
* layout
)
423 { this->do_define_standard_symbols(symtab
, layout
); }
425 // Return the output section name to use given an input section
426 // name, or NULL if no target specific name mapping is required.
427 // Set *PLEN to the length of the name if returning non-NULL.
429 output_section_name(const Relobj
* relobj
,
432 { return this->do_output_section_name(relobj
, name
, plen
); }
434 // Add any special sections for this symbol to the gc work list.
436 gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const
437 { this->do_gc_mark_symbol(symtab
, sym
); }
440 // This struct holds the constant information for a child class. We
441 // use a struct to avoid the overhead of virtual function calls for
442 // simple information.
445 // Address size (32 or 64).
447 // Whether the target is big endian.
449 // The code to store in the e_machine field of the ELF header.
450 elfcpp::EM machine_code
;
451 // Whether this target has a specific make_symbol function.
452 bool has_make_symbol
;
453 // Whether this target has a specific resolve function.
455 // Whether this target has a specific code fill function.
457 // Whether an object file with no .note.GNU-stack sections implies
458 // that the stack should be executable.
459 bool is_default_stack_executable
;
460 // Whether a relocation to a merged section can be processed to
461 // retrieve the contents.
462 bool can_icf_inline_merge_sections
;
463 // Prefix character to strip when checking for wrapping.
465 // The default dynamic linker name.
466 const char* dynamic_linker
;
467 // The default text segment address.
468 uint64_t default_text_segment_address
;
469 // The ABI specified page size.
470 uint64_t abi_pagesize
;
471 // The common page size used by actual implementations.
472 uint64_t common_pagesize
;
473 // Whether PF_X segments must contain nothing but the contents of
474 // SHF_EXECINSTR sections (no non-executable data, no headers).
475 bool isolate_execinstr
;
476 // If nonzero, distance from the text segment to the read-only segment.
477 uint64_t rosegment_gap
;
478 // The special section index for small common symbols; SHN_UNDEF
480 elfcpp::Elf_Half small_common_shndx
;
481 // The special section index for large common symbols; SHN_UNDEF
483 elfcpp::Elf_Half large_common_shndx
;
484 // Section flags for small common section.
485 elfcpp::Elf_Xword small_common_section_flags
;
486 // Section flags for large common section.
487 elfcpp::Elf_Xword large_common_section_flags
;
488 // Name of attributes section if it is not ".gnu.attributes".
489 const char* attributes_section
;
490 // Vendor name of vendor attributes.
491 const char* attributes_vendor
;
494 Target(const Target_info
* pti
)
495 : pti_(pti
), processor_specific_flags_(0),
496 are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE
)
499 // Virtual function which may be implemented by the child class.
501 do_new_output_section(Output_section
*) const
504 // Virtual function which may be implemented by the child class.
506 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*)
509 // Virtual function which may be implemented by the child class.
511 do_dynsym_value(const Symbol
*) const
512 { gold_unreachable(); }
514 // Virtual function which must be implemented by the child class if
517 do_code_fill(section_size_type
) const
518 { gold_unreachable(); }
520 // Virtual function which may be implemented by the child class.
522 do_is_defined_by_abi(const Symbol
*) const
525 // Adjust the output file header before it is written out. VIEW
526 // points to the header in external form. LEN is the length, and
527 // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
528 // By default, we set the EI_OSABI field if requested (in
531 do_adjust_elf_header(unsigned char*, int) const = 0;
533 // Virtual function which may be overridden by the child class.
535 do_is_local_label_name(const char*) const;
537 // Virtual function that must be overridden by a target which uses
538 // target specific relocations.
540 do_reloc_symbol_index(void*, unsigned int) const
541 { gold_unreachable(); }
543 // Virtual function that must be overridden by a target which uses
544 // target specific relocations.
546 do_reloc_addend(void*, unsigned int, uint64_t) const
547 { gold_unreachable(); }
549 // Virtual functions that must be overridden by a target that uses
550 // STT_GNU_IFUNC symbols.
552 do_plt_address_for_global(const Symbol
*) const
553 { gold_unreachable(); }
556 do_plt_address_for_local(const Relobj
*, unsigned int) const
557 { gold_unreachable(); }
560 do_tls_offset_for_local(const Relobj
*, unsigned int, unsigned int) const
561 { gold_unreachable(); }
564 do_tls_offset_for_global(Symbol
*, unsigned int) const
565 { gold_unreachable(); }
567 // Virtual function which may be overriden by the child class.
569 do_can_check_for_function_pointers() const
572 // Virtual function which may be overridden by the child class. We
573 // recognize some default sections for which we don't care whether
574 // they have function pointers.
576 do_section_may_have_icf_unsafe_pointers(const char* section_name
) const
578 // We recognize sections for normal vtables, construction vtables and
580 return (!is_prefix_of(".rodata._ZTV", section_name
)
581 && !is_prefix_of(".data.rel.ro._ZTV", section_name
)
582 && !is_prefix_of(".rodata._ZTC", section_name
)
583 && !is_prefix_of(".data.rel.ro._ZTC", section_name
)
584 && !is_prefix_of(".eh_frame", section_name
));
588 do_ehframe_datarel_base() const
589 { gold_unreachable(); }
591 // Virtual function which may be overridden by the child class. The
592 // default implementation is that any function not defined by the
593 // ABI is a call to a non-split function.
595 do_is_call_to_non_split(const Symbol
* sym
, unsigned int) const;
597 // Virtual function which may be overridden by the child class.
599 do_calls_non_split(Relobj
* object
, unsigned int, section_offset_type
,
600 section_size_type
, unsigned char*, section_size_type
,
601 std::string
*, std::string
*) const;
603 // make_elf_object hooks. There are four versions of these for
604 // different address sizes and endianness.
606 // Set processor specific flags.
608 set_processor_specific_flags(elfcpp::Elf_Word flags
)
610 this->processor_specific_flags_
= flags
;
611 this->are_processor_specific_flags_set_
= true;
614 #ifdef HAVE_TARGET_32_LITTLE
615 // Virtual functions which may be overridden by the child class.
617 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
618 const elfcpp::Ehdr
<32, false>&);
621 #ifdef HAVE_TARGET_32_BIG
622 // Virtual functions which may be overridden by the child class.
624 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
625 const elfcpp::Ehdr
<32, true>&);
628 #ifdef HAVE_TARGET_64_LITTLE
629 // Virtual functions which may be overridden by the child class.
631 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
632 const elfcpp::Ehdr
<64, false>& ehdr
);
635 #ifdef HAVE_TARGET_64_BIG
636 // Virtual functions which may be overridden by the child class.
638 do_make_elf_object(const std::string
& name
, Input_file
* input_file
,
639 off_t offset
, const elfcpp::Ehdr
<64, true>& ehdr
);
642 // Virtual functions which may be overridden by the child class.
643 virtual Output_section
*
644 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
645 elfcpp::Elf_Xword flags
);
647 // Virtual function which may be overridden by the child class.
650 { return parameters
->options().relax(); }
652 // Virtual function which may be overridden by the child class.
654 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*)
657 // A function for targets to call. Return whether BYTES/LEN matches
658 // VIEW/VIEW_SIZE at OFFSET.
660 match_view(const unsigned char* view
, section_size_type view_size
,
661 section_offset_type offset
, const char* bytes
, size_t len
) const;
663 // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
666 set_view_to_nop(unsigned char* view
, section_size_type view_size
,
667 section_offset_type offset
, size_t len
) const;
669 // This must be overridden by the child class if it has target-specific
670 // attributes subsection in the attribute section.
672 do_attribute_arg_type(int) const
673 { gold_unreachable(); }
675 // This may be overridden by the child class.
677 do_attributes_order(int num
) const
680 // This may be overridden by the child class.
682 do_select_as_default_target()
685 // This may be overridden by the child class.
687 do_define_standard_symbols(Symbol_table
*, Layout
*)
690 // This may be overridden by the child class.
692 do_output_section_name(const Relobj
*, const char*, size_t*) const
695 // This may be overridden by the child class.
697 do_gc_mark_symbol(Symbol_table
*, Symbol
*) const
701 // The implementations of the four do_make_elf_object virtual functions are
702 // almost identical except for their sizes and endianness. We use a template.
703 // for their implementations.
704 template<int size
, bool big_endian
>
706 do_make_elf_object_implementation(const std::string
&, Input_file
*, off_t
,
707 const elfcpp::Ehdr
<size
, big_endian
>&);
709 Target(const Target
&);
710 Target
& operator=(const Target
&);
712 // The target information.
713 const Target_info
* pti_
;
714 // Processor-specific flags.
715 elfcpp::Elf_Word processor_specific_flags_
;
716 // Whether the processor-specific flags are set at least once.
717 bool are_processor_specific_flags_set_
;
718 // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
719 // the ELF header. This is handled at this level because it is
720 // OS-specific rather than processor-specific.
721 elfcpp::ELFOSABI osabi_
;
724 // The abstract class for a specific size and endianness of target.
725 // Each actual target implementation class should derive from an
726 // instantiation of Sized_target.
728 template<int size
, bool big_endian
>
729 class Sized_target
: public Target
732 // Make a new symbol table entry for the target. This should be
733 // overridden by a target which needs additional information in the
734 // symbol table. This will only be called if has_make_symbol()
736 virtual Sized_symbol
<size
>*
738 { gold_unreachable(); }
740 // Resolve a symbol for the target. This should be overridden by a
741 // target which needs to take special action. TO is the
742 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
743 // VERSION is the version of SYM. This will only be called if
744 // has_resolve() returns true.
746 resolve(Symbol
*, const elfcpp::Sym
<size
, big_endian
>&, Object
*,
748 { gold_unreachable(); }
750 // Process the relocs for a section, and record information of the
751 // mapping from source to destination sections. This mapping is later
752 // used to determine unreferenced garbage sections. This procedure is
753 // only called during garbage collection.
755 gc_process_relocs(Symbol_table
* symtab
,
757 Sized_relobj_file
<size
, big_endian
>* object
,
758 unsigned int data_shndx
,
759 unsigned int sh_type
,
760 const unsigned char* prelocs
,
762 Output_section
* output_section
,
763 bool needs_special_offset_handling
,
764 size_t local_symbol_count
,
765 const unsigned char* plocal_symbols
) = 0;
767 // Scan the relocs for a section, and record any information
768 // required for the symbol. SYMTAB is the symbol table. OBJECT is
769 // the object in which the section appears. DATA_SHNDX is the
770 // section index that these relocs apply to. SH_TYPE is the type of
771 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
772 // the relocation data. RELOC_COUNT is the number of relocs.
773 // LOCAL_SYMBOL_COUNT is the number of local symbols.
774 // OUTPUT_SECTION is the output section.
775 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
776 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
777 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
778 // pointers to the global symbol table from OBJECT.
780 scan_relocs(Symbol_table
* symtab
,
782 Sized_relobj_file
<size
, big_endian
>* object
,
783 unsigned int data_shndx
,
784 unsigned int sh_type
,
785 const unsigned char* prelocs
,
787 Output_section
* output_section
,
788 bool needs_special_offset_handling
,
789 size_t local_symbol_count
,
790 const unsigned char* plocal_symbols
) = 0;
792 // Relocate section data. SH_TYPE is the type of the relocation
793 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
794 // information. RELOC_COUNT is the number of relocs.
795 // OUTPUT_SECTION is the output section.
796 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
797 // to correspond to the output section. VIEW is a view into the
798 // output file holding the section contents, VIEW_ADDRESS is the
799 // virtual address of the view, and VIEW_SIZE is the size of the
800 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
801 // parameters refer to the complete output section data, not just
802 // the input section data.
804 relocate_section(const Relocate_info
<size
, big_endian
>*,
805 unsigned int sh_type
,
806 const unsigned char* prelocs
,
808 Output_section
* output_section
,
809 bool needs_special_offset_handling
,
811 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
812 section_size_type view_size
,
813 const Reloc_symbol_changes
*) = 0;
815 // Scan the relocs during a relocatable link. The parameters are
816 // like scan_relocs, with an additional Relocatable_relocs
817 // parameter, used to record the disposition of the relocs.
819 scan_relocatable_relocs(Symbol_table
* symtab
,
821 Sized_relobj_file
<size
, big_endian
>* object
,
822 unsigned int data_shndx
,
823 unsigned int sh_type
,
824 const unsigned char* prelocs
,
826 Output_section
* output_section
,
827 bool needs_special_offset_handling
,
828 size_t local_symbol_count
,
829 const unsigned char* plocal_symbols
,
830 Relocatable_relocs
*) = 0;
832 // Emit relocations for a section during a relocatable link, and for
833 // --emit-relocs. The parameters are like relocate_section, with
834 // additional parameters for the view of the output reloc section.
836 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
837 unsigned int sh_type
,
838 const unsigned char* prelocs
,
840 Output_section
* output_section
,
841 typename
elfcpp::Elf_types
<size
>::Elf_Off
842 offset_in_output_section
,
843 const Relocatable_relocs
*,
845 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
846 section_size_type view_size
,
847 unsigned char* reloc_view
,
848 section_size_type reloc_view_size
) = 0;
850 // Perform target-specific processing in a relocatable link. This is
851 // only used if we use the relocation strategy RELOC_SPECIAL.
852 // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
853 // section type. PRELOC_IN points to the original relocation. RELNUM is
854 // the index number of the relocation in the relocation section.
855 // OUTPUT_SECTION is the output section to which the relocation is applied.
856 // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
857 // within the output section. VIEW points to the output view of the
858 // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
859 // is the size of the output view and PRELOC_OUT points to the new
860 // relocation in the output object.
862 // A target only needs to override this if the generic code in
863 // target-reloc.h cannot handle some relocation types.
866 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>*
868 unsigned int /* sh_type */,
869 const unsigned char* /* preloc_in */,
871 Output_section
* /* output_section */,
872 typename
elfcpp::Elf_types
<size
>::Elf_Off
873 /* offset_in_output_section */,
874 unsigned char* /* view */,
875 typename
elfcpp::Elf_types
<size
>::Elf_Addr
877 section_size_type
/* view_size */,
878 unsigned char* /* preloc_out*/)
879 { gold_unreachable(); }
881 // Return the number of entries in the GOT. This is only used for
882 // laying out the incremental link info sections. A target needs
883 // to implement this to support incremental linking.
886 got_entry_count() const
887 { gold_unreachable(); }
889 // Return the number of entries in the PLT. This is only used for
890 // laying out the incremental link info sections. A target needs
891 // to implement this to support incremental linking.
894 plt_entry_count() const
895 { gold_unreachable(); }
897 // Return the offset of the first non-reserved PLT entry. This is
898 // only used for laying out the incremental link info sections.
899 // A target needs to implement this to support incremental linking.
902 first_plt_entry_offset() const
903 { gold_unreachable(); }
905 // Return the size of each PLT entry. This is only used for
906 // laying out the incremental link info sections. A target needs
907 // to implement this to support incremental linking.
910 plt_entry_size() const
911 { gold_unreachable(); }
913 // Create the GOT and PLT sections for an incremental update.
914 // A target needs to implement this to support incremental linking.
916 virtual Output_data_got_base
*
917 init_got_plt_for_update(Symbol_table
*,
919 unsigned int /* got_count */,
920 unsigned int /* plt_count */)
921 { gold_unreachable(); }
923 // Reserve a GOT entry for a local symbol, and regenerate any
924 // necessary dynamic relocations.
926 reserve_local_got_entry(unsigned int /* got_index */,
927 Sized_relobj
<size
, big_endian
>* /* obj */,
928 unsigned int /* r_sym */,
929 unsigned int /* got_type */)
930 { gold_unreachable(); }
932 // Reserve a GOT entry for a global symbol, and regenerate any
933 // necessary dynamic relocations.
935 reserve_global_got_entry(unsigned int /* got_index */, Symbol
* /* gsym */,
936 unsigned int /* got_type */)
937 { gold_unreachable(); }
939 // Register an existing PLT entry for a global symbol.
940 // A target needs to implement this to support incremental linking.
943 register_global_plt_entry(Symbol_table
*, Layout
*,
944 unsigned int /* plt_index */,
946 { gold_unreachable(); }
948 // Force a COPY relocation for a given symbol.
949 // A target needs to implement this to support incremental linking.
952 emit_copy_reloc(Symbol_table
*, Symbol
*, Output_section
*, off_t
)
953 { gold_unreachable(); }
955 // Apply an incremental relocation.
958 apply_relocation(const Relocate_info
<size
, big_endian
>* /* relinfo */,
959 typename
elfcpp::Elf_types
<size
>::Elf_Addr
/* r_offset */,
960 unsigned int /* r_type */,
961 typename
elfcpp::Elf_types
<size
>::Elf_Swxword
/* r_addend */,
962 const Symbol
* /* gsym */,
963 unsigned char* /* view */,
964 typename
elfcpp::Elf_types
<size
>::Elf_Addr
/* address */,
965 section_size_type
/* view_size */)
966 { gold_unreachable(); }
968 // Handle target specific gc actions when adding a gc reference from
969 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
972 gc_add_reference(Symbol_table
* symtab
,
974 unsigned int src_shndx
,
976 unsigned int dst_shndx
,
977 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
) const
979 this->do_gc_add_reference(symtab
, src_obj
, src_shndx
,
980 dst_obj
, dst_shndx
, dst_off
);
984 Sized_target(const Target::Target_info
* pti
)
987 gold_assert(pti
->size
== size
);
988 gold_assert(pti
->is_big_endian
? big_endian
: !big_endian
);
991 // Set the EI_OSABI field if requested.
993 do_adjust_elf_header(unsigned char*, int) const;
995 // Handle target specific gc actions when adding a gc reference.
997 do_gc_add_reference(Symbol_table
*, Object
*, unsigned int,
998 Object
*, unsigned int,
999 typename
elfcpp::Elf_types
<size
>::Elf_Addr
) const
1003 } // End namespace gold.
1005 #endif // !defined(GOLD_TARGET_H)