1 // target.h -- target support for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
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
)
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
); }
452 // Return the name of the entry point symbol.
454 entry_symbol_name() const
455 { return this->pti_
->entry_symbol_name
; }
458 // This struct holds the constant information for a child class. We
459 // use a struct to avoid the overhead of virtual function calls for
460 // simple information.
463 // Address size (32 or 64).
465 // Whether the target is big endian.
467 // The code to store in the e_machine field of the ELF header.
468 elfcpp::EM machine_code
;
469 // Whether this target has a specific make_symbol function.
470 bool has_make_symbol
;
471 // Whether this target has a specific resolve function.
473 // Whether this target has a specific code fill function.
475 // Whether an object file with no .note.GNU-stack sections implies
476 // that the stack should be executable.
477 bool is_default_stack_executable
;
478 // Whether a relocation to a merged section can be processed to
479 // retrieve the contents.
480 bool can_icf_inline_merge_sections
;
481 // Prefix character to strip when checking for wrapping.
483 // The default dynamic linker name.
484 const char* dynamic_linker
;
485 // The default text segment address.
486 uint64_t default_text_segment_address
;
487 // The ABI specified page size.
488 uint64_t abi_pagesize
;
489 // The common page size used by actual implementations.
490 uint64_t common_pagesize
;
491 // Whether PF_X segments must contain nothing but the contents of
492 // SHF_EXECINSTR sections (no non-executable data, no headers).
493 bool isolate_execinstr
;
494 // If nonzero, distance from the text segment to the read-only segment.
495 uint64_t rosegment_gap
;
496 // The special section index for small common symbols; SHN_UNDEF
498 elfcpp::Elf_Half small_common_shndx
;
499 // The special section index for large common symbols; SHN_UNDEF
501 elfcpp::Elf_Half large_common_shndx
;
502 // Section flags for small common section.
503 elfcpp::Elf_Xword small_common_section_flags
;
504 // Section flags for large common section.
505 elfcpp::Elf_Xword large_common_section_flags
;
506 // Name of attributes section if it is not ".gnu.attributes".
507 const char* attributes_section
;
508 // Vendor name of vendor attributes.
509 const char* attributes_vendor
;
510 // Name of the main entry point to the program.
511 const char* entry_symbol_name
;
514 Target(const Target_info
* pti
)
515 : pti_(pti
), processor_specific_flags_(0),
516 are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE
)
519 // Virtual function which may be implemented by the child class.
521 do_new_output_section(Output_section
*) const
524 // Virtual function which may be implemented by the child class.
526 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*)
529 // Virtual function which may be implemented by the child class.
531 do_dynsym_value(const Symbol
*) const
532 { gold_unreachable(); }
534 // Virtual function which must be implemented by the child class if
537 do_code_fill(section_size_type
) const
538 { gold_unreachable(); }
540 // Virtual function which may be implemented by the child class.
542 do_is_defined_by_abi(const Symbol
*) const
545 // Adjust the output file header before it is written out. VIEW
546 // points to the header in external form. LEN is the length, and
547 // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
548 // By default, we set the EI_OSABI field if requested (in
551 do_adjust_elf_header(unsigned char*, int) = 0;
553 // Return address and size to plug into eh_frame FDEs associated with a PLT.
555 do_plt_fde_location(const Output_data
* plt
, unsigned char* oview
,
556 uint64_t* address
, off_t
* len
) const;
558 // Virtual function which may be overridden by the child class.
560 do_is_local_label_name(const char*) const;
562 // Virtual function that must be overridden by a target which uses
563 // target specific relocations.
565 do_reloc_symbol_index(void*, unsigned int) const
566 { gold_unreachable(); }
568 // Virtual function that must be overridden by a target which uses
569 // target specific relocations.
571 do_reloc_addend(void*, unsigned int, uint64_t) const
572 { gold_unreachable(); }
574 // Virtual functions that must be overridden by a target that uses
575 // STT_GNU_IFUNC symbols.
577 do_plt_address_for_global(const Symbol
*) const
578 { gold_unreachable(); }
581 do_plt_address_for_local(const Relobj
*, unsigned int) const
582 { gold_unreachable(); }
585 do_tls_offset_for_local(const Relobj
*, unsigned int, unsigned int) const
586 { gold_unreachable(); }
589 do_tls_offset_for_global(Symbol
*, unsigned int) const
590 { gold_unreachable(); }
593 do_function_location(Symbol_location
*) const = 0;
595 // Virtual function which may be overriden by the child class.
597 do_can_check_for_function_pointers() const
600 // Virtual function which may be overridden by the child class. We
601 // recognize some default sections for which we don't care whether
602 // they have function pointers.
604 do_section_may_have_icf_unsafe_pointers(const char* section_name
) const
606 // We recognize sections for normal vtables, construction vtables and
608 return (!is_prefix_of(".rodata._ZTV", section_name
)
609 && !is_prefix_of(".data.rel.ro._ZTV", section_name
)
610 && !is_prefix_of(".rodata._ZTC", section_name
)
611 && !is_prefix_of(".data.rel.ro._ZTC", section_name
)
612 && !is_prefix_of(".eh_frame", section_name
));
616 do_ehframe_datarel_base() const
617 { gold_unreachable(); }
619 // Virtual function which may be overridden by the child class. The
620 // default implementation is that any function not defined by the
621 // ABI is a call to a non-split function.
623 do_is_call_to_non_split(const Symbol
* sym
, unsigned int) const;
625 // Virtual function which may be overridden by the child class.
627 do_calls_non_split(Relobj
* object
, unsigned int, section_offset_type
,
628 section_size_type
, unsigned char*, section_size_type
,
629 std::string
*, std::string
*) const;
631 // make_elf_object hooks. There are four versions of these for
632 // different address sizes and endianness.
634 // Set processor specific flags.
636 set_processor_specific_flags(elfcpp::Elf_Word flags
)
638 this->processor_specific_flags_
= flags
;
639 this->are_processor_specific_flags_set_
= true;
642 #ifdef HAVE_TARGET_32_LITTLE
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, false>&);
649 #ifdef HAVE_TARGET_32_BIG
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
<32, true>&);
656 #ifdef HAVE_TARGET_64_LITTLE
657 // Virtual functions which may be overridden by the child class.
659 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
660 const elfcpp::Ehdr
<64, false>& ehdr
);
663 #ifdef HAVE_TARGET_64_BIG
664 // Virtual functions which may be overridden by the child class.
666 do_make_elf_object(const std::string
& name
, Input_file
* input_file
,
667 off_t offset
, const elfcpp::Ehdr
<64, true>& ehdr
);
670 // Virtual functions which may be overridden by the child class.
671 virtual Output_section
*
672 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
673 elfcpp::Elf_Xword flags
);
675 // Virtual function which may be overridden by the child class.
678 { return parameters
->options().relax(); }
680 // Virtual function which may be overridden by the child class.
682 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*)
685 // A function for targets to call. Return whether BYTES/LEN matches
686 // VIEW/VIEW_SIZE at OFFSET.
688 match_view(const unsigned char* view
, section_size_type view_size
,
689 section_offset_type offset
, const char* bytes
, size_t len
) const;
691 // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
694 set_view_to_nop(unsigned char* view
, section_size_type view_size
,
695 section_offset_type offset
, size_t len
) const;
697 // This must be overridden by the child class if it has target-specific
698 // attributes subsection in the attribute section.
700 do_attribute_arg_type(int) const
701 { gold_unreachable(); }
703 // This may be overridden by the child class.
705 do_attributes_order(int num
) const
708 // This may be overridden by the child class.
710 do_select_as_default_target()
713 // This may be overridden by the child class.
715 do_define_standard_symbols(Symbol_table
*, Layout
*)
718 // This may be overridden by the child class.
720 do_output_section_name(const Relobj
*, const char*, size_t*) const
723 // This may be overridden by the child class.
725 do_gc_mark_symbol(Symbol_table
*, Symbol
*) const
729 // The implementations of the four do_make_elf_object virtual functions are
730 // almost identical except for their sizes and endianness. We use a template.
731 // for their implementations.
732 template<int size
, bool big_endian
>
734 do_make_elf_object_implementation(const std::string
&, Input_file
*, off_t
,
735 const elfcpp::Ehdr
<size
, big_endian
>&);
737 Target(const Target
&);
738 Target
& operator=(const Target
&);
740 // The target information.
741 const Target_info
* pti_
;
742 // Processor-specific flags.
743 elfcpp::Elf_Word processor_specific_flags_
;
744 // Whether the processor-specific flags are set at least once.
745 bool are_processor_specific_flags_set_
;
746 // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
747 // the ELF header. This is handled at this level because it is
748 // OS-specific rather than processor-specific.
749 elfcpp::ELFOSABI osabi_
;
752 // The abstract class for a specific size and endianness of target.
753 // Each actual target implementation class should derive from an
754 // instantiation of Sized_target.
756 template<int size
, bool big_endian
>
757 class Sized_target
: public Target
760 // Make a new symbol table entry for the target. This should be
761 // overridden by a target which needs additional information in the
762 // symbol table. This will only be called if has_make_symbol()
764 virtual Sized_symbol
<size
>*
766 { gold_unreachable(); }
768 // Resolve a symbol for the target. This should be overridden by a
769 // target which needs to take special action. TO is the
770 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
771 // VERSION is the version of SYM. This will only be called if
772 // has_resolve() returns true.
774 resolve(Symbol
*, const elfcpp::Sym
<size
, big_endian
>&, Object
*,
776 { gold_unreachable(); }
778 // Process the relocs for a section, and record information of the
779 // mapping from source to destination sections. This mapping is later
780 // used to determine unreferenced garbage sections. This procedure is
781 // only called during garbage collection.
783 gc_process_relocs(Symbol_table
* symtab
,
785 Sized_relobj_file
<size
, big_endian
>* object
,
786 unsigned int data_shndx
,
787 unsigned int sh_type
,
788 const unsigned char* prelocs
,
790 Output_section
* output_section
,
791 bool needs_special_offset_handling
,
792 size_t local_symbol_count
,
793 const unsigned char* plocal_symbols
) = 0;
795 // Scan the relocs for a section, and record any information
796 // required for the symbol. SYMTAB is the symbol table. OBJECT is
797 // the object in which the section appears. DATA_SHNDX is the
798 // section index that these relocs apply to. SH_TYPE is the type of
799 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
800 // the relocation data. RELOC_COUNT is the number of relocs.
801 // LOCAL_SYMBOL_COUNT is the number of local symbols.
802 // OUTPUT_SECTION is the output section.
803 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
804 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
805 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
806 // pointers to the global symbol table from OBJECT.
808 scan_relocs(Symbol_table
* symtab
,
810 Sized_relobj_file
<size
, big_endian
>* object
,
811 unsigned int data_shndx
,
812 unsigned int sh_type
,
813 const unsigned char* prelocs
,
815 Output_section
* output_section
,
816 bool needs_special_offset_handling
,
817 size_t local_symbol_count
,
818 const unsigned char* plocal_symbols
) = 0;
820 // Relocate section data. SH_TYPE is the type of the relocation
821 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
822 // information. RELOC_COUNT is the number of relocs.
823 // OUTPUT_SECTION is the output section.
824 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
825 // to correspond to the output section. VIEW is a view into the
826 // output file holding the section contents, VIEW_ADDRESS is the
827 // virtual address of the view, and VIEW_SIZE is the size of the
828 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
829 // parameters refer to the complete output section data, not just
830 // the input section data.
832 relocate_section(const Relocate_info
<size
, big_endian
>*,
833 unsigned int sh_type
,
834 const unsigned char* prelocs
,
836 Output_section
* output_section
,
837 bool needs_special_offset_handling
,
839 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
840 section_size_type view_size
,
841 const Reloc_symbol_changes
*) = 0;
843 // Scan the relocs during a relocatable link. The parameters are
844 // like scan_relocs, with an additional Relocatable_relocs
845 // parameter, used to record the disposition of the relocs.
847 scan_relocatable_relocs(Symbol_table
* symtab
,
849 Sized_relobj_file
<size
, big_endian
>* object
,
850 unsigned int data_shndx
,
851 unsigned int sh_type
,
852 const unsigned char* prelocs
,
854 Output_section
* output_section
,
855 bool needs_special_offset_handling
,
856 size_t local_symbol_count
,
857 const unsigned char* plocal_symbols
,
858 Relocatable_relocs
*) = 0;
860 // Emit relocations for a section during a relocatable link, and for
861 // --emit-relocs. The parameters are like relocate_section, with
862 // additional parameters for the view of the output reloc section.
864 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
865 unsigned int sh_type
,
866 const unsigned char* prelocs
,
868 Output_section
* output_section
,
869 typename
elfcpp::Elf_types
<size
>::Elf_Off
870 offset_in_output_section
,
871 const Relocatable_relocs
*,
873 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
874 section_size_type view_size
,
875 unsigned char* reloc_view
,
876 section_size_type reloc_view_size
) = 0;
878 // Perform target-specific processing in a relocatable link. This is
879 // only used if we use the relocation strategy RELOC_SPECIAL.
880 // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
881 // section type. PRELOC_IN points to the original relocation. RELNUM is
882 // the index number of the relocation in the relocation section.
883 // OUTPUT_SECTION is the output section to which the relocation is applied.
884 // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
885 // within the output section. VIEW points to the output view of the
886 // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
887 // is the size of the output view and PRELOC_OUT points to the new
888 // relocation in the output object.
890 // A target only needs to override this if the generic code in
891 // target-reloc.h cannot handle some relocation types.
894 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>*
896 unsigned int /* sh_type */,
897 const unsigned char* /* preloc_in */,
899 Output_section
* /* output_section */,
900 typename
elfcpp::Elf_types
<size
>::Elf_Off
901 /* offset_in_output_section */,
902 unsigned char* /* view */,
903 typename
elfcpp::Elf_types
<size
>::Elf_Addr
905 section_size_type
/* view_size */,
906 unsigned char* /* preloc_out*/)
907 { gold_unreachable(); }
909 // Return the number of entries in the GOT. This is only used for
910 // laying out the incremental link info sections. A target needs
911 // to implement this to support incremental linking.
914 got_entry_count() const
915 { gold_unreachable(); }
917 // Return the number of entries in the PLT. This is only used for
918 // laying out the incremental link info sections. A target needs
919 // to implement this to support incremental linking.
922 plt_entry_count() const
923 { gold_unreachable(); }
925 // Return the offset of the first non-reserved PLT entry. This is
926 // only used for laying out the incremental link info sections.
927 // A target needs to implement this to support incremental linking.
930 first_plt_entry_offset() const
931 { gold_unreachable(); }
933 // Return the size of each PLT entry. This is only used for
934 // laying out the incremental link info sections. A target needs
935 // to implement this to support incremental linking.
938 plt_entry_size() const
939 { gold_unreachable(); }
941 // Create the GOT and PLT sections for an incremental update.
942 // A target needs to implement this to support incremental linking.
944 virtual Output_data_got_base
*
945 init_got_plt_for_update(Symbol_table
*,
947 unsigned int /* got_count */,
948 unsigned int /* plt_count */)
949 { gold_unreachable(); }
951 // Reserve a GOT entry for a local symbol, and regenerate any
952 // necessary dynamic relocations.
954 reserve_local_got_entry(unsigned int /* got_index */,
955 Sized_relobj
<size
, big_endian
>* /* obj */,
956 unsigned int /* r_sym */,
957 unsigned int /* got_type */)
958 { gold_unreachable(); }
960 // Reserve a GOT entry for a global symbol, and regenerate any
961 // necessary dynamic relocations.
963 reserve_global_got_entry(unsigned int /* got_index */, Symbol
* /* gsym */,
964 unsigned int /* got_type */)
965 { gold_unreachable(); }
967 // Register an existing PLT entry for a global symbol.
968 // A target needs to implement this to support incremental linking.
971 register_global_plt_entry(Symbol_table
*, Layout
*,
972 unsigned int /* plt_index */,
974 { gold_unreachable(); }
976 // Force a COPY relocation for a given symbol.
977 // A target needs to implement this to support incremental linking.
980 emit_copy_reloc(Symbol_table
*, Symbol
*, Output_section
*, off_t
)
981 { gold_unreachable(); }
983 // Apply an incremental relocation.
986 apply_relocation(const Relocate_info
<size
, big_endian
>* /* relinfo */,
987 typename
elfcpp::Elf_types
<size
>::Elf_Addr
/* r_offset */,
988 unsigned int /* r_type */,
989 typename
elfcpp::Elf_types
<size
>::Elf_Swxword
/* r_addend */,
990 const Symbol
* /* gsym */,
991 unsigned char* /* view */,
992 typename
elfcpp::Elf_types
<size
>::Elf_Addr
/* address */,
993 section_size_type
/* view_size */)
994 { gold_unreachable(); }
996 // Handle target specific gc actions when adding a gc reference from
997 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1000 gc_add_reference(Symbol_table
* symtab
,
1002 unsigned int src_shndx
,
1004 unsigned int dst_shndx
,
1005 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
) const
1007 this->do_gc_add_reference(symtab
, src_obj
, src_shndx
,
1008 dst_obj
, dst_shndx
, dst_off
);
1012 Sized_target(const Target::Target_info
* pti
)
1015 gold_assert(pti
->size
== size
);
1016 gold_assert(pti
->is_big_endian
? big_endian
: !big_endian
);
1019 // Set the EI_OSABI field if requested.
1021 do_adjust_elf_header(unsigned char*, int);
1023 // Handle target specific gc actions when adding a gc reference.
1025 do_gc_add_reference(Symbol_table
*, Object
*, unsigned int,
1026 Object
*, unsigned int,
1027 typename
elfcpp::Elf_types
<size
>::Elf_Addr
) const
1031 do_function_location(Symbol_location
*) const
1035 } // End namespace gold.
1037 #endif // !defined(GOLD_TARGET_H)