Skip to content

Commit 56d1cc7

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fixed GH-11127 (JIT fault)
2 parents 0e5ac62 + c155949 commit 56d1cc7

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8749,7 +8749,17 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
87498749
| // if (CACHED_PTR(opline->result.num))
87508750
| ldr REG2, EX->run_time_cache
87518751
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, REG2, opline->result.num, TMP1
8752-
| cbz REG0, >1
8752+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
8753+
&& func
8754+
&& (func->common.fn_flags & ZEND_ACC_IMMUTABLE)
8755+
&& opline->opcode != ZEND_INIT_FCALL) {
8756+
/* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */
8757+
| LOAD_ADDR REG1, ((ptrdiff_t)func)
8758+
| cmp REG0, REG1
8759+
| bne >1
8760+
} else {
8761+
| cbz REG0, >1
8762+
}
87538763
|.cold_code
87548764
|1:
87558765
if (opline->opcode == ZEND_INIT_FCALL

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9392,8 +9392,28 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
93929392
| // if (CACHED_PTR(opline->result.num))
93939393
| mov r2, EX->run_time_cache
93949394
| mov r0, aword [r2 + opline->result.num]
9395-
| test r0, r0
9396-
| jz >1
9395+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
9396+
&& func
9397+
&& (func->common.fn_flags & ZEND_ACC_IMMUTABLE)
9398+
&& opline->opcode != ZEND_INIT_FCALL) {
9399+
/* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */
9400+
| .if X64
9401+
|| if (!IS_SIGNED_32BIT(func)) {
9402+
| mov64 r1, ((ptrdiff_t)func)
9403+
| cmp r0, r1
9404+
|| } else {
9405+
| cmp r0, func
9406+
|| }
9407+
| .else
9408+
| cmp r0, func
9409+
| .endif
9410+
| jnz >1
9411+
|.cold_code
9412+
|1:
9413+
} else {
9414+
| test r0, r0
9415+
| jz >1
9416+
}
93979417
|.cold_code
93989418
|1:
93999419
if (opline->opcode == ZEND_INIT_FCALL
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
define('C', '1');
3+
function f($u) {
4+
return $u==C ? '0' : '1';
5+
}
6+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
JIT INIT_FCALL: 003 incorrect init fcall guard (fail with tracing JIT and --repeat 3)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.jit_max_polymorphic_calls=0
9+
opcache.jit=tracing
10+
opcache.jit_hot_loop=64
11+
opcache.jit_hot_func=127
12+
opcache.jit_hot_return=8
13+
opcache.jit_hot_side_exit=8
14+
--FILE--
15+
<?php
16+
include(__DIR__ . '/init_fcall_003.inc');
17+
for($a=1; $a<100; $a++){
18+
f('1');
19+
f('1');
20+
f('1');
21+
}
22+
touch(__DIR__ . '/init_fcall_003.inc');
23+
opcache_invalidate(__DIR__ . '/init_fcall_003.inc', true);
24+
?>
25+
DONE
26+
--EXPECT--
27+
DONE

0 commit comments

Comments
 (0)