Conversation
Previously, `+fix-cortex-a53-835769` was statically included in `base.features` for `aarch64-unknown-fuchsia`. This caused the Cortex-A53 erratum workaround to be unconditionally enabled regardless of the selected target CPU (e.g., when passing `-C target-cpu=cortex-a73`). The behavior we want is to have it enabled by default only for the generic CPU (armv8-a), and it should be togglable via the normal `-Ctarget-features=` flag. This matches the target-feature logic in clang. AI: Note gemini was used to help verify this does match Clang's behavior and write out the matrix of different test invocations. I reviewed this code to the best of my ability before submitting.
|
These commits modify compiler targets. |
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? @RalfJung afaik you've been reworking the target feature system, not sure how this fits into that |
|
|
| "generic" | "cortex-a53" | ||
| ) | ||
| { | ||
| extend_backend_features("fix-cortex-a53-835769", true); |
There was a problem hiding this comment.
This hack (wtf is even going on there) looks LLVM-specific but the file you put it in is also used for other backends.
There was a problem hiding this comment.
Above this is what looks like another instance of something target/LLVM-specific that was added here so I assumed the existing precedent was that it was ok to include such things here.
For that you have to make it a Rust target feature, i.e., add it in I can give general advice for target feature but cannot review whatever insanity this weird hack is. I just wonder if this is really the best way to deal with whatever problem this solves. @rustbot reroll |
Yes, |
|
Actually, I mixed things up. features in the target spec can be overwritten by |
|
TBH IMO this would be best handled by LLVM. LLVM can realize that the selected target CPU does not need whatever that "fix" thing is any more, and then stop applying it. Asking frontends to do this means that it requires hacks in a whole bunch of places as it does not follow the usual structure of a target feature. Cc @nikic |
|
Also not at all familiar with this code |
|
@rustbot reroll |
|
@rustbot reroll |
|
☔ The latest upstream changes (presumably #161432) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
This particular target feature is only relevant to this CPU since later arm CPUs have a hardware fix for it so it's worthwhile conditioning the target feature on the CPU.
There is an ongoing effort to move all the target-specific stuff handled by drivers into the TargetParser but that migration isn't complete and there's still a bunch of stuff missing before it could be used by other frontends. After that, we'd also need to teach rust to use it which might take some time. |
I understand. So why does LLVM not do that? It's natural do to it there. It's a pretty bad hack and a maintenance hassle to do it in rustc (and every other frontend). The target feature we are asking for is "please make sure this hardware bug doesn't affect the code". Newer hardware implements that feature for free so it should be a NOP if LLVM knows that the hardware is new enough. I think this doesn't need any moving around of anything in LLVM, just a slightly smarter logic for what that target feature actually does: only apply the fix if the feature is enabled and the selected CPU actually needs the fix. |
This strikes me as the correct approach here - is there a reason that LLVM couldn't do this? |
Previously,
+fix-cortex-a53-835769was statically included inbase.featuresforaarch64-unknown-fuchsia. This caused the Cortex-A53 erratum workaround to be unconditionally enabled regardless of the selected target CPU (e.g., when passing-C target-cpu=cortex-a73).The behavior we want is to have it enabled by default only for the generic CPU (armv8-a), and it should be togglable via the normal
-Ctarget-features=flag. This matches the target-feature logic in clang.AI: Note gemini was used to help verify this does match Clang's behavior and write out the matrix of different test invocations. I reviewed this code to the best of my ability before submitting.