cryptopp-cmake
cryptopp-cmake copied to clipboard
Crash when compiled as a universal binary (x86_64 + arm64) for macOS
When we compile cryptopp as a universal binary (x86_64 + arm64) using this CMake script, running the cryptest validation test fails. It also crashes my application that relies on this, even though compilation succeeds.
The same universal binary compiled using the GNUMakeFile provided by cryptopp passes all validation tests without issue. To compile using the GNUMakeFile you can enter: CXXFLAGS="-DNDEBUG -g2 -O3 -stdlib=libc++ -arch x86_64 -arch arm64" make -j 4
on a fresh cryptopp install.
I've tried to further reduce the problem, and finally the problem isn't with the universal binary per se, but rather with how the CMake script handles the CRYPTOPP_DISABLE_ASM flag. If you compile with cmake -G Ninja .. -DCRYPTOPP_DISABLE_ASM=1
you'll have the same issue.
Steps
- Download this repo.
- Run:
mkdir build
cd build
cmake -G Ninja .. -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
...
-- [cryptopp] CMake version 3.29.3
-- [cryptopp] System Darwin
-- [cryptopp] Processor x86_64
-- [cryptopp] CMAKE_OSX_ARCHITECTURES : x86_64;arm64
-- [cryptopp] CMAKE_HOST_SYSTEM_PROCESSOR : x86_64
-- [cryptopp] CMAKE_SYSTEM_PROCESSOR : x86_64
-- [cryptopp] Target architecture detected as: x86_64;arm64 -> CRYPTOPP_AMD64
-- [cryptopp] Target architecture detected as: x86_64;arm64 -> CRYPTOPP_ARMV8
-- [cryptopp] Performing Test CRYPTOPP_X86_WAQ
-- [cryptopp] Performing Test CRYPTOPP_X86_WAQ - Failed
-- [cryptopp] Performing Test CRYPTOPP_HAVE_SSE2
-- [cryptopp] Performing Test CRYPTOPP_HAVE_SSE2 - Failed
-- [cryptopp] Performing Test CRYPTOPP_ARM_NEON_HEADER
-- [cryptopp] Performing Test CRYPTOPP_ARM_NEON_HEADER - Failed
-- [cryptopp] Performing Test CRYPTOPP_ARM_ACLE_HEADER
-- [cryptopp] Performing Test CRYPTOPP_ARM_ACLE_HEADER - Failed
-- [cryptopp] Performing Test CRYPTOPP_ARM_SIMD
-- [cryptopp] Performing Test CRYPTOPP_ARM_SIMD - Failed
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- [cryptopp] Generating cmake package config files
-- [cryptopp] Generating pkgconfig files
-- [cryptopp] Platform: x86_64
-- [cryptopp] Compiler definitions: CRYPTOPP_DISABLE_ASM=1;CRYPTOPP_DISABLE_ASM=1
-- [cryptopp] Compiler options:
-- [cryptopp] Build type: Release
- Compilation succeeds, but running validation tests fail:
cd cryptopp
./cryptest v
Using seed: 1717168127
Testing Settings...
passed: Your machine is little endian.
passed: Your machine is 64-bit.
passed: sizeof(byte) == 1
passed: sizeof(word16) == 2
passed: sizeof(word32) == 4
passed: sizeof(word64) == 8
passed: sizeof(word128) == 16
passed: sizeof(hword) == 4, sizeof(word) == 8, sizeof(dword) == 16
passed: cacheLineSize == 64
hasSSE2 == 0, hasSSSE3 == 0, hasSSE4.1 == 0, hasSSE4.2 == 0, hasAVX == 0, hasAVX2 == 0, hasAESNI == 0, hasCLMUL == 0, hasRDRAND == 0, hasRDSEED == 0, hasSHA == 0, isP4 == 0
...
Testing RandomPool generator...
passed: 10240 generated bytes compressed to 10245 bytes by DEFLATE
passed: IncorporateEntropy with 128 bytes
passed: GenerateWord32 and Crop
passed: DiscardBytes with 1024 bytes
zsh: segmentation fault ./cryptest v
OS: macOS 12.7.5 CPU: 1.6 GHz Dual-Core Intel Core i5 Compiler: Apple clang version 14.0.0 (clang-1400.0.29.202) Version: master, most recent commit on Mar 11, 2024