From 741fd1cdf70ddbed13ffea5f37059b3947eab1dc Mon Sep 17 00:00:00 2001 From: lazerg Date: Wed, 5 Aug 2026 06:07:11 +0500 Subject: [PATCH 1/3] Fix GH-22206: avoid musttail in zend_runtime_jit() in the tail-call VM --- ext/opcache/jit/zend_jit.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index 76510743d333..fc1df982a577 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -3159,7 +3159,13 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV zend_runtime_jit(Z return; // ZEND_VM_CONTINUE #else opline = orig_opline; +# if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL + /* zend_try() uses setjmp(), which GCC 16 refuses to combine with the guaranteed + * tail call of ZEND_OPCODE_RETURN(); a plain call is fine for this cold path. */ + return ((zend_vm_opcode_handler_t)opline->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); +# else ZEND_OPCODE_RETURN(); +# endif #endif } From 5c3d09ac065c26ddabe8690eabf1e04c5f1fcbdc Mon Sep 17 00:00:00 2001 From: lazerg Date: Thu, 6 Aug 2026 15:02:38 +0500 Subject: [PATCH 2/3] Fix GH-22206: restrict the tail-call VM to Clang --- Zend/zend_vm_gen.php | 2 +- Zend/zend_vm_opcodes.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_vm_gen.php b/Zend/zend_vm_gen.php index 1ffa80f718dc..6e6349bee0ad 100755 --- a/Zend/zend_vm_gen.php +++ b/Zend/zend_vm_gen.php @@ -2523,7 +2523,7 @@ function gen_vm_opcodes_header( $str .= "# define ZEND_VM_KIND\t\tZEND_VM_KIND_HYBRID\n"; } if ($GLOBALS["vm_kind_name"][ZEND_VM_GEN_KIND] === "ZEND_VM_KIND_HYBRID" || $GLOBALS["vm_kind_name"][ZEND_VM_GEN_KIND] === "ZEND_VM_KIND_CALL") { - $str .= "#elif defined(HAVE_MUSTTAIL) && defined(HAVE_PRESERVE_NONE) && (defined(__x86_64__) || defined(__aarch64__))\n"; + $str .= "#elif defined(HAVE_MUSTTAIL) && defined(HAVE_PRESERVE_NONE) && (defined(__x86_64__) || defined(__aarch64__)) && defined(__clang__)\n"; $str .= "# define ZEND_VM_KIND\t\tZEND_VM_KIND_TAILCALL\n"; $str .= "#else\n"; $str .= "# define ZEND_VM_KIND\t\tZEND_VM_KIND_CALL\n"; diff --git a/Zend/zend_vm_opcodes.h b/Zend/zend_vm_opcodes.h index dae282705d53..34e24ec14b1e 100644 --- a/Zend/zend_vm_opcodes.h +++ b/Zend/zend_vm_opcodes.h @@ -42,7 +42,7 @@ static const char *const zend_vm_kind_name[] = { /* HYBRID requires support for computed GOTO and global register variables*/ #elif (defined(__GNUC__) && defined(HAVE_GCC_GLOBAL_REGS)) # define ZEND_VM_KIND ZEND_VM_KIND_HYBRID -#elif defined(HAVE_MUSTTAIL) && defined(HAVE_PRESERVE_NONE) && (defined(__x86_64__) || defined(__aarch64__)) +#elif defined(HAVE_MUSTTAIL) && defined(HAVE_PRESERVE_NONE) && (defined(__x86_64__) || defined(__aarch64__)) && defined(__clang__) # define ZEND_VM_KIND ZEND_VM_KIND_TAILCALL #else # define ZEND_VM_KIND ZEND_VM_KIND_CALL From d118828442999373af59130cdfee205a6bf48bb7 Mon Sep 17 00:00:00 2001 From: lazerg Date: Thu, 6 Aug 2026 15:57:13 +0500 Subject: [PATCH 3/3] Revert "Fix GH-22206: avoid musttail in zend_runtime_jit() in the tail-call VM" --- ext/opcache/jit/zend_jit.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index fc1df982a577..76510743d333 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -3159,13 +3159,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV zend_runtime_jit(Z return; // ZEND_VM_CONTINUE #else opline = orig_opline; -# if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL - /* zend_try() uses setjmp(), which GCC 16 refuses to combine with the guaranteed - * tail call of ZEND_OPCODE_RETURN(); a plain call is fine for this cold path. */ - return ((zend_vm_opcode_handler_t)opline->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); -# else ZEND_OPCODE_RETURN(); -# endif #endif }