From 8769302a8b6feffbf213820ced0fe7a08112f06c Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 5 Dec 2018 13:22:10 -0500 Subject: [PATCH] Add CRYPTOPP_DISABLE_MIXED_ASM define and feature test (GH #756, PR #757) --- Filelist.txt | 1 + GNUmakefile | 12 +++++++++--- TestPrograms/test_mixed_asm.cxx | 31 +++++++++++++++++++++++++++++++ config.h | 14 +++++--------- cpu.h | 2 +- gcm.cpp | 22 +++++++++++----------- gcm.h | 2 +- integer.cpp | 2 +- panama.h | 2 +- rijndael.h | 2 +- salsa.h | 2 +- sha.h | 2 +- sosemanuk.h | 2 +- tiger.h | 2 +- vmac.h | 2 +- whrlpool.h | 2 +- 16 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 TestPrograms/test_mixed_asm.cxx diff --git a/Filelist.txt b/Filelist.txt index 65f12c33..5d786837 100644 --- a/Filelist.txt +++ b/Filelist.txt @@ -539,6 +539,7 @@ TestPrograms/test_arm_sha.cxx TestPrograms/test_arm_sm3.cxx TestPrograms/test_arm_sm4.cxx TestPrograms/test_cxx.cxx +TestPrograms/test_mixed_asm.cxx TestPrograms/test_newlib.cxx TestPrograms/test_ppc_aes.cxx TestPrograms/test_ppc_altivec.cxx diff --git a/GNUmakefile b/GNUmakefile index 97652470..25dc0546 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -106,9 +106,6 @@ ifeq ($(GCC_COMPILER)$(OSXPORT_COMPILER),11) ifeq ($(findstring -Wa,-q,$(CXXFLAGS)),) CXXFLAGS += -Wa,-q endif - ifeq ($(findstring -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER,$(CXXFLAGS)),) - CXXFLAGS += -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER=1 - endif endif # Hack to skip CPU feature tests for some recipes @@ -418,6 +415,15 @@ ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) endif endif +# Most Clang cannot handle mixed asm with positional arguments, where the +# body is Intel style with no prefix and the templates are AT&T style. +# Also see https://bugs.llvm.org/show_bug.cgi?id=39895 . +TPROG = TestPrograms/test_mixed_asm.cxx +HAVE_OPT = $(shell $(CXX) $(TCXXFLAGS) $(ZOPT) $(TPROG) -o $(TOUT) 2>&1 | tr ' ' '\n' | wc -l) +ifneq ($(strip $(HAVE_OPT)),0) + CXXFLAGS += -DCRYPTOPP_DISABLE_MIXED_ASM +endif + # IS_X86, IS_X32 and IS_X64 endif diff --git a/TestPrograms/test_mixed_asm.cxx b/TestPrograms/test_mixed_asm.cxx new file mode 100644 index 00000000..ada17e61 --- /dev/null +++ b/TestPrograms/test_mixed_asm.cxx @@ -0,0 +1,31 @@ +// Most Clang cannot handle mixed asm with positional arguments, where the +// body is Intel style with no prefix and the templates are AT&T style. +// Also see https://bugs.llvm.org/show_bug.cgi?id=39895 . +#include +int main(int argc, char* argv[]) +{ + size_t ret = 1, N = 1; + asm __volatile__ + ( +#if defined(__amd64__) || defined(__x86_64__) + ".intel_syntax noprefix ;\n" + "xor rsi, rsi ;\n" + "neg %1 ;\n" + "inc %1 ;\n" + "push %1 ;\n" + "pop rax ;\n" + ".att_syntax prefix ;\n" + : "=a" (ret) : "c" (N) : "%rsi" +#else + ".intel_syntax noprefix ;\n" + "xor esi, esi ;\n" + "neg %1 ;\n" + "inc %1 ;\n" + "push %1 ;\n" + "pop eax ;\n" + ".att_syntax prefix ;\n" + : "=a" (ret) : "c" (N) : "%esi" +#endif + ); + return (int)ret; +} diff --git a/config.h b/config.h index a25b6481..7ca27c19 100644 --- a/config.h +++ b/config.h @@ -278,10 +278,8 @@ const lword LWORD_MAX = W64LIT(0xffffffffffffffff); // Apple and LLVM's Clang. Apple Clang version 7.0 roughly equals LLVM Clang version 3.7 #if defined(__clang__) && defined(__apple_build_version__) #define CRYPTOPP_APPLE_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) - #define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1 #elif defined(__clang__) #define CRYPTOPP_LLVM_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) - #define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1 #endif #ifdef _MSC_VER @@ -293,13 +291,11 @@ const lword LWORD_MAX = W64LIT(0xffffffffffffffff); #define CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 1 #endif -// Clang due to "Inline assembly operands don't work with .intel_syntax", http://llvm.org/bugs/show_bug.cgi?id=24232. Still broke as of Clang 3.9. -// TODO: supply the upper version when LLVM fixes it. We set it to 20.0 for compilation purposes. -#if (defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION <= 200000)) || \ - (defined(CRYPTOPP_APPLE_CLANG_VERSION) && (CRYPTOPP_APPLE_CLANG_VERSION <= 200000)) || \ - defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER) - #define CRYPTOPP_DISABLE_INTEL_ASM 1 -#endif +// Some Clang cannot handle mixed asm with positional arguments, where the +// body is Intel style with no prefix and the templates are AT&T style. +// Define this is the Makefile misdetects the configuration. +// Also see https://bugs.llvm.org/show_bug.cgi?id=39895 . +// #define CRYPTOPP_DISABLE_MIXED_ASM 1 // define hword, word, and dword. these are used for multiprecision integer arithmetic // Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx diff --git a/cpu.h b/cpu.h index b21ad356..f7b554db 100644 --- a/cpu.h +++ b/cpu.h @@ -40,7 +40,7 @@ #endif // Applies to both X86/X32/X64 and ARM32/ARM64 -#if defined(CRYPTOPP_LLVM_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) || defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER) +#if defined(CRYPTOPP_LLVM_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) #define NEW_LINE "\n" #define INTEL_PREFIX ".intel_syntax;" #define INTEL_NOPREFIX ".intel_syntax;" diff --git a/gcm.cpp b/gcm.cpp index 473477c4..d1c3011c 100644 --- a/gcm.cpp +++ b/gcm.cpp @@ -12,13 +12,6 @@ #ifndef CRYPTOPP_IMPORTS #ifndef CRYPTOPP_GENERATE_X64_MASM -#if defined(CRYPTOPP_DISABLE_GCM_ASM) -# undef CRYPTOPP_X86_ASM_AVAILABLE -# undef CRYPTOPP_X32_ASM_AVAILABLE -# undef CRYPTOPP_X64_ASM_AVAILABLE -# undef CRYPTOPP_SSE2_ASM_AVAILABLE -#endif - // Visual Studio .Net 2003 compiler crash #if defined(_MSC_VER) && (_MSC_VER < 1400) # pragma optimize("", off) @@ -27,13 +20,20 @@ #include "gcm.h" #include "cpu.h" +#if defined(CRYPTOPP_DISABLE_GCM_ASM) +# undef CRYPTOPP_X86_ASM_AVAILABLE +# undef CRYPTOPP_X32_ASM_AVAILABLE +# undef CRYPTOPP_X64_ASM_AVAILABLE +# undef CRYPTOPP_SSE2_ASM_AVAILABLE +#endif + NAMESPACE_BEGIN(CryptoPP) #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) // Different assemblers accept different mnemonics: 'movd eax, xmm0' vs // 'movd rax, xmm0' vs 'mov eax, xmm0' vs 'mov rax, xmm0' -#if (CRYPTOPP_LLVM_CLANG_VERSION >= 30600) || (CRYPTOPP_APPLE_CLANG_VERSION >= 70000) || defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER) -// 'movd eax, xmm0' only. REG_WORD() macro not used. +#if defined(CRYPTOPP_DISABLE_MIXED_ASM) +// 'movd eax, xmm0' only. REG_WORD() macro not used. Clang path. # define USE_MOVD_REG32 1 #elif defined(__GNUC__) || defined(_MSC_VER) // 'movd eax, xmm0' or 'movd rax, xmm0'. REG_WORD() macro supplies REG32 or REG64. @@ -712,7 +712,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) AS2( add WORD_REG(cx), 16 ) AS2( sub WORD_REG(dx), 1 ) - ATT_NOPREFIX + // ATT_NOPREFIX ASJ( jnz, 0, b ) INTEL_NOPREFIX AS2( movdqa [WORD_REG(si)], xmm0 ) @@ -799,7 +799,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) AS2( add WORD_REG(cx), 16 ) AS2( sub WORD_REG(dx), 1 ) - ATT_NOPREFIX + // ATT_NOPREFIX ASJ( jnz, 1, b ) INTEL_NOPREFIX AS2( movdqa [WORD_REG(si)], xmm0 ) diff --git a/gcm.h b/gcm.h index b285c89b..db42aad5 100644 --- a/gcm.h +++ b/gcm.h @@ -12,7 +12,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_GCM_ASM 1 #endif diff --git a/integer.cpp b/integer.cpp index cf04c962..e73e5d8c 100644 --- a/integer.cpp +++ b/integer.cpp @@ -88,7 +88,7 @@ // "Inline assembly operands don't work with .intel_syntax", // http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # undef CRYPTOPP_X86_ASM_AVAILABLE # undef CRYPTOPP_X32_ASM_AVAILABLE # undef CRYPTOPP_X64_ASM_AVAILABLE diff --git a/panama.h b/panama.h index 50fe2d86..7a77f3a4 100644 --- a/panama.h +++ b/panama.h @@ -11,7 +11,7 @@ #include "secblock.h" // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler error with .intel_syntax -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_PANAMA_ASM #endif diff --git a/rijndael.h b/rijndael.h index d75a20ae..65512f59 100644 --- a/rijndael.h +++ b/rijndael.h @@ -15,7 +15,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_RIJNDAEL_ASM 1 #endif diff --git a/salsa.h b/salsa.h index 7765c919..a42d684b 100644 --- a/salsa.h +++ b/salsa.h @@ -11,7 +11,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_SALSA_ASM 1 #endif diff --git a/sha.h b/sha.h index 5a2f985f..aed1ecfa 100644 --- a/sha.h +++ b/sha.h @@ -13,7 +13,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_SHA_ASM 1 #endif diff --git a/sosemanuk.h b/sosemanuk.h index 05b5578c..94ebcfea 100644 --- a/sosemanuk.h +++ b/sosemanuk.h @@ -12,7 +12,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_SOSEMANUK_ASM 1 #endif diff --git a/tiger.h b/tiger.h index b1e632a6..f76ca3e4 100644 --- a/tiger.h +++ b/tiger.h @@ -12,7 +12,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_TIGER_ASM 1 #endif diff --git a/vmac.h b/vmac.h index bb29ce35..e229abc2 100644 --- a/vmac.h +++ b/vmac.h @@ -13,7 +13,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_VMAC_ASM 1 #endif diff --git a/whrlpool.h b/whrlpool.h index e6213f7e..33e4b302 100644 --- a/whrlpool.h +++ b/whrlpool.h @@ -15,7 +15,7 @@ // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 -#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) +#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) # define CRYPTOPP_DISABLE_WHIRLPOOL_ASM 1 #endif