-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
-C target_cpu=cortex-a72
(and -target-cpu=native
on Raspberry Pi) wrongly enables crypto features that are optional on Cortex-A72
#125033
Comments
WG-prioritization assigning priority (Zulip discussion). Since in our support list this arch has the most support: @rustbot label -I-prioritize +P-critical |
From today's comment in the upstream LLVM issue:
Assuming that is accurate, there are a few interesting things:
|
Also, from the LLVM issue:
So, one workaround would be to use that. But, I don't see rustc providing a mechanism to choose the ARM architecture level instead of a specific CPU. |
@rustbot label -P-critical +P-high We aren't going to block the next stable release because of this issue so tagging this as P-high instead. |
Mmh. If I run the Rust compiler with I do not believe it is realistic for rustc to "correct" LLVM on the very long list of AArch64 CPUs, so it would be best to fix this upstream. |
If you do |
Even worse, if you compile on a Pi4 with |
If you build a binary with |
That's a different situation, because you're building for a CPU with more capabilities than what you're running on. In the case of |
Understandable. However, I think it is worth making an exception for this particular case:
|
No, it is not. When you build code for the P6, you get code for a P68, a CPU model that was revised and upgraded from the P6. When you build code for the Cortex-A72, you get code for a revised and upgraded Cortex-A72 model.
I assure you, there will be other SBCs that people will say are very popular and demand that we fix this sort of thing for them.
LLVM has been willing to break compatibility with target features. I don't see why why we would believe their target CPUs are any more stable. |
I mean, it's not exactly the same thing. P6 and P68 are architectures. It covers CPU designs that have been released over the course of, what, 10 years?
Meanwhile, the Cortex-A72 is a CPU design. ARM doesn't produce any, and licensees are free to implement optional features, at their discretion. And note that it's a single design. And we can talk about whether the Cortex-A72 definition should include various options or not all we want, but the fact that
If we stick to using only the required, by design, features of a given CPU design, then we won't have more demands. |
Splendid! Then if that is all we need to do, would you care to PR your alternative database of CPU features for aarch64 CPU models to rustc, since LLVM's cannot be relied on and they apparently are not interested in changing that? |
It seems like the key problem here is that |
@nikic Hm. Shouldn't that be done for the Windows cases as well? Indeed, all of the cases like that, with a static name? if (condition)
Feature["name"] = true |
Hm, I suppose there's only one in that file outside the AArch64 set. |
heads up crabs, llvm/llvm-project#95694 got merged, I'll let y'all figure out how to backport that or what. |
This isn't fixed upstream though? Maybe the |
The |
@briansmith It's a separate issue because it applies to almost every single |
Building with
RUSTFLAGS="-C target_cpu=cortex-a72"
statically enables thetarget_feature="aes"
,target_feature="crc"
,target_feature="pmuv3"
, andtarget_feature="sha2"
. However, at least the crypto features AES, CRC, and SHA2 are optional on this CPU. The definition for this target is wrong. See the upstream LLVM bug: llvm/llvm-project#90365.The main consequence is that crypto libraries that use
cfg(target_feature = ...)
feature detection for these hardware instructions are getting miscompiled, causing the programs to, at best, crash with an illegal instruction exception. This particular affects Raspberry Pi users compiling withRUSTLFAGS=-target-cpu=native
. From briansmith/ring#1858 (comment):I verified this is an issue on Rust 1.61 stable, 1.78 stable, and rustc 1.80.0-nightly (6e1d947 2024-05-10).
Although some crypto libraries may work around this issue, these workarounds have negative consequences. In the case of ring's workaround, the result of the workaround is bloat and worse performance on all AArch64 CPUs that actually are guaranteed to have the crypto extensions (except on Fuchsia, Windows, and macOS).
The text was updated successfully, but these errors were encountered: