* testsuite/relro_test.cc: Include <cstdio>, <cstdlib>, and
authorIan Lance Taylor <ian@airs.com>
Mon, 9 Jun 2008 19:12:34 +0000 (19:12 +0000)
committerIan Lance Taylor <ian@airs.com>
Mon, 9 Jun 2008 19:12:34 +0000 (19:12 +0000)
<exception>.
(throwing, orig_terminate): New static variables.
(terminate_handler): New static function.
(t2): Set terminate handler.

gold/ChangeLog
gold/testsuite/relro_test.cc

index f534b6dac5402c82e91ed81df2d1afda04946355..ded95ca26b2cb33fb4c2f85f1d38ef2a8aafdf42 100644 (file)
@@ -1,3 +1,11 @@
+2008-06-09  Ian Lance Taylor  <iant@google.com>
+
+       * testsuite/relro_test.cc: Include <cstdio>, <cstdlib>, and
+       <exception>.
+       (throwing, orig_terminate): New static variables.
+       (terminate_handler): New static function.
+       (t2): Set terminate handler.
+
 2008-06-05  Kris Van Hees  <kris.van.hees@oracle.com>
 
        PR 6584
index d1bd9dd1db085ba73505d4de4cd7a05c783056b0..1fc1b43887c2e77b43d8e5095ea6e16662dfaf37 100644 (file)
@@ -22,6 +22,9 @@
 
 #include <cassert>
 #include <csignal>
+#include <cstdio>
+#include <cstdlib>
+#include <exception>
 #include <stdint.h>
 #include <unistd.h>
 
@@ -69,15 +72,42 @@ t1()
   return true;
 }
 
+// Tell terminate handler that we are throwing from a signal handler.
+
+static bool throwing;
+
 // A signal handler for SIGSEGV.
 
 extern "C"
 void
 sigsegv_handler(int)
 {
+  throwing = true;
   throw 0;
 }
 
+// The original terminate handler.
+
+std::terminate_handler orig_terminate;
+
+// Throwing an exception out of a signal handler doesn't always work
+// reliably.  When that happens the program will call terminate.  We
+// set a terminate handler to indicate that the test probably passed.
+
+void
+terminate_handler()
+{
+  if (!throwing)
+    {
+      orig_terminate();
+      ::exit(EXIT_FAILURE);
+    }
+  fprintf(stderr,
+         "relro_test: terminate called due to failure to throw through signal handler\n");
+  fprintf(stderr, "relro_test: assuming test succeeded\n");
+  ::exit(EXIT_SUCCESS);
+}
+
 // Use a separate function to throw the exception, so that we don't
 // need to use -fnon-call-exceptions.
 
@@ -100,6 +130,7 @@ bool
 t2()
 {
   signal(SIGSEGV, sigsegv_handler);
+  orig_terminate = std::set_terminate(terminate_handler);
 
   try
     {