From f0323c2f6875c75b72a5832e746c9b2baf90eedd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 9 Nov 2007 23:19:11 +0000 Subject: [PATCH] From Craig Silverstein: Add test for debug messages. --- gold/testsuite/Makefile.am | 17 +++++++++++- gold/testsuite/Makefile.in | 32 +++++++++++++++------- gold/testsuite/debug_msg.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++ gold/testsuite/debug_msg.sh | 58 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 11 deletions(-) create mode 100644 gold/testsuite/debug_msg.cc create mode 100755 gold/testsuite/debug_msg.sh diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 5c42b3f..ad47d28 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -21,11 +21,17 @@ if THREADS THREADSLIB = -lpthread endif +check_SCRIPTS = debug_msg.sh +check_DATA = + TESTS = object_unittest -check_SCRIPTS = if GCC +TESTS += debug_msg.sh + +check_DATA += debug_msg.err + if NATIVE_LINKER NATIVE_PROGS = \ @@ -108,6 +114,15 @@ object_unittest_SOURCES = object_unittest.cc if GCC +debug_msg.o: debug_msg.cc + $(CXXCOMPILE) -O0 -c -w -o $@ $(srcdir)/debug_msg.cc +debug_msg.err: debug_msg.o + if $(CXXLINK) -Bgcctestdir/ -o debug_msg debug_msg.o 2>debug_msg.err; \ + then \ + echo 2>&1 "Link of debug_msg.o should have failed"; \ + exit 1; \ + fi + if NATIVE_LINKER gcctestdir/ld: ../ld-new diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 1cfea39..2587b68 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -42,23 +42,25 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ -@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_1 = \ +@GCC_TRUE@am__append_1 = debug_msg.sh +@GCC_TRUE@am__append_2 = debug_msg.err +@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_3 = \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_1_nonpic_test \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_2_nonpic_test \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_same_shared_nonpic_test \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_separate_shared_12_nonpic_test \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_separate_shared_21_nonpic_test -@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_2 = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_4 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_pic_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_shared_test -@GCC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@am__append_3 = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@am__append_5 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@ tls_static_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@ tls_static_pic_test -@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_4 = \ +@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_6 = \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_shared_nonpic_test check_PROGRAMS = object_unittest$(EXEEXT) $(am__EXEEXT_5) @@ -552,8 +554,9 @@ INCLUDES = \ @INCINTL@ @THREADS_TRUE@THREADSLIB = -lpthread -TESTS = object_unittest $(NATIVE_TESTING) -check_SCRIPTS = +check_SCRIPTS = debug_msg.sh +check_DATA = $(am__append_2) +TESTS = object_unittest $(am__append_1) $(NATIVE_TESTING) @GCC_TRUE@@NATIVE_LINKER_TRUE@NATIVE_PROGS = constructor_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_static_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_test \ @@ -571,9 +574,9 @@ check_SCRIPTS = @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_same_shared_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_separate_shared_12_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_separate_shared_21_test \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test $(am__append_1) \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(am__append_2) $(am__append_3) \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(am__append_4) +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test $(am__append_3) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(am__append_4) $(am__append_5) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(am__append_6) @GCC_TRUE@@NATIVE_LINKER_TRUE@NATIVE_TESTING = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_pic_test \ @@ -1074,7 +1077,7 @@ distdir: $(DISTFILES) done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_LIBRARIES) $(check_PROGRAMS) \ - $(check_SCRIPTS) + $(check_SCRIPTS) $(check_DATA) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile @@ -1165,6 +1168,15 @@ uninstall-am: uninstall-info-am tags uninstall uninstall-am uninstall-info-am +@GCC_TRUE@debug_msg.o: debug_msg.cc +@GCC_TRUE@ $(CXXCOMPILE) -O0 -c -w -o $@ $(srcdir)/debug_msg.cc +@GCC_TRUE@debug_msg.err: debug_msg.o +@GCC_TRUE@ if $(CXXLINK) -Bgcctestdir/ -o debug_msg debug_msg.o 2>debug_msg.err; \ +@GCC_TRUE@ then \ +@GCC_TRUE@ echo 2>&1 "Link of debug_msg.o should have failed"; \ +@GCC_TRUE@ exit 1; \ +@GCC_TRUE@ fi + @GCC_TRUE@@NATIVE_LINKER_TRUE@gcctestdir/ld: ../ld-new @GCC_TRUE@@NATIVE_LINKER_TRUE@ test -d gcctestdir || mkdir -p gcctestdir @GCC_TRUE@@NATIVE_LINKER_TRUE@ rm -f gcctestdir/ld diff --git a/gold/testsuite/debug_msg.cc b/gold/testsuite/debug_msg.cc new file mode 100644 index 0000000..ab73a8d --- /dev/null +++ b/gold/testsuite/debug_msg.cc @@ -0,0 +1,67 @@ +// debug_msg.cc -- a test case for printing debug info for missing symbols. + +// Copyright 2006, 2007 Free Software Foundation, Inc. +// Written by Ian Lance Taylor . + +// 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. + +// This file is constructed to have undefined references. In +// debug_msg.sh, we will try to link this file, and analyze the +// error messages that are produced. + +extern int undef_int; +extern float undef_float; +extern void undef_fn1(); +extern void undef_fn2(); + +int* badref1 = &undef_int; +static float* badref2 = &undef_float; +void (*fn_array[])() = +{ + undef_fn1, + undef_fn2 +}; + +template +int testfn(Foo x) +{ + undef_fn1(); + undef_fn2(); + return undef_int; +} + +class Base +{ + virtual void virtfn() { undef_fn1(); } +}; + +class Derived : public Base +{ + virtual void virtfn() { undef_fn2(); } +}; + +int main() +{ + testfn(5); + testfn(4.0); + + Base b; + Derived d; + + return 0; +} diff --git a/gold/testsuite/debug_msg.sh b/gold/testsuite/debug_msg.sh new file mode 100755 index 0000000..53e9d88 --- /dev/null +++ b/gold/testsuite/debug_msg.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# debug_msg.sh -- a test case for printing debug info for missing symbols. + +# Copyright 2006, 2007 Free Software Foundation, Inc. +# Written by Ian Lance Taylor . + +# 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. + +# This file goes with debug_msg.cc, a C++ source file constructed to +# have undefined references. We compile that file with debug +# information and then try to link it, and make sure the proper errors +# are displayed. The errors will be found in debug_msg.err. + +check() +{ + if ! grep -q "$1" debug_msg.err + then + echo "Did not find expected error:" + echo " $1" + echo "" + echo "Actual error output below:" + cat debug_msg.err + exit 1 + fi +} + +# We don't know how the compiler might order these variables, so we +# can't test for the actual offset from .data, hence the regexp. +check "debug_msg.o: in function fn_array:debug_msg.cc(.data+0x[0-9a-fA-F]*): undefined reference to 'undef_fn1()'" +check "debug_msg.o: in function fn_array:debug_msg.cc(.data+0x[0-9a-fA-F]*): undefined reference to 'undef_fn2()'" +check "debug_msg.o: in function badref1:debug_msg.cc(.data+0x[0-9a-fA-F]*): undefined reference to 'undef_int'" + +check "debug_msg.o: in function Base::virtfn():${srcdir}/debug_msg.cc:50: undefined reference to 'undef_fn1()'" +check "debug_msg.o: in function Derived::virtfn():${srcdir}/debug_msg.cc:55: undefined reference to 'undef_fn2()'" +check "debug_msg.o: in function int testfn(int):${srcdir}/debug_msg.cc:43: undefined reference to 'undef_fn1()'" +check "debug_msg.o: in function int testfn(int):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'" +check "debug_msg.o: in function int testfn(int):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'" +check "debug_msg.o: in function int testfn(double):${srcdir}/debug_msg.cc:43: undefined reference to 'undef_fn1()'" +check "debug_msg.o: in function int testfn(double):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'" +check "debug_msg.o: in function int testfn(double):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'" + +exit 0 -- 2.7.4