Skip to content

Commit ed0b593

Browse files
authored
Fixed GH-11127 (JIT fault)
* Fixed GH-11127 (JIT fault) * Added test * Add new line
1 parent 25ad171 commit ed0b593

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
@@ -8836,7 +8836,17 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
88368836
| // if (CACHED_PTR(opline->result.num))
88378837
| ldr REG2, EX->run_time_cache
88388838
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, REG2, opline->result.num, TMP1
8839-
| cbz REG0, >1
8839+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
8840+
&& func
8841+
&& (func->common.fn_flags & ZEND_ACC_IMMUTABLE)
8842+
&& opline->opcode != ZEND_INIT_FCALL) {
8843+
/* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */
8844+
| LOAD_ADDR REG1, ((ptrdiff_t)func)
8845+
| cmp REG0, REG1
8846+
| bne >1
8847+
} else {
8848+
| cbz REG0, >1
8849+
}
88408850
|.cold_code
88418851
|1:
88428852
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
@@ -9453,8 +9453,28 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
94539453
| // if (CACHED_PTR(opline->result.num))
94549454
| mov r2, EX->run_time_cache
94559455
| mov r0, aword [r2 + opline->result.num]
9456-
| test r0, r0
9457-
| jz >1
9456+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
9457+
&& func
9458+
&& (func->common.fn_flags & ZEND_ACC_IMMUTABLE)
9459+
&& opline->opcode != ZEND_INIT_FCALL) {
9460+
/* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */
9461+
| .if X64
9462+
|| if (!IS_SIGNED_32BIT(func)) {
9463+
| mov64 r1, ((ptrdiff_t)func)
9464+
| cmp r0, r1
9465+
|| } else {
9466+
| cmp r0, func
9467+
|| }
9468+
| .else
9469+
| cmp r0, func
9470+
| .endif
9471+
| jnz >1
9472+
|.cold_code
9473+
|1:
9474+
} else {
9475+
| test r0, r0
9476+
| jz >1
9477+
}
94589478
|.cold_code
94599479
|1:
94609480
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)