Skip to content

nightly-2025-02-18 wasm-opt cannot process resulting binary #137315

Closed

Description

@Ddystopia

I bisected by hand and at nightly-2025-02-18 wasm-opt started giving errors like this:

...
[wasm-validator error in function 2590] unexpected false: Bulk memory operations require bulk memory [--enable-bulk-memory], on
(memory.copy
 (local.get $0)
 (i32.add
  (local.get $4)
  (i32.const 8)
 )
 (i32.const 40)
)
[wasm-validator error in function 2621] unexpected false: Bulk memory operations require bulk memory [--enable-bulk-memory], on
(memory.copy
 (i32.add
  (local.get $2)
  (i32.shl
   (local.get $8)
   (i32.const 2)
  )
 )
 (i32.add
  (local.get $2)
  (i32.shl
   (local.get $0)
   (i32.const 2)
  )
 )
 (local.get $5)
)
...

It asks for --enable-bulk-memory, if give it to it, other errors reveal (this is the whole output):

> wasm-opt -Oz project.wasm -o new.wasm --enable-bulk-memory
[wasm-validator error in function 520] unexpected false: all used features should be allowed, on
(i32.trunc_sat_f32_s
 (f32.mul
  (local.get $13)
  (f32.const 20)
 )
)
[wasm-validator error in function 520] unexpected false: all used features should be allowed, on
(i32.trunc_sat_f32_u
 (local.tee $13
  (f32.add
   (local.get $13)
   (f32.const 60)
  )
 )
)
[wasm-validator error in function 1103] unexpected false: all used features should be allowed, on
(i32.trunc_sat_f64_u
 (local.tee $4
  (call $fimport$187
   (i32.load
    (i32.load
     (local.get $1)
    )
   )
   (i32.load offset=12
    (local.get $2)
   )
  )
 )
)
[wasm-validator error in function 1120] unexpected false: all used features should be allowed, on
(i64.trunc_sat_f64_s
 (local.get $4)
)
[wasm-validator error in function 1908] unexpected false: all used features should be allowed, on
(i64.trunc_sat_f64_u
 (local.get $9)
)
Fatal: error validating input

For wasm-opt I tried versions form 116 to 120, all failed.

I am compiling web application with dioxus, it uses wasm-bindgen.

Activity

  1. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 20, 2025
  2. saethlin commented on Feb 20, 2025

    @saethlin
    Member

    Can you share a reproducer?

    I bisected by hand and at nightly-2025-02-18

    Can you bisect using cargo-bisect-rustc to find the relevant PR?

  3. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    O-wasmTarget: WASM (WebAssembly), http://webassembly.org/
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 20, 2025
  4. nikic commented on Feb 20, 2025

    @nikic
    Contributor

    This is due to the LLVM 20 upgrade, which enables bulk-memory and nontrapping-fptoint by default. Need to update https://doc.rust-lang.org/rustc/platform-support/wasm32-unknown-unknown.html#enabled-webassembly-features.

    cc @alexcrichton

  5. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    and removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.
    on Feb 20, 2025
  6. 12 remaining items

  7. added 2 commits that reference this issue on Feb 20, 2025
    48dbbe2
    3d5e773
  8. eric-seppanen commented on Feb 21, 2025

    @eric-seppanen

    A lot of downstream tools (e.g. trunk) call out to wasm-opt, and it causes a lot of downstream build breakage when new wasm features get turned on. The error messages are uninformative and it's not always obvious what the fix is.

    So far the discussion here hasn't led to a clear way forward. It would be nice if wasm-opt weren't so critical to the rust-webassembly ecosystem, but in the meantime it seems like this should be called out in the release notes so people aren't surprised by the breakage.

  9. eric-seppanen commented on Feb 21, 2025

    @eric-seppanen

    It would be very helpful if someone with deep webassembly knowledge could weigh in on trunk-rs/trunk#904 .

    Would any of these options be the recommended way forward? Should trunk enable all the latest things by default as soon as llvm/rustc does?

  10. added a commit that references this issue on Feb 21, 2025
    84bc955
  11. alexcrichton commented on Feb 21, 2025

    @alexcrichton
    Member

    @eric-seppanen have you reached out to the wasm-opt/binaryen folks about this? I suspect they'd be accomodating to the suggestion to enable these proposals by default to match LLVM

  12. eric-seppanen commented on Feb 21, 2025

    @eric-seppanen

    @eric-seppanen have you reached out to the wasm-opt/binaryen folks about this? I suspect they'd be accomodating to the suggestion to enable these proposals by default to match LLVM

    @alexcrichton
    I don't really understand what request should be made. I'm not terribly familiar with the webassembly features, and I'm not a trunk maintainer. What would it mean to say "enable these proposals by default to match LLVM"? Does that mean that each wasm-opt release has a set of defaults that matches a particular llvm version? Or that it should inspect the incoming binaries and somehow determine which set of features to enable for its output? Is this problem specific to rust, or do I need to understand how other languages handle this issue?

  13. alexcrichton commented on Feb 21, 2025

    @alexcrichton
    Member

    I'd recommend making a request that the default set of enabled features in binaryen either be (a) proposals that are stage 4+ or (b) proposals that are on-by-default in LLVM. In wasmtime/wasm-tools we do (a) and find that it works well for our use cases, but binaryen might have other use cases as well.

    In my mind if binaryen has good reason for not enabling a feature by default then that should be a factor in a decision to enable something in LLVM by default. Often though I find that things aren't on-by-default because it's just forgotten about.

  14. added a commit that references this issue on Jun 17, 2025
  15. added a commit that references this issue on Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-discussionCategory: Discussion or questions that doesn't represent real issues.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions