ARMv8 feature detection broken, leading to illegal instruction crashes
The detection of ARMv8 (AArch64) features in SIMDExt.cmake is broken, incorrectly detecting features as available when the CPU does not support them. This is because the source snippets with inline assembly used for HAVE_ARMV8_CRC and HAVE_ARMV8_CRYPTO compile fine even without the features on the CPU, but the resulting programs then crash. A half-fix would be to replace check_cxx_source_compiles with check_cxx_source_runs.
However, checking for feature availability based on the ability to compile and run inline ASM will not work well, since it entirely ignores the compiler's march settings as to which features are available. For example, on my system I compile with march=armv8-a, that is without +crypto necessary for pmull instructions, yet the crypto snippet in SIMDExt.cmake compiles just fine. The resulting binary crashes on my system however, since I do not have the crypto extension (RPi 3).
So: the current ARM feature checks are broken, but even the simple fix won't improve the situation that the resulting code may not run on the target system specified by march/mcpu/mtune.
#1 Updated by Robin McCorkell 9 months ago
After a little more testing, I have found the problem is caused by the `asm(".arch_extension ...");` directives in the tests in SIMDExt.cmake, which unconditionally enable the selected extension for the architecture. Since we want to detect the architecture features, these directives break the tests.
Removing these directives from the tests causes test compilation to fail if march doesn't list the needed feature, which is the expected behaviour.
GitHub PR incoming