crypto: disable ASan instrumentation of SSE4 SHA256 for GCC
What changed, and why it matters
This is a build-compatibility fix, not a security vulnerability in normal Bitcoin operation. It stops a specific compiler sanitizer (GCC's AddressSanitizer, used only in debug/test builds) from crashing when running SHA-256 self-tests on older CPUs that lack SHA-NI hardware support. The change does not affect production releases or how Bitcoin validates transactions.
No urgent action needed. Treat as a normal build/test fix. Ensure CI debug builds with GCC ASan on non-SHA-NI hardware or emulators pass SHA256 self-tests after applying the patch.
Security signals we found
Compiler sanitizer incompatibility with inline assembly
SIGSEGV during cryptographic self-test under debug build configuration
Conditional CPU code path (SSE4 vs SHA-NI) involved in failure
No change to cryptographic algorithm or runtime validation logic
Evidence from the diff
The commit moves and broadens an existing attribute((no_sanitize(“address”))) annotation on sha256_sse4::Transform so it also applies to GCC, not just Clang. Without the attribute, GCC’s ASan-instrumented inline assembly in this file causes a SIGSEGV during SHA256AutoDetect()’s self-test on the SSE4 code path. The fix restructures preprocessor checks to use SANITIZE_ADDRESS for GCC and __has_feature(address_sanitizer) for Clang, and places the attribute at the start of the function definition because GCC does not support it between the declarator and the opening brace.
Changed components
src/crypto/sha256_sse4.cppGCC + AddressSanitizer debug buildsSHA256AutoDetect() SSE4 self-test pathInspect captured patch +14 / −9
diff --git a/src/crypto/sha256_sse4.cpp b/src/crypto/sha256_sse4.cpp
index 2d37d124..4464ec92 100644
--- a/src/crypto/sha256_sse4.cpp
+++ b/src/crypto/sha256_sse4.cpp
@@ -12,18 +12,23 @@
namespace sha256_sse4
{
-void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks)
-#if defined(__clang__)
- /*
- clang is unable to compile this with -O0 and -fsanitize=address.
- See upstream bug: https://github.com/llvm/llvm-project/issues/92182.
- This also fails to compile with -O2, -fcf-protection & -fsanitize=address.
- See https://github.com/bitcoin/bitcoin/issues/31913.
- */
-#if __has_feature(address_sanitizer)
+/*
+Both Clang and GCC fail with ASan on this inline assembly:
+- Clang: compile failure with -O0 or -O2 + -fcf-protection under ASan.
+ See https://github.com/llvm/llvm-project/issues/92182
+ and https://github.com/bitcoin/bitcoin/issues/31913.
+- GCC: runtime SEGV during SHA256AutoDetect()'s self-test under ASan,
+ regardless of optimization level.
+ See https://github.com/bitcoin/bitcoin/issues/34881.
+*/
+#if defined(__SANITIZE_ADDRESS__)
+ __attribute__((no_sanitize("address")))
+#elif defined(__clang__)
+#if __has_feature(address_sanitizer) // fallback can be removed once support for Clang 21 is dropped
__attribute__((no_sanitize("address")))
#endif
#endif
+void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks)
{
static const uint32_t K256 alignas(16) [] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.