Description
Building with RUSTFLAGS="-C target_cpu=cortex-a72"
statically enables the target_feature="aes"
, target_feature="crc"
, target_feature="pmuv3"
, and target_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 with RUSTLFAGS=-target-cpu=native
. From briansmith/ring#1858 (comment):
$ rustc --print cfg --target=aarch64-unknown-linux-gnu -C target_cpu=cortex-a72 | grep feature target_feature="aes" target_feature="crc" target_feature="neon" target_feature="pmuv3" target_feature="sha2"
Without
-C target_cpu=cortex-a72
we get the correct feature flags:$ rustc --print cfg --target=aarch64-unknown-linux-gnu | grep feature target_feature="neon"
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).