Skip to content
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

Fix printing native CPU on cross-compiled compiler. #110668

Merged
merged 1 commit into from
Apr 24, 2023

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Apr 22, 2023

If rustc is cross-compiled from a different host, then the "native" entry in rustc --print=target-cpus would not appear. There is a check in the printing code that will avoid printing the "native" entry if the user has passed --target. However, that check was comparing the --target value with the LLVM_TARGET_TRIPLE which is the triple of the host that rustc was built on (the "build" target in Rust lingo), not the target it was being built for (the "host" in Rust lingo). This fixes it to use the target that LLVM was built for (which I'm pretty sure this is the correct function to determine that).

This fixes the cpu listing for aarch64-apple-darwin which is built on CI using the x86_64-apple-darwin host.

@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2023

r? @cuviper

(rustbot has picked a reviewer for you, use r? to override)

@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 Apr 22, 2023
@cuviper
Copy link
Member

cuviper commented Apr 22, 2023

That's amusing, e.g. from an aarch64-linux host I can get this mismatch:

$ rustc --print target-cpus --target x86_64-unknown-linux-gnu
Available CPUs for this target:
    native         - Select the CPU of the current host (currently neoverse-v1).

... because the toolchain was built in Rust CI on x86_64, so it thinks native is a match and reports the aarch64 CPU.

It seems this is an LLVM bug:
https://github.com/llvm/llvm-project/blob/745221268125e86b1543a7aa643414e9cc8cb2d2/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp#L26-L27

  // FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on,
  //        rather than a valid triple for the current process.

I think the default target is not necessarily the runtime host either, if you had an LLVM configured as a cross-compiler by default, but it's probably more often correct.

@ehuss ehuss force-pushed the fix-native-cpu-list branch from 7629401 to e4e4110 Compare April 23, 2023 16:36
@cuviper
Copy link
Member

cuviper commented Apr 23, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 23, 2023

📌 Commit e4e4110 has been approved by cuviper

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 Apr 23, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 24, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#110661 (rustdoc: clean up settings.css and settings.js)
 - rust-lang#110663 (Add note about change in bootstrap defaults)
 - rust-lang#110664 (stop `x fmt` formatting untracked directories)
 - rust-lang#110668 (Fix printing native CPU on cross-compiled compiler.)
 - rust-lang#110689 (Fix grammar in core::hint::unreachable_unchecked() docs)
 - rust-lang#110700 (Don't infer fn return type to return itself)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 12a539f into rust-lang:master Apr 24, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

4 participants