Skip to content

Commit 5882da2

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix phpGH-16829: Segmentation fault with opcache.jit=tracing enabled on aarch64
2 parents b112d27 + e55bf9a commit 5882da2

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

ext/opcache/jit/zend_jit_vm_helpers.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,15 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
961961
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
962962
if (UNEXPECTED(!jit_extension)
963963
|| UNEXPECTED(!(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE))) {
964-
stop = ZEND_JIT_TRACE_STOP_INTERPRETER;
964+
#ifdef HAVE_GCC_GLOBAL_REGS
965+
if (execute_data->prev_execute_data != prev_execute_data) {
966+
#else
967+
if (rc < 0) {
968+
#endif
969+
stop = ZEND_JIT_TRACE_STOP_RETURN;
970+
} else {
971+
stop = ZEND_JIT_TRACE_STOP_INTERPRETER;
972+
}
965973
break;
966974
}
967975
offset = jit_extension->offset;

ext/opcache/tests/jit/gh16829.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-16829 (Segmentation fault with opcache.jit=tracing enabled on aarch64)
3+
--INI--
4+
opcache.jit_buffer_size=32M
5+
--EXTENSIONS--
6+
opcache
7+
--FILE--
8+
<?php
9+
touch('gh16829_1.inc');
10+
require_once('gh16829_1.inc');
11+
?>
12+
DONE
13+
--EXPECT--
14+
DONE

ext/opcache/tests/jit/gh16829_1.inc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
# inline Reproducer class definition and segfaults will go away
3+
require_once('Reproducer.php');
4+
5+
# remove $someVar1\2 or $someVar3 and loop at the end of the file and segfaults will go away
6+
$someVar2 = null;
7+
$someVar1 = null;
8+
$someVar3 = [];
9+
10+
for ($i = 0; $i < 10; $i++) {
11+
Reproducer::loops();
12+
}
13+
14+
foreach ($someVar3 as $_) {
15+
}
16+
?>

ext/opcache/tests/jit/gh16829_2.inc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
class Reproducer
3+
{
4+
/**
5+
* Remove $params arg and segfaults will go away
6+
*/
7+
public static function loops(array $params = []): int
8+
{
9+
$arrCount = 2000;
10+
# Replace `$arrCount % 16` with 0 and segfaults will go away
11+
$arrCount2 = $arrCount - $arrCount % 16;
12+
$result = 0;
13+
14+
for ($baseIdx = 0; $baseIdx < $arrCount2; $baseIdx++) {
15+
}
16+
17+
while ($baseIdx < $arrCount) {
18+
}
19+
20+
return $result;
21+
}
22+
}
23+
?>

0 commit comments

Comments
 (0)