Skip to content

wasm32-wasip2 on non-nightly produces bad Wasm when opt-level > 1 #148715

@tliron

Description

@tliron

This was very hard to pin-point!

The background is that I am using wasmtime with the Component Model to run components that I am creating from Rust + wit-bindgen targeting wasm32-wasip2.

I noticed something very odd. The debug builds of my Wasm worked fine, but release builds caused some very weird errors from wasmtime.

After a lot of trial-and-error I discovered that the issue only happens when going beyond opt-level 1. Essentially running cargo build with CARGO_PROFILE_RELEASE_OPT_LEVEL=1 solved the problem.

I further discovered that this issue doesn't happen when using cargo +nightly build, which can use the default opt-level 3 without a problem.

This might be a known issue. If it's solved in nightly, that means it might find its way to the standard channel.

However, just in case this is a fluke (or other people encounter this bug and search for solutions), hopefully this issue will help track it.

Meta

rustc --version --verbose:

rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: x86_64-unknown-linux-gnu
release: 1.91.0
LLVM version: 21.1.2

rustc +nightly --version --verbose:

rustc 1.93.0-nightly (843f8ce2e 2025-11-07)
binary: rustc
commit-hash: 843f8ce2ebc01d35a30484eadc8a84cdc6130844
commit-date: 2025-11-07
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchO-wasmTarget: WASM (WebAssembly), http://webassembly.org/needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions