[php-src] master: Merge branch 'PHP-8.6'
| From: | Arnaud Le Blanc | Date: | Thu, 22 Oct 2026 09:44:36 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142556@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-10-22T11:44:23+02:00
Commit: https://github.com/php/php-src/commit/a330119ddc62cbddb8571388122ec9ac9dfcf3ca
Raw diff: https://github.com/php/php-src/commit/a330119ddc62cbddb8571388122ec9ac9dfcf3ca.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
JIT: Fix TLS access with SHM reattachment (8.6 follow-up) (#24456)
Changed paths:
M ext/opcache/jit/zend_jit_ir.c
Diff:
diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c
index 69b57bfdc8a3..15278b16f810 100644
--- a/ext/opcache/jit/zend_jit_ir.c
+++ b/ext/opcache/jit/zend_jit_ir.c
@@ -357,6 +357,8 @@ static int zend_jit_assign_to_variable(zend_jit_ctx *jit,
static ir_ref jit_CONST_FUNC(zend_jit_ctx *jit, uintptr_t addr, uint16_t flags);
+static ir_ref jit_ADD_OFFSET(zend_jit_ctx *jit, ir_ref addr, uintptr_t offset);
+
static void zend_jit_preserve_parent_regs(zend_jit_ctx *jit,
zend_ssa *ssa,
zend_jit_trace_info *parent,
@@ -519,9 +521,28 @@ static ir_ref jit_TLS(zend_jit_ctx *jit)
if (tsrm_ls_cache_tcb_offset == 0 && tsrm_tls_index == -1) {
jit->tls = ir_CALL(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_get_tsrm_ls_cache));
} else {
+# ifdef ZEND_OPCACHE_SHM_REATTACHMENT
+ /* Different processes may load TLS variables in a different order, so
+ * they may have a different module index. Fetch the module index at
+ * runtime from tsrm_tls_index. Its address is stable as it's in the same
+ * module as execute_ex (whose address is checked before SHM reattachment). */
+
+# ifdef _WIN64
+ const int offset = 0x58;
+# else
+ const int offset = 0x2c;
+# endif
+
+ /* NtCurrentTeb()->ThreadLocalStoragePointer */
+ ir_ref tls_array = ir_TLS(-1, offset);
+
+ ir_ref index = ir_LOAD_A(ir_CONST_ADDR(&tsrm_tls_index));
+ jit->tls = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(ir_ADD_A(tls_array, index)), tsrm_tls_offset));
+# else
jit->tls = ir_TLS(
tsrm_ls_cache_tcb_offset ? tsrm_ls_cache_tcb_offset : tsrm_tls_index,
tsrm_ls_cache_tcb_offset ? IR_NULL : tsrm_tls_offset);
+# endif
}
return jit->tls;
@@ -3390,10 +3411,6 @@ static void zend_jit_setup(bool reattached)
#endif
#ifdef ZTS
-# ifdef ZEND_OPCACHE_SHM_REATTACHMENT
- /* Different processes may load TLS variables in a different order, so we
- * can not rely on offsets. We will fallback to runtime resolution. */
-# else
zend_result result = zend_jit_resolve_tsrm_ls_cache_offsets(
&tsrm_ls_cache_tcb_offset,
&tsrm_tls_index,
@@ -3403,7 +3420,6 @@ static void zend_jit_setup(bool reattached)
zend_accel_error(ACCEL_LOG_INFO,
"Could not get _tsrm_ls_cache offsets, will fallback to runtime resolution");
}
-# endif
#endif
#if !defined(ZEND_WIN32) && !defined(IR_TARGET_AARCH64)