X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gold%2Ftarget.h;h=089d7b377c3b38132253286cf793ed7d6e457168;hb=bb1183e25ae74ba21500fb4e39bc1ca9822e3086;hp=a7e2ca7e43b54b97b7bb9cf95eefa18222358451;hpb=26d3c67de1d0e6434dabb908e5a6fa002f5b1db8;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/target.h b/gold/target.h index a7e2ca7e43..089d7b377c 100644 --- a/gold/target.h +++ b/gold/target.h @@ -1,6 +1,6 @@ // target.h -- target support for gold -*- C++ -*- -// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2006-2020 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -36,6 +36,7 @@ #include "elfcpp.h" #include "options.h" #include "parameters.h" +#include "stringpool.h" #include "debug.h" namespace gold @@ -49,18 +50,19 @@ template class Sized_relobj_file; class Relocatable_relocs; template -class Relocate_info; +struct Relocate_info; class Reloc_symbol_changes; class Symbol; template class Sized_symbol; class Symbol_table; class Output_data; -template -class Output_data_got; +class Output_data_got_base; class Output_section; class Input_objects; class Task; +struct Symbol_location; +class Versions; // The abstract class for target specific handling. @@ -70,34 +72,6 @@ class Target virtual ~Target() { } - // Virtual function which is set to return true by a target if - // it can use relocation types to determine if a function's - // pointer is taken. - virtual bool - can_check_for_function_pointers() const - { return false; } - - // This function is used in ICF (icf.cc). This is set to true by - // the target if a relocation to a merged section can be processed - // to retrieve the contents of the merged section. - virtual bool - can_icf_inline_merge_sections () const - { return false; } - - // Whether a section called SECTION_NAME may have function pointers to - // sections not eligible for safe ICF folding. - virtual bool - 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)); - } - // Return the bit size that this target implements. This should // return 32 or 64. int @@ -145,9 +119,19 @@ class Target { return this->pti_->dynamic_linker; } // Return the default address to use for the text segment. + // If a -z max-page-size argument has set the ABI page size + // to a value larger than the default starting address, + // bump the starting address up to the page size, to avoid + // misaligning the text segment in the file. uint64_t default_text_segment_address() const - { return this->pti_->default_text_segment_address; } + { + uint64_t addr = this->pti_->default_text_segment_address; + uint64_t pagesize = this->abi_pagesize(); + if (addr < pagesize) + addr = pagesize; + return addr; + } // Return the ABI specified page size. uint64_t @@ -171,6 +155,16 @@ class Target this->abi_pagesize()); } + // Return whether PF_X segments must contain nothing but the contents of + // SHF_EXECINSTR sections (no non-executable data, no headers). + bool + isolate_execinstr() const + { return this->pti_->isolate_execinstr; } + + uint64_t + rosegment_gap() const + { return this->pti_->rosegment_gap; } + // If we see some object files with .note.GNU-stack sections, and // some objects files without them, this returns whether we should // consider the object files without them to imply that the stack @@ -255,9 +249,15 @@ class Target // Adjust the output file header before it is written out. VIEW // points to the header in external form. LEN is the length. void - adjust_elf_header(unsigned char* view, int len) const + adjust_elf_header(unsigned char* view, int len) { return this->do_adjust_elf_header(view, len); } + // Return address and size to plug into eh_frame FDEs associated with a PLT. + void + plt_fde_location(const Output_data* plt, unsigned char* oview, + uint64_t* address, off_t* len) const + { return this->do_plt_fde_location(plt, oview, address, len); } + // Return whether NAME is a local label name. This is used to implement the // --discard-locals options. bool @@ -274,25 +274,72 @@ class Target reloc_addend(void* arg, unsigned int type, uint64_t addend) const { return this->do_reloc_addend(arg, type, addend); } - // Return the PLT section to use for a global symbol. This is used - // for STT_GNU_IFUNC symbols. - Output_data* - plt_section_for_global(const Symbol* sym) const - { return this->do_plt_section_for_global(sym); } + // Return the PLT address to use for a global symbol. + uint64_t + plt_address_for_global(const Symbol* sym) const + { return this->do_plt_address_for_global(sym); } + + // Return the PLT address to use for a local symbol. + uint64_t + plt_address_for_local(const Relobj* object, unsigned int symndx) const + { return this->do_plt_address_for_local(object, symndx); } + + // Return the offset to use for the GOT_INDX'th got entry which is + // for a local tls symbol specified by OBJECT, SYMNDX. + int64_t + tls_offset_for_local(const Relobj* object, + unsigned int symndx, + unsigned int got_indx) const + { return do_tls_offset_for_local(object, symndx, got_indx); } + + // Return the offset to use for the GOT_INDX'th got entry which is + // for global tls symbol GSYM. + int64_t + tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const + { return do_tls_offset_for_global(gsym, got_indx); } + + // For targets that use function descriptors, if LOC is the location + // of a function, modify it to point at the function entry location. + void + function_location(Symbol_location* loc) const + { return do_function_location(loc); } + + // Return whether this target can use relocation types to determine + // if a function's address is taken. + bool + can_check_for_function_pointers() const + { return this->do_can_check_for_function_pointers(); } + + // Return whether a relocation to a merged section can be processed + // to retrieve the contents. + bool + can_icf_inline_merge_sections () const + { return this->pti_->can_icf_inline_merge_sections; } + + // Whether a section called SECTION_NAME may have function pointers to + // sections not eligible for safe ICF folding. + virtual bool + section_may_have_icf_unsafe_pointers(const char* section_name) const + { return this->do_section_may_have_icf_unsafe_pointers(section_name); } - // Return the PLT section to use for a local symbol. This is used - // for STT_GNU_IFUNC symbols. - Output_data* - plt_section_for_local(const Relobj* object, unsigned int symndx) const - { return this->do_plt_section_for_local(object, symndx); } + // Return the base to use for the PC value in an FDE when it is + // encoded using DW_EH_PE_datarel. This does not appear to be + // documented anywhere, but it is target specific. Any use of + // DW_EH_PE_datarel in gcc requires defining a special macro + // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value. + uint64_t + ehframe_datarel_base() const + { return this->do_ehframe_datarel_base(); } - // Return true if a reference to SYM from a reloc of type R_TYPE + // Return true if a reference to SYM from a reloc at *PRELOC // means that the current function may call an object compiled // without -fsplit-stack. SYM is known to be defined in an object // compiled without -fsplit-stack. bool - is_call_to_non_split(const Symbol* sym, unsigned int r_type) const - { return this->do_is_call_to_non_split(sym, r_type); } + is_call_to_non_split(const Symbol* sym, const unsigned char* preloc, + const unsigned char* view, + section_size_type view_size) const + { return this->do_is_call_to_non_split(sym, preloc, view, view_size); } // A function starts at OFFSET in section SHNDX in OBJECT. That // function was compiled with -fsplit-stack, but it refers to a @@ -303,10 +350,12 @@ class Target void calls_non_split(Relobj* object, unsigned int shndx, section_offset_type fnoffset, section_size_type fnsize, + const unsigned char* prelocs, size_t reloc_count, unsigned char* view, section_size_type view_size, std::string* from, std::string* to) const { - this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size, + this->do_calls_non_split(object, shndx, fnoffset, fnsize, + prelocs, reloc_count, view, view_size, from, to); } @@ -344,7 +393,7 @@ class Target return pass < 2; return this->do_relax(pass, input_objects, symtab, layout, task); - } + } // Return the target-specific name of attributes section. This is // NULL if a target does not use attributes section or if it uses @@ -364,7 +413,7 @@ class Target { return ((this->pti_->attributes_section != NULL && strcmp(name, this->pti_->attributes_section) == 0) - || strcmp(name, ".gnu.attributes") == 0); + || strcmp(name, ".gnu.attributes") == 0); } // Return a bit mask of argument types for attribute with TAG. @@ -383,7 +432,87 @@ class Target // which may be used for expensive, target-specific initialization. void select_as_default_target() - { this->do_select_as_default_target(); } + { this->do_select_as_default_target(); } + + // Return the value to store in the EI_OSABI field in the ELF + // header. + elfcpp::ELFOSABI + osabi() const + { return this->osabi_; } + + // Set the value to store in the EI_OSABI field in the ELF header. + void + set_osabi(elfcpp::ELFOSABI osabi) + { this->osabi_ = osabi; } + + // Define target-specific standard symbols. + void + define_standard_symbols(Symbol_table* symtab, Layout* layout) + { this->do_define_standard_symbols(symtab, layout); } + + // Return the output section name to use given an input section + // name, or NULL if no target specific name mapping is required. + // Set *PLEN to the length of the name if returning non-NULL. + const char* + output_section_name(const Relobj* relobj, + const char* name, + size_t* plen) const + { return this->do_output_section_name(relobj, name, plen); } + + // Add any special sections for this symbol to the gc work list. + void + gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const + { this->do_gc_mark_symbol(symtab, sym); } + + // Return the name of the entry point symbol. + const char* + entry_symbol_name() const + { return this->pti_->entry_symbol_name; } + + // Return the size in bits of SHT_HASH entry. + int + hash_entry_size() const + { return this->pti_->hash_entry_size; } + + // Return the section type to use for unwind sections. + unsigned int + unwind_section_type() const + { return this->pti_->unwind_section_type; } + + // Whether the target has a custom set_dynsym_indexes method. + bool + has_custom_set_dynsym_indexes() const + { return this->do_has_custom_set_dynsym_indexes(); } + + // Custom set_dynsym_indexes method for a target. + unsigned int + set_dynsym_indexes(std::vector* dyn_symbols, unsigned int index, + std::vector* syms, Stringpool* dynpool, + Versions* versions, Symbol_table* symtab) const + { + return this->do_set_dynsym_indexes(dyn_symbols, index, syms, dynpool, + versions, symtab); + } + + // Get the custom dynamic tag value. + unsigned int + dynamic_tag_custom_value(elfcpp::DT tag) const + { return this->do_dynamic_tag_custom_value(tag); } + + // Adjust the value written to the dynamic symbol table. + void + adjust_dyn_symbol(const Symbol* sym, unsigned char* view) const + { this->do_adjust_dyn_symbol(sym, view); } + + // Return whether to include the section in the link. + bool + should_include_section(elfcpp::Elf_Word sh_type) const + { return this->do_should_include_section(sh_type); } + + // Finalize the target-specific properties in the .note.gnu.property section. + void + finalize_gnu_properties(Layout* layout) const + { this->do_finalize_gnu_properties(layout); } protected: // This struct holds the constant information for a child class. We @@ -406,6 +535,9 @@ class Target // 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. @@ -416,6 +548,11 @@ class Target 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; @@ -430,11 +567,19 @@ class Target 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) + are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE) { } // Virtual function which may be implemented by the child class. @@ -466,10 +611,15 @@ class Target // 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::ehdr_size. - // By default, we do nothing. + // By default, we set the EI_OSABI field if requested (in + // Sized_target). virtual void - do_adjust_elf_header(unsigned char*, int) const - { } + 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 @@ -489,24 +639,61 @@ class Target // Virtual functions that must be overridden by a target that uses // STT_GNU_IFUNC symbols. - virtual Output_data* - do_plt_section_for_global(const Symbol*) const + virtual uint64_t + do_plt_address_for_global(const Symbol*) const { gold_unreachable(); } - virtual Output_data* - do_plt_section_for_local(const Relobj*, unsigned int) const + 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, unsigned int) const; + 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, unsigned char*, section_size_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 @@ -519,7 +706,7 @@ class Target 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* @@ -576,7 +763,7 @@ class Target 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. + // attributes subsection in the attribute section. virtual int do_attribute_arg_type(int) const { gold_unreachable(); } @@ -591,6 +778,53 @@ class Target 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*, unsigned int, + std::vector*, 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 + { } + private: // The implementations of the four do_make_elf_object virtual functions are // almost identical except for their sizes and endianness. We use a template. @@ -609,6 +843,10 @@ class Target elfcpp::Elf_Word processor_specific_flags_; // Whether the processor-specific flags are set at least once. bool are_processor_specific_flags_set_; + // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of + // the ELF header. This is handled at this level because it is + // OS-specific rather than processor-specific. + elfcpp::ELFOSABI osabi_; }; // The abstract class for a specific size and endianness of target. @@ -624,7 +862,7 @@ class Sized_target : public Target // symbol table. This will only be called if has_make_symbol() // returns true. virtual Sized_symbol* - make_symbol() const + make_symbol(const char*, elfcpp::STT, Object*, unsigned int, uint64_t) { gold_unreachable(); } // Resolve a symbol for the target. This should be overridden by a @@ -632,7 +870,7 @@ class Sized_target : public Target // pre-existing symbol. SYM is the new symbol, seen in OBJECT. // VERSION is the version of SYM. This will only be called if // has_resolve() returns true. - virtual void + virtual bool resolve(Symbol*, const elfcpp::Sym&, Object*, const char*) { gold_unreachable(); } @@ -719,24 +957,39 @@ class Sized_target : public Target const unsigned char* plocal_symbols, Relocatable_relocs*) = 0; - // Relocate a section during a relocatable link. The parameters are - // like relocate_section, with additional parameters for the view of - // the output reloc section. + // Scan the relocs for --emit-relocs. The parameters are + // like scan_relocatable_relocs. + virtual void + emit_relocs_scan(Symbol_table* symtab, + Layout* layout, + Sized_relobj_file* object, + unsigned int data_shndx, + unsigned int sh_type, + const unsigned char* prelocs, + size_t reloc_count, + Output_section* output_section, + bool needs_special_offset_handling, + size_t local_symbol_count, + const unsigned char* plocal_syms, + Relocatable_relocs* rr) = 0; + + // Emit relocations for a section during a relocatable link, and for + // --emit-relocs. The parameters are like relocate_section, with + // additional parameters for the view of the output reloc section. virtual void - relocate_for_relocatable(const Relocate_info*, - unsigned int sh_type, - const unsigned char* prelocs, - size_t reloc_count, - Output_section* output_section, - off_t offset_in_output_section, - const Relocatable_relocs*, - unsigned char* view, - typename elfcpp::Elf_types::Elf_Addr - view_address, - section_size_type view_size, - unsigned char* reloc_view, - section_size_type reloc_view_size) = 0; - + relocate_relocs(const Relocate_info*, + unsigned int sh_type, + const unsigned char* prelocs, + size_t reloc_count, + Output_section* output_section, + typename elfcpp::Elf_types::Elf_Off + offset_in_output_section, + unsigned char* view, + typename elfcpp::Elf_types::Elf_Addr view_address, + section_size_type view_size, + unsigned char* reloc_view, + section_size_type reloc_view_size) = 0; + // Perform target-specific processing in a relocatable link. This is // only used if we use the relocation strategy RELOC_SPECIAL. // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation @@ -759,14 +1012,15 @@ class Sized_target : public Target const unsigned char* /* preloc_in */, size_t /* relnum */, Output_section* /* output_section */, - off_t /* offset_in_output_section */, + typename elfcpp::Elf_types::Elf_Off + /* offset_in_output_section */, unsigned char* /* view */, typename elfcpp::Elf_types::Elf_Addr /* view_address */, section_size_type /* view_size */, unsigned char* /* preloc_out*/) { gold_unreachable(); } - + // Return the number of entries in the GOT. This is only used for // laying out the incremental link info sections. A target needs // to implement this to support incremental linking. @@ -799,10 +1053,18 @@ class Sized_target : public Target plt_entry_size() const { gold_unreachable(); } + // Return the size of each GOT entry. This is only used for + // laying out the incremental link info sections. A target needs + // to implement this if its GOT size is different. + + virtual unsigned int + got_entry_size() const + { return size / 8; } + // Create the GOT and PLT sections for an incremental update. // A target needs to implement this to support incremental linking. - virtual Output_data_got* + virtual Output_data_got_base* init_got_plt_for_update(Symbol_table*, Layout*, unsigned int /* got_count */, @@ -829,7 +1091,8 @@ class Sized_target : public Target // A target needs to implement this to support incremental linking. virtual void - register_global_plt_entry(unsigned int /* plt_index */, + register_global_plt_entry(Symbol_table*, Layout*, + unsigned int /* plt_index */, Symbol*) { gold_unreachable(); } @@ -853,6 +1116,46 @@ class Sized_target : public Target section_size_type /* view_size */) { gold_unreachable(); } + // Handle target specific gc actions when adding a gc reference from + // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX + // and DST_OFF. + void + gc_add_reference(Symbol_table* symtab, + Relobj* src_obj, + unsigned int src_shndx, + Relobj* dst_obj, + unsigned int dst_shndx, + typename elfcpp::Elf_types::Elf_Addr dst_off) const + { + this->do_gc_add_reference(symtab, src_obj, src_shndx, + dst_obj, dst_shndx, dst_off); + } + + // Return the r_sym field from a relocation. + // Most targets can use the default version of this routine, + // but some targets have a non-standard r_info field, and will + // need to provide a target-specific version. + virtual unsigned int + get_r_sym(const unsigned char* preloc) const + { + // Since REL and RELA relocs share the same structure through + // the r_info field, we can just use REL here. + elfcpp::Rel rel(preloc); + return elfcpp::elf_r_sym(rel.get_r_info()); + } + + // Record a target-specific program property in the .note.gnu.property + // section. + virtual void + record_gnu_property(unsigned int, unsigned int, size_t, + const unsigned char*, const Object*) + { } + + // Merge the target-specific program properties from the current object. + virtual void + merge_gnu_properties(const Object*) + { } + protected: Sized_target(const Target::Target_info* pti) : Target(pti) @@ -860,6 +1163,21 @@ class Sized_target : public Target gold_assert(pti->size == size); gold_assert(pti->is_big_endian ? big_endian : !big_endian); } + + // Set the EI_OSABI field if requested. + virtual void + do_adjust_elf_header(unsigned char*, int); + + // Handle target specific gc actions when adding a gc reference. + virtual void + do_gc_add_reference(Symbol_table*, Relobj*, unsigned int, + Relobj*, unsigned int, + typename elfcpp::Elf_types::Elf_Addr) const + { } + + virtual void + do_function_location(Symbol_location*) const + { } }; } // End namespace gold.