bytecodealliance / bytecodealliance/wasmtime

Crash when Wasmtime invokes nondefault AssemblyScript function

Open
#3,474 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

I originally raised this at AssemblyScript (https://github.com/AssemblyScript/assemblyscript/issues/2099) but they appear to view it as an issue with Wasm runtimes; they have raised a Wasmer bug but my use case is Wasmtime.

-----

Consider the following AssemblyScript program:

```
import "wasi";

export function foo(): void {
console.log("foo");
console.log(Math.random().toString());
}

console.log("start");
```

Compile this using

```
asc test.ts --explicitStart --debug
```

Now run `wasmtime run --invoke foo ./build/untouched.wasm`

It crashes with:

```
Caused by:
0: failed to invoke `foo`
1: exit with invalid exit status outside of [0..126)
wasm backtrace:
0: 0x5a9 - !~lib/wasi/index/abort
1: 0x2c4a - !~lib/rt/itcms/visitRoots
2: 0x2e73 - !~lib/rt/itcms/step
3: 0x2fb2 - !~lib/rt/itcms/interrupt
4: 0x31ea - !~lib/rt/itcms/__new
5: 0x3441 - !~lib/util/number/dtoa
6: 0x322c - !~lib/number/F64#toString
7: 0x337b - !assembly/index/foo```
```

The crash occurs within the AssemblyScript garbage collector while trying to allocate a string.

I believe the reason AssemblyScript considers this a runtime bug is that they set up the GC in the implicit `_start` function. Calling `wasmtime run --invoke foo` bypasses `_start` and therefore the GC is not set up when it needs to do the allocation.

This also occurs when invoking the function via the Wasmtime Rust crate hosted in my own program (https://github.com/deislabs/wagi/issues/128).

There are additional details and discussion in the original AssemblyScript issue https://github.com/AssemblyScript/assemblyscript/issues/2099.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.