Skip to content

Commit c155949

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fixed GH-11127 (JIT fault)
2 parents 7e50735 + ed0b593 commit c155949

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
@@ -8734,7 +8734,17 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
87348734
| // if (CACHED_PTR(opline->result.num))
87358735
| ldr REG2, EX->run_time_cache
87368736
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, REG2, opline->result.num, TMP1
8737-
| cbz REG0, >1
8737+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
8738+
&& func
8739+
&& (func->common.fn_flags & ZEND_ACC_IMMUTABLE)
8740+
&& opline->opcode != ZEND_INIT_FCALL) {
8741+
/* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */
8742+
| LOAD_ADDR REG1, ((ptrdiff_t)func)
8743+
| cmp REG0, REG1
8744+
| bne >1
8745+
} else {
8746+
| cbz REG0, >1
8747+
}
87388748
|.cold_code
87398749
|1:
87408750
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
@@ -9369,8 +9369,28 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
93699369
| // if (CACHED_PTR(opline->result.num))
93709370
| mov r2, EX->run_time_cache
93719371
| mov r0, aword [r2 + opline->result.num]
9372-
| test r0, r0
9373-
| jz >1
9372+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
9373+
&& func
9374+
&& (func->common.fn_flags & ZEND_ACC_IMMUTABLE)
9375+
&& opline->opcode != ZEND_INIT_FCALL) {
9376+
/* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */
9377+
| .if X64
9378+
|| if (!IS_SIGNED_32BIT(func)) {
9379+
| mov64 r1, ((ptrdiff_t)func)
9380+
| cmp r0, r1
9381+
|| } else {
9382+
| cmp r0, func
9383+
|| }
9384+
| .else
9385+
| cmp r0, func
9386+
| .endif
9387+
| jnz >1
9388+
|.cold_code
9389+
|1:
9390+
} else {
9391+
| test r0, r0
9392+
| jz >1
9393+
}
93749394
|.cold_code
93759395
|1:
93769396
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)