]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Fix build on old Linux/glibc on ARM64
authorLasse Collin <lasse.collin@tukaani.org>
Sun, 28 Sep 2025 15:32:05 +0000 (18:32 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 31 Oct 2025 17:21:48 +0000 (19:21 +0200)
getauxval() can be available even if HWCAP_CRC32 isn't #defined, so
both have to be checked. HWCAP_CRC32 was added in glibc 2.24 (2016).

Fixes: https://github.com/tukaani-project/xz/issues/190
CMakeLists.txt
configure.ac
src/liblzma/check/crc32_arm64.h
src/liblzma/check/crc_common.h

index f3416e0aa7bcb40c93da2c08b3a77623b21decc4..cb5ef7f157d93ba6268ee0df0c1080b5555ab5f5 100644 (file)
@@ -1379,6 +1379,13 @@ if(XZ_ARM64_CRC32)
         check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)
         tuklib_add_definition_if(liblzma HAVE_GETAUXVAL)
 
+        # With getauxval() we also need HWCAP_CRC32 which was
+        # added in glibc 2.24.
+        if(HAVE_GETAUXVAL)
+            check_symbol_exists(HWCAP_CRC32 sys/auxv.h HAVE_HWCAP_CRC32)
+            tuklib_add_definition_if(liblzma HAVE_HWCAP_CRC32)
+        endif()
+
         # elf_aux_info() is supported on FreeBSD and OpenBSD >= 7.6.
         check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
         tuklib_add_definition_if(liblzma HAVE_ELF_AUX_INFO)
index 3b29cd8477d07209483f845804565b3d7ab9ca05..658b91bb2fc64204e31f4cd27958cf9840b5a4e9 100644 (file)
@@ -1168,7 +1168,8 @@ int main(void)
 
 # Check for ARM64 CRC32 instruction runtime detection.
 #
-#   - getauxval() is supported on Linux.
+#   - getauxval() is supported on Linux. We also need HWCAP_CRC32 which was
+#     added in glibc 2.24.
 #
 #   - elf_aux_info() is supported on FreeBSD and OpenBSD >= 7.6.
 #
@@ -1180,6 +1181,9 @@ int main(void)
 #
 AS_IF([test "x$enable_arm64_crc32" = xyes], [
        AC_CHECK_FUNCS([getauxval elf_aux_info sysctlbyname], [break])
+       AC_CHECK_DECL([HWCAP_CRC32], [AC_DEFINE([HAVE_HWCAP_CRC32], [1],
+               [Define to 1 if 'HWCAP_CRC32' is declared in <sys/auxv.h>.])],
+               [], [[#include <sys/auxv.h>]])
 ])
 
 
index fb0e8f0105a9e7ddf5abb3a8f8ef3bb2b48ab128..cce1131b336f991e9c91eedd60c078a9019773a4 100644 (file)
@@ -23,7 +23,8 @@
 // If both versions are going to be built, we need runtime detection
 // to check if the instructions are supported.
 #if defined(CRC32_GENERIC) && defined(CRC32_ARCH_OPTIMIZED)
-#      if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
+#      if (defined(HAVE_GETAUXVAL) && defined(HAVE_HWCAP_CRC32)) \
+                       || defined(HAVE_ELF_AUX_INFO)
 #              include <sys/auxv.h>
 #      elif defined(_WIN32)
 #              include <processthreadsapi.h>
@@ -103,7 +104,7 @@ crc32_arch_optimized(const uint8_t *buf, size_t size, uint32_t crc)
 static inline bool
 is_arch_extension_supported(void)
 {
-#if defined(HAVE_GETAUXVAL)
+#if defined(HAVE_GETAUXVAL) && defined(HAVE_HWCAP_CRC32)
        return (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
 
 #elif defined(HAVE_ELF_AUX_INFO)
index d65ff7407714533691a2fea3b47f94e3ebce44ad..4897dfee49ae02e509eaac7d2dbb60192c53b114 100644 (file)
@@ -89,7 +89,8 @@ extern const uint64_t lzma_crc64_table[4][256];
 // ARM64
 //
 // Keep this in sync with changes to crc32_arm64.h
-#if defined(_WIN32) || defined(HAVE_GETAUXVAL) \
+#if defined(_WIN32) \
+               || (defined(HAVE_GETAUXVAL) && defined(HAVE_HWCAP_CRC32)) \
                || defined(HAVE_ELF_AUX_INFO) \
                || (defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME))
 #      define CRC_ARM64_RUNTIME_DETECTION 1