Skip to content

hash: MSVC ARM64's C4324 off for the hasher, and the canaries declared constinit - #12

Merged
pinhopro merged 2 commits into
mainfrom
fix/msvc-arm64-c4324-constinit
Nov 23, 2026
Merged

pinhopro merged 2 commits into
mainfrom
fix/msvc-arm64-c4324-constinit

Conversation

@pinhopro

Copy link
Copy Markdown
Contributor

Two small fixes of webcpp::hash.

  • digest.hpp: the hasher turns MSVC's C4324 off for itself (push/pop around the class template). libsodium's states are CRYPTO_ALIGN(16) or CRYPTO_ALIGN(64), so hasher<Digest, backends::sodium> is padded after its last member to that alignment, which no member order avoids. MSVC for ARM64 reports that trailing padding under /W4 (an error under /WX) and stopped 14 tests (xof_sodium, digests_sodium, blake2b_sodium, capabilities, capabilities_botan, agreement_families, agreement_families_botan, allocation, and their no-exceptions twins). MSVC for x64 reports only padding before an aligned member, never after the last one: a probe on the Windows VM gave both architectures the same layouts (448 bytes, alignment 64) and warned on ARM64 alone, on 14.3 and 14.5.
  • The backends' canaries (BLAKE3, Botan, BearSSL, libsodium, XKCP) are declared constinit, which clang-tidy's bugprone-dynamic-static-initializers reads, in place of four NOLINT suppressions, as webcpp::crypto's canaries are (crypto 46a0df6); src/canary_botan.cpp, the one C++ definition, repeats constinit.

Verified locally: native clang, gcc and Emscripten lanes (b2 -a libs/hash/test libs/hash/example), MSVC 14.3 and 14.5 on ARM64 (msvc-lane, with hash's and crypto's tests), the Linux lint (full) and the macOS lint.

R added 2 commits November 23, 2026 06:24
…g padding an aligned backend state needs is its intended layout

libsodium's states are CRYPTO_ALIGN(16) or CRYPTO_ALIGN(64), so hasher<Digest, backends::sodium>
is padded after its last member to that alignment, and no order of the members avoids it. MSVC
for ARM64 reports that trailing padding as C4324 under /W4, which /WX makes an error, and stopped
14 tests (xof_sodium, digests_sodium, blake2b_sodium, capabilities, capabilities_botan,
agreement_families, agreement_families_botan, allocation and their no-exceptions twins). MSVC for
x64 reports only padding before an aligned member, never after the last one: a probe on the
Windows VM, 14.3 and 14.5, gave both architectures the same layouts (448 bytes, alignment 64)
and warned on ARM64 alone. The push and pop around the class template silence its
instantiations and nothing else.
…ynamic-static-initializers reads, in place of four suppressions

Each canary's declaration (BLAKE3, Botan, BearSSL, libsodium, and XKCP's, which carried no
suppression) is a namespace-scope variable without an initialiser, which the check reports in a
header as one that may be dynamically initialised. Its definition is a constant, so its
initialisation is static; constinit on the declaration states it, as webcpp::crypto's canaries
do (crypto 46a0df6). src/canary_botan.cpp, the one definition in C++, repeats constinit on its
initialising declaration, as the standard asks.
@pinhopro
pinhopro merged commit eed3aab into main Nov 23, 2026
1 of 3 checks passed
@pinhopro
pinhopro deleted the fix/msvc-arm64-c4324-constinit branch November 23, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant