Closed
Description
I tried to build a wasm binary with MVP opcode only, so I disabled the features:
RUSTFLAGS='-C link-arg=-zstack-size=32768 -C target-feature=-mutable-globals,-sign-ext,-multivalue,-simd128'
cargo build --release --target=wasm32-unknown-unknown
I expected to see no sign-extension opcode in the wasm binary.
Instead, this happened:
$ wasm-tools parse -t target/wasm32-unknown-unknown/release/output.wasm -o hello.wat
$ cat hello.wat | grep i32.ext
i32.extend8_s
Meta
rustc --version --verbose
:
rustc 1.70.0-nightly (ec2f40c6b 2023-03-30)
binary: rustc
commit-hash: ec2f40c6b04f0e9850dd1f454e8639d319f4ed9b
commit-date: 2023-03-30
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 16.0.0
Backtrace
<backtrace>
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationArea: Enabling/disabling target features like AVX, Neon, etc.Category: This is a bug.Target: WASM (WebAssembly), http://webassembly.org/Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
CryZe commentedon Apr 1, 2023
You can not deactivate default features, because std is prebuilt. You need
-Z build-std
to build std yourself. Also these features are considered the default by LLVM ever since the recent upgrade to LLVM 16:https://github.com/llvm/llvm-project/blob/f991f30845bb464a1a8e240b3512bac0258417db/llvm/lib/Target/WebAssembly/WebAssembly.td#L99-L106
This should possibly be mentioned in the Rust 1.70 release notes though?
nikic commentedon Apr 1, 2023
cc @alexcrichton to confirm that we're fine with inheriting this change to default target features in Rust.
alexcrichton commentedon Apr 1, 2023
More context for this change can be found in these locations:
In that sense this is an expected change, but at the same time the change was made with the expectation that most users are running on an engine that implements sign-extension. @laizy could you expand a bit more on your motivation for excluding these sign-extension instructions?
I do agree, though, that this should be mentioned in the detailed release notes. It's unfortunately a bit opaque since not all users of wasm are intimately familiar with proposals and whether or not engines support them, but it's a change nonetheless worth mentioning.
laizy commentedon Apr 3, 2023
I have tried to use
-Z build-std=core, alloc
, still not work:RUSTFLAGS="-C link-arg=-zstack-size=32768 -C target-feature=-mutable-globals,-sign-ext,-multivalue,-simd128" cargo build -Z build-std=core,alloc --release --target=wasm32-unknown-unknown
@alexcrichton Our blockchain platform has used Wasm as a virtual machine running smart contracts and has been running steadily for many years. The MVP opcodes is fully sufficient for our use case. I hope there are ways to turn off these default extension features to avoid frequent upgrades every time a new feature is introduced.
alexcrichton commentedon Apr 5, 2023
Could you share the code used to reproduce this?
These upgrades will not be frequent. This is the first time it's changed in 5 years.
shanemadden commentedon Apr 15, 2023
The use case I have for wanting to build without these extensions isn't critical (servers for a game which don't support the extensions in the old version of nodejs they're running), but a way to successfully disable them to be able to build for such environments would be appreciated!
alexcrichton commentedon Apr 15, 2023
It would be helpful to have a reproduction of this to run to test out fixes. I tested something locally and
-Ctarget-cpu=mvp
was sufficient to disable sign extension instructions. I don't know why-C target-feature=-sign-ext
isn't working and that may be an LLVM bug. I can't confirm whether this works for others though without a means of reproduction.CryZe commentedon Apr 15, 2023
I just tried the following:
compiled with:
RUSTFLAGS="-C target-feature=-sign-ext" cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
to make sure std being precompiled isn't causing problems, and it totally still contains the sign-ext instructions:
So you are right, this is some sort of LLVM bug.
shanemadden commentedon Apr 16, 2023
Confirming that
-Ctarget-cpu=mvp
results in a file without the sign-ext opcodes, while-Ctarget-feature=-sign-ext
does not, in my testing as well.alexcrichton commentedon Apr 16, 2023
@sunfishcode would you perhaps know more about this behavior? I would expect that with
-sign-ext
on the function then even without-mcpu=mvp
sign-extension instructions wouldn't get generated, but I'm not sure.49 remaining items