Commit graph

6364 commits

Author SHA1 Message Date
Ilija Tovilo
bbd9732f83
Revert "Fix infinite recursion on deprecated attribute evaluation"
This reverts commit 272f7f75e2.

Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later
with a fix for GH-18463 (GH-18464).
2025-05-01 09:47:14 +09:00
Niels Dossche
1a1a83f1fc
Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64
On win64, xmm6-xmm15 are preserved registers, but the prologues and
epilogues of JITted code don't handle these. The issue occurs when
calling into the JIT code again via an internal handler
(like call_user_func). Therefore, we want to save/restore xmm registers
upon entering/leaving execute_ex. Since MSVC x64 does not support inline
assembly, we create an assembly wrapper around the real execute_ex
function.
The alternative is to always save/restore these xmm registers into the
fixed call frame, but this causes unnecessary overhead.
The same issue occurs for ARM64 platforms for floating point register
8 to 15. However, there we can use inline asm to fix this.

Closes GH-18352.
2025-04-21 13:15:43 +02:00
Florian Engelhardt
061b46e09d
Save opline in zend_jit_hot_func()
Closes GH-18289
2025-04-15 14:11:32 +02:00
Niels Dossche
14853ea2f2
Fix reproducibility of test GH-17190
The test failure did not trigger for me when playing with the JIT code.
From the original issue report some INI settings were not set properly.
2025-04-11 17:54:28 +02:00
Niels Dossche
4a12a9f3e9
Fix GH-18294: assertion failure zend_jit_ir.c
The JIT helper `zend_jit_assign_op_to_typed_ref` expects a `zval*` as an
argument, so we have to store to the stack if OP1_DATA(=op3) is in a
register.

Closes GH-18299.
2025-04-11 17:54:19 +02:00
Dmitry Stogov
79dc7a2d26
Update IR
IR commit: 8d17022fb61ebfed9f6be81a8182ea31202697ed
2025-04-02 16:20:09 +03:00
Dmitry Stogov
2b9840894d
Update IR
IR commit: dd228777b67334d8ed51de44f427d66d4ac99c08
2025-03-27 22:24:46 +03:00
Ilija Tovilo
272f7f75e2
Fix infinite recursion on deprecated attribute evaluation
Fixes GH-17711
Fixes GH-18022
Closes GH-17712
2025-03-26 23:39:38 +01:00
Ilija Tovilo
d5bdf8f508
Fix segfault when evaluating const expr default value of child prop with added hooks
Introduced by GH-17870. Not adding a NEWS entry since this is fixed in
the same version.

Fixes oss-fuzz #403816122
Closes GH-18098
2025-03-23 16:35:04 +01:00
Niels Dossche
7d1a2d03e4
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  [ci skip] Make sure opcache can output in these tests
2025-03-21 16:35:57 +01:00
Niels Dossche
071f707a6d
[ci skip] Make sure opcache can output in these tests 2025-03-21 16:35:47 +01:00
Niels Dossche
d765b60778
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18107: Opcache CFG jmp optimization with try-finally breaks the exception table
2025-03-21 13:57:16 +01:00
Niels Dossche
2ec8d37eb4
Fix GH-18107: Opcache CFG jmp optimization with try-finally breaks the exception table
If there's a try-finally where the try_op starts on a basic block with a
single JMP, and the JMP optimization causes that basic block to become
unreachable, then we update try_op.
In this case, there is no catch_op, so try_op is erroneously set to 0,
we should instead set it to `b->start`.

Closes GH-18110.
2025-03-21 13:56:31 +01:00
Niels Dossche
66498152f1
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18112: NULL access with preloading and INI option
2025-03-20 19:12:47 +01:00
Niels Dossche
e9c0296240
Fix GH-18112: NULL access with preloading and INI option
Preloading shutdown calls request shutdown which will deactivate the
virtual cwd state. However, further startup code still assumes the state
that was set by virtual_cwd_startup(). So we need to reactivate it
manually.

Creating a test was a bit difficult because the INI setting I wanted to
test this with is overridden by the test runner apparently.
To reproduce the issue, create an empty file test.php and execute this
in a ZTS build:
`php -d opcache.preload=./ext/opcache/tests/preload_class_alias_2.inc -d "error_log=" -d "allow_url_include=1" test.php`

Closes GH-18117.
2025-03-20 19:12:06 +01:00
Niels Dossche
9488684703
Add test for GH-18113
Fixed in https://github.com/dstogov/ir/pull/110 and merged via b932c267.

