Skip to content

Commit

Permalink
Add CRYPTOPP_DISABLE_MIXED_ASM define and feature test (GH #756, PR #757
Browse files Browse the repository at this point in the history
)
  • Loading branch information
noloader committed Dec 5, 2018
1 parent 4b295f1 commit 8769302
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 34 deletions.
1 change: 1 addition & 0 deletions Filelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
31 changes: 31 additions & 0 deletions TestPrograms/test_mixed_asm.cxx
Original file line number Diff line number Diff line change
@@ -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 <cstddef>
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;
}
14 changes: 5 additions & 9 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:https://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:https://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx
Expand Down
2 changes: 1 addition & 1 deletion cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
22 changes: 11 additions & 11 deletions gcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion gcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

// "Inline assembly operands don't work with .intel_syntax",
// http:https://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
Expand Down
2 changes: 1 addition & 1 deletion panama.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion rijndael.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion salsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion sosemanuk.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion tiger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion vmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down
2 changes: 1 addition & 1 deletion whrlpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://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

Expand Down

0 comments on commit 8769302

Please sign in to comment.