+ // This struct holds the constant information for a child class. We
+ // use a struct to avoid the overhead of virtual function calls for
+ // simple information.
+ struct Target_info
+ {
+ // Address size (32 or 64).
+ int size;
+ // Whether the target is big endian.
+ bool is_big_endian;
+ // The code to store in the e_machine field of the ELF header.
+ elfcpp::EM machine_code;
+ // Whether this target has a specific make_symbol function.
+ bool has_make_symbol;
+ // Whether this target has a specific resolve function.
+ bool has_resolve;
+ // Whether this target has a specific code fill function.
+ bool has_code_fill;
+ // Whether an object file with no .note.GNU-stack sections implies
+ // that the stack should be executable.
+ bool is_default_stack_executable;
+ // Whether a relocation to a merged section can be processed to
+ // retrieve the contents.
+ bool can_icf_inline_merge_sections;
+ // Prefix character to strip when checking for wrapping.
+ char wrap_char;
+ // The default dynamic linker name.
+ const char* dynamic_linker;
+ // The default text segment address.
+ uint64_t default_text_segment_address;
+ // The ABI specified page size.
+ uint64_t abi_pagesize;
+ // The common page size used by actual implementations.
+ uint64_t common_pagesize;
+ // Whether PF_X segments must contain nothing but the contents of
+ // SHF_EXECINSTR sections (no non-executable data, no headers).
+ bool isolate_execinstr;
+ // If nonzero, distance from the text segment to the read-only segment.
+ uint64_t rosegment_gap;
+ // The special section index for small common symbols; SHN_UNDEF
+ // if none.
+ elfcpp::Elf_Half small_common_shndx;
+ // The special section index for large common symbols; SHN_UNDEF
+ // if none.
+ elfcpp::Elf_Half large_common_shndx;
+ // Section flags for small common section.
+ elfcpp::Elf_Xword small_common_section_flags;
+ // Section flags for large common section.
+ elfcpp::Elf_Xword large_common_section_flags;
+ // Name of attributes section if it is not ".gnu.attributes".
+ const char* attributes_section;
+ // Vendor name of vendor attributes.
+ const char* attributes_vendor;
+ // Name of the main entry point to the program.
+ const char* entry_symbol_name;
+ // Size (in bits) of SHT_HASH entry. Always equal to 32, except for
+ // 64-bit S/390.
+ const int hash_entry_size;
+ // Processor-specific section type for ".eh_frame" (unwind) sections.
+ // SHT_PROGBITS if there is no special section type.
+ const unsigned int unwind_section_type;
+ };
+
+ Target(const Target_info* pti)
+ : pti_(pti), processor_specific_flags_(0),
+ are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE)
+ { }
+
+ // Virtual function which may be implemented by the child class.
+ virtual void
+ do_new_output_section(Output_section*) const
+ { }
+
+ // Virtual function which may be implemented by the child class.
+ virtual void
+ do_finalize_sections(Layout*, const Input_objects*, Symbol_table*)
+ { }
+
+ // Virtual function which may be implemented by the child class.
+ virtual uint64_t
+ do_dynsym_value(const Symbol*) const
+ { gold_unreachable(); }
+
+ // Virtual function which must be implemented by the child class if
+ // needed.
+ virtual std::string
+ do_code_fill(section_size_type) const
+ { gold_unreachable(); }
+
+ // Virtual function which may be implemented by the child class.
+ virtual bool
+ do_is_defined_by_abi(const Symbol*) const
+ { return false; }
+
+ // Adjust the output file header before it is written out. VIEW
+ // points to the header in external form. LEN is the length, and
+ // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
+ // By default, we set the EI_OSABI field if requested (in
+ // Sized_target).
+ virtual void
+ do_adjust_elf_header(unsigned char*, int) = 0;
+
+ // Return address and size to plug into eh_frame FDEs associated with a PLT.
+ virtual void
+ do_plt_fde_location(const Output_data* plt, unsigned char* oview,
+ uint64_t* address, off_t* len) const;
+
+ // Virtual function which may be overridden by the child class.
+ virtual bool
+ do_is_local_label_name(const char*) const;
+
+ // Virtual function that must be overridden by a target which uses
+ // target specific relocations.
+ virtual unsigned int
+ do_reloc_symbol_index(void*, unsigned int) const
+ { gold_unreachable(); }
+
+ // Virtual function that must be overridden by a target which uses
+ // target specific relocations.
+ virtual uint64_t
+ do_reloc_addend(void*, unsigned int, uint64_t) const
+ { gold_unreachable(); }
+
+ // Virtual functions that must be overridden by a target that uses
+ // STT_GNU_IFUNC symbols.
+ virtual uint64_t
+ do_plt_address_for_global(const Symbol*) const
+ { gold_unreachable(); }
+
+ virtual uint64_t
+ do_plt_address_for_local(const Relobj*, unsigned int) const
+ { gold_unreachable(); }
+
+ virtual int64_t
+ do_tls_offset_for_local(const Relobj*, unsigned int, unsigned int) const
+ { gold_unreachable(); }
+
+ virtual int64_t
+ do_tls_offset_for_global(Symbol*, unsigned int) const
+ { gold_unreachable(); }
+
+ virtual void
+ do_function_location(Symbol_location*) const = 0;
+
+ // Virtual function which may be overriden by the child class.
+ virtual bool
+ do_can_check_for_function_pointers() const
+ { return false; }
+
+ // Virtual function which may be overridden by the child class. We
+ // recognize some default sections for which we don't care whether
+ // they have function pointers.
+ virtual bool
+ do_section_may_have_icf_unsafe_pointers(const char* section_name) const
+ {
+ // We recognize sections for normal vtables, construction vtables and
+ // EH frames.
+ return (!is_prefix_of(".rodata._ZTV", section_name)
+ && !is_prefix_of(".data.rel.ro._ZTV", section_name)
+ && !is_prefix_of(".rodata._ZTC", section_name)
+ && !is_prefix_of(".data.rel.ro._ZTC", section_name)
+ && !is_prefix_of(".eh_frame", section_name));
+ }
+
+ virtual uint64_t
+ do_ehframe_datarel_base() const
+ { gold_unreachable(); }
+
+ // Virtual function which may be overridden by the child class. The
+ // default implementation is that any function not defined by the
+ // ABI is a call to a non-split function.
+ virtual bool
+ do_is_call_to_non_split(const Symbol* sym, const unsigned char*,
+ const unsigned char*, section_size_type) const;
+
+ // Virtual function which may be overridden by the child class.
+ virtual void
+ do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
+ section_size_type, const unsigned char*, size_t,
+ unsigned char*, section_size_type,
+ std::string*, std::string*) const;
+
+ // make_elf_object hooks. There are four versions of these for
+ // different address sizes and endianness.
+
+ // Set processor specific flags.
+ void
+ set_processor_specific_flags(elfcpp::Elf_Word flags)
+ {
+ this->processor_specific_flags_ = flags;
+ this->are_processor_specific_flags_set_ = true;
+ }
+
+#ifdef HAVE_TARGET_32_LITTLE
+ // Virtual functions which may be overridden by the child class.
+ virtual Object*
+ do_make_elf_object(const std::string&, Input_file*, off_t,
+ const elfcpp::Ehdr<32, false>&);
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+ // Virtual functions which may be overridden by the child class.
+ virtual Object*
+ do_make_elf_object(const std::string&, Input_file*, off_t,
+ const elfcpp::Ehdr<32, true>&);
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+ // Virtual functions which may be overridden by the child class.
+ virtual Object*
+ do_make_elf_object(const std::string&, Input_file*, off_t,
+ const elfcpp::Ehdr<64, false>& ehdr);
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+ // Virtual functions which may be overridden by the child class.
+ virtual Object*
+ do_make_elf_object(const std::string& name, Input_file* input_file,
+ off_t offset, const elfcpp::Ehdr<64, true>& ehdr);
+#endif
+
+ // Virtual functions which may be overridden by the child class.
+ virtual Output_section*
+ do_make_output_section(const char* name, elfcpp::Elf_Word type,
+ elfcpp::Elf_Xword flags);
+
+ // Virtual function which may be overridden by the child class.
+ virtual bool
+ do_may_relax() const
+ { return parameters->options().relax(); }
+
+ // Virtual function which may be overridden by the child class.
+ virtual bool
+ do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*)
+ { return false; }
+
+ // A function for targets to call. Return whether BYTES/LEN matches
+ // VIEW/VIEW_SIZE at OFFSET.
+ bool
+ match_view(const unsigned char* view, section_size_type view_size,
+ section_offset_type offset, const char* bytes, size_t len) const;
+
+ // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
+ // for LEN bytes.
+ void
+ set_view_to_nop(unsigned char* view, section_size_type view_size,
+ section_offset_type offset, size_t len) const;
+
+ // This must be overridden by the child class if it has target-specific
+ // attributes subsection in the attribute section.
+ virtual int
+ do_attribute_arg_type(int) const
+ { gold_unreachable(); }
+
+ // This may be overridden by the child class.
+ virtual int
+ do_attributes_order(int num) const
+ { return num; }
+
+ // This may be overridden by the child class.
+ virtual void
+ do_select_as_default_target()
+ { }
+
+ // This may be overridden by the child class.
+ virtual void
+ do_define_standard_symbols(Symbol_table*, Layout*)
+ { }
+
+ // This may be overridden by the child class.
+ virtual const char*
+ do_output_section_name(const Relobj*, const char*, size_t*) const
+ { return NULL; }
+
+ // This may be overridden by the child class.
+ virtual void
+ do_gc_mark_symbol(Symbol_table*, Symbol*) const
+ { }
+
+ // This may be overridden by the child class.
+ virtual bool
+ do_has_custom_set_dynsym_indexes() const
+ { return false; }
+
+ // This may be overridden by the child class.
+ virtual unsigned int
+ do_set_dynsym_indexes(std::vector<Symbol*>*, unsigned int,
+ std::vector<Symbol*>*, Stringpool*, Versions*,
+ Symbol_table*) const
+ { gold_unreachable(); }
+
+ // This may be overridden by the child class.
+ virtual unsigned int
+ do_dynamic_tag_custom_value(elfcpp::DT) const
+ { gold_unreachable(); }
+
+ // This may be overridden by the child class.
+ virtual void
+ do_adjust_dyn_symbol(const Symbol*, unsigned char*) const
+ { }
+
+ // This may be overridden by the child class.
+ virtual bool
+ do_should_include_section(elfcpp::Elf_Word) const
+ { return true; }
+
+ // Finalize the target-specific properties in the .note.gnu.property section.
+ virtual void
+ do_finalize_gnu_properties(Layout*) const