Fix arm64 macOS build with Homebrew#1678
Fix arm64 macOS build with Homebrew#1678audriusbuika wants to merge 2 commits intoveracrypt:masterfrom
Conversation
|
Thanks for investigating the Apple Silicon/Homebrew build failure. The local arm64 build issue is real, but I do not think this PR cannot be merged as-is because the On Apple Silicon, The Please scope the plain-object fallback to the local arm64 build only, for example by keying it on |
| ifeq "$(CPU_ARCH)" "arm64" | ||
| # x86-only intrinsics sources are compiled as plain objects on arm64 | ||
| # (their bodies are #ifdef-gated to x86/x64 and become empty translation units) | ||
| OBJS += ../Crypto/blake2s_SSE41.o | ||
| OBJS += ../Crypto/blake2s_SSSE3.o | ||
| OBJS += ../Crypto/Sha2Intel.o | ||
| OBJS += ../Crypto/Argon2/src/opt_avx2.o | ||
| else |
There was a problem hiding this comment.
This condition is too broad. CPU_ARCH=arm64 is also true for the normal non-local macOS build on Apple Silicon, which still produces a universal x86_64 + arm64 binary. In that path this block makes the x86_64 slice compile Argon2/src/opt_avx2.c as plain .o instead of .oavx2, so __AVX2__ is not defined and fill_segment_avx2() becomes the stub that returns ARGON2_INCORRECT_PARAMETER. Please scope this fallback to the local arm64-only case, e.g. LOCAL_DEVELOPMENT_BUILD=true plus CPU_ARCH=arm64, not CPU_ARCH=arm64 alone.
|
|
||
| # On arm64 hosts, x86 feature flags are rejected by clang. | ||
| # Source files are guarded by CRYPTOPP_BOOL_X86/X64 so they produce empty objects on arm64. | ||
| ifeq "$(CPU_ARCH)" "arm64" |
There was a problem hiding this comment.
This has the same scoping issue as the Volume.make change: CPU_ARCH=arm64 is true on Apple Silicon even for the normal non-local macOS build, which still targets a universal x86_64 + arm64 binary.
For that universal path, the x86_64 slice still needs these feature flags. In particular, clearing X86_SHANI_FLAGS makes Sha2Intel.oshani compile without -msha: with Apple clang this fails because _mm_sha256msg1_epu32 requires the sha target feature.
Please either leave these pattern rules unchanged and avoid selecting the x86-specific suffix objects for local arm64-only builds, or gate this flag clearing on the local arm64-only case, e.g. LOCAL_DEVELOPMENT_BUILD=true plus CPU_ARCH=arm64, not CPU_ARCH=arm64 alone.
Problem
On Apple Silicon,
./src/Build/build_veracrypt_macosx.sh -bfails to build:Once the flag issue is worked around, the link step then fails with missing
arm64 symbols:
_aes_encrypt,_aes_hw_cpu_*, and_sha256_compress_digest_armv8.Root Cause
Two separate issues surface together on arm64:
The pattern rules in
src/Build/Include/Makefile.inc(%.oshani,%.osse41,%.ossse3,%.oaesni,%.oavx2) always append x86-onlyflags such as
-mssse3 -msse4.1 -msha. clang rejects those flags whentargeting arm64, even though the source bodies are already guarded by
CRYPTOPP_BOOL_X86/X64and would compile to empty objects.src/Volume/Volume.makehas no arm64 object list for local MacOSXbuilds. The build script sets
COMPILE_ASM=falseon arm64 hosts (yasmcan't assemble x86 asm for an arm64-only build), which leaves the
MacOSX branch empty, and the generic arm64 branch below it is never
reached. As a result, no AES or SHA-256 backend ends up in the link.
Fix
src/Build/Include/Makefile.inc— move the x86 feature flags intovariables that are empty when
CPU_ARCH=arm64. x86/x64 builds keep thesame flags they had before; arm64 compiles the same sources without
them, and the existing
#ifdefguards take care of the rest.src/Volume/Volume.make—else ifeq "$(CPU_ARCH)" "arm64"branch inside the MacOSXblock that pulls in
Aes_hw_armv8.oarmv8crypto,Aescrypt.o, andsha256_armv8.oarmv8crypto— the symbols the linker was missing.Sha2Intel,blake2s_SSE41,blake2s_SSSE3, andopt_avx2as plain.ofiles so they skip the x86-flag pattern rules.Verification
The build now completes on arm64 (macOS 24.6, SDK 26.2) and produces a
working
src/Main/VeraCryptbinary. x86_64 and universal-binary releasebuilds are untouched — the new paths only activate when
CPU_ARCH=arm64.