From Craig Silverstein: Add test for debug messages.
authorIan Lance Taylor <iant@google.com>
Fri, 9 Nov 2007 23:19:11 +0000 (23:19 +0000)
committerIan Lance Taylor <iant@google.com>
Fri, 9 Nov 2007 23:19:11 +0000 (23:19 +0000)
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/debug_msg.cc [new file with mode: 0644]
gold/testsuite/debug_msg.sh [new file with mode: 0755]

index 5c42b3fb3bd45f13fdc31122e03e388d26eb3406..ad47d2827a721475837f9d2f3bff9f6ee875bdf8 100644 (file)
@@ -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
index 1cfea398ce0a8e64da7632cf0da52e8f606dabb7..2587b682d77a9a034d5b8870498387db40ba9e7d 100644 (file)
@@ -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 (file)
index 0000000..ab73a8d
--- /dev/null
@@ -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 <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.
+
+// 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<class Foo>
+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 (executable)
index 0000000..53e9d88
--- /dev/null
@@ -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 <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.
+
+# 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>(int):${srcdir}/debug_msg.cc:43: undefined reference to 'undef_fn1()'"
+check "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'"
+check "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'"
+check "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:43: undefined reference to 'undef_fn1()'"
+check "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'"
+check "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'"
+
+exit 0
This page took 0.028436 seconds and 4 git commands to generate.