diff options
author | Sriraman Tallam <tmsriram@google.com> | 2009-10-13 21:17:43 +0000 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2009-10-13 21:17:43 +0000 |
commit | 032ce4e9e37bd92e928352fca78b1eee3bb41fdd (patch) | |
tree | ca3bb0efd21ae5b265a39f8b4179c4d28d3465b2 /gold/icf.cc | |
parent | 55b126d49cd449155a9057c7212d0b2e74bab465 (diff) | |
download | gdb-032ce4e9e37bd92e928352fca78b1eee3bb41fdd.zip gdb-032ce4e9e37bd92e928352fca78b1eee3bb41fdd.tar.gz gdb-032ce4e9e37bd92e928352fca78b1eee3bb41fdd.tar.bz2 |
* gc.h (gc_process_relocs): Check if icf is enabled using new
function.
* gold.cc (queue_initial_tasks): Likewise.
(queue_middle_tasks): Likewise.
* object.cc (do_layout): Likewise.
* symtab.cc (is_section_folded): Likewise.
* main.cc (main): Likewise.
* reloc.cc (Read_relocs::run): Likewise.
(Sized_relobj::do_scan_relocs): Likewise.
* icf.cc (is_function_ctor_or_dtor): New function.
(Icf::find_identical_sections): Check if function is ctor or dtor when
safe icf is chosen.
* options.h (General_options::icf): Change option to be an enum.
(Icf_status): New enum.
(icf_enabled): New method.
(icf_safe_folding): New method.
(set_icf_status): New method.
(icf_status_): New variable.
* (options.cc) (General_options::finalize): Set icf_status_.
* testsuite/Makefile.am: Add commands to build icf_safe_test. Modify
icf_test and icf_keep_unique_test to use the --icf enum flag.
* testsuite/icf_safe_test.sh: New file.
* testsuite/icf_safe_test.cc: New file.
Diffstat (limited to 'gold/icf.cc')
-rw-r--r-- | gold/icf.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/gold/icf.cc b/gold/icf.cc index 411cf2e..03b927a 100644 --- a/gold/icf.cc +++ b/gold/icf.cc @@ -114,6 +114,7 @@ #include "icf.h" #include "symtab.h" #include "libiberty.h" +#include "demangle.h" namespace gold { @@ -530,6 +531,22 @@ match_sections(unsigned int iteration_num, return converged; } +// During safe icf (--icf=safe), only fold functions that are ctors or dtors. +// This function returns true if the mangled function name is a ctor or a +// dtor. + +static bool +is_function_ctor_or_dtor(const char* mangled_func_name) +{ + if ((is_prefix_of("_ZN", mangled_func_name) + || is_prefix_of("_ZZ", mangled_func_name)) + && (is_gnu_v3_mangled_ctor(mangled_func_name) + || is_gnu_v3_mangled_dtor(mangled_func_name))) + { + return true; + } + return false; +} // This is the main ICF function called in gold.cc. This does the // initialization and calls match_sections repeatedly (twice by default) @@ -552,14 +569,19 @@ Icf::find_identical_sections(const Input_objects* input_objects, { for (unsigned int i = 0;i < (*p)->shnum(); ++i) { + const char* section_name = (*p)->section_name(i).c_str(); // Only looking to fold functions, so just look at .text sections. - if (!is_prefix_of(".text.", (*p)->section_name(i).c_str())) + if (!is_prefix_of(".text.", section_name)) continue; if (!(*p)->is_section_included(i)) continue; if (parameters->options().gc_sections() && symtab->gc()->is_section_garbage(*p, i)) continue; + // With --icf=safe, check if mangled name is a ctor or a dtor. + if (parameters->options().icf_safe_folding() + && !is_function_ctor_or_dtor(section_name + 6)) + continue; this->id_section_.push_back(Section_id(*p, i)); this->section_id_[Section_id(*p, i)] = section_num; this->kept_section_id_.push_back(section_num); |