]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Check that sys/auxv.h exists at configure time and add preprocessor define for it.
authorMika Lindqvist <postmaster@raasu.org>
Tue, 12 Apr 2022 22:22:29 +0000 (01:22 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 22 Apr 2022 11:51:37 +0000 (13:51 +0200)
* Protect including sys/auxv.h in all relevant files with the new preprocessor define
* Test for both existence of both sys/auxv.h and getauxval() with both cmake and configure

CMakeLists.txt
arch/arm/arm_features.c
arch/power/power_features.c
arch/s390/s390_features.c
cmake/detect-intrinsics.cmake
configure

index 0dd196130cbc8480109bd53dd898bebcd1a63a6a..e4e4b73327242cbe893ba828937af328009590ef 100644 (file)
@@ -290,6 +290,10 @@ endif()
 #
 # Check for standard/system includes
 #
+check_include_file(sys/auxv.h  HAVE_SYS_AUXV_H)
+if(HAVE_SYS_AUXV_H)
+    add_definitions(-DHAVE_SYS_AUXV_H)
+endif()
 check_include_file(sys/sdt.h   HAVE_SYS_SDT_H)
 if(HAVE_SYS_SDT_H)
     add_definitions(-DHAVE_SYS_SDT_H)
@@ -660,7 +664,8 @@ if(WITH_OPTIM)
             endif()
         endif()
     elseif(BASEARCH_S360_FOUND)
-        if(WITH_CRC32_VX)
+        check_s390_intrinsics()
+        if(HAVE_S390_INTRIN)
             add_definitions(-DS390_FEATURES)
             list(APPEND ZLIB_ARCH_HDRS ${ARCHDIR}/s390_features.h)
             list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/s390_features.c)
index 195c94992de9708dacde6c8f116d0b1223c5e467..f6b67687f3e9bfdd6a14633dbdc54d25184e8b78 100644 (file)
@@ -1,6 +1,6 @@
 #include "../../zbuild.h"
 
-#if defined(__linux__)
+#if defined(__linux__) && defined(HAVE_SYS_AUXV_H)
 #  include <sys/auxv.h>
 #  ifdef ARM_ASM_HWCAP
 #    include <asm/hwcap.h>
index 9186b40d83a67380ad1f9a2d48742126d776de88..65599d9a79d91cb897e9ff315c07a78ca59d3322 100644 (file)
@@ -1,10 +1,12 @@
 /* power_features.c - POWER feature check
  * Copyright (C) 2020 Matheus Castanho <msc@linux.ibm.com>, IBM
- * Copyright (C) 2021 Mika T. Lindqvist <postmaster@raasu.org>
+ * Copyright (C) 2021-2022 Mika T. Lindqvist <postmaster@raasu.org>
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-#include <sys/auxv.h>
+#ifdef HAVE_SYS_AUXV_H
+#  include <sys/auxv.h>
+#endif
 #include "../../zbuild.h"
 #include "power_features.h"
 
index 465fe0f3763e2c805459d49c68af29a28b0eb279..30bdde91e33c43f0e1d36fdfa73bb55d2a938aa9 100644 (file)
@@ -1,10 +1,14 @@
 #include "../../zbuild.h"
 #include "s390_features.h"
 
-#include <sys/auxv.h>
+#ifdef HAVE_SYS_AUXV_H
+#  include <sys/auxv.h>
+#endif
 
-Z_INTERNAL int s390_cpu_has_vx;
+Z_INTERNAL int s390_cpu_has_vx = 0;
 
 void Z_INTERNAL s390_check_features(void) {
+#ifdef S390_FEATURES
     s390_cpu_has_vx = getauxval(AT_HWCAP) & HWCAP_S390_VX;
+#endif
 }
index 9a4e54c3dc816e2058af0ddc9e978e101153e94b..80fecf2b1d610683710e416a52a3415d28bc819a 100644 (file)
@@ -306,6 +306,16 @@ macro(check_power8_intrinsics)
     set(CMAKE_REQUIRED_FLAGS)
 endmacro()
 
+macro(check_s390_intrinsics)
+    check_c_source_compiles(
+        "#include <sys/auxv.h>
+        int main() {
+            return (getauxval(AT_HWCAP) & HWCAP_S390_VX);
+        }"
+        HAVE_S390_INTRIN
+    )
+endmacro()
+
 macro(check_sse2_intrinsics)
     if(CMAKE_C_COMPILER_ID MATCHES "Intel")
         if(CMAKE_HOST_UNIX OR APPLE)
index aed1909ccb7461e787e0c7adfac4150f37e290ff..a357e1c8aa64aa7c2fc52113dcdeef9953da8162 100755 (executable)
--- a/configure
+++ b/configure
@@ -733,6 +733,19 @@ else
   echo "Checking for strerror... No." | tee -a configure.log
 fi
 
+# check for getauxval() for architecture feature detection at run-time
+cat > $test.c <<EOF
+#include <sys/auxv.h>
+int main() { return getauxval(0); }
+EOF
+if try $CC $CFLAGS -o $test $test.c $LDSHAREDLIBC; then
+  echo "Checking for getauxval() in sys/auxv.h... Yes." | tee -a configure.log
+  CFLAGS="${CFLAGS} -DHAVE_SYS_AUXV_H"
+  SFLAGS="${SFLAGS} -DHAVE_SYS_AUXV_H"
+else
+  echo "Checking for getauxval() in sys/auxv.h... No." | tee -a configure.log
+fi
+
 # We need to remove consigured files (zconf.h etc) from source directory if building outside of it
 if [ "$SRCDIR" != "$BUILDDIR" ]; then
     rm -f $SRCDIR/zconf${SUFFIX}.h