-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Add the cpuid target feature
#146560
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
Add the cpuid target feature
#146560
Conversation
|
Some changes occurred in compiler/rustc_codegen_gcc
cc @Amanieu, @folkertdev, @sayantn |
This comment has been minimized.
This comment has been minimized.
8282246 to
d1b9074
Compare
d1b9074 to
5372c28
Compare
This comment has been minimized.
This comment has been minimized.
5372c28 to
38e000a
Compare
This comment has been minimized.
This comment has been minimized.
|
This PR adds a new Since CPUID support is implicitly enabled on most of our x86 targets, this effectively makes the CPUID intrinsic safe to call even before the @rfcbot merge |
|
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
cc @RalfJung |
|
I am a bit surprised to see this exposed as a target feature. The tracking issue says
However, even very old CPUs will have x87, right? So it seems like this will be enabled there? Is the CPUID instruction actually unsafe in those situations? If it reliably segfaults, it would not be unsafe (as long as the inline asm block doesn't claim it will always return). |
The Intel reference says that
so yes, it will reliably abort the program. This could result in problems though if LLVM decides to add a On SGX, |
38e000a to
22b4712
Compare
This comment has been minimized.
This comment has been minimized.
Right, exactly. If we had a target that ran on i386 or i486, then it should do CPUID detection. But if you're on i586 or i686, CPUID is always supported, by definition of the target. |
|
@rfcbot reviewed |
1 similar comment
|
@rfcbot reviewed |
|
Being explicit: not raising any blocking objection to the strategy of using target features to make cpuid safe, but I think it's a mistake to not just have cpuid safe everywhere it's available, and make it entirely unavailable on a hypothetical i386/i486 target. I don't think |
|
I feel very strongly that "should not be used" or "gives untrusted result" is not a reason to make it (Exactly what to do here I don't know that I have an opinion yet.) I'll also add that old x86 has a bunch of semantic problems too, like broken floating point, so anything pre-sse is already not "really" a tier 1 target -- maybe not even really a tier 2 one since lots of things just don't work reliably. |
|
We talked about this again in today's @rust-lang/lang meeting. Reiterating that this is not blocking, and if others want to do this with target features, so be it. I don't plan to check a box but I don't intend to raise a concern. That said, counterproposal: rather than a target feature, can we transition to |
|
To address the counterproposal of making |
|
It sounds good to me. In the lang call today, our general vibe was indeed not positive on the proposal in this PR, and as it stands, I estimate this proposed FCP will struggle. |
|
I have opened rust-lang/stdarch#1935 to make cpuid safe without any target features, let's rfc on that |
An i486 target can check if the ID bit in the EFLAGS register can be toggled and use that to feature-detect cpuid support. Ah yes, core_arch already implements has_cpuid |
it did, but then it was removed. I can't remember the rationale exactly. The link seems pretty old, it was removed like an year ago. |
|
☔ The latest upstream changes (presumably #148356) made this pull request unmergeable. Please resolve the merge conflicts. |
- Make `cpuid` and friends safe with `#[target_feature(enable = "cpuid")]` - Update documentation
22b4712 to
b5f8e73
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
☔ The latest upstream changes (presumably #147645) made this pull request unmergeable. Please resolve the merge conflicts. |
|
As the fcp on rust-lang/stdarch#1935 has completed, I am closing this |
|
I just want to clarify that contrary to some of the claims earlier in this thread, SGX doesn't support CPUID, calling the instruction results in an #UD exception. |
Tracking issue: #146558
r? @Amanieu
@rustbot label O-x86_32 O-x86_64 A-target-feature T-compiler T-libs-api