From a459570d94d8e803d9d6d9f35e06f92f1402865d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 30 Oct 2018 15:54:02 +0100 Subject: [PATCH] wasm: execute an 'unreachable' trap inst on panic This already happened when directly calling panic() but not with some runtime panics like accessing a slice out of bounds. --- src/runtime/panic.go | 5 +++++ src/runtime/runtime_wasm.go | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/runtime/panic.go b/src/runtime/panic.go index cac51733a..c7d3d14cc 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -1,5 +1,10 @@ package runtime +// trap is a compiler hint that this function cannot be executed. It is +// translated into either a trap instruction or a call to abort(). +//go:linkname trap llvm.trap +func trap() + // Builtin function panic(msg), used as a compiler intrinsic. func _panic(message interface{}) { printstring("panic: ") diff --git a/src/runtime/runtime_wasm.go b/src/runtime/runtime_wasm.go index cf4eca693..8e58eec5d 100644 --- a/src/runtime/runtime_wasm.go +++ b/src/runtime/runtime_wasm.go @@ -49,6 +49,7 @@ func align(ptr uintptr) uintptr { return (ptr + 3) &^ 3 } +// Abort executes the wasm 'unreachable' instruction. func abort() { - // TODO + trap() }