2_20-branch'.
Cherrypick from master 2009-10-13 21:17:43 UTC Sriraman Tallam <tmsriram@google.com> ' * gc.h (gc_process_relocs): Check if icf is enabled using new':
gold/testsuite/icf_safe_test.cc
gold/testsuite/icf_safe_test.sh
gold/testsuite/retain_symbols_file_test.sh
gold/testsuite/searched_file_test.cc
gold/testsuite/searched_file_test_lib.cc
gold/testsuite/split_i386.sh
gold/testsuite/split_i386_1.s
gold/testsuite/split_i386_2.s
gold/testsuite/split_i386_3.s
gold/testsuite/split_i386_4.s
gold/testsuite/split_i386_n.s
gold/testsuite/split_x86_64.sh
gold/testsuite/split_x86_64_1.s
gold/testsuite/split_x86_64_2.s
gold/testsuite/split_x86_64_3.s
gold/testsuite/split_x86_64_4.s
gold/testsuite/split_x86_64_n.s
--- /dev/null
+// icf_safe_test.cc -- a test case for gold
+
+// Copyright 2009 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 if identical code folding
+// in safe mode correctly folds only ctors and dtors. kept_func_1 must
+// not be folded into kept_func_2. The ctor and dtor of class A must
+// be folded.
+
+class A
+{
+ public:
+ A()
+ {
+ }
+ ~A()
+ {
+ }
+};
+
+A a;
+
+int kept_func_1()
+{
+ return 1;
+}
+
+int kept_func_2()
+{
+ return 1;
+}
+
+int main()
+{
+ return 0;
+}
--- /dev/null
+# icf_safe_test.sh -- test --icf=safe
+
+# Copyright 2009 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 if --icf=safe works as expected.
+# File icf_safe_test.cc is in this test. This program checks if only
+# ctors and dtors are folded.
+
+check_nofold()
+{
+ 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 "Safe Identical Code Folding folded" $2 "and" $3
+ exit 1
+ fi
+}
+
+check_fold()
+{
+ 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 "Safe Identical Code Folding did not fold " $2 "and" $3
+ exit 1
+ fi
+}
+
+check_nofold icf_safe_test.stdout "kept_func_1" "kept_func_2"
+check_fold icf_safe_test.stdout "_ZN1AD1Ev" "_ZN1AC1Ev"
--- /dev/null
+#!/bin/sh
+
+# retain_symbols_file_test.sh -- a test case for -retain-symbols-file
+
+# Copyright 2009 Free Software Foundation, Inc.
+# Written by Craig Silverstein <csilvers@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 Makefile tries linking simple_test.o with -retain-symbols-file.
+# It then runs nm over the results. We check that the output is right.
+
+check_present()
+{
+ if ! grep -q "$1" retain_symbols_file_test.stdout
+ then
+ echo "Did not find expected symbol $1 in retain_symbols_file_test.stdout"
+ exit 1
+ fi
+}
+
+check_absent()
+{
+ if grep -q "$1" retain_symbols_file_test.stdout
+ then
+ echo "Found unexpected symbol $1 in retain_symbols_file_test.stdout"
+ exit 1
+ fi
+}
+
+check_present 't1'
+check_present 't16b::t16b()'
+check_present 't20a::get()'
+check_present 't18()'
+check_absent 't10'
+check_absent 't1()'
+check_absent 't16b::t()'
+
+exit 0
--- /dev/null
+// searched_file_test.cc -- test -l:foo.a for gold
+
+// Copyright 2009 Free Software Foundation, Inc.
+// Written by Chris Demetriou <cgd@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 Linux kernel builds an object file using a linker script, and
+// then links against that object file using the -R option. This is a
+// test for that usage.
+
+#include <cstdlib>
+
+extern int zero_from_lib;
+
+int
+main(int, char**)
+{
+ exit(zero_from_lib);
+}
+
--- /dev/null
+// searched_file_test_lib.cc -- test -l:foo.a for gold
+
+// Copyright 2009 Free Software Foundation, Inc.
+// Written by Chris Demetriou <cgd@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 Linux kernel builds an object file using a linker script, and
+// then links against that object file using the -R option. This is a
+// test for that usage.
+
+int zero_from_lib = 0;
--- /dev/null
+#!/bin/sh
+
+# split_i386.sh -- test -fstack-split for i386
+
+# Copyright 2009 Free Software Foundation, Inc.
+# Written by Ian Lance Taylor <iant@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.
+
+match()
+{
+ if ! egrep "$1" "$2" >/dev/null 2>&1; then
+ echo 1>&2 "could not find '$1' in $2"
+ exit 1
+ fi
+}
+
+nomatch()
+{
+ if egrep "$1" "$2" >/dev/null 2>&1; then
+ echo 1>&2 "found unexpected '$1' in $2"
+ exit 1
+ fi
+}
+
+match 'cmp.*+%gs:[^,]*,%esp' split_i386_1.stdout
+match 'call.*__morestack>?$' split_i386_1.stdout
+match 'lea.*-0x200\(%esp\),' split_i386_1.stdout
+
+match 'stc' split_i386_2.stdout
+match 'call.*__morestack_non_split>?$' split_i386_2.stdout
+nomatch 'call.*__morestack>?$' split_i386_2.stdout
+match 'lea.*-0x4200\(%esp\),' split_i386_2.stdout
+
+match 'failed to match' split_i386_3.stdout
+
+match 'call.*__morestack>?$' split_i386_4.stdout
+
+match 'cannot mix' split_i386_r.stdout
--- /dev/null
+# split_i386_1.s: i386 specific test case for -fsplit-stack.
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ cmp %gs:0x30,%esp
+ jae 1f
+ call __morestack
+ ret
+1:
+ call fn2
+ ret
+
+ .size fn1,. - fn1
+
+ .global fn2
+ .type fn2,@function
+fn2:
+ lea -0x200(%esp),%ecx
+ cmp %gs:0x30,%ecx
+ jae 1f
+ call __morestack
+ ret
+1:
+ call fn1
+ ret
+
+ .size fn2,. - fn2
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
--- /dev/null
+# split_i386_2.s: i386 specific, -fsplit-stack calling non-split
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ cmp %gs:0x30,%esp
+ jae 1f
+ call __morestack
+ ret
+1:
+ call fn3
+ ret
+
+ .size fn1,. - fn1
+
+ .global fn2
+ .type fn2,@function
+fn2:
+ lea -0x200(%esp),%ecx
+ cmp %gs:0x30,%ecx
+ jae 1f
+ call __morestack
+ ret
+1:
+ call fn3
+ ret
+
+ .size fn2,. - fn2
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
--- /dev/null
+# split_i386_3.s: i386 specific, adjustment failure
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ push %ebp
+ mov %esp,%ebp
+ cmp %gs:0x30,%esp
+ jae 1f
+ call __morestack
+ ret
+1:
+ call fn3
+ leave
+ ret
+
+ .size fn1,. - fn1
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
--- /dev/null
+# split_i386_4.s: i386 specific, permitted adjustment failure
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ push %ebp
+ mov %esp,%ebp
+ cmp %gs:0x30,%esp
+ jae 1f
+ call __morestack
+ ret
+1:
+ call fn3
+ leave
+ ret
+
+ .size fn1,. - fn1
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
+ .section .note.GNU-no-split-stack,"",@progbits
--- /dev/null
+# split_i386_n.s: i386 specific, -fsplit-stack calling non-split
+
+ .text
+
+ .global fn3
+ .type fn3,@function
+fn3:
+ ret
+
+ .size fn3,. - fn3
+
+ .section .note.GNU-stack,"",@progbits
--- /dev/null
+#!/bin/sh
+
+# split_x86_64.sh -- test -fstack-split for x86_64
+
+# Copyright 2009 Free Software Foundation, Inc.
+# Written by Ian Lance Taylor <iant@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.
+
+match()
+{
+ if ! egrep "$1" "$2" >/dev/null 2>&1; then
+ echo 1>&2 "could not find '$1' in $2"
+ exit 1
+ fi
+}
+
+nomatch()
+{
+ if egrep "$1" "$2" >/dev/null 2>&1; then
+ echo 1>&2 "found unexpected '$1' in $2"
+ exit 1
+ fi
+}
+
+match 'cmp.*+%fs:[^,]*,%rsp' split_x86_64_1.stdout
+match 'callq.*__morestack>?$' split_x86_64_1.stdout
+match 'lea.*-0x200\(%rsp\),' split_x86_64_1.stdout
+
+match 'stc' split_x86_64_2.stdout
+match 'callq.*__morestack_non_split>?$' split_x86_64_2.stdout
+nomatch 'callq.*__morestack>?$' split_x86_64_2.stdout
+match 'lea.*-0x4200\(%rsp\),' split_x86_64_2.stdout
+
+match 'failed to match' split_x86_64_3.stdout
+
+match 'callq.*__morestack>?$' split_x86_64_4.stdout
+
+match 'cannot mix' split_x86_64_r.stdout
--- /dev/null
+# split_x86_64_1.s: x86_64 specific test case for -fsplit-stack.
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ cmp %fs:0x70,%rsp
+ jae 1f
+ callq __morestack
+ retq
+1:
+ callq fn2
+ retq
+
+ .size fn1,. - fn1
+
+ .global fn2
+ .type fn2,@function
+fn2:
+ lea -0x200(%rsp),%r10
+ cmp %fs:0x70,%r10
+ jae 1f
+ callq __morestack
+ retq
+1:
+ callq fn1
+ retq
+
+ .size fn2,. - fn2
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
--- /dev/null
+# split_x86_64_2.s: x86_64 specific, -fsplit-stack calling non-split
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ cmp %fs:0x70,%rsp
+ jae 1f
+ callq __morestack
+ retq
+1:
+ callq fn3
+ retq
+
+ .size fn1,. - fn1
+
+ .global fn2
+ .type fn2,@function
+fn2:
+ lea -0x200(%rsp),%r10
+ cmp %fs:0x70,%r10
+ jae 1f
+ callq __morestack
+ retq
+1:
+ callq fn3
+ retq
+
+ .size fn2,. - fn2
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
--- /dev/null
+# split_x86_64_3.s: x86_64 specific, adjustment failure
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ push %rbp
+ mov %rsp,%rbp
+ cmp %fs:0x70,%rsp
+ jae 1f
+ callq __morestack
+ retq
+1:
+ callq fn3
+ leaveq
+ retq
+
+ .size fn1,. - fn1
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
--- /dev/null
+# split_x86_64_4.s: x86_64 specific, permitted adjustment failure
+
+ .text
+
+ .global fn1
+ .type fn1,@function
+fn1:
+ push %rbp
+ mov %rsp,%rbp
+ cmp %fs:0x70,%rsp
+ jae 1f
+ callq __morestack
+ retq
+1:
+ callq fn3
+ leaveq
+ retq
+
+ .size fn1,. - fn1
+
+ .section .note.GNU-stack,"",@progbits
+ .section .note.GNU-split-stack,"",@progbits
+ .section .note.GNU-no-split-stack,"",@progbits
--- /dev/null
+# split_x86_64_n.s: x86_64 specific, -fsplit-stack calling non-split
+
+ .text
+
+ .global fn3
+ .type fn3,@function
+fn3:
+ retq
+
+ .size fn3,. - fn3
+
+ .section .note.GNU-stack,"",@progbits