From: Ian Lance Taylor Date: Tue, 28 Jun 2011 21:15:42 +0000 (+0000) Subject: * target.h (Target::can_check_for_function_pointers): Rewrite. X-Git-Tag: sid-snapshot-20110701~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3ce541e970466431bf6abfa8ad58424a1d1a7ec;p=external%2Fbinutils.git * target.h (Target::can_check_for_function_pointers): Rewrite. Make non-virtual. (Target::can_icf_inline_merge_sections): Likewise. (Target::section_may_have_icf_unsafe_poineters): Likewise. (Target::Target_info): Add can_icf_inline_merge_sections field. (Target::do_can_check_for_function_pointers): New virtual function. (Target::do_section_may_have_icf_unsafe_pointers): Likewise. * arm.cc (Target_arm::do_can_check_for_function_pointers): Rename from can_check_for_function_pointers, move in file. (Target_arm::do_section_may_have_icf_unsafe_pointers): Rename from section_may_have_icf_unsafe_poineters, move in file. (Target_arm::arm_info): Initialize can_icf_inline_merge_sections. * i386.cc (Target_i386::do_can_check_for_function_pointers): Rename from can_check_for_function_pointers, move in file. (Target_i386::can_icf_inline_merge_sections): Remove. (Target_i386::i386_info): Initialize can_icf_inline_merge_sections. * powerpc.cc (Target_powerpc::powerpc_info) [all versions]: Initialize can_icf_inline_merge_sections. * sparc.cc (Target_sparc::sparc_info) [both version]: Likewise. * x86_64.cc (Target_x86_64::do_can_check_for_function_pointers): Rename from can_check_for_function_pointers, move in file. (Target_x86_64::can_icf_inline_merge_sections): Remove. (Target_x86_64::x86_64_info): Initialize can_icf_inline_merge_sections. * testsuite/testfile.cc (Target_test::test_target_info): Likewise. * icf.cc (get_section_contents): Correct formatting. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index 1ec3942..57fbfea 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,35 @@ +2011-06-28 Ian Lance Taylor + + * target.h (Target::can_check_for_function_pointers): Rewrite. + Make non-virtual. + (Target::can_icf_inline_merge_sections): Likewise. + (Target::section_may_have_icf_unsafe_poineters): Likewise. + (Target::Target_info): Add can_icf_inline_merge_sections field. + (Target::do_can_check_for_function_pointers): New virtual + function. + (Target::do_section_may_have_icf_unsafe_pointers): Likewise. + * arm.cc (Target_arm::do_can_check_for_function_pointers): Rename + from can_check_for_function_pointers, move in file. + (Target_arm::do_section_may_have_icf_unsafe_pointers): Rename from + section_may_have_icf_unsafe_poineters, move in file. + (Target_arm::arm_info): Initialize can_icf_inline_merge_sections. + * i386.cc (Target_i386::do_can_check_for_function_pointers): + Rename from can_check_for_function_pointers, move in file. + (Target_i386::can_icf_inline_merge_sections): Remove. + (Target_i386::i386_info): Initialize + can_icf_inline_merge_sections. + * powerpc.cc (Target_powerpc::powerpc_info) [all versions]: + Initialize can_icf_inline_merge_sections. + * sparc.cc (Target_sparc::sparc_info) [both version]: Likewise. + * x86_64.cc (Target_x86_64::do_can_check_for_function_pointers): + Rename from can_check_for_function_pointers, move in file. + (Target_x86_64::can_icf_inline_merge_sections): Remove. + (Target_x86_64::x86_64_info): Initialize + can_icf_inline_merge_sections. + * testsuite/testfile.cc (Target_test::test_target_info): + Likewise. + * icf.cc (get_section_contents): Correct formatting. + 2011-06-27 Ian Lance Taylor * symtab.cc (Symbol::versioned_name): New function. diff --git a/gold/arm.cc b/gold/arm.cc index c8732e0..bf41bc8 100644 --- a/gold/arm.cc +++ b/gold/arm.cc @@ -1,6 +1,6 @@ // arm.cc -- arm target support for gold. -// Copyright 2009, 2010 Free Software Foundation, Inc. +// Copyright 2009, 2010, 2011 Free Software Foundation, Inc. // Written by Doug Kwan based on the i386 code // by Ian Lance Taylor . // This file also contains borrowed and adapted code from @@ -2182,23 +2182,6 @@ class Target_arm : public Sized_target<32, big_endian> fix_cortex_a8_(false), cortex_a8_relocs_info_() { } - // 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 true; } - - // 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 (!is_prefix_of(".ARM.exidx", section_name) - && !is_prefix_of(".ARM.extab", section_name) - && Target::section_may_have_icf_unsafe_pointers(section_name)); - } - // Whether we can use BLX. bool may_use_blx() const @@ -2553,6 +2536,23 @@ class Target_arm : public Sized_target<32, big_endian> arm_reloc_property_table = new Arm_reloc_property_table(); } + // 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 + do_can_check_for_function_pointers() const + { return true; } + + // Whether a section called SECTION_NAME may have function pointers to + // sections not eligible for safe ICF folding. + virtual bool + do_section_may_have_icf_unsafe_pointers(const char* section_name) const + { + return (!is_prefix_of(".ARM.exidx", section_name) + && !is_prefix_of(".ARM.extab", section_name) + && Target::do_section_may_have_icf_unsafe_pointers(section_name)); + } + private: // The class which scans relocations. class Scan @@ -2946,6 +2946,7 @@ const Target::Target_info Target_arm::arm_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/libc.so.1", // dynamic_linker 0x8000, // default_text_segment_address diff --git a/gold/i386.cc b/gold/i386.cc index d60ac22..bd5eaaf 100644 --- a/gold/i386.cc +++ b/gold/i386.cc @@ -1,6 +1,6 @@ // i386.cc -- i386 target support for gold. -// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -171,14 +171,6 @@ class Target_i386 : public Target_freebsd<32, false> got_mod_index_offset_(-1U), tls_base_symbol_defined_(false) { } - inline bool - can_check_for_function_pointers() const - { return true; } - - virtual bool - can_icf_inline_merge_sections () const - { return true; } - // Process the relocations to determine unreferenced sections for // garbage collection. void @@ -291,6 +283,11 @@ class Target_i386 : public Target_freebsd<32, false> do_plt_section_for_local(const Relobj*, unsigned int) const { return this->plt_section(); } + // We can tell whether we take the address of a function. + inline bool + do_can_check_for_function_pointers() const + { return true; } + // Return whether SYM is call to a non-split function. bool do_is_call_to_non_split(const Symbol* sym, unsigned int) const; @@ -642,6 +639,7 @@ const Target::Target_info Target_i386::i386_info = false, // has_resolve true, // has_code_fill true, // is_default_stack_executable + true, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/libc.so.1", // dynamic_linker 0x08048000, // default_text_segment_address diff --git a/gold/icf.cc b/gold/icf.cc index 09dcba6..5935c5b 100644 --- a/gold/icf.cc +++ b/gold/icf.cc @@ -1,6 +1,6 @@ // icf.cc -- Identical Code Folding. // -// Copyright 2009, 2010 Free Software Foundation, Inc. +// Copyright 2009, 2010, 2011 Free Software Foundation, Inc. // Written by Sriraman Tallam . // This file is part of gold. @@ -373,7 +373,7 @@ get_section_contents(bool first_iteration, // This reloc points to a merge section. Hash the // contents of this section. if ((secn_flags & elfcpp::SHF_MERGE) != 0 - && parameters->target().can_icf_inline_merge_sections ()) + && parameters->target().can_icf_inline_merge_sections()) { uint64_t entsize = (it_v->first)->section_entsize(it_v->second); diff --git a/gold/powerpc.cc b/gold/powerpc.cc index c113bd2..78cda48 100644 --- a/gold/powerpc.cc +++ b/gold/powerpc.cc @@ -1,6 +1,6 @@ // powerpc.cc -- powerpc target support for gold. -// Copyright 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // Written by David S. Miller // and David Edelsohn @@ -383,6 +383,7 @@ Target::Target_info Target_powerpc<32, true>::powerpc_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/ld.so.1", // dynamic_linker 0x10000000, // default_text_segment_address @@ -406,6 +407,7 @@ Target::Target_info Target_powerpc<32, false>::powerpc_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/ld.so.1", // dynamic_linker 0x10000000, // default_text_segment_address @@ -429,6 +431,7 @@ Target::Target_info Target_powerpc<64, true>::powerpc_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/ld.so.1", // dynamic_linker 0x10000000, // default_text_segment_address @@ -452,6 +455,7 @@ Target::Target_info Target_powerpc<64, false>::powerpc_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/ld.so.1", // dynamic_linker 0x10000000, // default_text_segment_address diff --git a/gold/sparc.cc b/gold/sparc.cc index 080a480..0ce96f7 100644 --- a/gold/sparc.cc +++ b/gold/sparc.cc @@ -1,6 +1,6 @@ // sparc.cc -- sparc target support for gold. -// Copyright 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // Written by David S. Miller . // This file is part of gold. @@ -403,6 +403,7 @@ Target::Target_info Target_sparc<32, true>::sparc_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/ld.so.1", // dynamic_linker 0x00010000, // default_text_segment_address @@ -426,6 +427,7 @@ Target::Target_info Target_sparc<64, true>::sparc_info = false, // has_resolve false, // has_code_fill true, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/usr/lib/sparcv9/ld.so.1", // dynamic_linker 0x100000, // default_text_segment_address diff --git a/gold/target.h b/gold/target.h index a7e2ca7..1d523b8 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 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -70,34 +70,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 @@ -286,6 +258,24 @@ class Target plt_section_for_local(const Relobj* object, unsigned int symndx) const { return this->do_plt_section_for_local(object, symndx); } + // 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 true if a reference to SYM from a reloc of type R_TYPE // means that the current function may call an object compiled // without -fsplit-stack. SYM is known to be defined in an object @@ -406,6 +396,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. @@ -497,6 +490,26 @@ class Target do_plt_section_for_local(const Relobj*, unsigned int) const { gold_unreachable(); } + // 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 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. diff --git a/gold/testsuite/testfile.cc b/gold/testsuite/testfile.cc index 228077a..5843374 100644 --- a/gold/testsuite/testfile.cc +++ b/gold/testsuite/testfile.cc @@ -1,6 +1,6 @@ // testfile.cc -- Dummy ELF objects for testing purposes. -// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +// Copyright 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -94,6 +94,7 @@ const Target::Target_info Target_test::test_target_info = false, // has_resolve false, // has_code_fill false, // is_default_stack_executable + false, // can_icf_inline_merge_sections '\0', // wrap_char "/dummy", // dynamic_linker 0x08000000, // default_text_segment_address diff --git a/gold/x86_64.cc b/gold/x86_64.cc index cdfec9e..a6e9ddd 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -1,6 +1,6 @@ // x86_64.cc -- x86_64 target support for gold. -// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -217,20 +217,6 @@ class Target_x86_64 : public Target_freebsd<64, false> tls_base_symbol_defined_(false) { } - // This function should be defined in targets that can use relocation - // types to determine (implemented in local_reloc_may_be_function_pointer - // and global_reloc_may_be_function_pointer) - // if a function's pointer is taken. ICF uses this in safe mode to only - // fold those functions whose pointer is defintely not taken. For x86_64 - // pie binaries, safe ICF cannot be done by looking at relocation types. - inline bool - can_check_for_function_pointers() const - { return !parameters->options().pie(); } - - virtual bool - can_icf_inline_merge_sections () const - { return true; } - // Hook for a new output section. void do_new_output_section(Output_section*) const; @@ -347,6 +333,16 @@ class Target_x86_64 : public Target_freebsd<64, false> do_plt_section_for_local(const Relobj*, unsigned int) const { return this->plt_section(); } + // This function should be defined in targets that can use relocation + // types to determine (implemented in local_reloc_may_be_function_pointer + // and global_reloc_may_be_function_pointer) + // if a function's pointer is taken. ICF uses this in safe mode to only + // fold those functions whose pointer is defintely not taken. For x86_64 + // pie binaries, safe ICF cannot be done by looking at relocation types. + bool + do_can_check_for_function_pointers() const + { return !parameters->options().pie(); } + // Adjust -fsplit-stack code which calls non-split-stack code. void do_calls_non_split(Relobj* object, unsigned int shndx, @@ -755,6 +751,7 @@ const Target::Target_info Target_x86_64::x86_64_info = false, // has_resolve true, // has_code_fill true, // is_default_stack_executable + true, // can_icf_inline_merge_sections '\0', // wrap_char "/lib/ld64.so.1", // program interpreter 0x400000, // default_text_segment_address