Skip to content

Conversation

StackOverflowExcept1on
Copy link
Contributor

@StackOverflowExcept1on StackOverflowExcept1on commented Aug 17, 2025

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 17, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

// 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",
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@bjorn3 bjorn3 Aug 17, 2025

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.

Copy link
Contributor Author

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).

Copy link
Member

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.

Copy link
Contributor Author

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).

Copy link
Contributor Author

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.

Copy link
Member

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) {
, at which point wasm32v1-none should behave correctly too without having to change the target spec afaik.

Copy link
Contributor Author

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?

Copy link
Member

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),
Actually maybe getting the target features right would be non-trivial as that isn't plumbed through yet and not used for gcc either. So maybe only set the target cpu in linker.rs and just add a FIXME for the target features (and if you do need to set the target features just do it in the target spec)

@alexcrichton
Copy link
Member

r? @bjorn3

I think you may understand the intricacies here better than I

@rustbot rustbot assigned bjorn3 and unassigned alexcrichton Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wasm32v1-none still creates incorrect object files
4 participants