Skip to content

Commit 72184ab

Browse files
committed
Fix GH-15981: Segfault with frameless jumps and minimal JIT
Minimal JIT shouldn't generate a call to the complex handler, but instead rely on the VM and then check for a two-way jump. This moves the frameless codegen under the check `JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE`.
1 parent b666dc9 commit 72184ab

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ PHP NEWS
3636
- Intl:
3737
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)
3838

39+
- Opcache:
40+
. Fixed bug GH-15981 (Segfault with frameless jumps and minimal JIT).
41+
(nielsdos)
42+
3943
- PHPDBG:
4044
. Fix crashes in function registration + test. (nielsdos, Girgias)
4145

ext/opcache/jit/zend_jit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,11 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
24892489
goto jit_failure;
24902490
}
24912491
goto done;
2492+
case ZEND_JMP_FRAMELESS:
2493+
if (!zend_jit_jmp_frameless(&ctx, opline, /* exit_addr */ NULL, /* guard */ 0)) {
2494+
goto jit_failure;
2495+
}
2496+
goto done;
24922497
case ZEND_INIT_METHOD_CALL:
24932498
if (opline->op2_type != IS_CONST
24942499
|| Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) != IS_STRING) {
@@ -2644,17 +2649,13 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
26442649
case ZEND_FE_FETCH_R:
26452650
case ZEND_FE_FETCH_RW:
26462651
case ZEND_BIND_INIT_STATIC_OR_JMP:
2652+
case ZEND_JMP_FRAMELESS:
26472653
if (!zend_jit_handler(&ctx, opline,
26482654
zend_may_throw(opline, ssa_op, op_array, ssa)) ||
26492655
!zend_jit_cond_jmp(&ctx, opline + 1, ssa->cfg.blocks[b].successors[0])) {
26502656
goto jit_failure;
26512657
}
26522658
break;
2653-
case ZEND_JMP_FRAMELESS:
2654-
if (!zend_jit_jmp_frameless(&ctx, opline, /* exit_addr */ NULL, /* guard */ 0)) {
2655-
goto jit_failure;
2656-
}
2657-
break;
26582659
case ZEND_NEW:
26592660
if (!zend_jit_handler(&ctx, opline, 1)) {
26602661
return 0;

ext/opcache/tests/jit/gh15981.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-15981 (Segfault with frameless jumps and minimal JIT)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.jit=1111
7+
--FILE--
8+
<?php
9+
10+
namespace NS { // Namespace is important to reproduce the issue
11+
class Tester {
12+
static public function findExecutable(): string {
13+
return dirname(__DIR__);
14+
}
15+
}
16+
}
17+
18+
namespace {
19+
var_dump(NS\Tester::findExecutable());
20+
}
21+
22+
?>
23+
--EXPECTF--
24+
string(%d) "%s"

0 commit comments

Comments
 (0)