From b5a5d9e3f7022e546cdfd4ddc42fe4cc56839c05 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Mon, 7 Apr 2025 22:36:58 +0300 Subject: [PATCH] liblzma: Disable CLMUL CRC on old MSVC targeting 32-bit x86 On GitHub runners, VS 2019 16.11 (MSVC 19.29.30158) results in test failures. VS 2022 17.13 (MSVC 19.43.34808) works. In xz 5.6.x there was a #pragma-based workaround for MSVC builds for 32-bit x86. Another method was thought to work with the new rewritten CLMUL CRC. Apparently it doesn't. Keep it simple and disable CLMUL CRC with any non-recent MSVC when building for 32-bit x86. Fixes: 54eaea5ea49b ("liblzma: x86 CLMUL CRC: Rewrite") Fixes: https://github.com/tukaani-project/xz/issues/171 Reported-by: Andrew Murray --- src/liblzma/check/crc_common.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/liblzma/check/crc_common.h b/src/liblzma/check/crc_common.h index 7ea1e60b..d65ff740 100644 --- a/src/liblzma/check/crc_common.h +++ b/src/liblzma/check/crc_common.h @@ -134,10 +134,20 @@ extern const uint64_t lzma_crc64_table[4][256]; // built and runtime detection is used even if compiler flags // were set to allow CLMUL unconditionally. // - // - This doesn't work with MSVC as I don't know how to detect - // the features here. + // - The unconditional use doesn't work with MSVC as I don't know + // how to detect the features here. // -# if (defined(__SSSE3__) && defined(__SSE4_1__) && defined(__PCLMUL__) \ + // Don't enable CLMUL at all on old MSVC that targets 32-bit x86. + // There seems to be a compiler bug that produces broken code + // in optimized (Release) builds. It results in crashing tests. + // It is known that VS 2019 16.11 (MSVC 19.29.30158) is broken + // and that VS 2022 17.13 (MSVC 19.43.34808) works. +# if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 194334808 \ + && !defined(__INTEL_COMPILER) && !defined(__clang__) \ + && defined(_M_IX86) + // Old MSVC targeting 32-bit x86: Don't enable CLMUL at all. +# elif (defined(__SSSE3__) && defined(__SSE4_1__) \ + && defined(__PCLMUL__) \ && !defined(HAVE_CRC_X86_ASM)) \ || (defined(__e2k__) && __iset__ >= 6) # define CRC32_ARCH_OPTIMIZED 1