Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_target/src/spec/targets/wasm32v1_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub(crate) fn target() -> Target {
// For now this target just never has an entry symbol no matter the output
// type, so unconditionally pass this.
"--no-entry",
// It is also necessary to explicitly set CPU and features since some changes
// 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
"--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).

"--mllvm=-mattr=+mutable-globals",
],
);
options.add_pre_link_args(
Expand All @@ -37,7 +42,7 @@ pub(crate) fn target() -> Target {
// Make sure clang uses LLD as its linker and is configured appropriately
// otherwise
"--target=wasm32-unknown-unknown",
"-Wl,--no-entry",
"-Wl,--no-entry,--mllvm=-mcpu=mvp,--mllvm=-mattr=+mutable-globals",
],
);

Expand Down
Loading