wasm-by-example icon indicating copy to clipboard operation
wasm-by-example copied to clipboard

Update TinyGo Compiler Flag note for WASI

Open torch2424 opened this issue 4 years ago • 2 comments

From Dan Kegel in the Tinygo slack: "Hey Aaron, I think gc on wasm is conservative-ish by default since https://github.com/tinygo-org/tinygo/pull/1853, maybe remove mention of -gc=conservative? I dunno, I just work here :slightly_smiling_face: but I hear -scheduler=none and/or -gc=leaking are the flags to try when odd crashes happen..."

torch2424 avatar Jul 30 '21 20:07 torch2424

You also don't need -wasm-abi=generic: this is the default for WASI.

# Note, some features aren't fully supported by WASI. So if you hit nil pointer references
# You may want to play around with the scheduler and gc flags. For example:
# "-scheduler=none -gc=conservative" or "-scheduler=coroutines -gc=leaking"

Some other notes:

  • It's not really WASI that causes these bugs, it's TinyGo. WebAssembly currently doesn't support direct access to the stack which is why TinyGo has to do things differently on WebAssembly compared to other architectures.
  • The default for WebAssembly is indeed -gc=conservative -scheduler=coroutines. You can inspect these values like this:
$ tinygo info wasi
LLVM triple:       wasm32--wasi
GOOS:              linux
GOARCH:            arm
build tags:        tinygo.wasm wasi tinygo math_big_pure_go gc.conservative scheduler.coroutines serial.none
garbage collector: conservative
scheduler:         coroutines
cached GOROOT:     /home/ayke/.cache/tinygo/goroot-go1.16.2-c80939e3ef7edbc184c2946545bb39c528b92e6385a60d8c810f1438cfb5211f-syscall

To rule out bugs in the GC or scheduler passes, you can try -gc=leaking or -scheduler=none, or both.

aykevl avatar Aug 01 '21 10:08 aykevl

@aykevl Ah! Thank you very much for this insight! I'll go ahead and try to convert this in the example when I get the time! Thank you! 😀🎉

torch2424 avatar Aug 02 '21 21:08 torch2424