libgo patch committed: Print reason code if throw fails

Ian Lance Taylor iant@golang.org
Thu Oct 15 00:00:15 GMT 2020


This libgo patch by Nikhil Benesch prints the reason code if throwing
an unwind exception fails.  Calls to _Unwind_RaiseException and
friends *can* return due to bugs in libgo or memory corruption.  When
this occurs, print a message to stderr with the reason code before
aborting to aid debugging.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
-------------- next part --------------
61cc6ab950a64bb1a49f9c07c3efdd11d19484d5
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index e6eb8e5c335..45a7b422a29 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-cc1f7d613f9b0666bbf8aac3dd208d5adfe88546
+b73a8f17dfe8d7c7ecc9ccd0317be5abe71c5509
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/runtime/go-unwind.c b/libgo/runtime/go-unwind.c
index ad3142cb05d..16e05252ec9 100644
--- a/libgo/runtime/go-unwind.c
+++ b/libgo/runtime/go-unwind.c
@@ -59,20 +59,22 @@ void
 rethrowException ()
 {
   struct _Unwind_Exception *hdr;
+  _Unwind_Reason_Code reason;
 
   hdr = (struct _Unwind_Exception *) runtime_g()->exception;
 
 #ifdef __USING_SJLJ_EXCEPTIONS__
-  _Unwind_SjLj_Resume_or_Rethrow (hdr);
+  reason = _Unwind_SjLj_Resume_or_Rethrow (hdr);
 #else
 #if defined(_LIBUNWIND_STD_ABI)
-  _Unwind_RaiseException (hdr);
+  reason = _Unwind_RaiseException (hdr);
 #else
-  _Unwind_Resume_or_Rethrow (hdr);
+  reason = _Unwind_Resume_or_Rethrow (hdr);
 #endif
 #endif
 
   /* Rethrowing the exception should not return.  */
+  runtime_printf ("failed to rethrow unwind exception (reason=%d)\n", reason);
   abort();
 }
 
@@ -105,6 +107,7 @@ throwException ()
 {
   struct _Unwind_Exception *hdr;
   uintptr align;
+  _Unwind_Reason_Code reason;
 
   hdr = (struct _Unwind_Exception *)runtime_g ()->exception;
 
@@ -119,12 +122,13 @@ throwException ()
   hdr->exception_cleanup = NULL;
 
 #ifdef __USING_SJLJ_EXCEPTIONS__
-  _Unwind_SjLj_RaiseException (hdr);
+  reason = _Unwind_SjLj_RaiseException (hdr);
 #else
-  _Unwind_RaiseException (hdr);
+  reason = _Unwind_RaiseException (hdr);
 #endif
 
   /* Raising an exception should not return.  */
+  runtime_printf ("failed to throw unwind exception (reason=%d)\n", reason);
   abort ();
 }
 


More information about the Gcc-patches mailing list