aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/check/crc_clmul.c
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-10-20 19:17:46 +0800
committerJia Tan <jiat0218@gmail.com>2023-10-21 00:01:29 +0800
commit988e09f27b9b04a43d45d10f92782e0092ee27a9 (patch)
tree35149423b8a1da0a3c249ab44f2602ceb5365f3f /src/liblzma/check/crc_clmul.c
parentBuild: Remove check for COND_CHECK_CRC32 in check/Makefile.inc. (diff)
downloadxz-988e09f27b9b04a43d45d10f92782e0092ee27a9.tar.xz
liblzma: Move is_clmul_supported() back to crc_common.h.
This partially reverts creating crc_clmul.c (8c0f9376f58c0696d5d6719705164d35542dd891) where is_clmul_supported() was moved, extern'ed, and renamed to lzma_is_clmul_supported(). This caused a problem when the function call to lzma_is_clmul_supported() results in a call through the PLT. ifunc resolvers run very early in the dynamic loading sequence, so the PLT may not be setup properly at this point. Whether the PLT is used or not for lzma_is_clmul_supported() depened upon the compiler-toolchain used and flags. In liblzma compiled with GCC, for instance, GCC will go through the PLT for function calls internal to liblzma if the version scripts and symbol visibility hiding are not used. If lazy-binding is disabled, then it would have made any program linked with liblzma fail during dynamic loading in the ifunc resolver.
Diffstat (limited to 'src/liblzma/check/crc_clmul.c')
-rw-r--r--src/liblzma/check/crc_clmul.c45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/liblzma/check/crc_clmul.c b/src/liblzma/check/crc_clmul.c
index 7110fd7e..640415e7 100644
--- a/src/liblzma/check/crc_clmul.c
+++ b/src/liblzma/check/crc_clmul.c
@@ -372,48 +372,3 @@ lzma_crc64_clmul(const uint8_t *buf, size_t size, uint64_t crc)
&& defined(_M_IX86)
# pragma optimize("", on)
#endif
-
-
-////////////////////////
-// Detect CPU support //
-////////////////////////
-
-extern bool
-lzma_is_clmul_supported(void)
-{
- int success = 1;
- uint32_t r[4]; // eax, ebx, ecx, edx
-
-#if defined(_MSC_VER)
- // This needs <intrin.h> with MSVC. ICC has it as a built-in
- // on all platforms.
- __cpuid(r, 1);
-#elif defined(HAVE_CPUID_H)
- // Compared to just using __asm__ to run CPUID, this also checks
- // that CPUID is supported and saves and restores ebx as that is
- // needed with GCC < 5 with position-independent code (PIC).
- success = __get_cpuid(1, &r[0], &r[1], &r[2], &r[3]);
-#else
- // Just a fallback that shouldn't be needed.
- __asm__("cpuid\n\t"
- : "=a"(r[0]), "=b"(r[1]), "=c"(r[2]), "=d"(r[3])
- : "a"(1), "c"(0));
-#endif
-
- // Returns true if these are supported:
- // CLMUL (bit 1 in ecx)
- // SSSE3 (bit 9 in ecx)
- // SSE4.1 (bit 19 in ecx)
- const uint32_t ecx_mask = (1 << 1) | (1 << 9) | (1 << 19);
- return success && (r[2] & ecx_mask) == ecx_mask;
-
- // Alternative methods that weren't used:
- // - ICC's _may_i_use_cpu_feature: the other methods should work too.
- // - GCC >= 6 / Clang / ICX __builtin_cpu_supports("pclmul")
- //
- // CPUID decding is needed with MSVC anyway and older GCC. This keeps
- // the feature checks in the build system simpler too. The nice thing
- // about __builtin_cpu_supports would be that it generates very short
- // code as is it only reads a variable set at startup but a few bytes
- // doesn't matter here.
-}