From fcf8445f867f23d6249b09eb47679af439201075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 4 Oct 2025 19:54:08 +0200 Subject: [PATCH 1/2] /std:clatest for Windows --- win32/build/confutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/build/confutils.js b/win32/build/confutils.js index b6693df2a5c3d..611b62a415a7d 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -3255,7 +3255,7 @@ function toolset_setup_common_cflags() DEFINE('CFLAGS_PHP_OBJ', '$(CFLAGS_PHP) $(STATIC_EXT_CFLAGS)'); // General CFLAGS for building objects - DEFINE("CFLAGS", "/nologo $(BASE_INCLUDES) /D _WINDOWS /D WINDOWS=1 \ + DEFINE("CFLAGS", "/nologo /std:clatest $(BASE_INCLUDES) /D _WINDOWS /D WINDOWS=1 \ /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS \ /D _USE_MATH_DEFINES"); From eb2ed1163bd92783adb54a868798070a496cc008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 4 Oct 2025 19:20:05 +0200 Subject: [PATCH 2/2] =?UTF-8?q?TSRM:=20Replace=20`TSRM=5FTLS`=20by=20C11?= =?UTF-8?q?=E2=80=99s=20`thread=5Flocal`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TSRM/TSRM.c | 4 ++-- TSRM/TSRM.h | 19 +++++++++---------- Zend/zend_types.h | 4 ++-- ext/opcache/jit/tls/testing/def-vars.h | 2 +- ext/opcache/jit/tls/testing/def.c | 7 ++++++- ext/opcache/jit/tls/testing/main.c | 7 ++++++- ext/opcache/jit/tls/testing/user.c | 7 ++++++- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index e99993204b6f9..c899e4782e300 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -112,8 +112,8 @@ static pthread_key_t tls_key; # define tsrm_tls_get() pthread_getspecific(tls_key) #endif -TSRM_TLS bool in_main_thread = false; -TSRM_TLS bool is_thread_shutdown = false; +thread_local bool in_main_thread = false; +thread_local bool is_thread_shutdown = false; /* Startup TSRM (call once for the entire process) */ TSRM_API bool tsrm_startup(int expected_threads, int expected_resources, int debug_level, const char *debug_filename) diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index 80d6cbad04435..ab9f2f4f0abed 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -22,6 +22,11 @@ #include #include +#if __STDC_NO_THREADS__ +# define thread_local _Thread_local +#else +# include +#endif #ifdef TSRM_WIN32 # ifdef TSRM_EXPORTS @@ -142,12 +147,6 @@ TSRM_API bool tsrm_is_shutdown(void); TSRM_API const char *tsrm_api_name(void); TSRM_API bool tsrm_is_managed_thread(void); -#ifdef TSRM_WIN32 -# define TSRM_TLS __declspec(thread) -#else -# define TSRM_TLS __thread -#endif - #ifndef __has_attribute # define __has_attribute(x) 0 #endif @@ -175,10 +174,10 @@ TSRM_API bool tsrm_is_managed_thread(void); #define TSRMG_BULK_STATIC(id, type) ((type) (*((void ***) TSRMLS_CACHE))[TSRM_UNSHUFFLE_RSRC_ID(id)]) #define TSRMG_FAST_STATIC(offset, type, element) (TSRMG_FAST_BULK_STATIC(offset, type)->element) #define TSRMG_FAST_BULK_STATIC(offset, type) ((type) (((char*) TSRMLS_CACHE)+(offset))) -#define TSRMLS_MAIN_CACHE_EXTERN() extern TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR; -#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL; -#define TSRMLS_CACHE_EXTERN() extern TSRM_TLS void *TSRMLS_CACHE; -#define TSRMLS_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE = NULL; +#define TSRMLS_MAIN_CACHE_EXTERN() extern thread_local void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR; +#define TSRMLS_MAIN_CACHE_DEFINE() thread_local void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL; +#define TSRMLS_CACHE_EXTERN() extern thread_local void *TSRMLS_CACHE; +#define TSRMLS_CACHE_DEFINE() thread_local void *TSRMLS_CACHE = NULL; #define TSRMLS_CACHE_UPDATE() TSRMLS_CACHE = tsrm_get_ls_cache() #define TSRMLS_CACHE _tsrm_ls_cache diff --git a/Zend/zend_types.h b/Zend/zend_types.h index a3d3e4da6362d..e43ef5041cd38 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -77,8 +77,8 @@ typedef ZEND_RESULT_CODE zend_result; #endif #ifdef ZTS -#define ZEND_TLS static TSRM_TLS -#define ZEND_EXT_TLS TSRM_TLS +#define ZEND_TLS static thread_local +#define ZEND_EXT_TLS thread_local #else #define ZEND_TLS static #define ZEND_EXT_TLS diff --git a/ext/opcache/jit/tls/testing/def-vars.h b/ext/opcache/jit/tls/testing/def-vars.h index 66cdc2442b8cd..9b975363d32c6 100644 --- a/ext/opcache/jit/tls/testing/def-vars.h +++ b/ext/opcache/jit/tls/testing/def-vars.h @@ -1,7 +1,7 @@ /* Declare a few additional TLS variables to fill any surplus space, * so _tsrm_ls_cache is allocated in the dynamic section. */ -#define DEF_VAR(prefix, num) __thread void* prefix##num +#define DEF_VAR(prefix, num) thread_local void* prefix##num #define DEF_VARS(prefix) \ DEF_VAR(prefix, 0000); \ DEF_VAR(prefix, 0001); \ diff --git a/ext/opcache/jit/tls/testing/def.c b/ext/opcache/jit/tls/testing/def.c index f18d577e278a5..fe8e10416ae91 100644 --- a/ext/opcache/jit/tls/testing/def.c +++ b/ext/opcache/jit/tls/testing/def.c @@ -4,13 +4,18 @@ #include #include #include +#if __STDC_NO_THREADS__ +# define thread_local _Thread_local +#else +# include +#endif #ifdef NO_SURPLUS # include "def-vars.h" DEF_VARS(def); #endif -__thread void* _tsrm_ls_cache; +thread_local void* _tsrm_ls_cache; size_t tsrm_get_ls_cache_tcb_offset(void) { return 0; diff --git a/ext/opcache/jit/tls/testing/main.c b/ext/opcache/jit/tls/testing/main.c index 75d40ff7888ea..9d2125f59d43f 100644 --- a/ext/opcache/jit/tls/testing/main.c +++ b/ext/opcache/jit/tls/testing/main.c @@ -1,12 +1,17 @@ #include #include +#if __STDC_NO_THREADS__ +# define thread_local _Thread_local +#else +# include +#endif #ifdef NO_SURPLUS # include "def-vars.h" DEF_VARS(main); #endif -__thread int some_tls_var; +thread_local int some_tls_var; #ifndef DL_DECL int decl(void); diff --git a/ext/opcache/jit/tls/testing/user.c b/ext/opcache/jit/tls/testing/user.c index c27e608f3f4b1..80d696a18fc47 100644 --- a/ext/opcache/jit/tls/testing/user.c +++ b/ext/opcache/jit/tls/testing/user.c @@ -1,9 +1,14 @@ /* _tsrm_ls_cache is used / inspected here */ +#if __STDC_NO_THREADS__ +# define thread_local _Thread_local +#else +# include +#endif #include "../zend_jit_tls.h" -extern __thread void* _tsrm_ls_cache; +extern thread_local void* _tsrm_ls_cache; int test(void) {