[php-src] PHP-8.5: zend_jit_resolve_tsrm_ls_cache_offsets: clobber volatile registers (#22832)

Arnaud Le Blanc via GitHub <[email protected]> Tue, 21 Jul 2026 17:08:28 +0000
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Arnaud Le Blanc (arnaud-lb)
Committer: GitHub (web-flow)
Pusher: arnaud-lb
Date: 2026-07-21T19:08:25+02:00

Commit: https://github.com/php/php-src/commit/8c96f53d91c594a7fa0d9d95ec78c1e42250dcb4
Raw diff: https://github.com/php/php-src/commit/8c96f53d91c594a7fa0d9d95ec78c1e42250dcb4.diff

zend_jit_resolve_tsrm_ls_cache_offsets: clobber volatile registers (#22832)

Changed paths:
  M  ext/opcache/jit/tls/zend_jit_tls_aarch64.c
  M  ext/opcache/jit/tls/zend_jit_tls_x86.c
  M  ext/opcache/jit/tls/zend_jit_tls_x86_64.c


Diff:

diff --git a/ext/opcache/jit/tls/zend_jit_tls_aarch64.c b/ext/opcache/jit/tls/zend_jit_tls_aarch64.c
index 24f0f88454b6..43be504aeff9 100644
--- a/ext/opcache/jit/tls/zend_jit_tls_aarch64.c
+++ b/ext/opcache/jit/tls/zend_jit_tls_aarch64.c
@@ -126,7 +126,9 @@ zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
 		"add   %2, x8, x0\n"
 		: "=r" (thread_pointer), "=r" (insn), "=r" (addr)
 		:
-		: "x0", "x1", "x8");
+		/* Resolver call clobbers only a few registers: https://github.com/ARM-software/abi-aa/blob/ee4b3c12d57c8424ff60c2ae56e10690d0604ab6/sysvabi64/sysvabi64.rst#calling-convention.
+		 * We also clobber x8. */
+		: "x0", "x1", "x8", "x30", "cc", "memory");
 
 	ZEND_ASSERT(addr == &_tsrm_ls_cache);
 
diff --git a/ext/opcache/jit/tls/zend_jit_tls_x86.c b/ext/opcache/jit/tls/zend_jit_tls_x86.c
index 4e06bbd1eacd..04ab195b708a 100644
--- a/ext/opcache/jit/tls/zend_jit_tls_x86.c
+++ b/ext/opcache/jit/tls/zend_jit_tls_x86.c
@@ -110,6 +110,12 @@ zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
 		/* Load thread pointer address */
 		"movl   %%gs:0, %%ebx\n"
 		: "=a" (t_addr), "=S" (code), "=b" (thread_pointer)
+		:
+		/* call may clobber volatile registers */
+		: "ecx", "edx",
+		  "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
+		  "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
+		  "cc", "memory"
 	);
 
 	ZEND_ASSERT(t_addr == &_tsrm_ls_cache);
diff --git a/ext/opcache/jit/tls/zend_jit_tls_x86_64.c b/ext/opcache/jit/tls/zend_jit_tls_x86_64.c
index bea2968ffd21..ad5af6c5be57 100644
--- a/ext/opcache/jit/tls/zend_jit_tls_x86_64.c
+++ b/ext/opcache/jit/tls/zend_jit_tls_x86_64.c
@@ -106,6 +106,14 @@ zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
 		/* Load thread pointer address */
 		"movq   %%fs:0, %%rsi\n"
 		: "=a" (addr), "=b" (code), "=S" (thread_pointer)
+		:
+		/* call may clobber volatile registers */
+		: "rcx", "rdx", "rdi",
+		  "r8", "r9", "r10", "r11",
+		  "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
+		  "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
+		  "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
+		  "cc", "memory"
 	);
 
 	ZEND_ASSERT(addr == &_tsrm_ls_cache);