Index: icf.cc =================================================================== RCS file: /cvs/src/src/gold/icf.cc,v retrieving revision 1.11 diff -u -u -p -r1.11 icf.cc --- icf.cc 10 Mar 2010 01:26:57 -0000 1.11 +++ icf.cc 20 Apr 2010 21:11:47 -0000 @@ -304,7 +304,12 @@ get_section_contents(bool first_iteratio symtab->icf()->section_to_int_map(); Icf::Uniq_secn_id_map::iterator section_id_map_it = section_id_map.find(reloc_secn); - if (section_id_map_it != section_id_map.end()) + bool is_sym_preemptible = (*it_s != NULL + && !(*it_s)->is_from_dynobj() + && !(*it_s)->is_undefined() + && (*it_s)->is_preemptible()); + if (!is_sym_preemptible + && section_id_map_it != section_id_map.end()) { // This is a reloc to a section that might be folded. if (num_tracked_relocs) @@ -338,7 +343,14 @@ get_section_contents(bool first_iteratio { uint64_t entsize = (it_v->first)->section_entsize(it_v->second); - long long offset = it_a->first + it_a->second; + long long offset = it_a->first; + + unsigned long long addend = it_a->second; + // Ignoring the addend when it is a negative value. See the + // comments in Merged_symbol_value::Value in object.h. + if (addend < 0xffffff00) + offset = offset + addend; + section_size_type secn_len; const unsigned char* str_contents = (it_v->first)->section_contents(it_v->second, Index: symtab.cc =================================================================== RCS file: /cvs/src/src/gold/symtab.cc,v retrieving revision 1.138 diff -u -u -p -r1.138 symtab.cc --- symtab.cc 12 Jan 2010 06:41:36 -0000 1.138 +++ symtab.cc 20 Apr 2010 21:11:47 -0000 @@ -306,7 +306,7 @@ Sized_symbol::allocate_common(Outp // table. inline bool -Symbol::should_add_dynsym_entry() const +Symbol::should_add_dynsym_entry(Symbol_table* symtab) const { // If the symbol is used by a dynamic relocation, we need to add it. if (this->needs_dynsym_entry()) @@ -324,7 +324,8 @@ Symbol::should_add_dynsym_entry() const bool is_ordinary; unsigned int shndx = this->shndx(&is_ordinary); if (is_ordinary && shndx != elfcpp::SHN_UNDEF - && !relobj->is_section_included(shndx)) + && !relobj->is_section_included(shndx) + && !symtab->is_section_folded(relobj, shndx)) return false; } @@ -1072,7 +1073,8 @@ Symbol_table::add_from_relobj( bool is_defined_in_discarded_section = false; if (st_shndx != elfcpp::SHN_UNDEF && is_ordinary - && !relobj->is_section_included(st_shndx)) + && !relobj->is_section_included(st_shndx) + && !this->is_section_folded(relobj, st_shndx)) { st_shndx = elfcpp::SHN_UNDEF; is_defined_in_discarded_section = true; @@ -2253,7 +2255,7 @@ Symbol_table::set_dynsym_indexes(unsigne // some symbols appear more than once in the symbol table, with // and without a version. - if (!sym->should_add_dynsym_entry()) + if (!sym->should_add_dynsym_entry(this)) sym->set_dynsym_index(-1U); else if (!sym->has_dynsym_index()) { Index: symtab.h =================================================================== RCS file: /cvs/src/src/gold/symtab.h,v retrieving revision 1.105 diff -u -u -p -r1.105 symtab.h --- symtab.h 12 Feb 2010 03:23:26 -0000 1.105 +++ symtab.h 20 Apr 2010 21:11:47 -0000 @@ -274,7 +274,7 @@ class Symbol // Return whether this symbol should be added to the dynamic symbol // table. bool - should_add_dynsym_entry() const; + should_add_dynsym_entry(Symbol_table*) const; // Return whether this symbol has been seen in a regular object. bool Index: target-reloc.h =================================================================== RCS file: /cvs/src/src/gold/target-reloc.h,v retrieving revision 1.40 diff -u -u -p -r1.40 target-reloc.h --- target-reloc.h 3 Mar 2010 19:31:54 -0000 1.40 +++ target-reloc.h 20 Apr 2010 21:11:47 -0000 @@ -83,7 +83,8 @@ scan_relocs( shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); if (is_ordinary && shndx != elfcpp::SHN_UNDEF - && !object->is_section_included(shndx)) + && !object->is_section_included(shndx) + && !symtab->is_section_folded(object, shndx)) { // RELOC is a relocation against a local symbol in a // section we are discarding. We can ignore this @@ -102,7 +103,6 @@ scan_relocs( continue; } - scan.local(symtab, layout, target, object, data_shndx, output_section, reloc, r_type, lsym); } Index: x86_64.cc =================================================================== RCS file: /cvs/src/src/gold/x86_64.cc,v retrieving revision 1.107 diff -u -u -p -r1.107 x86_64.cc --- x86_64.cc 13 Feb 2010 02:04:21 -0000 1.107 +++ x86_64.cc 20 Apr 2010 21:11:47 -0000 @@ -1398,14 +1398,10 @@ Target_x86_64::Scan::unsupported_reloc_g object->name().c_str(), r_type, gsym->demangled_name().c_str()); } -// Returns true if this relocation type could be that of a function pointer -// only if the target is not position-independent code. +// Returns true if this relocation type could be that of a function pointer. inline bool Target_x86_64::Scan::possible_function_pointer_reloc(unsigned int r_type) { - if (parameters->options().shared()) - return false; - switch (r_type) { case elfcpp::R_X86_64_64: @@ -1413,6 +1409,11 @@ Target_x86_64::Scan::possible_function_p case elfcpp::R_X86_64_32S: case elfcpp::R_X86_64_16: case elfcpp::R_X86_64_8: + case elfcpp::R_X86_64_GOT64: + case elfcpp::R_X86_64_GOT32: + case elfcpp::R_X86_64_GOTPCREL64: + case elfcpp::R_X86_64_GOTPCREL: + case elfcpp::R_X86_64_GOTPLT64: { return true; } 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.129 diff -u -u -p -r1.129 Makefile.am --- testsuite/Makefile.am 6 Apr 2010 21:56:24 -0000 1.129 +++ testsuite/Makefile.am 20 Apr 2010 21:11:47 -0000 @@ -193,6 +193,33 @@ icf_safe_so_test_1.stdout: icf_safe_so_t icf_safe_so_test_2.stdout: icf_safe_so_test $(TEST_READELF) -h icf_safe_so_test > icf_safe_so_test_2.stdout +check_SCRIPTS += icf_virtual_function_folding_test.sh +MOSTLYCLEANFILES += icf_virtual_function_folding_test +icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc + $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $< +icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_virtual_function_folding_test.o -pie + +check_SCRIPTS += icf_preemptible_functions_test.sh +check_DATA += icf_preemptible_functions_test.stdout +MOSTLYCLEANFILES += icf_preemptible_functions_test +icf_preemptible_functions_test.o: icf_preemptible_functions_test.cc + $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $< +icf_preemptible_functions_test: icf_preemptible_functions_test.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_preemptible_functions_test.o -fPIC -shared +icf_preemptible_functions_test.stdout: icf_preemptible_functions_test + $(TEST_NM) icf_preemptible_functions_test > icf_preemptible_functions_test.stdout + +check_SCRIPTS += icf_string_merge_test.sh +check_DATA += icf_string_merge_test.stdout +MOSTLYCLEANFILES += icf_string_merge_test +icf_string_merge_test.o: icf_string_merge_test.cc + $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $< +icf_string_merge_test: icf_string_merge_test.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_string_merge_test.o +icf_string_merge_test.stdout: icf_string_merge_test + $(TEST_NM) icf_string_merge_test > icf_string_merge_test.stdout + check_PROGRAMS += basic_test check_PROGRAMS += basic_static_test check_PROGRAMS += basic_pic_test Index: testsuite/icf_preemptible_functions_test.cc =================================================================== RCS file: testsuite/icf_preemptible_functions_test.cc diff -N testsuite/icf_preemptible_functions_test.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_preemptible_functions_test.cc 20 Apr 2010 21:11:47 -0000 @@ -0,0 +1,47 @@ +// icf_preemptible_functions_test.cc -- a test case for gold + +// Copyright 2010 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 that preemptible functions are +// correctly handled by ICF. In this program, foo and bar should not +// be folded although they are identical as zap or zip could be preempted. + +int zap() +{ + return 0; +} + +int zip() +{ + return 0; +} + +int foo() +{ + zap(); + return 0; +} + +int bar() +{ + zip(); + return 0; +} Index: testsuite/icf_preemptible_functions_test.sh =================================================================== RCS file: testsuite/icf_preemptible_functions_test.sh diff -N testsuite/icf_preemptible_functions_test.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_preemptible_functions_test.sh 20 Apr 2010 21:11:47 -0000 @@ -0,0 +1,35 @@ +# icf_preemptible_functions_test.sh -- test --icf=all + +# Copyright 2010 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. + + +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 should not fold" $2 "and" $3 + exit 1 + fi +} + +check icf_preemptible_functions_test.stdout "_Z3foov" "_Z3barv" Index: testsuite/icf_safe_so_test.sh =================================================================== RCS file: /cvs/src/src/gold/testsuite/icf_safe_so_test.sh,v retrieving revision 1.2 diff -u -u -p -r1.2 icf_safe_so_test.sh --- testsuite/icf_safe_so_test.sh 4 Mar 2010 01:33:22 -0000 1.2 +++ testsuite/icf_safe_so_test.sh 20 Apr 2010 21:11:47 -0000 @@ -27,8 +27,7 @@ error_if_symbol_absent() { - is_symbol_present $1 $2 - if [ $? != 0 ]; + if ! is_symbol_present $1 $2; then echo "Symbol" $2 "not present, possibly folded." exit 1 @@ -37,7 +36,7 @@ error_if_symbol_absent() is_symbol_present() { - result=`grep $2 $1` + grep $2 $1 > /dev/null 2>&1 return $? } @@ -56,14 +55,12 @@ check_nofold() check_fold() { - is_symbol_present $1 $2 - if [ $? != 0 ]; + if ! is_symbol_present $1 $2 then return 0 fi - is_symbol_present $1 $3 - if [ $? != 0 ]; + if ! is_symbol_present $1 $3 then return 0 fi @@ -89,13 +86,13 @@ arch_specific_safe_fold() X86_32_specific_safe_fold() { - grep -q -e "Intel 80386" $1 >& /dev/null + grep -e "Intel 80386" $1 > /dev/null 2>&1 arch_specific_safe_fold $? $2 $3 $4 } X86_64_specific_safe_fold() { - grep -q -e "Advanced Micro Devices X86-64" $1 >& /dev/null + grep -e "Advanced Micro Devices X86-64" $1 > /dev/null 2>&1 arch_specific_safe_fold $? $2 $3 $4 } @@ -105,5 +102,4 @@ X86_32_specific_safe_fold icf_safe_so_te X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "foo_hidden" "foo_internal" X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "foo_hidden" "foo_static" X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "foo_internal" "foo_static" -X86_64_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout \ - "foo_glob" "bar_glob" +check_nofold icf_safe_so_test_1.stdout "foo_glob" "bar_glob" Index: testsuite/icf_string_merge_test.cc =================================================================== RCS file: testsuite/icf_string_merge_test.cc diff -N testsuite/icf_string_merge_test.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_string_merge_test.cc 20 Apr 2010 21:11:47 -0000 @@ -0,0 +1,50 @@ +// icf_string_merge_test.cc -- a test case for gold + +// Copyright 2010 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 is strings are handled correctly +// by ICF. ICF inlines strings that can be merged. In some cases, the +// addend of the relocation pointing to a string merge section must be +// ignored. This program has no pair of identical functions that can be +// folded. However, if the addend is not ignored then get2 and get3 will +// become identical. + +const char* const str1 = "aaaaaaaaaastr1"; +const char* const str2 = "bbbbaaaaaastr1"; +const char* const str3 = "cccccaaaaastr1"; + +const char* get1() +{ + return str1; +} +const char* get2() +{ + return str2; +} + +const char* get3() +{ + return str3; +} +int main() +{ + return 0; +} Index: testsuite/icf_string_merge_test.sh =================================================================== RCS file: testsuite/icf_string_merge_test.sh diff -N testsuite/icf_string_merge_test.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_string_merge_test.sh 20 Apr 2010 21:11:47 -0000 @@ -0,0 +1,37 @@ +# icf_string_merge_test.sh -- test --icf=all + +# Copyright 2010 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. + + +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 should not fold" $2 "and" $3 + exit 1 + fi +} + +check icf_string_merge_test.stdout "get1" "get2" +check icf_string_merge_test.stdout "get1" "get3" +check icf_string_merge_test.stdout "get2" "get3" Index: testsuite/icf_virtual_function_folding_test.cc =================================================================== RCS file: testsuite/icf_virtual_function_folding_test.cc diff -N testsuite/icf_virtual_function_folding_test.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_virtual_function_folding_test.cc 20 Apr 2010 21:11:47 -0000 @@ -0,0 +1,74 @@ +// icf_virtual_function_folding_test.cc -- a test case for gold + +// Copyright 2010 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. + +// Foo::fn1 is folded into fn2 with ICF. Since this file is linked as a +// position independent executable, a dynamic reloc is needed +// for the virtual call fn1 entry in the vtable. This test makes sure +// the call to Foo::fn1 works correctly after the folding. + +#include + +int fn2(void *) +{ + printf("fn1==fn2\n"); + return 0xA; +} + +namespace +{ + +class Bar +{ + public: + virtual int fn1(); +}; + +int Bar::fn1() +{ + return 123; +} + +class Foo : public Bar +{ + virtual int fn1(); +}; + +int Foo::fn1() +{ + printf("fn1==fn2\n"); + return 0xA; +} + +Bar* get() +{ + Bar *f = new Foo(); + return f; +} + +} // end of anonymous namespace. + +int main() +{ + Bar *f = get(); + f->fn1(); + return 0; +} Index: testsuite/icf_virtual_function_folding_test.sh =================================================================== RCS file: testsuite/icf_virtual_function_folding_test.sh diff -N testsuite/icf_virtual_function_folding_test.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/icf_virtual_function_folding_test.sh 20 Apr 2010 21:11:47 -0000 @@ -0,0 +1,35 @@ +#!/bin/sh + +# icf_virtual_function_folding_test.sh -- test --icf + +# Copyright 2010 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. + +check() +{ + ./icf_virtual_function_folding_test | grep $1 > /dev/null 2>&1 + if [ $? -gt 0 ] + then + echo "Program output incorrect after folding." $2 + exit 1 + fi +} + +check "fn1==fn2"