Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-opt crashes with a bus error on a 91 kB Wasm file #7333

Open
samestep opened this issue Feb 27, 2025 · 1 comment · May be fixed by #7334
Open

wasm-opt crashes with a bus error on a 91 kB Wasm file #7333

samestep opened this issue Feb 27, 2025 · 1 comment · May be fixed by #7334

Comments

@samestep
Copy link

samestep commented Feb 27, 2025

Issue

I've put my input file prospero-opt-grad.wat in a GitHub Gist here: https://gist.github.com/samestep/ca2333b48a0aac67dab4bba4e51be92d

I'm on a 2020 MacBook Pro with M1 chip. I downloaded binaryen-version_122-arm64-macos.tar.gz from GitHub Releases, and attempted to run it on this Wasm file as follows:

wasm-opt prospero-opt-grad.wat -O3 -o prospero-opt-grad-opt.wasm

This ran for 9 seconds and then crashed with the following error output:

zsh: bus error  wasm-opt prospero-opt-grad.wat -O3 -o prospero-opt-grad-opt.wasm

Context

This came up in samestep/floretta#7 while I was experimenting with automatic differentiation of Wasm for an example computation graph with 8k nodes to see how well it would work on a single large function without control flow.

In particular, I started with prospero.wat which I generated from prospero.vm using the code in that PR I linked, then ran it through wasm-opt like this:

wasm-opt prospero.wat -O3 -o prospero-opt.wasm

That worked fine. Then I took prospero-opt.wasm and ran it through my Floretta tool at commit 919c361, like this:

cargo run prospero-opt.wasm --reverse --export main backprop --wat -o prospero-opt-grad.wat

That also worked fine. Finally I ran prospero-opt-grad.wat through wasm-opt, which fails as detailed above. Also, to clarify, the "91 kB" number in this issue title comes from running this command:

wasm-tools parse prospero-opt-grad.wat -o prospero-opt-grad.wasm && wc -c prospero-opt-grad.wasm

The same wasm-opt error still happens when running on prospero-opt-grad.wasm instead of prospero-opt-grad.wat.

@kripken
Copy link
Member

kripken commented Feb 27, 2025

Adding -all fixes the error. This module does need features enabled due to use of at least multivalue.

The crash looks like an OOM - we accumulate all errors before printing, and it seems like there are just so many we run out of memory. I didn't check specifically why, but it might be the incredibly-deeply nested call $f32_mins - we may be trying to print out each nesting, leading to quadratic time.

We do need to accumulate errors before printing, for determinism, but perhaps we can stop after a fixed number, to avoid this...

@kripken kripken linked a pull request Feb 27, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants