cfallin opened PR #11690 from cfallin:wasm-impl-limit-function-size to bytecodealliance:main:
In #11682 we see a module with an extremely large single function body (function index 193). This causes a panic in Cranelift as we run out of SSA value numbers: the
ValueDataPackedbit-packing supports only 2^24 (16M) values per function.I started down the path of propagating
CodegenErrors everywhere throughout Cranelift to properly bubble up a
CodegenError::CodeTooLarge, but that turns out to be an extremely pervasive change: it means not only that we have more Result plumbing, but that (i) Cranelift's public API changes so that all function builder methods return Results, which is a huge change for any existing user; and (ii) ISLE can't generate Rust that propagates Results, so we need to awkwardly set an error flag on a context, return a fake Value, and "catch" it on the other side of the invocation, which is error-prone.I then considered a size-check on function bodies as they enter Cranelift, but at that point, realized that Wasm already provides for implementation limits for this purpose. The JS embedding spec at https://webassembly.github.io/spec/js-api/index.html#limits specifies that a function body can be at most 7_654_321 bytes (7.65MB). We don't have to follow the JS embedding's implementation limits, but there is good reason to expect that producers will try to stay within them, and the reasons that led to those limits in Web engines' compilers equally apply to ours. This PR thus instead enforces the limit directly.
Fixes #11682.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin requested fitzgen for a review on PR #11690.
cfallin requested wasmtime-compiler-reviewers for a review on PR #11690.
cfallin requested wasmtime-core-reviewers for a review on PR #11690.
fitzgen commented on PR #11690:
It might be better to enforce this in
wasmparser, where we enforce the rest of these implementation limits:
cfallin commented on PR #11690:
Good point -- opened https://github.com/bytecodealliance/wasm-tools/pull/2302 for this.
cfallin closed without merge PR #11690.
Last updated: Dec 06 2025 at 07:03 UTC