From c08cac0cd151a0afc616c38189ce9d7025145b96 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 2 Dec 2015 15:54:35 -0500 Subject: [PATCH] Fixed failed compile on OS X using "-arch i386" due to Clang defining __ILP32__ for everything that is 32-bit. MSVC, GCC, ICC and Comeau were OK --- config.h | 5 +++-- cryptest.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++-- gcm.cpp | 6 +++--- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/config.h b/config.h index 638bc3ce..50e34cf4 100644 --- a/config.h +++ b/config.h @@ -468,8 +468,9 @@ NAMESPACE_END #endif // Linux provides X32, which is 32-bit integers, longs and pointers on x86_64 using the full x86_64 register set. -// Detect via __ILP32__ (http://wiki.debian.org/X32Port). Both GCC and Clang provide the preprocessor macro. -#if ((__ILP32__ >= 1) || (_ILP32 >= 1)) +// Detect via __ILP32__ (http://wiki.debian.org/X32Port). However, __ILP32__ shows up in more places than +// the System V ABI specs calls out, like on just about any 32-bit system with Clang. +#if ((__ILP32__ >= 1) || (_ILP32 >= 1)) && defined(__x86_64__) #define CRYPTOPP_BOOL_X32 1 #else #define CRYPTOPP_BOOL_X32 0 diff --git a/cryptest.sh b/cryptest.sh index 4d61d6c9..b678ed1c 100755 --- a/cryptest.sh +++ b/cryptest.sh @@ -14,7 +14,7 @@ # Set to suite your taste TEST_RESULTS=cryptest-result.txt BENCHMARK_RESULTS=cryptest-bench.txt -WARN_TEST_RESULTS=cryptest-warn-result.txt +WARN_TEST_RESULTS=cryptest-warn.txt # Respect user's preferred flags, but filter the stuff we expliclty test #if [ ! -z "CXXFLAGS" ]; then @@ -33,6 +33,7 @@ IS_LINUX=$(uname -s | grep -i -c linux) IS_CYGWIN=$(uname -s | grep -i -c cygwin) IS_MINGW=$(uname -s | grep -i -c mingw) IS_OPENBSD=$(uname -s | grep -i -c openbsd) +IS_X86_OR_X64=$(uname -m | egrep -i -c "(i386|i586|i686|amd64|x86_64)") # We need to use the C++ compiler to determine if c++11 is available. Otherwise # a mis-detection occurs on Mac OS X 10.9 and above. Below, we use the same @@ -105,12 +106,22 @@ if [ "$IS_CYGWIN" -ne "0" ] || [ "$IS_MINGW" -ne "0" ]; then HAVE_ASAN=0 fi -#Final fixups for compilers liek GCC on ARM64 +# Final fixups for compilers like GCC on ARM64 if [ "$HAVE_UBSAN" -eq "0" ] || [ "$HAVE_ASAN" -eq "0" ]; then HAVE_UBAN=0 HAVE_ASAN=0 fi +# Set to 0 if you don't have Multiarch +if [ "$IS_X86_OR_X64" -ne "0" ]; then +$CXX -x c++ -arch i386 -arch x86_64 -c adhoc.cpp.proto -o $TMP/adhoc > /dev/null 2>&1 +if [ "$?" -eq "0" ]; then + HAVE_MULTIARCH=1 +else + HAVE_MULTIARCH=0 +fi +fi + # Set to 0 if you don't have Valgrind. Valgrind tests take a long time... HAVE_VALGRIND=$(which valgrind 2>&1 | grep -v "no valgrind" | grep -i -c valgrind) @@ -128,6 +139,9 @@ if [ "$IS_DARWIN" -ne "0" ]; then echo "IS_DARWIN: $IS_DARWIN" unset MallocScribble MallocPreScribble MallocGuardEdges fi +if [ "$HAVE_MULTIARCH" -ne "0" ]; then + echo "HAVE_MULTIARCH: $HAVE_MULTIARCH" +fi if [ "$IS_LINUX" -ne "0" ]; then echo "IS_LINUX: $IS_LINUX" fi @@ -611,6 +625,48 @@ if [ "$IS_DARWIN" -ne "0" ] && [ "$HAVE_CXX11" -ne "0" ]; then ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" fi +############################################ +# Darwin, Multiarch, c++03 +if [ "$IS_DARWIN" -ne "0" ] && [ "$IS_X86_OR_X64" -ne "0" ]; then + echo + echo "************************************" | tee -a "$TEST_RESULTS" + echo "Testing: Darwin, Multiarch, c++03" | tee -a "$TEST_RESULTS" + echo + + unset CXXFLAGS + "$MAKE" clean > /dev/null 2>&1 + export CXXFLAGS="-DNDEBUG -g2 -O2 -arch i386 -arch x86_64 -std=c++03 $ADD_CXXFLAGS" + "$MAKE" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" + + echo "Running i386 version..." + arch -i386 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" + arch -i386 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" + echo "Running x86_64 version..." + arch -x86_64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" + arch -x86_64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" +fi + +############################################ +# Darwin, Multiarch, c++11 +if [ "$IS_DARWIN" -ne "0" ] && [ "$IS_X86_OR_X64" -ne "0" ]; then + echo + echo "************************************" | tee -a "$TEST_RESULTS" + echo "Testing: Darwin, Multiarch, c++11" | tee -a "$TEST_RESULTS" + echo + + unset CXXFLAGS + "$MAKE" clean > /dev/null 2>&1 + export CXXFLAGS="-DNDEBUG -g2 -O2 -arch i386 -arch x86_64 -std=c++11 $ADD_CXXFLAGS" + "$MAKE" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" + + echo "Running i386 version..." + arch -i386 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" + arch -i386 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" + echo "Running x86_64 version..." + arch -x86_64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" + arch -x86_64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" +fi + ############################################ # Darwin, c++03, Malloc Guards if [ "$IS_DARWIN" -ne "0" ] && [ "$HAVE_CXX03" -ne "0" ]; then diff --git a/gcm.cpp b/gcm.cpp index 9f401c88..9e46766f 100644 --- a/gcm.cpp +++ b/gcm.cpp @@ -686,7 +686,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) AS2( psrldq xmm0, 15 ) #if (CRYPTOPP_CLANG_VERSION >= 30600) || (CRYPTOPP_APPLE_CLANG_VERSION >= 70000) AS2( movd edi, xmm0 ) -#elif defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) +#elif (defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION)) && defined(CRYPTOPP_X64_ASM_AVAILABLE) AS2( mov WORD_REG(di), xmm0 ) #else // GNU Assembler AS2( movd WORD_REG(di), xmm0 ) @@ -701,7 +701,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) AS2( psrldq xmm1, 15 ) #if (CRYPTOPP_CLANG_VERSION >= 30600) || (CRYPTOPP_APPLE_CLANG_VERSION >= 70000) AS2( movd edi, xmm1 ) -#elif defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) +#elif (defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION)) && defined(CRYPTOPP_X64_ASM_AVAILABLE) AS2( mov WORD_REG(di), xmm1 ) #else AS2( movd WORD_REG(di), xmm1 ) @@ -712,7 +712,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) AS2( psrldq xmm0, 15 ) #if (CRYPTOPP_CLANG_VERSION >= 30600) || (CRYPTOPP_APPLE_CLANG_VERSION >= 70000) AS2( movd edi, xmm0 ) -#elif defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) +#elif (defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION)) && defined(CRYPTOPP_X64_ASM_AVAILABLE) AS2( mov WORD_REG(di), xmm0 ) #else AS2( movd WORD_REG(di), xmm0 )