Closes GH-18113.
2025-03-19 23:49:43 +01:00
Dmitry Stogov
b932c267f8
Update IR
IR commit: 3d0124a06ee4321e1305f893b74840033d939e88
2025-03-20 01:10:56 +03:00
Ilija Tovilo
56841998de
Fix IN_ARRAY optimization
in_array() calls are compiled to frameless calls. Adjust the
optimization appropriately. Luckily, frameless opcodes simplify the
optimization quite a bit.

Fixes GH-18050
Closes GH-18066
2025-03-18 13:42:53 +01:00
Niels Dossche
f4ba3564f5
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Correct check for maximum string length in JIT helpers
2025-03-13 23:49:42 +01:00
Niels Dossche
413938143b
Fix GH-18037: SEGV Zend/zend_execute.c
A frameless icall with 3 arguments is a special case because it uses
OP_DATA, but this was not added to the list, so the opline pointed to
the wrong address resulting in UBSAN report or crash.

Closes GH-18048.
2025-03-13 23:48:24 +01:00
Niels Dossche
a7d2703246
Correct check for maximum string length in JIT helpers
This is a bit of a theoretical issue, but the maximum string length is
actually ZSTR_MAX_LEN instead of SIZE_MAX. The resulting check is a bit
slower but should still be relatively cheap.

