summaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-01-29 00:49:23 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-29 00:49:23 +0000
commit053a1f232023b15c21bdd8e89f67de21d8aea285 (patch)
tree30cc483c1055da9667de55c49b7ef3673f6266b4 /libgo
parent45e7df858b408b0277ee3580f6a67696d5cfd8b4 (diff)
downloadgcc-053a1f232023b15c21bdd8e89f67de21d8aea285.tar.gz
runtime: 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. The gc runtime doesn't do this because the gc compiler always emit an instruction following a panic call, presumably an UNDEF instruction which turns into an architecture-specific illegal instruction. Our compiler doesn't do this. Reviewed-on: https://go-review.googlesource.com/c/159437 From-SVN: r268358
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/runtime/panic.go4
-rw-r--r--libgo/runtime/go-runtime-error.c2
2 files changed, 3 insertions, 3 deletions
diff --git a/libgo/go/runtime/panic.go b/libgo/go/runtime/panic.go
index bfd2f2d542b..9b8ffb91859 100644
--- a/libgo/go/runtime/panic.go
+++ b/libgo/go/runtime/panic.go
@@ -53,7 +53,7 @@ var indexError = error(errorString("index out of range"))
// 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)))
}
diff --git a/libgo/runtime/go-runtime-error.c b/libgo/runtime/go-runtime-error.c
index f1c16502d97..5db355564dc 100644
--- a/libgo/runtime/go-runtime-error.c
+++ b/libgo/runtime/go-runtime-error.c
@@ -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)