1 // target.h -- target support for gold -*- C++ -*-
3 // Copyright (C) 2006-2014 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 // The abstract class Target is the interface for target specific
24 // support. It defines abstract methods which each target must
25 // implement. Typically there will be one target per processor, but
26 // in some cases it may be necessary to have subclasses.
28 // For speed and consistency we want to use inline functions to handle
29 // relocation processing. So besides implementations of the abstract
30 // methods, each target is expected to define a template
31 // specialization of the relocation functions.
38 #include "parameters.h"
39 #include "stringpool.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;
67 // The abstract class for target specific handling.
75 // Return the bit size that this target implements. This should
79 { return this->pti_->size; }
81 // Return whether this target is big-endian.
84 { return this->pti_->is_big_endian; }
86 // Machine code to store in e_machine field of ELF header.
89 { return this->pti_->machine_code; }
91 // Processor specific flags to store in e_flags field of ELF header.
93 processor_specific_flags() const
94 { return this->processor_specific_flags_; }
96 // Whether processor specific flags are set at least once.
98 are_processor_specific_flags_set() const
99 { return this->are_processor_specific_flags_set_; }
101 // Whether this target has a specific make_symbol function.
103 has_make_symbol() const
104 { return this->pti_->has_make_symbol; }
106 // Whether this target has a specific resolve function.
109 { return this->pti_->has_resolve; }
111 // Whether this target has a specific code fill function.
113 has_code_fill() const
114 { return this->pti_->has_code_fill; }
116 // Return the default name of the dynamic linker.
118 dynamic_linker() const
119 { return this->pti_->dynamic_linker; }
121 // Return the default address to use for the text segment.
123 default_text_segment_address() const
124 { return this->pti_->default_text_segment_address; }
126 // Return the ABI specified page size.
130 if (parameters->options().max_page_size() > 0)
131 return parameters->options().max_page_size();
133 return this->pti_->abi_pagesize;
136 // Return the common page size used on actual systems.
138 common_pagesize() const
140 if (parameters->options().common_page_size() > 0)
141 return std::min(parameters->options().common_page_size(),
142 this->abi_pagesize());
144 return std::min(this->pti_->common_pagesize,
145 this->abi_pagesize());
148 // Return whether PF_X segments must contain nothing but the contents of
149 // SHF_EXECINSTR sections (no non-executable data, no headers).
151 isolate_execinstr() const
152 { return this->pti_->isolate_execinstr; }
155 rosegment_gap() const
156 { return this->pti_->rosegment_gap; }
158 // If we see some object files with .note.GNU-stack sections, and
159 // some objects files without them, this returns whether we should
160 // consider the object files without them to imply that the stack
161 // should be executable.
163 is_default_stack_executable() const
164 { return this->pti_->is_default_stack_executable; }
166 // Return a character which may appear as a prefix for a wrap
167 // symbol. If this character appears, we strip it when checking for
168 // wrapping and add it back when forming the final symbol name.
169 // This should be '\0' if not special prefix is required, which is
173 { return this->pti_->wrap_char; }
175 // Return the special section index which indicates a small common
176 // symbol. This will return SHN_UNDEF if there are no small common
179 small_common_shndx() const
180 { return this->pti_->small_common_shndx; }
182 // Return values to add to the section flags for the section holding
183 // small common symbols.
185 small_common_section_flags() const
187 gold_assert(this->pti_->small_common_shndx != elfcpp::SHN_UNDEF);
188 return this->pti_->small_common_section_flags;
191 // Return the special section index which indicates a large common
192 // symbol. This will return SHN_UNDEF if there are no large common
195 large_common_shndx() const
196 { return this->pti_->large_common_shndx; }
198 // Return values to add to the section flags for the section holding
199 // large common symbols.
201 large_common_section_flags() const
203 gold_assert(this->pti_->large_common_shndx != elfcpp::SHN_UNDEF);
204 return this->pti_->large_common_section_flags;
207 // This hook is called when an output section is created.
209 new_output_section(Output_section* os) const
210 { this->do_new_output_section(os); }
212 // This is called to tell the target to complete any sections it is
213 // handling. After this all sections must have their final size.
215 finalize_sections(Layout* layout, const Input_objects* input_objects,
216 Symbol_table* symtab)
217 { return this->do_finalize_sections(layout, input_objects, symtab); }
219 // Return the value to use for a global symbol which needs a special
220 // value in the dynamic symbol table. This will only be called if
221 // the backend first calls symbol->set_needs_dynsym_value().
223 dynsym_value(const Symbol* sym) const
224 { return this->do_dynsym_value(sym); }
226 // Return a string to use to fill out a code section. This is
227 // basically one or more NOPS which must fill out the specified
230 code_fill(section_size_type length) const
231 { return this->do_code_fill(length); }
233 // Return whether SYM is known to be defined by the ABI. This is
234 // used to avoid inappropriate warnings about undefined symbols.
236 is_defined_by_abi(const Symbol* sym) const
237 { return this->do_is_defined_by_abi(sym); }
239 // Adjust the output file header before it is written out. VIEW
240 // points to the header in external form. LEN is the length.
242 adjust_elf_header(unsigned char* view, int len)
243 { return this->do_adjust_elf_header(view, len); }
245 // Return address and size to plug into eh_frame FDEs associated with a PLT.
247 plt_fde_location(const Output_data* plt, unsigned char* oview,
248 uint64_t* address, off_t* len) const
249 { return this->do_plt_fde_location(plt, oview, address, len); }
251 // Return whether NAME is a local label name. This is used to implement the
252 // --discard-locals options.
254 is_local_label_name(const char* name) const
255 { return this->do_is_local_label_name(name); }
257 // Get the symbol index to use for a target specific reloc.
259 reloc_symbol_index(void* arg, unsigned int type) const
260 { return this->do_reloc_symbol_index(arg, type); }
262 // Get the addend to use for a target specific reloc.
264 reloc_addend(void* arg, unsigned int type, uint64_t addend) const
265 { return this->do_reloc_addend(arg, type, addend); }
267 // Return the PLT address to use for a global symbol.
269 plt_address_for_global(const Symbol* sym) const
270 { return this->do_plt_address_for_global(sym); }
272 // Return the PLT address to use for a local symbol.
274 plt_address_for_local(const Relobj* object, unsigned int symndx) const
275 { return this->do_plt_address_for_local(object, symndx); }
277 // Return the offset to use for the GOT_INDX'th got entry which is
278 // for a local tls symbol specified by OBJECT, SYMNDX.
280 tls_offset_for_local(const Relobj* object,
282 unsigned int got_indx) const
283 { return do_tls_offset_for_local(object, symndx, got_indx); }
285 // Return the offset to use for the GOT_INDX'th got entry which is
286 // for global tls symbol GSYM.
288 tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const
289 { return do_tls_offset_for_global(gsym, got_indx); }
291 // For targets that use function descriptors, if LOC is the location
292 // of a function, modify it to point at the function entry location.
294 function_location(Symbol_location* loc) const
295 { return do_function_location(loc); }
297 // Return whether this target can use relocation types to determine
298 // if a function's address is taken.
300 can_check_for_function_pointers() const
301 { return this->do_can_check_for_function_pointers(); }
303 // Return whether a relocation to a merged section can be processed
304 // to retrieve the contents.
306 can_icf_inline_merge_sections () const
307 { return this->pti_->can_icf_inline_merge_sections; }
309 // Whether a section called SECTION_NAME may have function pointers to
310 // sections not eligible for safe ICF folding.
312 section_may_have_icf_unsafe_pointers(const char* section_name) const
313 { return this->do_section_may_have_icf_unsafe_pointers(section_name); }
315 // Return the base to use for the PC value in an FDE when it is
316 // encoded using DW_EH_PE_datarel. This does not appear to be
317 // documented anywhere, but it is target specific. Any use of
318 // DW_EH_PE_datarel in gcc requires defining a special macro
319 // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value.
321 ehframe_datarel_base() const
322 { return this->do_ehframe_datarel_base(); }
324 // Return true if a reference to SYM from a reloc of type R_TYPE
325 // means that the current function may call an object compiled
326 // without -fsplit-stack. SYM is known to be defined in an object
327 // compiled without -fsplit-stack.
329 is_call_to_non_split(const Symbol* sym, unsigned int r_type) const
330 { return this->do_is_call_to_non_split(sym, r_type); }
332 // A function starts at OFFSET in section SHNDX in OBJECT. That
333 // function was compiled with -fsplit-stack, but it refers to a
334 // function which was compiled without -fsplit-stack. VIEW is a
335 // modifiable view of the section; VIEW_SIZE is the size of the
336 // view. The target has to adjust the function so that it allocates
339 calls_non_split(Relobj* object, unsigned int shndx,
340 section_offset_type fnoffset, section_size_type fnsize,
341 unsigned char* view, section_size_type view_size,
342 std::string* from, std::string* to) const
344 this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size,
348 // Make an ELF object.
349 template<int size, bool big_endian>
351 make_elf_object(const std::string& name, Input_file* input_file,
352 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
353 { return this->do_make_elf_object(name, input_file, offset, ehdr); }
355 // Make an output section.
357 make_output_section(const char* name, elfcpp::Elf_Word type,
358 elfcpp::Elf_Xword flags)
359 { return this->do_make_output_section(name, type, flags); }
361 // Return true if target wants to perform relaxation.
365 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
366 if (is_debugging_enabled(DEBUG_RELAXATION))
369 return this->do_may_relax();
372 // Perform a relaxation pass. Return true if layout may be changed.
374 relax(int pass, const Input_objects* input_objects, Symbol_table* symtab,
375 Layout* layout, const Task* task)
377 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
378 if (is_debugging_enabled(DEBUG_RELAXATION))
381 return this->do_relax(pass, input_objects, symtab, layout, task);
384 // Return the target-specific name of attributes section. This is
385 // NULL if a target does not use attributes section or if it uses
386 // the default section name ".gnu.attributes".
388 attributes_section() const
389 { return this->pti_->attributes_section; }
391 // Return the vendor name of vendor attributes.
393 attributes_vendor() const
394 { return this->pti_->attributes_vendor; }
396 // Whether a section called NAME is an attribute section.
398 is_attributes_section(const char* name) const
400 return ((this->pti_->attributes_section != NULL
401 && strcmp(name, this->pti_->attributes_section) == 0)
402 || strcmp(name, ".gnu.attributes") == 0);
405 // Return a bit mask of argument types for attribute with TAG.
407 attribute_arg_type(int tag) const
408 { return this->do_attribute_arg_type(tag); }
410 // Return the attribute tag of the position NUM in the list of fixed
411 // attributes. Normally there is no reordering and
412 // attributes_order(NUM) == NUM.
414 attributes_order(int num) const
415 { return this->do_attributes_order(num); }
417 // When a target is selected as the default target, we call this method,
418 // which may be used for expensive, target-specific initialization.
420 select_as_default_target()
421 { this->do_select_as_default_target(); }
423 // Return the value to store in the EI_OSABI field in the ELF
427 { return this->osabi_; }
429 // Set the value to store in the EI_OSABI field in the ELF header.
431 set_osabi(elfcpp::ELFOSABI osabi)
432 { this->osabi_ = osabi; }
434 // Define target-specific standard symbols.
436 define_standard_symbols(Symbol_table* symtab, Layout* layout)
437 { this->do_define_standard_symbols(symtab, layout); }
439 // Return the output section name to use given an input section
440 // name, or NULL if no target specific name mapping is required.
441 // Set *PLEN to the length of the name if returning non-NULL.
443 output_section_name(const Relobj* relobj,
446 { return this->do_output_section_name(relobj, name, plen); }
448 // Add any special sections for this symbol to the gc work list.
450 gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const
451 { this->do_gc_mark_symbol(symtab, sym); }
453 // Return the name of the entry point symbol.
455 entry_symbol_name() const
456 { return this->pti_->entry_symbol_name; }
458 // Whether the target has a custom set_dynsym_indexes method.
460 has_custom_set_dynsym_indexes() const
461 { return this->do_has_custom_set_dynsym_indexes(); }
463 // Custom set_dynsym_indexes method for a target.
465 set_dynsym_indexes(std::vector<Symbol*>* dyn_symbols, unsigned int index,
466 std::vector<Symbol*>* syms, Stringpool* dynpool,
467 Versions* versions, Symbol_table* symtab) const
469 return this->do_set_dynsym_indexes(dyn_symbols, index, syms, dynpool,
473 // Get the custom dynamic tag value.
475 dynamic_tag_custom_value(elfcpp::DT tag) const
476 { return this->do_dynamic_tag_custom_value(tag); }
478 // Adjust the value written to the dynamic symbol table.
480 adjust_dyn_symbol(const Symbol* sym, unsigned char* view) const
481 { this->do_adjust_dyn_symbol(sym, view); }
483 // Return whether to include the section in the link.
485 should_include_section(elfcpp::Elf_Word sh_type) const
486 { return this->do_should_include_section(sh_type); }
489 // This struct holds the constant information for a child class. We
490 // use a struct to avoid the overhead of virtual function calls for
491 // simple information.
494 // Address size (32 or 64).
496 // Whether the target is big endian.
498 // The code to store in the e_machine field of the ELF header.
499 elfcpp::EM machine_code;
500 // Whether this target has a specific make_symbol function.
501 bool has_make_symbol;
502 // Whether this target has a specific resolve function.
504 // Whether this target has a specific code fill function.
506 // Whether an object file with no .note.GNU-stack sections implies
507 // that the stack should be executable.
508 bool is_default_stack_executable;
509 // Whether a relocation to a merged section can be processed to
510 // retrieve the contents.
511 bool can_icf_inline_merge_sections;
512 // Prefix character to strip when checking for wrapping.
514 // The default dynamic linker name.
515 const char* dynamic_linker;
516 // The default text segment address.
517 uint64_t default_text_segment_address;
518 // The ABI specified page size.
519 uint64_t abi_pagesize;
520 // The common page size used by actual implementations.
521 uint64_t common_pagesize;
522 // Whether PF_X segments must contain nothing but the contents of
523 // SHF_EXECINSTR sections (no non-executable data, no headers).
524 bool isolate_execinstr;
525 // If nonzero, distance from the text segment to the read-only segment.
526 uint64_t rosegment_gap;
527 // The special section index for small common symbols; SHN_UNDEF
529 elfcpp::Elf_Half small_common_shndx;
530 // The special section index for large common symbols; SHN_UNDEF
532 elfcpp::Elf_Half large_common_shndx;
533 // Section flags for small common section.
534 elfcpp::Elf_Xword small_common_section_flags;
535 // Section flags for large common section.
536 elfcpp::Elf_Xword large_common_section_flags;
537 // Name of attributes section if it is not ".gnu.attributes".
538 const char* attributes_section;
539 // Vendor name of vendor attributes.
540 const char* attributes_vendor;
541 // Name of the main entry point to the program.
542 const char* entry_symbol_name;
545 Target(const Target_info* pti)
546 : pti_(pti), processor_specific_flags_(0),
547 are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE)
550 // Virtual function which may be implemented by the child class.
552 do_new_output_section(Output_section*) const
555 // Virtual function which may be implemented by the child class.
557 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*)
560 // Virtual function which may be implemented by the child class.
562 do_dynsym_value(const Symbol*) const
563 { gold_unreachable(); }
565 // Virtual function which must be implemented by the child class if
568 do_code_fill(section_size_type) const
569 { gold_unreachable(); }
571 // Virtual function which may be implemented by the child class.
573 do_is_defined_by_abi(const Symbol*) const
576 // Adjust the output file header before it is written out. VIEW
577 // points to the header in external form. LEN is the length, and
578 // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
579 // By default, we set the EI_OSABI field if requested (in
582 do_adjust_elf_header(unsigned char*, int) = 0;
584 // Return address and size to plug into eh_frame FDEs associated with a PLT.
586 do_plt_fde_location(const Output_data* plt, unsigned char* oview,
587 uint64_t* address, off_t* len) const;
589 // Virtual function which may be overridden by the child class.
591 do_is_local_label_name(const char*) const;
593 // Virtual function that must be overridden by a target which uses
594 // target specific relocations.
596 do_reloc_symbol_index(void*, unsigned int) const
597 { gold_unreachable(); }
599 // Virtual function that must be overridden by a target which uses
600 // target specific relocations.
602 do_reloc_addend(void*, unsigned int, uint64_t) const
603 { gold_unreachable(); }
605 // Virtual functions that must be overridden by a target that uses
606 // STT_GNU_IFUNC symbols.
608 do_plt_address_for_global(const Symbol*) const
609 { gold_unreachable(); }
612 do_plt_address_for_local(const Relobj*, unsigned int) const
613 { gold_unreachable(); }
616 do_tls_offset_for_local(const Relobj*, unsigned int, unsigned int) const
617 { gold_unreachable(); }
620 do_tls_offset_for_global(Symbol*, unsigned int) const
621 { gold_unreachable(); }
624 do_function_location(Symbol_location*) const = 0;
626 // Virtual function which may be overriden by the child class.
628 do_can_check_for_function_pointers() const
631 // Virtual function which may be overridden by the child class. We
632 // recognize some default sections for which we don't care whether
633 // they have function pointers.
635 do_section_may_have_icf_unsafe_pointers(const char* section_name) const
637 // We recognize sections for normal vtables, construction vtables and
639 return (!is_prefix_of(".rodata._ZTV", section_name)
640 && !is_prefix_of(".data.rel.ro._ZTV", section_name)
641 && !is_prefix_of(".rodata._ZTC", section_name)
642 && !is_prefix_of(".data.rel.ro._ZTC", section_name)
643 && !is_prefix_of(".eh_frame", section_name));
647 do_ehframe_datarel_base() const
648 { gold_unreachable(); }
650 // Virtual function which may be overridden by the child class. The
651 // default implementation is that any function not defined by the
652 // ABI is a call to a non-split function.
654 do_is_call_to_non_split(const Symbol* sym, unsigned int) const;
656 // Virtual function which may be overridden by the child class.
658 do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
659 section_size_type, unsigned char*, section_size_type,
660 std::string*, std::string*) const;
662 // make_elf_object hooks. There are four versions of these for
663 // different address sizes and endianness.
665 // Set processor specific flags.
667 set_processor_specific_flags(elfcpp::Elf_Word flags)
669 this->processor_specific_flags_ = flags;
670 this->are_processor_specific_flags_set_ = true;
673 #ifdef HAVE_TARGET_32_LITTLE
674 // Virtual functions which may be overridden by the child class.
676 do_make_elf_object(const std::string&, Input_file*, off_t,
677 const elfcpp::Ehdr<32, false>&);
680 #ifdef HAVE_TARGET_32_BIG
681 // Virtual functions which may be overridden by the child class.
683 do_make_elf_object(const std::string&, Input_file*, off_t,
684 const elfcpp::Ehdr<32, true>&);
687 #ifdef HAVE_TARGET_64_LITTLE
688 // Virtual functions which may be overridden by the child class.
690 do_make_elf_object(const std::string&, Input_file*, off_t,
691 const elfcpp::Ehdr<64, false>& ehdr);
694 #ifdef HAVE_TARGET_64_BIG
695 // Virtual functions which may be overridden by the child class.
697 do_make_elf_object(const std::string& name, Input_file* input_file,
698 off_t offset, const elfcpp::Ehdr<64, true>& ehdr);
701 // Virtual functions which may be overridden by the child class.
702 virtual Output_section*
703 do_make_output_section(const char* name, elfcpp::Elf_Word type,
704 elfcpp::Elf_Xword flags);
706 // Virtual function which may be overridden by the child class.
709 { return parameters->options().relax(); }
711 // Virtual function which may be overridden by the child class.
713 do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*)
716 // A function for targets to call. Return whether BYTES/LEN matches
717 // VIEW/VIEW_SIZE at OFFSET.
719 match_view(const unsigned char* view, section_size_type view_size,
720 section_offset_type offset, const char* bytes, size_t len) const;
722 // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
725 set_view_to_nop(unsigned char* view, section_size_type view_size,
726 section_offset_type offset, size_t len) const;
728 // This must be overridden by the child class if it has target-specific
729 // attributes subsection in the attribute section.
731 do_attribute_arg_type(int) const
732 { gold_unreachable(); }
734 // This may be overridden by the child class.
736 do_attributes_order(int num) const
739 // This may be overridden by the child class.
741 do_select_as_default_target()
744 // This may be overridden by the child class.
746 do_define_standard_symbols(Symbol_table*, Layout*)
749 // This may be overridden by the child class.
751 do_output_section_name(const Relobj*, const char*, size_t*) const
754 // This may be overridden by the child class.
756 do_gc_mark_symbol(Symbol_table*, Symbol*) const
759 // This may be overridden by the child class.
761 do_has_custom_set_dynsym_indexes() const
764 // This may be overridden by the child class.
766 do_set_dynsym_indexes(std::vector<Symbol*>*, unsigned int,
767 std::vector<Symbol*>*, Stringpool*, Versions*,
769 { gold_unreachable(); }
771 // This may be overridden by the child class.
773 do_dynamic_tag_custom_value(elfcpp::DT) const
774 { gold_unreachable(); }
776 // This may be overridden by the child class.
778 do_adjust_dyn_symbol(const Symbol*, unsigned char*) const
781 // This may be overridden by the child class.
783 do_should_include_section(elfcpp::Elf_Word) const
787 // The implementations of the four do_make_elf_object virtual functions are
788 // almost identical except for their sizes and endianness. We use a template.
789 // for their implementations.
790 template<int size, bool big_endian>
792 do_make_elf_object_implementation(const std::string&, Input_file*, off_t,
793 const elfcpp::Ehdr<size, big_endian>&);
795 Target(const Target&);
796 Target& operator=(const Target&);
798 // The target information.
799 const Target_info* pti_;
800 // Processor-specific flags.
801 elfcpp::Elf_Word processor_specific_flags_;
802 // Whether the processor-specific flags are set at least once.
803 bool are_processor_specific_flags_set_;
804 // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
805 // the ELF header. This is handled at this level because it is
806 // OS-specific rather than processor-specific.
807 elfcpp::ELFOSABI osabi_;
810 // The abstract class for a specific size and endianness of target.
811 // Each actual target implementation class should derive from an
812 // instantiation of Sized_target.
814 template<int size, bool big_endian>
815 class Sized_target : public Target
818 // Make a new symbol table entry for the target. This should be
819 // overridden by a target which needs additional information in the
820 // symbol table. This will only be called if has_make_symbol()
822 virtual Sized_symbol<size>*
824 { gold_unreachable(); }
826 // Resolve a symbol for the target. This should be overridden by a
827 // target which needs to take special action. TO is the
828 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
829 // VERSION is the version of SYM. This will only be called if
830 // has_resolve() returns true.
832 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
834 { gold_unreachable(); }
836 // Process the relocs for a section, and record information of the
837 // mapping from source to destination sections. This mapping is later
838 // used to determine unreferenced garbage sections. This procedure is
839 // only called during garbage collection.
841 gc_process_relocs(Symbol_table* symtab,
843 Sized_relobj_file<size, big_endian>* object,
844 unsigned int data_shndx,
845 unsigned int sh_type,
846 const unsigned char* prelocs,
848 Output_section* output_section,
849 bool needs_special_offset_handling,
850 size_t local_symbol_count,
851 const unsigned char* plocal_symbols) = 0;
853 // Scan the relocs for a section, and record any information
854 // required for the symbol. SYMTAB is the symbol table. OBJECT is
855 // the object in which the section appears. DATA_SHNDX is the
856 // section index that these relocs apply to. SH_TYPE is the type of
857 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
858 // the relocation data. RELOC_COUNT is the number of relocs.
859 // LOCAL_SYMBOL_COUNT is the number of local symbols.
860 // OUTPUT_SECTION is the output section.
861 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
862 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
863 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
864 // pointers to the global symbol table from OBJECT.
866 scan_relocs(Symbol_table* symtab,
868 Sized_relobj_file<size, big_endian>* object,
869 unsigned int data_shndx,
870 unsigned int sh_type,
871 const unsigned char* prelocs,
873 Output_section* output_section,
874 bool needs_special_offset_handling,
875 size_t local_symbol_count,
876 const unsigned char* plocal_symbols) = 0;
878 // Relocate section data. SH_TYPE is the type of the relocation
879 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
880 // information. RELOC_COUNT is the number of relocs.
881 // OUTPUT_SECTION is the output section.
882 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
883 // to correspond to the output section. VIEW is a view into the
884 // output file holding the section contents, VIEW_ADDRESS is the
885 // virtual address of the view, and VIEW_SIZE is the size of the
886 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
887 // parameters refer to the complete output section data, not just
888 // the input section data.
890 relocate_section(const Relocate_info<size, big_endian>*,
891 unsigned int sh_type,
892 const unsigned char* prelocs,
894 Output_section* output_section,
895 bool needs_special_offset_handling,
897 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
898 section_size_type view_size,
899 const Reloc_symbol_changes*) = 0;
901 // Scan the relocs during a relocatable link. The parameters are
902 // like scan_relocs, with an additional Relocatable_relocs
903 // parameter, used to record the disposition of the relocs.
905 scan_relocatable_relocs(Symbol_table* symtab,
907 Sized_relobj_file<size, big_endian>* object,
908 unsigned int data_shndx,
909 unsigned int sh_type,
910 const unsigned char* prelocs,
912 Output_section* output_section,
913 bool needs_special_offset_handling,
914 size_t local_symbol_count,
915 const unsigned char* plocal_symbols,
916 Relocatable_relocs*) = 0;
918 // Emit relocations for a section during a relocatable link, and for
919 // --emit-relocs. The parameters are like relocate_section, with
920 // additional parameters for the view of the output reloc section.
922 relocate_relocs(const Relocate_info<size, big_endian>*,
923 unsigned int sh_type,
924 const unsigned char* prelocs,
926 Output_section* output_section,
927 typename elfcpp::Elf_types<size>::Elf_Off
928 offset_in_output_section,
929 const Relocatable_relocs*,
931 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
932 section_size_type view_size,
933 unsigned char* reloc_view,
934 section_size_type reloc_view_size) = 0;
936 // Perform target-specific processing in a relocatable link. This is
937 // only used if we use the relocation strategy RELOC_SPECIAL.
938 // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
939 // section type. PRELOC_IN points to the original relocation. RELNUM is
940 // the index number of the relocation in the relocation section.
941 // OUTPUT_SECTION is the output section to which the relocation is applied.
942 // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
943 // within the output section. VIEW points to the output view of the
944 // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
945 // is the size of the output view and PRELOC_OUT points to the new
946 // relocation in the output object.
948 // A target only needs to override this if the generic code in
949 // target-reloc.h cannot handle some relocation types.
952 relocate_special_relocatable(const Relocate_info<size, big_endian>*
954 unsigned int /* sh_type */,
955 const unsigned char* /* preloc_in */,
957 Output_section* /* output_section */,
958 typename elfcpp::Elf_types<size>::Elf_Off
959 /* offset_in_output_section */,
960 unsigned char* /* view */,
961 typename elfcpp::Elf_types<size>::Elf_Addr
963 section_size_type /* view_size */,
964 unsigned char* /* preloc_out*/)
965 { gold_unreachable(); }
967 // Return the number of entries in the GOT. This is only used for
968 // laying out the incremental link info sections. A target needs
969 // to implement this to support incremental linking.
972 got_entry_count() const
973 { gold_unreachable(); }
975 // Return the number of entries in the PLT. This is only used for
976 // laying out the incremental link info sections. A target needs
977 // to implement this to support incremental linking.
980 plt_entry_count() const
981 { gold_unreachable(); }
983 // Return the offset of the first non-reserved PLT entry. This is
984 // only used for laying out the incremental link info sections.
985 // A target needs to implement this to support incremental linking.
988 first_plt_entry_offset() const
989 { gold_unreachable(); }
991 // Return the size of each PLT entry. This is only used for
992 // laying out the incremental link info sections. A target needs
993 // to implement this to support incremental linking.
996 plt_entry_size() const
997 { gold_unreachable(); }
999 // Create the GOT and PLT sections for an incremental update.
1000 // A target needs to implement this to support incremental linking.
1002 virtual Output_data_got_base*
1003 init_got_plt_for_update(Symbol_table*,
1005 unsigned int /* got_count */,
1006 unsigned int /* plt_count */)
1007 { gold_unreachable(); }
1009 // Reserve a GOT entry for a local symbol, and regenerate any
1010 // necessary dynamic relocations.
1012 reserve_local_got_entry(unsigned int /* got_index */,
1013 Sized_relobj<size, big_endian>* /* obj */,
1014 unsigned int /* r_sym */,
1015 unsigned int /* got_type */)
1016 { gold_unreachable(); }
1018 // Reserve a GOT entry for a global symbol, and regenerate any
1019 // necessary dynamic relocations.
1021 reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */,
1022 unsigned int /* got_type */)
1023 { gold_unreachable(); }
1025 // Register an existing PLT entry for a global symbol.
1026 // A target needs to implement this to support incremental linking.
1029 register_global_plt_entry(Symbol_table*, Layout*,
1030 unsigned int /* plt_index */,
1032 { gold_unreachable(); }
1034 // Force a COPY relocation for a given symbol.
1035 // A target needs to implement this to support incremental linking.
1038 emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t)
1039 { gold_unreachable(); }
1041 // Apply an incremental relocation.
1044 apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */,
1045 typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */,
1046 unsigned int /* r_type */,
1047 typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */,
1048 const Symbol* /* gsym */,
1049 unsigned char* /* view */,
1050 typename elfcpp::Elf_types<size>::Elf_Addr /* address */,
1051 section_size_type /* view_size */)
1052 { gold_unreachable(); }
1054 // Handle target specific gc actions when adding a gc reference from
1055 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1058 gc_add_reference(Symbol_table* symtab,
1060 unsigned int src_shndx,
1062 unsigned int dst_shndx,
1063 typename elfcpp::Elf_types<size>::Elf_Addr dst_off) const
1065 this->do_gc_add_reference(symtab, src_obj, src_shndx,
1066 dst_obj, dst_shndx, dst_off);
1070 Sized_target(const Target::Target_info* pti)
1073 gold_assert(pti->size == size);
1074 gold_assert(pti->is_big_endian ? big_endian : !big_endian);
1077 // Set the EI_OSABI field if requested.
1079 do_adjust_elf_header(unsigned char*, int);
1081 // Handle target specific gc actions when adding a gc reference.
1083 do_gc_add_reference(Symbol_table*, Object*, unsigned int,
1084 Object*, unsigned int,
1085 typename elfcpp::Elf_types<size>::Elf_Addr) const
1089 do_function_location(Symbol_location*) const
1093 } // End namespace gold.
1095 #endif // !defined(GOLD_TARGET_H)