Closes GH-18049.
2025-03-13 23:47:45 +01:00
Dmitry Stogov
ae67eb0490
Update IR
IR commit: 8bb0acca45a7b0f12691f4258e41462599efbd74
2025-03-13 03:07:43 +03:00
Dmitry Stogov
1b9d659c3f
Fix register allocarion for result of ASSIGN_OBJ (#17994)
This fixes few failures in Symfony unit tests with function JIT
2025-03-07 19:28:51 +03:00
Dmitry Stogov
5885b9490c
Fix function JIT for Wordpress unit tests 2025-03-07 02:30:30 +03:00
Niels Dossche
bac1ed6579
Add test for GH-17966
This was fixed via https://github.com/dstogov/ir/pull/109 which was
merged in cc70838dc9.
2025-03-06 21:55:53 +01:00
Dmitry Stogov
cc70838dc9
Merge IR
IR commit: 0441281e95ce9736131eddc71ce666389dcccd4b
2025-03-06 23:00:53 +03:00
Niels Dossche
f6c2e40a11
Fix GH-15834: Segfault with hook "simple get" cache slot and minimal JIT
The FETCH_OBJ_R VM handler has an optimization that directly enters into
a hook if it is a simpler getter hook. This is not compatible with the
minimal JIT because the minimal JIT will try to continue executing the
opcodes after the FETCH_OBJ_R.
To solve this, we check whether the opcode is still the expected one
after the execution of the VM handler. If it is not, we know that we are
going to execute a simple hook. In that case, exit to the VM.

Closes GH-17909.
2025-03-06 19:37:21 +01:00
Dmitry Stogov
f016caa312
Merge IR
IR commit: 1a02c4819f210a1f4548b83850ed7cd5c76c13aa
2025-03-03 23:48:08 +03:00
Niels Dossche
422e90db3b
Fix branch target in zend_jit_push_call_frame() (#17949)
Introduced by accident in 3b4a58da44.
Will request a cherry-pick.
2025-02-28 09:20:02 +01:00
Dmitry Stogov
819b1988a0
Update IR
IR commit: ca93e781eaf6b0949690d3df272ecf44528ff4a8
2025-02-25 02:23:05 +03:00
Niels Dossche
3b4a58da44
Backport GH-17869 to PHP 8.3 JIT
Closes GH-17918.
2025-02-24 21:45:03 +01:00
Niels Dossche
5ede5415e1
Fix GH-17868: Cannot allocate memory with tracing JIT on 8.4.4
The generated code tries to initialize the run time cache for even
internal closures, but it should only initialize the run time cache for
user closures. We fix this by adding a check for the function type.
If `func` is known, then we can check the type at code generation time.

Closes GH-17869.
2025-02-24 19:36:13 +01:00
Bob Weinand
53fa98ecd3
Fix GH-17715: Handle preloaded internal function runtime cache (#17835)
This solely affects the builtin enum functions currently.

Given that these are stored in SHM, we cannot simply hardwire a pointer into the internal function runtime cache on NTS too, but have to use a MAP_PTR (like on ZTS).
Now, by design, the runtime cache of internal functions no longer is reset between requests, hence we need to store them explicitly as static runtime cache.

On NTS builds we cannot trivially move the pointers into CG(internal_run_time_cache) as they're directly stored on the individual functions (on ZTS we could simply iterate the static map_ptrs).
Hence, we have the choice between having opcache managing the internal run_time_cache for its preloaded functions itself or realloc CG(internal_run_time_cache) and iterate through all functions to assign the new address. We choose the latter for simplicity and initial speed.
2025-02-24 14:35:47 +01:00
David Carlier
e8dda54dd5
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-23 10:45:46 +00:00
David Carlier
cefdf00e7e
Fix GH-17899: zend_test_compile_string crash on invalid script path.
when opcache is enabled.

close GH-17901
2025-02-23 10:45:10 +00:00
Dmitry Stogov
dd404dc419
Update IR
IR commit: 1499748be439e7f786c0ee2c4f738c126af57df8
2025-02-20 23:58:08 +03:00
Dmitry Stogov
352aca1ee1
Update IR
IR commit: 7f920cb660a1ef615a3059eab77b86ca1a43121e
2025-02-18 21:32:17 +03:00
Niels Dossche
34d8befe8d
Fix GH-17747: Exception on reading property in register-based FETCH_OBJ_R breaks JIT
When read_property fails, it may return `&EG(uninitialized_zval)`, and
the exception is handled in the VM. The VM will try to
`zval_ptr_dtor_nogc` the result, but the result was never set, resulting
in dtor'ing garbage data. To solve this, we check when a different zval*
was returned and initialize the result with UNDEF. We don't need to copy
as the slow_ex handler return values are used directly in a register.

Closes GH-17749.
2025-02-11 21:55:23 +01:00
Dmitry Stogov
9fb355b863
Update IR
IR commit: 8ec4979470fe2a123d0e56da92aa8d5d19b6e54c
2025-02-10 16:47:47 +03:00
Dmitry Stogov
c730175be8
IR Update
IR commit: 36329a0398ff57929c51c52084027730a75b9862
2025-02-06 02:04:03 +03:00
Niels Dossche
78da288222
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17577: JIT packed type guard crash
2025-02-03 19:35:32 +01:00
Niels Dossche
0c3cf1f311
Fix GH-17577: JIT packed type guard crash
When a guard check is created for a variable to check if it's a packed array,
it is possible that there was no prior type check for that variable.
This happens in the global scope for example when the variable aliases.
In the test, this causes a dereference of address 8 because the integer
element in `$a` is interpreted as an array address.

This patch adds a check to see if the guard is handled.
If we were not able to determine or guard the type then we also cannot know the array is packed.

Closes GH-17584.
2025-02-03 19:34:39 +01:00
Niels Dossche
6d6380c09d
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17654: Multiple classes using same trait causes function JIT crash
2025-02-03 19:28:20 +01:00
Niels Dossche
f88445bdf8
Fix GH-17654: Multiple classes using same trait causes function JIT crash
This test has two classes that use the same trait. In function JIT mode
the same cache slot will be used. This causes problems because it is
primed for the first class and then reused for the second class,
resulting in an incorrect type check failure.

The current check for a megamorphic trait call requires current_frame to
not be NULL, but this is only set in tracing mode and not in function
mode.

This patch corrects the check.

Closes GH-17660.
2025-02-03 19:21:15 +01:00
Ilija Tovilo
ac42a8de75
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix missing GC_PERSISTENT_LOCAL flag on accel_globals.key
2025-01-28 12:55:55 +01:00
Ilija Tovilo
2ad778bc76
Fix missing GC_PERSISTENT_LOCAL flag on accel_globals.key 2025-01-28 12:55:09 +01:00
Ilija Tovilo
1432a13413
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix inline zend_string using struct padding
2025-01-27 19:51:47 +01:00
Ilija Tovilo
8ea9b04a23
Fix inline zend_string using struct padding
As explained by Snape3058: On 64-bit machines, we typically have 7 bytes
of padding between the zend_string.val[0] char and the following char[].
This means that zend_string.val[1-7] write to and read from the struct
padding, which is a bad idea.

Allocate the given string separately instead.

Fixes GH-17564
Closes GH-17576
2025-01-27 19:50:38 +01:00
Dmitry Stogov
63965f1de5
Update IR
IR commit: 02909bc123845fc2c41ec333b44b6f5ea1a196fe
2025-01-22 18:30:33 +03:00
Dmitry Stogov
9aaa469f99
Update IR
IR commit: d6d7fc489137aab218b04b59d770b497c5ae3832
2025-01-15 02:45:24 +03:00