Description
I am encountering a crash in Wasm generated with recent versions of AssemblyScript when I invoke a function other than the default entry point.
Repro setup
I am testing with AssemblyScript 0.19.17 and Wasmtime 0.30.0.
My index.ts
is as follows:
import "wasi";
import { Console } from "as-wasi";
export function foo(): void {
Console.log("foo");
}
My package.json
contains the following scripts:
"build:untouched": "asc assembly/index.ts --target debug --use abort=wasi_abort",
"build:optimized": "asc assembly/index.ts --target release --use abort=wasi_abort",
"build": "npm run build:untouched && npm run build:optimized"
Symptoms
What I ran:
npm run build
wasmtime run --invoke foo ./build/untouched.wasm
Expected output: foo
Actual output: many (stack overflow amount?) lines of error dump which repeats the following lines:
21386: 0x242f - <unknown>!~lib/as-wasi/as-wasi/wasi_abort
21387: 0x1044 - <unknown>!~lib/rt/itcms/visitRoots
21388: 0x1970 - <unknown>!~lib/rt/itcms/step
21389: 0x1a4c - <unknown>!~lib/rt/itcms/interrupt
21390: 0x1fda - <unknown>!~lib/rt/itcms/__new
21391: 0x2564 - <unknown>!~lib/string/String#concat
21392: 0xcd0 - <unknown>!~lib/string/String.__concat
Additional information
wasmtime run ./build/untouched.wasm
works fine without crashing. (If I add some top level statements and wasmtime run
then these are executed correctly.) It's only when I pass the --invoke
option that things go wrong.
The same problem occurs if I embed wasmtime
and call its API to invoke a function other than _start
.
The same problem occurs if I use ./build/optimized.wasm
, or the .wat
build output.
The problem does not occur with AssemblyScript 0.17.2/as-wasi 0.4.3. With these versions wasmtime run --invoke foo
runs correctly.
Please let me know if you need any more info - thanks!