From: lawadr <3211473+lawadr@users.noreply.github.com> Date: Thu, 30 Mar 2023 19:37:14 +0000 (+0100) Subject: Check for attribute aligned compiler support X-Git-Tag: 2.1.0-beta1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a60d93829d7cc17a9974896a5e0b85ea9a0ba5e;p=thirdparty%2Fzlib-ng.git Check for attribute aligned compiler support Check for compiler support in CMake and the configure script. This allows ALIGNED_ to be defined for more compilers so that more than just Clang, GCC and MSVC can build the project. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e5184cca3..ffde3d294 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -391,6 +391,20 @@ if(HAVE_ATTRIBUTE_VISIBILITY_INTERNAL) add_definitions(-DHAVE_VISIBILITY_INTERNAL) endif() +# +# Check for __attribute__((aligned(x))) support in the compiler +# +check_c_source_compiles( + "int main(void) { + __attribute__((aligned(8))) int test = 0; + (void)test; + return 0; + }" + HAVE_ATTRIBUTE_ALIGNED FAIL_REGEX "aligned") +if(HAVE_ATTRIBUTE_ALIGNED) + add_definitions(-DHAVE_ATTRIBUTE_ALIGNED) +endif() + # # check for _Thread_local() support in the compiler # diff --git a/configure b/configure index 2c320227f..896b0b8a4 100755 --- a/configure +++ b/configure @@ -985,6 +985,22 @@ EOF fi fi +# Check for attribute(aligned) support in compiler +cat > $test.c << EOF +int main(void) { + __attribute__((aligned(8))) int test = 0; + (void)test; + return 0; +} +EOF +if try ${CC} ${CFLAGS} $test.c $LDSHAREDLIBC; then + echo "Checking for attribute(aligned) ... Yes." | tee -a configure.log + CFLAGS="$CFLAGS -DHAVE_ATTRIBUTE_ALIGNED" + SFLAGS="$SFLAGS -DHAVE_ATTRIBUTE_ALIGNED" +else + echo "Checking for attribute(aligned) ... No." | tee -a configure.log +fi + # Check for _Thread_local support in compiler cat > $test.c << EOF _Thread_local int test; diff --git a/zbuild.h b/zbuild.h index de1999cff..922b2cae2 100644 --- a/zbuild.h +++ b/zbuild.h @@ -190,7 +190,7 @@ # define UNLIKELY(x) x #endif /* (un)likely */ -#if defined(__clang__) || defined(__GNUC__) +#if defined(HAVE_ATTRIBUTE_ALIGNED) # define ALIGNED_(x) __attribute__ ((aligned(x))) #elif defined(_MSC_VER) # define ALIGNED_(x) __declspec(align(x))