From: Mika Lindqvist Date: Tue, 12 Apr 2022 22:22:29 +0000 (+0300) Subject: Check that sys/auxv.h exists at configure time and add preprocessor define for it. X-Git-Tag: 2.1.0-beta1~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1baa6b439c06f3d0e6be3e381cc746ffb55aee1;p=thirdparty%2Fzlib-ng.git Check that sys/auxv.h exists at configure time and add preprocessor define for it. * 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dd19613..e4e4b733 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/arch/arm/arm_features.c b/arch/arm/arm_features.c index 195c9499..f6b67687 100644 --- a/arch/arm/arm_features.c +++ b/arch/arm/arm_features.c @@ -1,6 +1,6 @@ #include "../../zbuild.h" -#if defined(__linux__) +#if defined(__linux__) && defined(HAVE_SYS_AUXV_H) # include # ifdef ARM_ASM_HWCAP # include diff --git a/arch/power/power_features.c b/arch/power/power_features.c index 9186b40d..65599d9a 100644 --- a/arch/power/power_features.c +++ b/arch/power/power_features.c @@ -1,10 +1,12 @@ /* power_features.c - POWER feature check * Copyright (C) 2020 Matheus Castanho , IBM - * Copyright (C) 2021 Mika T. Lindqvist + * Copyright (C) 2021-2022 Mika T. Lindqvist * For conditions of distribution and use, see copyright notice in zlib.h */ -#include +#ifdef HAVE_SYS_AUXV_H +# include +#endif #include "../../zbuild.h" #include "power_features.h" diff --git a/arch/s390/s390_features.c b/arch/s390/s390_features.c index 465fe0f3..30bdde91 100644 --- a/arch/s390/s390_features.c +++ b/arch/s390/s390_features.c @@ -1,10 +1,14 @@ #include "../../zbuild.h" #include "s390_features.h" -#include +#ifdef HAVE_SYS_AUXV_H +# include +#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 } diff --git a/cmake/detect-intrinsics.cmake b/cmake/detect-intrinsics.cmake index 9a4e54c3..80fecf2b 100644 --- a/cmake/detect-intrinsics.cmake +++ b/cmake/detect-intrinsics.cmake @@ -306,6 +306,16 @@ macro(check_power8_intrinsics) set(CMAKE_REQUIRED_FLAGS) endmacro() +macro(check_s390_intrinsics) + check_c_source_compiles( + "#include + 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) diff --git a/configure b/configure index aed1909c..a357e1c8 100755 --- 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 < +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