From 121014baf0e80fa1fc386b7d1ff379d243377dd8 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 2 Oct 2023 05:25:39 -0400 Subject: [PATCH] Return 0-values for XGETBV64 and CPUID64 when CRYPTOPP_DISABLE_ASM is in effect (GH #1240) Some folks were defining CRYPTOPP_DISABLE_ASM and not building the *.asm files on WIndows. That happened to work until we refactored code for XGetBV and CpuId. These alternate build systems are going to be the death of us... --- cpu.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cpu.cpp b/cpu.cpp index 44b57c4dd..ff8c5ceed 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -388,9 +388,14 @@ extern bool CPU_ProbeSSE2(); // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85684. word64 XGetBV(word32 num) { +// Explicitly handle CRYPTOPP_DISABLE_ASM case. +// https://github.com/weidai11/cryptopp/issues/1240 +#if defined(CRYPTOPP_DISABLE_ASM) + return 0; + // Required by Visual Studio 2008 and below and Clang on Windows. // Use it for all MSVC-compatible compilers. -#if defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) +#elif defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) return XGETBV64(num); @@ -446,9 +451,15 @@ word64 XGetBV(word32 num) // cpu.cpp (131): E2211 Inline assembly not allowed in inline and template functions bool CpuId(word32 func, word32 subfunc, word32 output[4]) { +// Explicitly handle CRYPTOPP_DISABLE_ASM case. +// https://github.com/weidai11/cryptopp/issues/1240 +#if defined(CRYPTOPP_DISABLE_ASM) + output[0] = output[1] = output[2] = output[3] = 0; + return false; + // Required by Visual Studio 2008 and below and Clang on Windows. // Use it for all MSVC-compatible compilers. -#if defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) +#elif defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) CPUID64(func, subfunc, output); return true;