cvs diff: Diffing . Index: ChangeLog =================================================================== RCS file: /cvs/src/src/gold/ChangeLog,v retrieving revision 1.265 diff -u -u -p -r1.265 ChangeLog --- ChangeLog 11 Aug 2009 17:09:14 -0000 1.265 +++ ChangeLog 12 Aug 2009 18:48:05 -0000 @@ -1,3 +1,15 @@ +2009-08-12 Sriraman Tallam + + * icf.cc (Icf::find_identical_sections): Unfold symbols that have + been maked as --keep-unique. + (Icf::unfold_section): New function. + * icf.h (Icf::unfold_section): New function. + * options.h (Genereal_options::keep_unique): New option. + * testsuite/Makefile.am: Add commands to build icf_keep_unique_test. + * testsuite/Makefile.in: Regenerate. + * testsuite/icf_keep_unique_test.sh: New file. + * testsuite/icf_keep_unique_test.cc: New file. + 2009-08-11 Doug Kwan * arm.cc: Update comments. Index: icf.cc =================================================================== RCS file: /cvs/src/src/gold/icf.cc,v retrieving revision 1.1 diff -u -u -p -r1.1 icf.cc --- icf.cc 5 Aug 2009 20:51:56 -0000 1.1 +++ icf.cc 12 Aug 2009 18:48:05 -0000 @@ -598,9 +598,47 @@ Icf::find_identical_sections(const Input program_name, num_iterations); } + // Unfold --keep-unique symbols. + for (options::String_set::const_iterator p = + parameters->options().keep_unique_begin(); + p != parameters->options().keep_unique_end(); + ++p) + { + const char* name = p->c_str(); + Symbol* sym = symtab->lookup(name); + if (sym != NULL + && sym->source() == Symbol::FROM_OBJECT + && !sym->object()->is_dynamic()) + { + Object* obj = sym->object(); + bool is_ordinary; + unsigned int shndx = sym->shndx(&is_ordinary); + if (is_ordinary) + { + this->unfold_section(obj, shndx); + } + } + + } + this->icf_ready(); } +// Unfolds the section denoted by OBJ and SHNDX if folded. + +void +Icf::unfold_section(Object* obj, unsigned int shndx) +{ + Section_id secn(obj, shndx); + Uniq_secn_id_map::iterator it = this->section_id_.find(secn); + if (it == this->section_id_.end()) + return; + unsigned int section_num = it->second; + unsigned int kept_section_id = this->kept_section_id_[section_num]; + if (kept_section_id != section_num) + this->kept_section_id_[section_num] = section_num; +} + // This function determines if the section corresponding to the // given object and index is folded based on if the kept section // is different from this section. Index: icf.h =================================================================== RCS file: /cvs/src/src/gold/icf.h,v retrieving revision 1.1 diff -u -u -p -r1.1 icf.h --- icf.h 5 Aug 2009 20:51:56 -0000 1.1 +++ icf.h 12 Aug 2009 18:48:05 -0000 @@ -87,6 +87,10 @@ class Icf is_icf_ready() { return this->icf_ready_; } + // Unfolds the section denoted by OBJ and SHNDX if folded. + void + unfold_section(Object* obj, unsigned int shndx); + // Returns the kept section corresponding to the // given section. bool Index: options.h =================================================================== RCS file: /cvs/src/src/gold/options.h,v retrieving revision 1.103 diff -u -u -p -r1.103 options.h --- options.h 5 Aug 2009 20:51:56 -0000 1.103 +++ options.h 12 Aug 2009 18:48:06 -0000 @@ -814,7 +814,7 @@ class General_options N_("Do not link against shared libraries"), NULL); DEFINE_bool(icf, options::TWO_DASHES, '\0', false, - N_("Fold identical functions"), + N_("Identical Code Folding (Fold identical functions)"), N_("Don't fold identical functions (default)")); DEFINE_uint(icf_iterations, options::TWO_DASHES , '\0', 0, @@ -824,6 +824,9 @@ class General_options N_("List folded identical sections on stderr"), N_("Do not list folded identical sections")); + DEFINE_set(keep_unique, options::TWO_DASHES, '\0', + N_("Do not fold this symbol during ICF"), N_("SYMBOL")); + DEFINE_bool(gc_sections, options::TWO_DASHES, '\0', false, N_("Remove unused sections"), N_("Don't remove unused sections (default)")); cvs diff: Diffing po cvs diff: Diffing testsuite Index: testsuite/Makefile.am =================================================================== RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v retrieving revision 1.96 diff -u -u -p -r1.96 Makefile.am --- testsuite/Makefile.am 7 Aug 2009 18:29:54 -0000 1.96 +++ testsuite/Makefile.am 12 Aug 2009 18:48:06 -0000 @@ -133,6 +133,14 @@ icf_test: icf_test.o gcctestdir/ld icf_test.stdout: icf_test $(TEST_NM) -C icf_test > icf_test.stdout +check_SCRIPTS += icf_keep_unique_test.sh +check_DATA += icf_keep_unique_test.stdout +icf_keep_unique_test.o: icf_keep_unique_test.cc + $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $< +icf_keep_unique_test: icf_keep_unique_test.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -Wl,--icf -Wl,--keep-unique,_Z11unique_funcv icf_keep_unique_test.o +icf_keep_unique_test.stdout: icf_keep_unique_test + $(TEST_NM) -C icf_keep_unique_test > icf_keep_unique_test.stdout check_PROGRAMS += basic_test check_PROGRAMS += basic_static_test Index: testsuite/Makefile.in =================================================================== RCS file: /cvs/src/src/gold/testsuite/Makefile.in,v retrieving revision 1.101 diff -u -u -p -r1.101 Makefile.in --- testsuite/Makefile.in 7 Aug 2009 18:29:54 -0000 1.101 +++ testsuite/Makefile.in 12 Aug 2009 18:48:06 -0000 @@ -58,6 +58,7 @@ check_PROGRAMS = object_unittest$(EXEEXT # and --dynamic-list-cpp-typeinfo @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_1 = gc_comdat_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_tls_test.sh icf_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.sh weak_plt.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg.sh undef_symbol.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_1.sh ver_test_2.sh \ @@ -77,6 +78,7 @@ check_PROGRAMS = object_unittest$(EXEEXT @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 = gc_comdat_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_tls_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_test.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.dbg \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_plt_shared.so debug_msg.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_so.err \ @@ -2331,6 +2333,12 @@ uninstall-am: uninstall-info-am @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf icf_test.o @GCC_TRUE@@NATIVE_LINKER_TRUE@icf_test.stdout: icf_test @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -C icf_test > icf_test.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_keep_unique_test.o: icf_keep_unique_test.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_keep_unique_test: icf_keep_unique_test.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf -Wl,--keep-unique,_Z11unique_funcv icf_keep_unique_test.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_keep_unique_test.stdout: icf_keep_unique_test +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -C icf_keep_unique_test > icf_keep_unique_test.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@basic_test.o: basic_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@basic_test: basic_test.o gcctestdir/ld Index: testsuite/icf_keep_unique_test.cc =================================================================== RCS file: testsuite/icf_keep_unique_test.cc diff -N testsuite/icf_keep_unique_test.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_keep_unique_test.cc 12 Aug 2009 18:48:06 -0000 @@ -0,0 +1,39 @@ +// icf_keep_unique_test.cc -- a test case for gold + +// Copyright 2009 Free Software Foundation, Inc. +// Written by Sriraman Tallam . + +// This file is part of gold. + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +// MA 02110-1301, USA. + +// The goal of this program is to verify if --keep-unique works +// as intended when used with --icf. + +int kept_func() +{ + return 0; +} + +int unique_func() +{ + return 0; +} + +int main() +{ + return 1; +} Index: testsuite/icf_keep_unique_test.sh =================================================================== RCS file: testsuite/icf_keep_unique_test.sh diff -N testsuite/icf_keep_unique_test.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_keep_unique_test.sh 12 Aug 2009 18:48:06 -0000 @@ -0,0 +1,39 @@ +#!/bin/sh + +# icf_keep_unique_test.sh -- test --icf --keep-unique + +# Copyright 2009 Free Software Foundation, Inc. +# Written by Sriraman Tallam . + +# This file is part of gold. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +# The goal of this program is to verify if --keep-unique works +# as intended when used with --icf. + +check() +{ + func_addr_1=`grep $2 $1 | awk '{print $1}'` + func_addr_2=`grep $3 $1 | awk '{print $1}'` + if [ $func_addr_1 = $func_addr_2 ] + then + echo "Identical Code Folding with keep-unique failed to unfold" $2 + exit 1 + fi +} + +check icf_keep_unique_test.stdout "kept_func" "unique_func"