Can not disable reference-types feature for wasm32 target with -C linker-plugin-lto flag #130604
Copy link
Copy link
Closed
Closed
Copy link
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Description
Code
Code is minimized as much as possible and here is a demo repository: https://github.com/StackOverflowExcept1on/wasm-builder-regression/
wasm-checker- simple CLI tool that passes wasm to parity-wasm parser (it does not support reference-types)wasm-program- this is smart contract that panics and terminates with an errorwasm-project- some intermediate directory that is generated by our utility- check.sh source code
git clone https://github.com/StackOverflowExcept1on/wasm-builder-regression.git
cd wasm-builder-regression/wasm-project
./check.sh Finished `release` profile [optimized] target(s) in 8.30s
Compiling gear-wasm v0.45.1
Compiling wasm-checker v0.1.0 (/mnt/tmpfs/wasm-builder-regression/wasm-checker)
Finished `release` profile [optimized] target(s) in 1.68s
Running `/mnt/tmpfs/wasm-builder-regression/wasm-checker/target/release/wasm-checker ./target/wasm32-unknown-unknown/release/wasm_program.wasm`
Error: InvalidTableReference(128)
If I remove flag -C linker-plugin-lto, it works as described in #128511
I expected to see this happen: I can disable reference-types via -Ctarget-cpu=mvp and -Zbuild-std
Instead, this happened: there is some kind of conflict between compiler flags?
Version it worked on
It most recently worked on: nightly-2024-07-31
Version with regression
rustc +nightly-2024-08-01 --version --verbose:
rustc 1.82.0-nightly (28a58f2fa 2024-07-31)
binary: rustc
commit-hash: 28a58f2fa7f0c46b8fab8237c02471a915924fe5
commit-date: 2024-07-31
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
Reacted by Raúl Kripalani
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Activity
alexcrichton commentedon Sep 20, 2024
Thanks for the report! I'm not actually sure what's going on here. My best guess though is that
wasm-ldis performing codegen on behalf of-Clinker-plugin-ltoand it's not configured the same way as rustc. For example-Ctarget-cpuis a Rust compiler flag which it translates to LLVM, but this isn't passed towasm-ld. (AFAIK there's no way to pass this flag towasm-ld).The LLVM IR going into
wasm-ldlooks like it's correctly annotated with"target-cpu"="mvp"on functions which also perplexes me...Put another way, you're doing everything right here, and the bug lies somewhere in the interaction of codegen in
wasm-ldand configuring LLVM with features disabled. It might be a bug inwasm-lditself or it might be a bug in rustc. A reduction of this issue is:Locally I see:
I've opened llvm/llvm-project#109443 to see if folks have thoughts there.
apiraino commentedon Oct 9, 2024
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
StackOverflowExcept1on commentedon Dec 14, 2024
@alexcrichton this bug is also reproduced on the new target
wasm32v1-none.alexcrichton commentedon Dec 16, 2024
Can you provide reproduction steps necessary? Just saying "also reproduced on the new target" isn't too helpful at indicating what you're doing to reproduce this or what is even being reproduced.
StackOverflowExcept1on commentedon Dec 16, 2024
@alexcrichton Of course, same example, but with different branch: https://github.com/StackOverflowExcept1on/wasm-builder-regression/tree/wasm32v1-none
git clone https://github.com/StackOverflowExcept1on/wasm-builder-regression.git --branch wasm32v1-none cd wasm-builder-regression/wasm-project ./check.shalexcrichton commentedon Dec 16, 2024
Oh, that's still the same bug at llvm/llvm-project#109443, which still hasn't been fixed.
StackOverflowExcept1on commentedon Mar 5, 2025
@alexcrichton I can confirm that this problem is solved at least in nightly Rust
StackOverflowExcept1on commentedon Mar 5, 2025
nightly-2025-02-18fixed my problem! It's most likely related to #135763