Bugfix: Build fails to enable ARM CPU crypto extensions#309
Conversation
When building on an ARM64 CPU with the crypto extensions, the build process fails to enable the custom assembler version. It instead uses the software version. This patch relates to this issue: bitcoinknots#308 Example build command: cmake -B build \ -DENABLE_WALLET=OFF \ -DWITH_ZMQ=ON \ -DENABLE_TOR_SUBPROCESS=OFF \ -D RDTS_CONSENT=IMPLICIT \ -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g0 -march=native" When you run bitcoind, this appears near the top of the log: 2026-05-31T23:36:14.290939Z Using the 'standard' SHA256 implementation After *MANY* hours, I have finally tracked this down. In this file: ./cmake/introspection.cmake Line 282 has: The GCC target has to be a *feature*, not an architecture. For example, this is valid: You can match an architecture using this syntax: I think matching on the feature is better, because there may be other ARM CPUs with the crypto feature set (in the future) that are not this exact architecture. Also note that if you apply this fix, it still works even without -marchive=native. With the fix applied, you now get this in the log: 2026-06-02T09:42:45Z Using the 'arm_shani(1way;2way)' SHA256 implementation
|
I have tested this code change by mining a block on testnet4. |
There was a problem hiding this comment.
Pull request overview
Fixes ARM64 builds failing to detect/enable the optimized ARM SHA-NI (“crypto extensions”) SHA256 implementation by correcting the GCC #pragma target syntax used during CMake feature introspection.
Changes:
- Update the GCC target pragma in the ARM SHA-NI compile check to use a feature specifier (
"+crypto") rather than an architecture string ("armv8-a+crypto").
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I can confirm this bug and the proposed fix on AWS Graviton4 (c8g.medium, ARM Neoverse V2). Environment
Fix
-#pragma GCC target ("armv8-a+crypto")
+#pragma GCC target ("+crypto")ConfirmationBefore fix (startup log): After fix (startup log): Binary Verification$ objdump -d bitcoind | grep -c 'sha256'
BenchmarksSame machine, same chain data (block 952,280), warm EBS volume. Only the binary was swapped between runs.
Both tests are I/O-mixed workloads (LevelDB reads dominate). The actual SHA256 throughput improvement is much larger — isolated ImpactThis affects all aarch64/ARM64 builds using GCC. Anyone running Knots on Raspberry Pi 4/5, AWS Graviton, Ampere, Apple Silicon (Linux), or any ARM64 platform with crypto extensions is silently falling back to software SHA256. The |
When building on an ARM64 CPU with the crypto extensions, the build process fails to enable the custom assembler version. It instead uses the software version.
This patch relates to this issue:
#308
Example build command:
cmake -B build
-DENABLE_WALLET=OFF
-DWITH_ZMQ=ON
-DENABLE_TOR_SUBPROCESS=OFF
-D RDTS_CONSENT=IMPLICIT
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g0 -march=native"
When you run bitcoind, this appears near the top of the log:
2026-05-31T23:36:14.290939Z Using the 'standard' SHA256 implementation
After MANY hours, I have finally tracked this down. In this file: ./cmake/introspection.cmake
Line 282 has:
#pragma GCC target ("armv8-a+crypto")
The GCC target has to be a feature, not an architecture. For example, this is valid:
#pragma GCC target ("+crypto")
You can match an architecture using this syntax:
#pragma GCC target ("arch=armv8-a+crypto")
I think matching on the feature is better, because there may be other ARM CPUs with the crypto feature set (in the future) that are not this exact architecture.
Also note that if you apply this fix, it still works even without -marchive=native.
With the fix applied, you now get this in the log:
2026-06-02T09:42:45Z Using the 'arm_shani(1way;2way)' SHA256 implementation