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. This is used
260 // for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative
261 // to this PLT address.
263 plt_address_for_global(const Symbol
* sym
) const
264 { return this->do_plt_address_for_global(sym
); }
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.
270 plt_address_for_local(const Relobj
* object
, unsigned int symndx
) const
271 { return this->do_plt_address_for_local(object
, symndx
); }
273 // Return whether this target can use relocation types to determine
274 // if a function's address is taken.
276 can_check_for_function_pointers() const
277 { return this->do_can_check_for_function_pointers(); }
279 // Return whether a relocation to a merged section can be processed
280 // to retrieve the contents.
282 can_icf_inline_merge_sections () const
283 { return this->pti_
->can_icf_inline_merge_sections
; }
285 // Whether a section called SECTION_NAME may have function pointers to
286 // sections not eligible for safe ICF folding.
288 section_may_have_icf_unsafe_pointers(const char* section_name
) const
289 { return this->do_section_may_have_icf_unsafe_pointers(section_name
); }
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.
297 ehframe_datarel_base() const
298 { return this->do_ehframe_datarel_base(); }
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.
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
); }
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
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
320 this->do_calls_non_split(object
, shndx
, fnoffset
, fnsize
, view
, view_size
,
324 // Make an ELF object.
325 template<int size
, bool big_endian
>
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
); }
331 // Make an 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
); }
337 // Return true if target wants to perform relaxation.
341 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
342 if (is_debugging_enabled(DEBUG_RELAXATION
))
345 return this->do_may_relax();
348 // Perform a relaxation pass. Return true if layout may be changed.
350 relax(int pass
, const Input_objects
* input_objects
, Symbol_table
* symtab
,
351 Layout
* layout
, const Task
* task
)
353 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
354 if (is_debugging_enabled(DEBUG_RELAXATION
))
357 return this->do_relax(pass
, input_objects
, symtab
, layout
, task
);
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".
364 attributes_section() const
365 { return this->pti_
->attributes_section
; }
367 // Return the vendor name of vendor attributes.
369 attributes_vendor() const
370 { return this->pti_
->attributes_vendor
; }
372 // Whether a section called NAME is an attribute section.
374 is_attributes_section(const char* name
) const
376 return ((this->pti_
->attributes_section
!= NULL
377 && strcmp(name
, this->pti_
->attributes_section
) == 0)
378 || strcmp(name
, ".gnu.attributes") == 0);
381 // Return a bit mask of argument types for attribute with TAG.
383 attribute_arg_type(int tag
) const
384 { return this->do_attribute_arg_type(tag
); }
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.
390 attributes_order(int num
) const
391 { return this->do_attributes_order(num
); }
393 // When a target is selected as the default target, we call this method,
394 // which may be used for expensive, target-specific initialization.
396 select_as_default_target()
397 { this->do_select_as_default_target(); }
399 // Return the value to store in the EI_OSABI field in the ELF
403 { return this->osabi_
; }
405 // Set the value to store in the EI_OSABI field in the ELF header.
407 set_osabi(elfcpp::ELFOSABI osabi
)
408 { this->osabi_
= osabi
; }
410 // Define target-specific standard symbols.
412 define_standard_symbols(Symbol_table
* symtab
, Layout
* layout
)
413 { this->do_define_standard_symbols(symtab
, layout
); }
415 // Return the output section name to use given an input section
416 // name, or NULL if no target specific name mapping is required.
417 // Set *PLEN to the length of the name if returning non-NULL.
419 output_section_name(const Relobj
* relobj
,
422 { return this->do_output_section_name(relobj
, name
, plen
); }
424 // Add any special sections for this symbol to the gc work list.
426 gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const
427 { this->do_gc_mark_symbol(symtab
, sym
); }
430 // This struct holds the constant information for a child class. We
431 // use a struct to avoid the overhead of virtual function calls for
432 // simple information.
435 // Address size (32 or 64).
437 // Whether the target is big endian.
439 // The code to store in the e_machine field of the ELF header.
440 elfcpp::EM machine_code
;
441 // Whether this target has a specific make_symbol function.
442 bool has_make_symbol
;
443 // Whether this target has a specific resolve function.
445 // Whether this target has a specific code fill function.
447 // Whether an object file with no .note.GNU-stack sections implies
448 // that the stack should be executable.
449 bool is_default_stack_executable
;
450 // Whether a relocation to a merged section can be processed to
451 // retrieve the contents.
452 bool can_icf_inline_merge_sections
;
453 // Prefix character to strip when checking for wrapping.
455 // The default dynamic linker name.
456 const char* dynamic_linker
;
457 // The default text segment address.
458 uint64_t default_text_segment_address
;
459 // The ABI specified page size.
460 uint64_t abi_pagesize
;
461 // The common page size used by actual implementations.
462 uint64_t common_pagesize
;
463 // Whether PF_X segments must contain nothing but the contents of
464 // SHF_EXECINSTR sections (no non-executable data, no headers).
465 bool isolate_execinstr
;
466 // If nonzero, distance from the text segment to the read-only segment.
467 uint64_t rosegment_gap
;
468 // The special section index for small common symbols; SHN_UNDEF
470 elfcpp::Elf_Half small_common_shndx
;
471 // The special section index for large common symbols; SHN_UNDEF
473 elfcpp::Elf_Half large_common_shndx
;
474 // Section flags for small common section.
475 elfcpp::Elf_Xword small_common_section_flags
;
476 // Section flags for large common section.
477 elfcpp::Elf_Xword large_common_section_flags
;
478 // Name of attributes section if it is not ".gnu.attributes".
479 const char* attributes_section
;
480 // Vendor name of vendor attributes.
481 const char* attributes_vendor
;
484 Target(const Target_info
* pti
)
485 : pti_(pti
), processor_specific_flags_(0),
486 are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE
)
489 // Virtual function which may be implemented by the child class.
491 do_new_output_section(Output_section
*) const
494 // Virtual function which may be implemented by the child class.
496 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*)
499 // Virtual function which may be implemented by the child class.
501 do_dynsym_value(const Symbol
*) const
502 { gold_unreachable(); }
504 // Virtual function which must be implemented by the child class if
507 do_code_fill(section_size_type
) const
508 { gold_unreachable(); }
510 // Virtual function which may be implemented by the child class.
512 do_is_defined_by_abi(const Symbol
*) const
515 // Adjust the output file header before it is written out. VIEW
516 // points to the header in external form. LEN is the length, and
517 // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
518 // By default, we set the EI_OSABI field if requested (in
521 do_adjust_elf_header(unsigned char*, int) const = 0;
523 // Virtual function which may be overridden by the child class.
525 do_is_local_label_name(const char*) const;
527 // Virtual function that must be overridden by a target which uses
528 // target specific relocations.
530 do_reloc_symbol_index(void*, unsigned int) const
531 { gold_unreachable(); }
533 // Virtual function that must be overridden by a target which uses
534 // target specific relocations.
536 do_reloc_addend(void*, unsigned int, uint64_t) const
537 { gold_unreachable(); }
539 // Virtual functions that must be overridden by a target that uses
540 // STT_GNU_IFUNC symbols.
542 do_plt_address_for_global(const Symbol
*) const
543 { gold_unreachable(); }
546 do_plt_address_for_local(const Relobj
*, unsigned int) const
547 { gold_unreachable(); }
549 // Virtual function which may be overriden by the child class.
551 do_can_check_for_function_pointers() const
554 // Virtual function which may be overridden by the child class. We
555 // recognize some default sections for which we don't care whether
556 // they have function pointers.
558 do_section_may_have_icf_unsafe_pointers(const char* section_name
) const
560 // We recognize sections for normal vtables, construction vtables and
562 return (!is_prefix_of(".rodata._ZTV", section_name
)
563 && !is_prefix_of(".data.rel.ro._ZTV", section_name
)
564 && !is_prefix_of(".rodata._ZTC", section_name
)
565 && !is_prefix_of(".data.rel.ro._ZTC", section_name
)
566 && !is_prefix_of(".eh_frame", section_name
));
570 do_ehframe_datarel_base() const
571 { gold_unreachable(); }
573 // Virtual function which may be overridden by the child class. The
574 // default implementation is that any function not defined by the
575 // ABI is a call to a non-split function.
577 do_is_call_to_non_split(const Symbol
* sym
, unsigned int) const;
579 // Virtual function which may be overridden by the child class.
581 do_calls_non_split(Relobj
* object
, unsigned int, section_offset_type
,
582 section_size_type
, unsigned char*, section_size_type
,
583 std::string
*, std::string
*) const;
585 // make_elf_object hooks. There are four versions of these for
586 // different address sizes and endianness.
588 // Set processor specific flags.
590 set_processor_specific_flags(elfcpp::Elf_Word flags
)
592 this->processor_specific_flags_
= flags
;
593 this->are_processor_specific_flags_set_
= true;
596 #ifdef HAVE_TARGET_32_LITTLE
597 // Virtual functions which may be overridden by the child class.
599 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
600 const elfcpp::Ehdr
<32, false>&);
603 #ifdef HAVE_TARGET_32_BIG
604 // Virtual functions which may be overridden by the child class.
606 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
607 const elfcpp::Ehdr
<32, true>&);
610 #ifdef HAVE_TARGET_64_LITTLE
611 // Virtual functions which may be overridden by the child class.
613 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
614 const elfcpp::Ehdr
<64, false>& ehdr
);
617 #ifdef HAVE_TARGET_64_BIG
618 // Virtual functions which may be overridden by the child class.
620 do_make_elf_object(const std::string
& name
, Input_file
* input_file
,
621 off_t offset
, const elfcpp::Ehdr
<64, true>& ehdr
);
624 // Virtual functions which may be overridden by the child class.
625 virtual Output_section
*
626 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
627 elfcpp::Elf_Xword flags
);
629 // Virtual function which may be overridden by the child class.
632 { return parameters
->options().relax(); }
634 // Virtual function which may be overridden by the child class.
636 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*)
639 // A function for targets to call. Return whether BYTES/LEN matches
640 // VIEW/VIEW_SIZE at OFFSET.
642 match_view(const unsigned char* view
, section_size_type view_size
,
643 section_offset_type offset
, const char* bytes
, size_t len
) const;
645 // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
648 set_view_to_nop(unsigned char* view
, section_size_type view_size
,
649 section_offset_type offset
, size_t len
) const;
651 // This must be overridden by the child class if it has target-specific
652 // attributes subsection in the attribute section.
654 do_attribute_arg_type(int) const
655 { gold_unreachable(); }
657 // This may be overridden by the child class.
659 do_attributes_order(int num
) const
662 // This may be overridden by the child class.
664 do_select_as_default_target()
667 // This may be overridden by the child class.
669 do_define_standard_symbols(Symbol_table
*, Layout
*)
672 // This may be overridden by the child class.
674 do_output_section_name(const Relobj
*, const char*, size_t*) const
677 // This may be overridden by the child class.
679 do_gc_mark_symbol(Symbol_table
*, Symbol
*) const
683 // The implementations of the four do_make_elf_object virtual functions are
684 // almost identical except for their sizes and endianness. We use a template.
685 // for their implementations.
686 template<int size
, bool big_endian
>
688 do_make_elf_object_implementation(const std::string
&, Input_file
*, off_t
,
689 const elfcpp::Ehdr
<size
, big_endian
>&);
691 Target(const Target
&);
692 Target
& operator=(const Target
&);
694 // The target information.
695 const Target_info
* pti_
;
696 // Processor-specific flags.
697 elfcpp::Elf_Word processor_specific_flags_
;
698 // Whether the processor-specific flags are set at least once.
699 bool are_processor_specific_flags_set_
;
700 // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
701 // the ELF header. This is handled at this level because it is
702 // OS-specific rather than processor-specific.
703 elfcpp::ELFOSABI osabi_
;
706 // The abstract class for a specific size and endianness of target.
707 // Each actual target implementation class should derive from an
708 // instantiation of Sized_target.
710 template<int size
, bool big_endian
>
711 class Sized_target
: public Target
714 // Make a new symbol table entry for the target. This should be
715 // overridden by a target which needs additional information in the
716 // symbol table. This will only be called if has_make_symbol()
718 virtual Sized_symbol
<size
>*
720 { gold_unreachable(); }
722 // Resolve a symbol for the target. This should be overridden by a
723 // target which needs to take special action. TO is the
724 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
725 // VERSION is the version of SYM. This will only be called if
726 // has_resolve() returns true.
728 resolve(Symbol
*, const elfcpp::Sym
<size
, big_endian
>&, Object
*,
730 { gold_unreachable(); }
732 // Process the relocs for a section, and record information of the
733 // mapping from source to destination sections. This mapping is later
734 // used to determine unreferenced garbage sections. This procedure is
735 // only called during garbage collection.
737 gc_process_relocs(Symbol_table
* symtab
,
739 Sized_relobj_file
<size
, big_endian
>* object
,
740 unsigned int data_shndx
,
741 unsigned int sh_type
,
742 const unsigned char* prelocs
,
744 Output_section
* output_section
,
745 bool needs_special_offset_handling
,
746 size_t local_symbol_count
,
747 const unsigned char* plocal_symbols
) = 0;
749 // Scan the relocs for a section, and record any information
750 // required for the symbol. SYMTAB is the symbol table. OBJECT is
751 // the object in which the section appears. DATA_SHNDX is the
752 // section index that these relocs apply to. SH_TYPE is the type of
753 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
754 // the relocation data. RELOC_COUNT is the number of relocs.
755 // LOCAL_SYMBOL_COUNT is the number of local symbols.
756 // OUTPUT_SECTION is the output section.
757 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
758 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
759 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
760 // pointers to the global symbol table from OBJECT.
762 scan_relocs(Symbol_table
* symtab
,
764 Sized_relobj_file
<size
, big_endian
>* object
,
765 unsigned int data_shndx
,
766 unsigned int sh_type
,
767 const unsigned char* prelocs
,
769 Output_section
* output_section
,
770 bool needs_special_offset_handling
,
771 size_t local_symbol_count
,
772 const unsigned char* plocal_symbols
) = 0;
774 // Relocate section data. SH_TYPE is the type of the relocation
775 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
776 // information. RELOC_COUNT is the number of relocs.
777 // OUTPUT_SECTION is the output section.
778 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
779 // to correspond to the output section. VIEW is a view into the
780 // output file holding the section contents, VIEW_ADDRESS is the
781 // virtual address of the view, and VIEW_SIZE is the size of the
782 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
783 // parameters refer to the complete output section data, not just
784 // the input section data.
786 relocate_section(const Relocate_info
<size
, big_endian
>*,
787 unsigned int sh_type
,
788 const unsigned char* prelocs
,
790 Output_section
* output_section
,
791 bool needs_special_offset_handling
,
793 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
794 section_size_type view_size
,
795 const Reloc_symbol_changes
*) = 0;
797 // Scan the relocs during a relocatable link. The parameters are
798 // like scan_relocs, with an additional Relocatable_relocs
799 // parameter, used to record the disposition of the relocs.
801 scan_relocatable_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
,
812 Relocatable_relocs
*) = 0;
814 // Emit relocations for a section during a relocatable link, and for
815 // --emit-relocs. The parameters are like relocate_section, with
816 // additional parameters for the view of the output reloc section.
818 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
819 unsigned int sh_type
,
820 const unsigned char* prelocs
,
822 Output_section
* output_section
,
823 off_t offset_in_output_section
,
824 const Relocatable_relocs
*,
826 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
827 section_size_type view_size
,
828 unsigned char* reloc_view
,
829 section_size_type reloc_view_size
) = 0;
831 // Perform target-specific processing in a relocatable link. This is
832 // only used if we use the relocation strategy RELOC_SPECIAL.
833 // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
834 // section type. PRELOC_IN points to the original relocation. RELNUM is
835 // the index number of the relocation in the relocation section.
836 // OUTPUT_SECTION is the output section to which the relocation is applied.
837 // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
838 // within the output section. VIEW points to the output view of the
839 // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
840 // is the size of the output view and PRELOC_OUT points to the new
841 // relocation in the output object.
843 // A target only needs to override this if the generic code in
844 // target-reloc.h cannot handle some relocation types.
847 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>*
849 unsigned int /* sh_type */,
850 const unsigned char* /* preloc_in */,
852 Output_section
* /* output_section */,
853 off_t
/* offset_in_output_section */,
854 unsigned char* /* view */,
855 typename
elfcpp::Elf_types
<size
>::Elf_Addr
857 section_size_type
/* view_size */,
858 unsigned char* /* preloc_out*/)
859 { gold_unreachable(); }
861 // Return the number of entries in the GOT. This is only used for
862 // laying out the incremental link info sections. A target needs
863 // to implement this to support incremental linking.
866 got_entry_count() const
867 { gold_unreachable(); }
869 // Return the number of entries in the PLT. This is only used for
870 // laying out the incremental link info sections. A target needs
871 // to implement this to support incremental linking.
874 plt_entry_count() const
875 { gold_unreachable(); }
877 // Return the offset of the first non-reserved PLT entry. This is
878 // only used for laying out the incremental link info sections.
879 // A target needs to implement this to support incremental linking.
882 first_plt_entry_offset() const
883 { gold_unreachable(); }
885 // Return the size of each PLT entry. This is only used for
886 // laying out the incremental link info sections. A target needs
887 // to implement this to support incremental linking.
890 plt_entry_size() const
891 { gold_unreachable(); }
893 // Create the GOT and PLT sections for an incremental update.
894 // A target needs to implement this to support incremental linking.
896 virtual Output_data_got_base
*
897 init_got_plt_for_update(Symbol_table
*,
899 unsigned int /* got_count */,
900 unsigned int /* plt_count */)
901 { gold_unreachable(); }
903 // Reserve a GOT entry for a local symbol, and regenerate any
904 // necessary dynamic relocations.
906 reserve_local_got_entry(unsigned int /* got_index */,
907 Sized_relobj
<size
, big_endian
>* /* obj */,
908 unsigned int /* r_sym */,
909 unsigned int /* got_type */)
910 { gold_unreachable(); }
912 // Reserve a GOT entry for a global symbol, and regenerate any
913 // necessary dynamic relocations.
915 reserve_global_got_entry(unsigned int /* got_index */, Symbol
* /* gsym */,
916 unsigned int /* got_type */)
917 { gold_unreachable(); }
919 // Register an existing PLT entry for a global symbol.
920 // A target needs to implement this to support incremental linking.
923 register_global_plt_entry(Symbol_table
*, Layout
*,
924 unsigned int /* plt_index */,
926 { gold_unreachable(); }
928 // Force a COPY relocation for a given symbol.
929 // A target needs to implement this to support incremental linking.
932 emit_copy_reloc(Symbol_table
*, Symbol
*, Output_section
*, off_t
)
933 { gold_unreachable(); }
935 // Apply an incremental relocation.
938 apply_relocation(const Relocate_info
<size
, big_endian
>* /* relinfo */,
939 typename
elfcpp::Elf_types
<size
>::Elf_Addr
/* r_offset */,
940 unsigned int /* r_type */,
941 typename
elfcpp::Elf_types
<size
>::Elf_Swxword
/* r_addend */,
942 const Symbol
* /* gsym */,
943 unsigned char* /* view */,
944 typename
elfcpp::Elf_types
<size
>::Elf_Addr
/* address */,
945 section_size_type
/* view_size */)
946 { gold_unreachable(); }
948 // Handle target specific gc actions when adding a gc reference from
949 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
952 gc_add_reference(Symbol_table
* symtab
,
954 unsigned int src_shndx
,
956 unsigned int dst_shndx
,
957 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
) const
959 this->do_gc_add_reference(symtab
, src_obj
, src_shndx
,
960 dst_obj
, dst_shndx
, dst_off
);
964 Sized_target(const Target::Target_info
* pti
)
967 gold_assert(pti
->size
== size
);
968 gold_assert(pti
->is_big_endian
? big_endian
: !big_endian
);
971 // Set the EI_OSABI field if requested.
973 do_adjust_elf_header(unsigned char*, int) const;
975 // Handle target specific gc actions when adding a gc reference.
977 do_gc_add_reference(Symbol_table
*, Object
*, unsigned int,
978 Object
*, unsigned int,
979 typename
elfcpp::Elf_types
<size
>::Elf_Addr
) const
983 } // End namespace gold.
985 #endif // !defined(GOLD_TARGET_H)