Skip to content

fix(compiler/rustc_codegen_llvm): apply target-cpu attribute #145275

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

Merged
merged 2 commits into from
Aug 15, 2025

Conversation

StackOverflowExcept1on
Copy link
Contributor

@StackOverflowExcept1on StackOverflowExcept1on commented Aug 11, 2025

Resolves #140174

r? @alexcrichton

try-job: test-various*

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 11, 2025
let mut attrs = SmallVec::<[_; 2]>::new();

let target_cpu = llvm_util::target_cpu(tcx.sess);
let target_cpu_attr = llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the method onto SimpleCx, it doesn't appear to use anything FullCx related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with the code base. What is the recommended way to do this? There is MiscCodegenMethods, but it probably has more methods.

@rust-log-analyzer

This comment has been minimized.

@alexcrichton
Copy link
Member

Would it be possible to add a test for this? Either a codegen test or something in tests/run-make/wasm-* might suffice. It'd be nice to have a full application validated with wasmparser, for example, where all features were disabled except for a minimal set.

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 12, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

The run-make-support library was changed

cc @jieyouxu

@StackOverflowExcept1on
Copy link
Contributor Author

@alexcrichton done

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-tidy Area: The tidy tool label Aug 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 12, 2025

The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging.

cc @davidtwco, @wesleywiser

@rust-log-analyzer

This comment has been minimized.

@@ -0,0 +1,25 @@
//@ only-wasm32v1-none
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I'm realizing now, does this actually run anywhere in CI? I don't believe tests are run for this target)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I ran the tests and looked at the output via wasm-dis | less

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since wasm32v1-none is a Tier2 target, it should probably be tested before publishing binaries: https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-2-without-host-tools.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to rephrase this test in terms of minicore in the test suite? I'm not sure if that's integrated into the run-make test suite though. In any case the main value from a test like this will be preventing regressions, but if it's not run on CI then it won't prevent regressions. If it's not run on CI I don't think it's worth adding a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what if we do the same test, but for wasm32-unknown-unknown target? This test will use -Z build-std and -C target-feature, and it will also need the rust-src component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately AFAIK -Zbuild-std is a known pain point in tests right now as it can take an excessively long amount of time to build and requires a lot of dependencies. I've seen comments in the past about how -Zbuild-std should be avoided in tests.

I don't see existing integration with minicore in run-make tests right now unfortunately. There is one test referencing it but the test's FIXME has not yet been updated.

Instead of using -Zbuild-std could this build tests/auxiliary/minicore.rs directly perhaps? I'll also cc @jieyouxu as you might know better how best to integrate minicore bits here than I

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I basically understand what you want. You want to use minicore instead of compiling core with the required features. But what should I do with alloc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will also need to somehow link any symbol marked as #[rustc_std_internal_symbol] with #![no_core]...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 13, 2025
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 13, 2025
@StackOverflowExcept1on
Copy link
Contributor Author

The PR is mostly ready, but I would like someone to run test-various on this PR. That way we can see if the test passes on wasm32-wasip1.

@Zalathar
Copy link
Contributor

@bors try jobs=test-various

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 14, 2025
…try>

fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute

try-job: test-various
@rust-bors
Copy link

rust-bors bot commented Aug 14, 2025

☀️ Try build successful (CI)
Build commit: 1cd152f (1cd152f07820ea259d1dbeb28855e8e059dc02e3, parent: 2c1ac85679678dfe5cce7ea8037735b0349ceaf3)

@StackOverflowExcept1on
Copy link
Contributor Author

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Aug 14, 2025

📌 Commit 3a250b7 has been approved by alexcrichton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 15, 2025
…1-none, r=alexcrichton

fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute

Resolves rust-lang#140174

r? `@alexcrichton`

try-job: `test-various*`
bors added a commit that referenced this pull request Aug 15, 2025
Rollup of 22 pull requests

