1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Commit Graph

615 Commits

Author SHA1 Message Date
Ilia Alshanetsky
80dc4c19d6 Fix GH-20838: JIT compiler produces wrong arithmetic results (#21383)
Insert type guards (CHECK_OP1_TRACE_TYPE / CHECK_OP2_TRACE_TYPE) on the
sensitive bailout paths in ADD/SUB/MUL JIT compilation: the MAY_BE_UNDEF
and non-numeric operand breaks. Guards are only emitted when the traced
operand type is IS_LONG or IS_DOUBLE, ensuring TSSA result type
predictions stay valid for side traces without affecting the normal
numeric fast path.


Fixes GH-20838

Co-authored-by: Dmitry Stogov <dmitrystogov@gmail.com>
2026-03-11 15:22:50 +03:00
Niels Dossche
32c0245531 Revert "Fix GH-20890: Segfault in zval_undefined_cv with non-simple property hook with minimal tracing JIT"
This reverts commit 57c62eb2b3.
2026-01-20 21:05:26 +01:00
Niels Dossche
57c62eb2b3 Fix GH-20890: Segfault in zval_undefined_cv with non-simple property hook with minimal tracing JIT
This is similar to f6c2e40a11 but for minimal JIT + tracing JIT.
Most of the times the tracing JIT shouldn't rely on going to the VM, but
in some cases, like in minimal JIT, it can and then it hits the same
bug.

Closes GH-20897.
2026-01-20 18:55:08 +01:00
Dmitry Stogov
d59ae9345c Cleanup SSA(s) in case of fatal error during tracing JIT
This fixes segfault becuse of UAF in ext/standard/tests/gh14643_longname.phpt
2025-09-02 10:04:40 +03:00
Arnaud Le Blanc
18276a8b42 Snapshotted poly_func / poly_this may be spilled
Polymorphic calls pass this and the function to side traces via snapshotting.
However, we assume that this/func are in registers, when in fact they may be
spilled.

Here I update snapshotting of poly_func/poly_this to support spilling:

 - In zend_jit_snapshot_handler, keep track of the C stack offset
   of the spilled register, in a way similar to how stack variables.
 - In zend_jit_start, do not pre-load the registers if they were spilled.
 - In zend_jit_trace_exit / zend_jit_trace_deoptimization, load from the
   stack if the register was spilled.
 - Store a reference to poly_func/poly_this in zend_jit_ctx so we can use that
   directly in the side trace.

Closes GH-18408
2025-05-14 12:27:57 +02:00
Arnaud Le Blanc
978c01ce15 JIT: Check exception on exit
Add a new exit flag (ZEND_JIT_EXIT_CHECK_EXCEPTION) that enables exception
checking during exit/deoptimization.

We already checked for exceptions during exit/deoptimization, but only when
ZEND_JIT_EXIT_FREE_OP1 or ZEND_JIT_EXIT_FREE_OP2 were set (presumably to
handle exceptions thrown during dtor). The new flag makes it possible to request
it explicitly.

This also fixes two issues in zend_jit_trace_exit():

- By returning 1, we were telling the caller (zend_jit_trace_exit_stub()) to
  execute the original op handler of EG(current_execute_data)->opline, but in
  reality we want to execute EX(opline), which should be EG(exception_op).

- EX(opline) is set to the value of %r15 in zend_jit_trace_exit_stub() before
  calling zend_jit_trace_exit(), but this may be the address of a
  zend_execute_data when the register is being reused to cache EX(call).

Fixes GH-18262
Closes GH-18297
2025-04-29 10:55:31 +02: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
2104097a79 Fix GH-17140 (Assertion failure in JIT trace exit with ZEND_FETCH_DIM_FUNC_ARG)
ZEND_FETCH_DIM_FUNC_ARG should also be repeated on undefined access,
consistent to how ZEND_FETCH_DIM_R is handled. The opcode was just
missing from the assertion list.

Closes GH-17148.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2024-12-16 19:46:11 +01:00
Dmitry Stogov
c5ce74c88c Fix GH-17003: Pecl 8.4 tracing JIT crash (#17032) 2024-12-03 20:42:27 +03:00
Niels Dossche
ed556939df Extract call_level conditions out to separate functions (#16949)
These are repeated a couple of times, so centralise it in 2 functions to
reduce repetition and make updating this less error-prone.
2024-11-26 21:22:12 +01:00
Dmitry Stogov
d0c336a666 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Use the immutable twin of temporary op_array (#16861)
2024-11-19 20:55:40 +03:00
Dmitry Stogov
d1a9281814 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Use the immutable twin of temporary op_array (#16861)
2024-11-19 20:55:32 +03:00
Dmitry Stogov
ef5844a1ca Use the immutable twin of temporary op_array (#16861) 2024-11-19 20:55:15 +03:00
Niels Dossche
4767c0626c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16770: Tracing JIT type mismatch when returning UNDEF
2024-11-14 22:34:12 +01:00
Niels Dossche
0bf74bf9d8 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16770: Tracing JIT type mismatch when returning UNDEF
2024-11-14 22:34:05 +01:00
Niels Dossche
cbb3b9371d Fix GH-16770: Tracing JIT type mismatch when returning UNDEF
When returning an UNDEF value, it actually becomes NULL.
The following code took this into account:
28344e0445/ext/opcache/jit/zend_jit_trace.c (L2196-L2199)

But the stack does not update the type to NULL, causing a mismatch.

Closes GH-16784.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2024-11-14 22:33:06 +01:00
Dmitry Stogov
f6256fa2c0 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix incorrect handling of ZEND_ACC_FINAL flag in JIT (#16778)
2024-11-13 14:43:43 +03:00
Dmitry Stogov
b9c6f07713 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix incorrect handling of ZEND_ACC_FINAL flag in JIT (#16778)
2024-11-13 14:39:18 +03:00
Dmitry Stogov
19809a526b Fix incorrect handling of ZEND_ACC_FINAL flag in JIT (#16778) 2024-11-13 14:38:54 +03:00
Dmitry Stogov
ddc49153f1 Improve JIT TRACE coverage (#16171)
Now it's possible that PHP tracing JIT loses some parts of the "hot"
code. In case we have a root LOOP trace with an inlined call of some
function, and we get a SIDE exit inside that function - we recorded a
side trace, but finished it a the RETURN of the inlined function. As
result the opcodes betwee RETURN from SIDE trace and LOOP exit were not
covered by tracer and were executed in interpreter.

This patch introduces a "ret_depth" argument that prevents stopping
tracing on RETURN of such SIDE trace.
2024-10-02 19:27:31 +03:00
Dmitry Stogov
b8ac4ca19d Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix possible NULL dereference
2024-09-26 15:44:16 +03:00
Dmitry Stogov
8b7f64fa41 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix possible NULL dereference
2024-09-26 15:44:05 +03:00
Dmitry Stogov
24d5912a30 Fix possible NULL dereference 2024-09-26 15:43:42 +03:00
Bob Weinand
654b787ee1 Add API to exempt function from being traced in JIT (#15559)
Internally accessible via zend_jit_blacklist_function / externally via opcache_jit_blacklist.
The functionality currently only affects tracing JIT, but may be extended to other JIT modes in future.
2024-09-24 14:20:38 +02:00
Dmitry Stogov
98f07fcfca Fix more issues reported in GH-15852
* Fix incorrect register allocation

* Avoid IR binding/spilling conflict

* Add missing type guard
2024-09-12 20:19:11 +03:00
Dmitry Stogov
4c11168f60 Fix GH-15656: php8.4beta4 JIT erronous results (#15732)
* Improve trace SSA construction and type inference

* Fix incorrect abstract stack maintenance

* Add missing register store

* Avoid IR binding for the dangerous case

* Fix access to possibly uninitilezed variable

* Improve trace SSA construction and type inference

* Fix IR constuction

Force load values into regesters before any branches to guarantee SSA
dominance property
2024-09-09 09:28:57 +03:00
Dmitry Stogov
16d4fb19a9 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15502: Crash with JIT and Excimer (#15601)
2024-08-27 21:12:53 +03:00
Dmitry Stogov
12b854f91b Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15502: Crash with JIT and Excimer (#15601)
2024-08-27 21:12:43 +03:00
Dmitry Stogov
eb87de1c87 Fix GH-15502: Crash with JIT and Excimer (#15601) 2024-08-27 21:12:29 +03:00
Gina Peter Banyard
a79c70f574 [RFC] Convert exit (and die) from language constructs to functions (#13483)
RFC: https://wiki.php.net/rfc/exit-as-function
2024-08-14 12:44:12 +01:00
Ilija Tovilo
780a8280d2 [RFC] Property hooks (#13455)
RFC: https://wiki.php.net/rfc/property-hooks

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2024-07-14 11:55:03 +02:00
Dmitry Stogov
1f48715798 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14475: PHP 8.3.7 with JIT encounters infinite loop on specific paths (#14558)
2024-06-17 09:38:17 +03:00
Dmitry Stogov
e842ddfe4f Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14475: PHP 8.3.7 with JIT encounters infinite loop on specific paths (#14558)
2024-06-17 09:38:02 +03:00
Dmitry Stogov
350af549a0 Fix GH-14475: PHP 8.3.7 with JIT encounters infinite loop on specific paths (#14558) 2024-06-17 09:37:44 +03:00
Dmitry Stogov
5109cf1010 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix incorrect conditions
2024-05-28 08:38:00 +03:00
Dmitry Stogov
034bd85ad1 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix incorrect conditions
2024-05-28 08:37:48 +03:00
Dmitry Stogov
48ae025c33 Fix incorrect conditions 2024-05-28 08:37:20 +03:00
Dmitry Stogov
58c281a6cf JIT: Add CPU registers support for ASSIGN_OBJ and ASSIGN_OBJ_OP (#14303)
* JIT: Add CPU registers support for ASSIGN_OBJ and ASSIGN_OBJ_OP

* Fix tests failures

* Fix tests failures

* Add missing GUARD
2024-05-23 19:25:06 +03:00
Dmitry Stogov
ace18f4919 JIT: Avoid IS_UNDEF check for ZEND_FETCH_DIM/OBJ_IS with a result type guard (#14298) 2024-05-22 17:33:40 +03:00
Dmitry Stogov
13d5c812e0 JIT: Add CPU registers support for FETCH_OBJ_R (#14253) 2024-05-19 22:18:30 +03:00
Ilija Tovilo
600d591cae Omit FETCH_THIS in closures
Non-static closures are guaranteed to have $this. The existing comment
highlights this, but fails to handle it correctly.

Closes GH-14181
2024-05-16 12:28:11 +02:00
Dmitry Stogov
7843e72f3b JIT: Avoid useless EG(exception) check in ASSIGN_DIM_OP (#14247) 2024-05-15 21:31:44 +03:00
Dmitry Stogov
5ef1824ebc JIT: Improve x86_64 code generated for PHP Array Bounds Checks (#14246) 2024-05-15 16:38:23 +03:00
Dmitry Stogov
0eb68eb8d8 JIT: Fix incorrect deoptimization info
Fixes third recently introduced failure in "Nightly" "master_COMMUNUTY_asan" job
2024-05-15 14:22:20 +03:00
Dmitry Stogov
273c2de6a7 JIT: Fix incorrect PHP register allocation
Fixes 2 of 3 recently introduced failures in "Nightly"
"master_COMMUNUTY_asan" job
2024-05-15 12:46:58 +03:00
Dmitry Stogov
446ff6a742 JIT: Implement CPU register usage for ASSIGN_DIM_OP (#14236) 2024-05-14 23:35:31 +03:00
Dmitry Stogov
4a91c8a1be JIT: Implement CPU register usage for ASSIGN_OP (#14235) 2024-05-14 22:54:00 +03:00
Dmitry Stogov
c8920aaf94 JIT: JIT: Implement CPU register usage for ISSET_ISEMPTY_DIM (#14227) 2024-05-14 14:05:04 +03:00
Dmitry Stogov
64f4aca6ba IT: Implement CPU register usage for FETCH_DIM_W (#14225) 2024-05-14 13:19:56 +03:00