diff options
author | Sriraman Tallam <tmsriram@google.com> | 2010-04-20 21:13:30 +0000 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2010-04-20 21:13:30 +0000 |
commit | ce97fa81e0c46d216b80b143ad8c02fff6906fef (patch) | |
tree | 539a9d93c76d2113b92da17405b144eba8fa92c5 /gold/testsuite | |
parent | ec31cde5942e935e74f6ff919ffc480dfa2f1bac (diff) | |
download | gdb-ce97fa81e0c46d216b80b143ad8c02fff6906fef.zip gdb-ce97fa81e0c46d216b80b143ad8c02fff6906fef.tar.gz gdb-ce97fa81e0c46d216b80b143ad8c02fff6906fef.tar.bz2 |
2010-04-18 Sriraman Tallam <tmsriram@google.com>
* icf.cc (get_section_contents): Check for preemptible functions.
Ignore addend when appropriate.
* symtab.cc (should_add_dynsym_entry): Add new parameter. Check for
section folded.
(add_from_relobj): Check for section folded.
(set_dynsym_indexes): Fix call to should_add_dynsym_entry.
* symtab.h (should_add_dynsym_entry): Add new parameter.
* target-reloc.h (scan_relocs): Check for section folded.
* x86_64.cc (Target_x86_64::Scan::possible_function_pointer_reloc):
Check reloc types for function pointers in shared objects.
* testsuite/Makefile.am (icf_virtual_function_folding_test): New test
case.
(icf_preemptible_functions_test): New test case.
(icf_string_merge_test): New test case.
* testsuite.Makefile.in: Regenerate.
* testsuite/icf_safe_so_test.sh: Change to not fold foo_glob and
bar_glob. Refactor code.
* testsuite/icf_preemptible_functions_test.cc: New file.
* testsuite/icf_preemptible_functions_test.sh: New file.
* testsuite/icf_string_merge_test.cc: New file.
* testsuite/icf_string_merge_test.sh: New file.
* testsuite/icf_virtual_function_folding_test.cc: New file.
* testsuite/icf_virtual_function_folding_test.sh: New file.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 27 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 24 | ||||
-rw-r--r-- | gold/testsuite/icf_preemptible_functions_test.cc | 47 | ||||
-rwxr-xr-x | gold/testsuite/icf_preemptible_functions_test.sh | 35 | ||||
-rwxr-xr-x | gold/testsuite/icf_safe_so_test.sh | 18 | ||||
-rw-r--r-- | gold/testsuite/icf_string_merge_test.cc | 50 | ||||
-rwxr-xr-x | gold/testsuite/icf_string_merge_test.sh | 37 | ||||
-rw-r--r-- | gold/testsuite/icf_virtual_function_folding_test.cc | 74 | ||||
-rwxr-xr-x | gold/testsuite/icf_virtual_function_folding_test.sh | 35 |
9 files changed, 336 insertions, 11 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 3bc0ec8..5b1c9a0 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -193,6 +193,33 @@ icf_safe_so_test_1.stdout: icf_safe_so_test 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 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 2d4b018..5cb2eb5 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -62,6 +62,9 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_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 \ @@ -91,6 +94,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test_2.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test_1.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test_2.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_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 \ @@ -112,6 +117,9 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_orphan_section_test icf_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test icf_safe_so_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.dbg \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/weak_undef_lib.so @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_4 = basic_test \ @@ -2554,6 +2562,22 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) icf_safe_so_test > icf_safe_so_test_1.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@icf_safe_so_test_2.stdout: icf_safe_so_test @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -h icf_safe_so_test > icf_safe_so_test_2.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_virtual_function_folding_test.o -pie +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_preemptible_functions_test.o: icf_preemptible_functions_test.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_preemptible_functions_test: icf_preemptible_functions_test.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_preemptible_functions_test.o -fPIC -shared +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_preemptible_functions_test.stdout: icf_preemptible_functions_test +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) icf_preemptible_functions_test > icf_preemptible_functions_test.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_string_merge_test.o: icf_string_merge_test.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_string_merge_test: icf_string_merge_test.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_string_merge_test.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_string_merge_test.stdout: icf_string_merge_test +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) icf_string_merge_test > icf_string_merge_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 diff --git a/gold/testsuite/icf_preemptible_functions_test.cc b/gold/testsuite/icf_preemptible_functions_test.cc new file mode 100644 index 0000000..35a96bc --- /dev/null +++ b/gold/testsuite/icf_preemptible_functions_test.cc @@ -0,0 +1,47 @@ +// icf_preemptible_functions_test.cc -- a test case for gold + +// Copyright 2010 Free Software Foundation, Inc. +// Written by Sriraman Tallam <tmsriram@google.com>. + +// 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; +} diff --git a/gold/testsuite/icf_preemptible_functions_test.sh b/gold/testsuite/icf_preemptible_functions_test.sh new file mode 100755 index 0000000..27cf459 --- /dev/null +++ b/gold/testsuite/icf_preemptible_functions_test.sh @@ -0,0 +1,35 @@ +# icf_preemptible_functions_test.sh -- test --icf=all + +# Copyright 2010 Free Software Foundation, Inc. +# Written by Sriraman Tallam <tmsriram@google.com>. + +# 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" diff --git a/gold/testsuite/icf_safe_so_test.sh b/gold/testsuite/icf_safe_so_test.sh index 262daef..47ad390 100755 --- a/gold/testsuite/icf_safe_so_test.sh +++ b/gold/testsuite/icf_safe_so_test.sh @@ -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_test_2.stdout icf_safe_so_test_1.stdout "f 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" diff --git a/gold/testsuite/icf_string_merge_test.cc b/gold/testsuite/icf_string_merge_test.cc new file mode 100644 index 0000000..b1e1191 --- /dev/null +++ b/gold/testsuite/icf_string_merge_test.cc @@ -0,0 +1,50 @@ +// icf_string_merge_test.cc -- a test case for gold + +// Copyright 2010 Free Software Foundation, Inc. +// Written by Sriraman Tallam <tmsriram@google.com>. + +// 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; +} diff --git a/gold/testsuite/icf_string_merge_test.sh b/gold/testsuite/icf_string_merge_test.sh new file mode 100755 index 0000000..f22f212 --- /dev/null +++ b/gold/testsuite/icf_string_merge_test.sh @@ -0,0 +1,37 @@ +# icf_string_merge_test.sh -- test --icf=all + +# Copyright 2010 Free Software Foundation, Inc. +# Written by Sriraman Tallam <tmsriram@google.com>. + +# 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" diff --git a/gold/testsuite/icf_virtual_function_folding_test.cc b/gold/testsuite/icf_virtual_function_folding_test.cc new file mode 100644 index 0000000..80f96ef --- /dev/null +++ b/gold/testsuite/icf_virtual_function_folding_test.cc @@ -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 <tmsriram@google.com>. + +// 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 <stdio.h> + +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; +} diff --git a/gold/testsuite/icf_virtual_function_folding_test.sh b/gold/testsuite/icf_virtual_function_folding_test.sh new file mode 100755 index 0000000..31c8339 --- /dev/null +++ b/gold/testsuite/icf_virtual_function_folding_test.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# icf_virtual_function_folding_test.sh -- test --icf + +# Copyright 2010 Free Software Foundation, Inc. +# Written by Sriraman Tallam <tmsriram@google.com>. + +# 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" |