Generated binary crashes with "RuntimeError: memory access out of bounds"
womeier opened this issue · comments
Description
The wasm-bindgen
build command succeeds, but the generated binary crashes with RuntimeError: memory access out of bounds
.
main.rs
is generated by the https://github.com/AU-COBRA/coq-rust-extraction plugin, it could be a bug there as well. I suspect it's in wasm-bindgen
, because the setup works with a standard rust setup.
Working setup without wasm-bindgen
cargo run
in the attached project works, it prints the expected result Some(O(PhantomData<&()>))
.
(The source program takes an arithmetic expression representing the sum of 1 to n, compiles it to a toy stack-machine
and executes it, then subtracts n*(n+1)/2
from the result, so the expected value is 0.)
Steps to Reproduce
In the attached project, the main file is exactly the same as in the working one above,
except for the lines at the bottom related to wasm-bindgen
.
wasm-pack build --target nodejs
- in
pkg/sm_gauss_nat.js
: replacewrite_string
withconsole.log
and addwasm.main()
at the bottom - then run with nodejs:
node --stack-size=1000000 sm_gauss_nat.js
- Fails with the following error
Error
wolfgang@laptop:~/sm_gauss_nat-extracted/pkg$ node --stack-size=1000000 sm_gauss_nat.js
wasm://wasm/0005b416:1
RuntimeError: memory access out of bounds
at wasm://wasm/0005b416:wasm-function[22]:0x3b74
at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
Node.js v20.11.1
Possibly relevant
The main.rs
is generated by a compiler, and the setup with the wasm-bindgen
macros works as expected on a few other programs. We have some other Wasm binaries here, which one can run with included Node.js
based run script,
I can provide more source code for the working examples in case it helps.
Thanks!