* gold patch committed: Code cleanup
@ 2011-06-28 21:18 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2011-06-28 21:18 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 1851 bytes --]
This patch cleans up some of the target ICF code to conform to the gold
standards. Public functions are not virtual. One of the virtual
functions could be replaced with a constant in Target_info. This patch
just shuffles some code and does not change any functionality.
Committed to mainline.
Ian
2011-06-28 Ian Lance Taylor <iant@google.com>
* 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 16263 bytes --]
Index: arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.135
diff -p -u -r1.135 arm.cc
--- arm.cc 27 Jun 2011 17:53:31 -0000 1.135
+++ arm.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <dougkwan@google.com> based on the i386 code
// by Ian Lance Taylor <iant@google.com>.
// This file also contains borrowed and adapted code from
@@ -2182,23 +2182,6 @@ class Target_arm : public Sized_target<3
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<3
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<big
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
Index: i386.cc
===================================================================
RCS file: /cvs/src/src/gold/i386.cc,v
retrieving revision 1.128
diff -p -u -r1.128 i386.cc
--- i386.cc 24 May 2011 21:41:10 -0000 1.128
+++ i386.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <iant@google.com>.
// This file is part of gold.
@@ -171,14 +171,6 @@ class Target_i386 : public Target_freebs
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_freebs
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::i
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
Index: icf.cc
===================================================================
RCS file: /cvs/src/src/gold/icf.cc,v
retrieving revision 1.19
diff -p -u -r1.19 icf.cc
--- icf.cc 2 Feb 2011 21:55:29 -0000 1.19
+++ icf.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <tmsriram@google.com>.
// This file is part of gold.
@@ -373,7 +373,7 @@ get_section_contents(bool first_iteratio
// 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);
Index: powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.37
diff -p -u -r1.37 powerpc.cc
--- powerpc.cc 24 May 2011 21:41:10 -0000 1.37
+++ powerpc.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <davem@davemloft.net>
// and David Edelsohn <edelsohn@gnu.org>
@@ -383,6 +383,7 @@ Target::Target_info Target_powerpc<32, t
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, f
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, t
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, f
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
Index: sparc.cc
===================================================================
RCS file: /cvs/src/src/gold/sparc.cc,v
retrieving revision 1.46
diff -p -u -r1.46 sparc.cc
--- sparc.cc 24 May 2011 21:41:10 -0000 1.46
+++ sparc.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <davem@davemloft.net>.
// This file is part of gold.
@@ -403,6 +403,7 @@ Target::Target_info Target_sparc<32, tru
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, tru
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
Index: target.h
===================================================================
RCS file: /cvs/src/src/gold/target.h,v
retrieving revision 1.58
diff -p -u -r1.58 target.h
--- target.h 8 Jun 2011 03:50:11 -0000 1.58
+++ target.h 28 Jun 2011 21:11:14 -0000
@@ -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 <iant@google.com>.
// 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.
Index: x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.127
diff -p -u -r1.127 x86_64.cc
--- x86_64.cc 17 Jun 2011 11:15:34 -0000 1.127
+++ x86_64.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <iant@google.com>.
// This file is part of gold.
@@ -217,20 +217,6 @@ class Target_x86_64 : public Target_free
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_free
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:
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
Index: testsuite/testfile.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/testfile.cc,v
retrieving revision 1.19
diff -p -u -r1.19 testfile.cc
--- testsuite/testfile.cc 24 May 2011 21:41:10 -0000 1.19
+++ testsuite/testfile.cc 28 Jun 2011 21:11:14 -0000
@@ -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 <iant@google.com>.
// This file is part of gold.
@@ -94,6 +94,7 @@ const Target::Target_info Target_test<si
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-06-28 21:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-28 21:18 gold patch committed: Code cleanup Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).