Closed jharveyb closed 4 months ago
The bug here is that TinyGo still calls runtime.putchar
even with -panic=trap
. We don't need a new option, we just need to make that option work correctly.
Here is a fix: https://github.com/tinygo-org/tinygo/pull/4195 Can you test it for your use case?
Here is a fix: #4195 Can you test it for your use case?
This worked btw, thanks for the fix!
I switched to a custom target like that specified in #4174 to drop all the runtime GC functions.
Related to #3068, #2491.
tl;dr there should be a
panic
build option to short-circuitruntime.runtimePanicAt
to justunreachable
vs. printing a string.I was trying to produce a WASM progra, that could accept & return a string from/to the host, similar to this wazero example.
I compiled with tinygo v0.30.0,
tinygo build -o main.wasm -no-debug -panic=trap -scheduler=none -gc=leaking -target=wasm main.go
.Inspecting the output with wasmer, I found
wasi_snapshot_preview1
fd_write
being imported. My program does not print anything, and only importsunsafe
.Converting the WASM to WAT, I found that the runtime will unconditionally try to print during a
runtimePanic
. This feels pretty unavoidable, as funcs in theunsafe
package likeSlice
orString
can panic, but are also useful for passing memory between the guest and host.Relevant WAT snippet:
Call graph:
Rust has the build option
panic_immediate_abort
to omit any string formatting on panic, for similar reasons of small code size & minimal dependencies. Adding something similar to TinyGo would allow for WASM programs that include the runtime without also requiring a WASI-compliant host.