From: Cameron Cawley Date: Thu, 29 Sep 2022 18:30:31 +0000 (+0100) Subject: Detect the availability of _Thread_local using a configure check X-Git-Tag: 2.1.0-beta1~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c118a14dd56d0484a8ca432cf801b9a6e6d024a;p=thirdparty%2Fzlib-ng.git Detect the availability of _Thread_local using a configure check --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2abeb69b6..20ca1beb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -386,6 +386,21 @@ if(HAVE_ATTRIBUTE_VISIBILITY_INTERNAL) add_definitions(-DHAVE_VISIBILITY_INTERNAL) endif() +# +# check for _Thread_local() support in the compiler +# +check_c_source_compiles( + "_Thread_local int test; + int main(void) { + (void)test; + return 0; + }" + HAVE_THREAD_LOCAL +) +if(HAVE_THREAD_LOCAL) + add_definitions(-DHAVE_THREAD_LOCAL) +endif() + # # check for __builtin_ctz() support in the compiler # @@ -401,6 +416,7 @@ check_c_source_compiles( if(HAVE_BUILTIN_CTZ) add_definitions(-DHAVE_BUILTIN_CTZ) endif() + # # check for __builtin_ctzll() support in the compiler # diff --git a/configure b/configure index 77005308c..a64e1403a 100755 --- a/configure +++ b/configure @@ -942,6 +942,22 @@ EOF fi fi +# Check for _Thread_local support in compiler +cat > $test.c << EOF +_Thread_local int test; +int main(void) { + (void)test; + return 0; +} +EOF +if try ${CC} ${CFLAGS} $test.c $LDSHAREDLIBC; then + echo "Checking for _Thread_local ... Yes." | tee -a configure.log + CFLAGS="$CFLAGS -DHAVE_THREAD_LOCAL" + SFLAGS="$SFLAGS -DHAVE_THREAD_LOCAL" +else + echo "Checking for _Thread_local ... No." | tee -a configure.log +fi + # Check for __builtin_ctz() support in compiler cat > $test.c << EOF int main(void) { diff --git a/zbuild.h b/zbuild.h index 384dace34..c96d48b31 100644 --- a/zbuild.h +++ b/zbuild.h @@ -27,7 +27,7 @@ /* Determine compiler support for TLS */ #ifndef Z_TLS -# if defined(STDC11) && !defined(__STDC_NO_THREADS__) +# ifdef HAVE_THREAD_LOCAL # define Z_TLS _Thread_local # elif defined(__GNUC__) || defined(__SUNPRO_C) # define Z_TLS __thread