From: Nathan Moinvaziri Date: Tue, 15 Mar 2022 01:30:51 +0000 (-0700) Subject: Make unaligned access being disabled configurable via build scripts. X-Git-Tag: 2.1.0-beta1~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c78c835a4981ff2305ff79d6c05fe0e2c22c8dc2;p=thirdparty%2Fzlib-ng.git Make unaligned access being disabled configurable via build scripts. --- diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5fdc38a1..a4d05f35 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -51,10 +51,11 @@ jobs: codecov: ubuntu_gcc_osb cflags: -O1 -g3 - - name: Ubuntu GCC -O3 + - name: Ubuntu GCC -O3 No Unaligned os: ubuntu-latest compiler: gcc cxx-compiler: g++ + cmake-args: -DWITH_UNALIGNED=OFF codecov: ubuntu_gcc_o3 cflags: -O3 diff --git a/CMakeLists.txt b/CMakeLists.txt index c41428c7..e18a3945 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ option(WITH_MAINTAINER_WARNINGS "Build with project maintainer warnings" OFF) option(WITH_CODE_COVERAGE "Enable code coverage reporting" OFF) option(WITH_INFLATE_STRICT "Build with strict inflate distance checking" OFF) option(WITH_INFLATE_ALLOW_INVALID_DIST "Build with zero fill for inflate invalid distances" OFF) +option(WITH_UNALIGNED "Support unaligned reads on platforms that support it" ON) set(ZLIB_SYMBOL_PREFIX "" CACHE STRING "Give this prefix to all publicly exported symbols. Useful when embedding into a larger library. @@ -137,6 +138,7 @@ mark_as_advanced(FORCE WITH_POWER8 WITH_INFLATE_STRICT WITH_INFLATE_ALLOW_INVALID_DIST + WITH_UNALIGNED INSTALL_UTILS ) @@ -247,6 +249,12 @@ else() endif() endif() +# Set architecture alignment requirements +if(NOT WITH_UNALIGNED) + add_definitions(-DNO_UNALIGNED) + message(STATUS "Unaligned reads manually disabled") +endif() + # Apply warning compiler flags if(WITH_MAINTAINER_WARNINGS) add_compile_options(${WARNFLAGS} ${WARNFLAGS_MAINTAINER} ${WARNFLAGS_DISABLE}) diff --git a/README.md b/README.md index 59899ad5..b0842bc4 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,7 @@ Advanced Build Options | WITH_CRC32_VX | --without-crc32-vx | Build with vectorized CRC32 on IBM Z | ON | | WITH_DFLTCC_DEFLATE | --with-dfltcc-deflate | Build with DFLTCC intrinsics for compression on IBM Z | OFF | | WITH_DFLTCC_INFLATE | --with-dfltcc-inflate | Build with DFLTCC intrinsics for decompression on IBM Z | OFF | +| WITH_UNALIGNED | --without-unaligned | Allow optimizations that use unaligned reads if safe on current arch| ON | | WITH_INFLATE_STRICT | | Build with strict inflate distance checking | OFF | | WITH_INFLATE_ALLOW_INVALID_DIST | | Build with zero fill for inflate invalid distances | OFF | | INSTALL_UTILS | | Copy minigzip and minideflate during install | OFF | diff --git a/configure b/configure index 17bd9fd8..35404ce5 100755 --- a/configure +++ b/configure @@ -86,6 +86,7 @@ mandir=${mandir-'${prefix}/share/man'} shared_ext='.so' shared=1 gzfileops=1 +unalignedok=1 compat=0 cover=0 build32=0 @@ -162,7 +163,8 @@ case "$1" in echo ' [--warn] Enables extra compiler warnings' | tee -a configure.log echo ' [--debug] Enables extra debug prints during operation' | tee -a configure.log echo ' [--zlib-compat] Compiles for zlib-compatible API instead of zlib-ng API' | tee -a configure.log - echo ' [--without-gzfileops] Compiles with the gzfile parts of the API enabled' | tee -a configure.log + echo ' [--without-unaligned] Compiles without fast unaligned access' | tee -a configure.log + echo ' [--without-gzfileops] Compiles without the gzfile parts of the API enabled' | tee -a configure.log echo ' [--without-optimizations] Compiles without support for optional instruction sets' | tee -a configure.log echo ' [--without-new-strategies] Compiles without using new additional deflate strategies' | tee -a configure.log echo ' [--without-acle] Compiles without ARM C Language Extensions' | tee -a configure.log @@ -194,6 +196,7 @@ case "$1" in -s* | --shared | --enable-shared) shared=1; shift ;; -t | --static) shared=0; shift ;; --zlib-compat) compat=1; shift ;; + --without-unaligned) unalignedok=0; shift ;; --without-gzfileops) gzfileops=0; shift ;; --cover) cover=1; shift ;; -3* | --32) build32=1; shift ;; @@ -910,6 +913,13 @@ else PIC_TESTOBJG="\$(OBJG)" fi +# set architecture alignment requirements +if test $unalignedok -eq 0; then + CFLAGS="${CFLAGS} -DNO_UANLIGNED" + SFLAGS="${SFLAGS} -DNO_UNALIGNED" + echo "Unaligned reads manually disabled." | tee -a configure.log +fi + # enable reduced memory configuration if test $reducedmem -eq 1; then echo "Configuring for reduced memory environment." | tee -a configure.log diff --git a/zbuild.h b/zbuild.h index 20e3e20e..0513bf0b 100644 --- a/zbuild.h +++ b/zbuild.h @@ -194,25 +194,27 @@ # define Tracecv(c, x) #endif -#if defined(__x86_64__) || defined(_M_X64) || defined(__amd64__) || defined(_M_AMD64) -# define UNALIGNED_OK -# define UNALIGNED64_OK -#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \ - defined(__i686__) || defined(_X86_) || defined(_M_IX86) -# define UNALIGNED_OK -#elif defined(__aarch64__) || defined(_M_ARM64) -# if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__) +#ifndef NO_UNALIGNED +# if defined(__x86_64__) || defined(_M_X64) || defined(__amd64__) || defined(_M_AMD64) # define UNALIGNED_OK # define UNALIGNED64_OK -# endif -#elif defined(__arm__) || (_M_ARM >= 7) -# if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__) -# define UNALIGNED_OK -# endif -#elif defined(__powerpc64__) || defined(__ppc64__) -# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \ + defined(__i686__) || defined(_X86_) || defined(_M_IX86) # define UNALIGNED_OK -# define UNALIGNED64_OK +# elif defined(__aarch64__) || defined(_M_ARM64) +# if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__) +# define UNALIGNED_OK +# define UNALIGNED64_OK +# endif +# elif defined(__arm__) || (_M_ARM >= 7) +# if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__) +# define UNALIGNED_OK +# endif +# elif defined(__powerpc64__) || defined(__ppc64__) +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define UNALIGNED_OK +# define UNALIGNED64_OK +# endif # endif #endif