-
Notifications
You must be signed in to change notification settings - Fork 13.7k
fix(compiler/rustc_target): set correct linker flags for wasm32v1-none
#145539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(compiler/rustc_target): set correct linker flags for wasm32v1-none
#145539
Conversation
These commits modify compiler targets. |
// were made to WebAssembly starting with LLVM 20.1.0: | ||
// https://releases.llvm.org/20.1.0/docs/ReleaseNotes.html#changes-to-the-webassembly-backend | ||
"--features=+mutable-globals", | ||
"--no-check-features", | ||
"--mllvm=-mcpu=mvp", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it at the place I indicated (the WasmLd implementation) has the advantage that it works for all wasm targets and also when the user passes -Ctarget-cpu
to override the target default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's probably good idea, but we need WasmTM->CPU
to be set from the command line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm-ld can't notice any difference between setting this cli arg in the target spec and setting it in the WasmLd implementation I linked to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right. I checked in the debugger and it's also worth adding --mllvm=-mattr=+mutable-globals
to change WasmTM->TargetFS
(features set).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't put the --mllvm=-mcpu=...
in compiler/rustc_codegen_ssa/src/back/linker.rs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you show demo code with RUSTC_LOG=debug where -C target-feature won't work? It seemed ok to me. The only problem is that with an empty file in the target_features section the features enabled by the user won't be displayed (since .bc files don't save features).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you mean something like -C target-features=-mutable-globals
and -C target-cpu=generic
, but I don't understand why user would want to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For wasm32v1-none it is maybe not all that relevant given that you probably don't want to enable any extra features, but for wasm32-unknown-unknown or wasm32-wasip1/2 if I use for example -Clinker-plugin-lto -Ctarget-features=+simd128
I would expect all functions to be compiled with simd128 enabled (including standard library functions) even if the leaf crate is empty (and thus nothing otherwise forces simd128 to be enabled). Supporting this requires passing --mllvm=-mcpu=
and --mllvm=-mattr=
in
fn push_linker_plugin_lto_args(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, you are suggesting to explicitly pass cpu and features to wasm-ld in push_linker_plugin_lto_args
depending on what the user is using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with a fallback to whatever target cpu and features is in the target spec. This is also what we do for gcc for example:
&format!("-plugin-opt=mcpu={}", self.target_cpu), |
r? @bjorn3 I think you may understand the intricacies here better than I |
Resolves #145491
r? @alexcrichton
https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/lld/wasm/Writer.cpp#L573-L691
https://releases.llvm.org/20.1.0/docs/ReleaseNotes.html#changes-to-the-webassembly-backend