Successful merges:

 - #118087 (Add Ref/RefMut try_map method)
 - #122661 (Change the desugaring of `assert!` for better error output)
 - #140740 (Add `-Zindirect-branch-cs-prefix`)
 - #142640 (Implement autodiff using intrinsics)
 - #143075 (compiler: Allow `extern "interrupt" fn() -> !`)
 - #144865 (Fix tail calls to `#[track_caller]` functions)
 - #144944 (E0793: Clarify that it applies to unions as well)
 - #144947 (Fix description of unsigned `checked_exact_div`)
 - #145004 (Couple of minor cleanups)
 - #145005 (strip prefix of temporary file names when it exceeds filesystem name length limit)
 - #145012 (Tail call diagnostics to include lifetime info)
 - #145065 (resolve: Introduce `RibKind::Block`)
 - #145120 (llvm: Accept new LLVM lifetime format)
 - #145189 (Weekly `cargo update`)
 - #145235 (Minor `[const]` tweaks)
 - #145275 (fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute)
 - #145322 (Resolve the prelude import in `build_reduced_graph`)
 - #145331 (Make std use the edition 2024 prelude)
 - #145369 (Do not ICE on private type in field of unresolved struct)
 - #145378 (Add `FnContext` in parser for diagnostic)
 - #145389 ([rustdoc] Revert "rustdoc search: prefer stable items in search results")
 - #145392 (coverage: Remove intermediate data structures from mapping creation)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 15, 2025
…1-none, r=alexcrichton

fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute

Resolves rust-lang#140174

r? ``@alexcrichton``

try-job: `test-various*`
bors added a commit that referenced this pull request Aug 15, 2025
Rollup of 21 pull requests

Successful merges:

 - #118087 (Add Ref/RefMut try_map method)
 - #122661 (Change the desugaring of `assert!` for better error output)
 - #142640 (Implement autodiff using intrinsics)
 - #143075 (compiler: Allow `extern "interrupt" fn() -> !`)
 - #144865 (Fix tail calls to `#[track_caller]` functions)
 - #144944 (E0793: Clarify that it applies to unions as well)
 - #144947 (Fix description of unsigned `checked_exact_div`)
 - #145004 (Couple of minor cleanups)
 - #145005 (strip prefix of temporary file names when it exceeds filesystem name length limit)
 - #145012 (Tail call diagnostics to include lifetime info)
 - #145065 (resolve: Introduce `RibKind::Block`)
 - #145120 (llvm: Accept new LLVM lifetime format)
 - #145189 (Weekly `cargo update`)
 - #145235 (Minor `[const]` tweaks)
 - #145275 (fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute)
 - #145322 (Resolve the prelude import in `build_reduced_graph`)
 - #145331 (Make std use the edition 2024 prelude)
 - #145369 (Do not ICE on private type in field of unresolved struct)
 - #145378 (Add `FnContext` in parser for diagnostic)
 - #145389 ([rustdoc] Revert "rustdoc search: prefer stable items in search results")
 - #145392 (coverage: Remove intermediate data structures from mapping creation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 201e632 into rust-lang:master Aug 15, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 15, 2025
rust-timer added a commit that referenced this pull request Aug 15, 2025
Rollup merge of #145275 - StackOverflowExcept1on:fix-wasm32v1-none, r=alexcrichton

fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute

Resolves #140174

r? ```@alexcrichton```

try-job: `test-various*`
@StackOverflowExcept1on StackOverflowExcept1on deleted the fix-wasm32v1-none branch August 15, 2025 12:42
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 15, 2025
…alexcrichton

fix(tests/rmake/wasm-unexpected-features): change features from `WASM1` to `MVP`

missed this in rust-lang#145275
since test calls `rustc` with  `-C target-cpu mvp`
try-job: `test-various`
rust-timer added a commit that referenced this pull request Aug 16, 2025
Rollup merge of #145436 - StackOverflowExcept1on:patch-1, r=alexcrichton

fix(tests/rmake/wasm-unexpected-features): change features from `WASM1` to `MVP`

missed this in #145275
since test calls `rustc` with  `-C target-cpu mvp`
try-job: `test-various`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

Many new wasm features are enabled if compile wasm32v1-none with -C linker-plugin-lto flag on LLVM 20+
8 participants