libgo patch committed: Use the call instruction's PC for panic-in-runtime checks

Ian Lance Taylor iant@golang.org
Tue Jan 29 00:53:00 GMT 2019


This patch by Cherry Zhang changes libgo to use the call instruction's
PC for panic-in-runtime detection.  If a panic happens in the runtime
we turn that into a fatal error.  We use the caller's PC to determine
if the panic call is inside the runtime. getcallerpc returns the PC
immediately after the call instruction.  If the call is the very last
instruction of a function, it may not find this PC belong to a runtime
function,
giving false result.  We need to back off the PC by 1 to the call
instruction.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
-------------- next part --------------
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268347)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-5ccb2d8593963e06ec3a35d362b384e82301d9f0
+c2cac0ba0a92e74d5675c3c9f4e53d2567dbc903
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/runtime/panic.go
===================================================================
--- libgo/go/runtime/panic.go	(revision 268158)
+++ libgo/go/runtime/panic.go	(working copy)
@@ -53,7 +53,7 @@ var indexError = error(errorString("inde
 // entire runtime stack for easier debugging.
 
 func panicindex() {
-	name, _, _ := funcfileline(getcallerpc(), -1)
+	name, _, _ := funcfileline(getcallerpc()-1, -1)
 	if hasPrefix(name, "runtime.") {
 		throw(string(indexError.(errorString)))
 	}
@@ -64,7 +64,7 @@ func panicindex() {
 var sliceError = error(errorString("slice bounds out of range"))
 
 func panicslice() {
-	name, _, _ := funcfileline(getcallerpc(), -1)
+	name, _, _ := funcfileline(getcallerpc()-1, -1)
 	if hasPrefix(name, "runtime.") {
 		throw(string(sliceError.(errorString)))
 	}
Index: libgo/runtime/go-runtime-error.c
===================================================================
--- libgo/runtime/go-runtime-error.c	(revision 268158)
+++ libgo/runtime/go-runtime-error.c	(working copy)
@@ -63,7 +63,7 @@ __go_runtime_error (int32 i)
   struct funcfileline_return fileline;
   bool in_runtime;
 
-  fileline = runtime_funcfileline ((uintptr) runtime_getcallerpc(), 0);
+  fileline = runtime_funcfileline ((uintptr) runtime_getcallerpc()-1, 0);
   in_runtime = (fileline.retfn.len > 0
 		&& (__builtin_strncmp ((const char *) fileline.retfn.str,
 				      "runtime.", 8)


More information about the Gcc-patches mailing list