Commit graph

121 commits

Author SHA1 Message Date
Niels Dossche
7a0beb4867
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18743: Incompatibility in Inline TLS Assembly on Alpine 3.22
2025-06-09 11:41:02 +02: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
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
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
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
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
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
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
28b448ac20
Fix GH-17307: Internal closure causes JIT failure
`bcadd(...)` is a closure for an internal function, and
`zend_jit_push_call_frame` takes into account both last_var and the
difference in argument numbers not only for user code but also for
internal code. However, this is inconsistent with
`zend_vm_calc_used_stack`, causing argument corruption.
Making this consistent fixes the issue.

I could only reproduce the assertion failure when using Valgrind.

Closes GH-17319.
2025-01-09 19:59:38 +01:00
Niels Dossche
f4fb77ed61
Fix GH-17257: UBSAN warning in ext/opcache/jit/zend_jit_vm_helpers.c
EX(opline) / opline can be stale if the IP is not stored, like in this
case on a trace enter. We always need to make sure that the opline is up
to date to make sure we don't use stale data.

Closes GH-17260.
2024-12-26 12:26:48 +01:00
Dmitry Stogov
f8d2e00964
Fix GH-17190: Assertion failure ext/opcache/jit/ir/ir_gcm.c (#17221) 2024-12-20 10:59:33 +03:00
Dmitry Stogov
6666cc83c5
Fix RC inference of op1 of FETCH_OBJ and INIT_METHOD_CALL
Fixes GH-17151
Closes GH-17152
2024-12-18 19:08:51 +01:00
Dmitry Stogov
ccc6c0f78c
Fix GH-15709: Crashing tests on Windows x64 (#17095)
This is a quick fix for the problem.
It'll work while all the JIT-ed functions have the same "fixed stack frame".
Unwinder uses hard-coded unwind data for this "fixed stack frame".

* Preallocate space for Win64 shadow args

* typo

* Setup unwinder for JIT functions

* Revert "Dynamically xfail test case which fails on CI"

This reverts commit 7cc327fd5a.

* Revert "Dynamically xfail test case which fails on CI"

This reverts commit bdde797159.

* Revert "Dynamically xfail test cases which fail on CI (GH-15710)"

This reverts commit 6d5962074f.

* Remove XFAIL sections

* Add hard-coded SEH unwind data for EXITCALL

* Fix unwind data

* Fix Windows multi-process support

* Typo
2024-12-13 02:05:45 +03:00
Dmitry Stogov
5ab2c02ea1
Fix GH-9011: Assertion failure with tracing JIT (#17042)
* Fix GH-9011: Assertion failure with tracing JIT

* Temporay SKIP the test on 64-bit Windows because of GH-15709
2024-12-04 19:49:17 +03:00
Dmitry Stogov
89b82ef709
Fix GH-16996: 8.4 tracing JIT phpseclib failures (#17030)
* Fix GH-16996: 8.4 tracing JIT phpseclib failures

This prevents conflicts caused by spilling to bound PHP stack slots by
creating copies.

* Fix build
2024-12-03 20:43:15 +03:00
Dmitry Stogov
03bb112fb2
Fix GH-16984: function JIT overflow bug (#17015) 2024-12-02 13:30:26 +03:00
Dmitry Stogov
b89d7ff92a
Fix GH-16821: runtime error: member access within misaligned address when running phpseclib tests (#16951) 2024-11-27 00:43:45 +03:00
Dmitry Stogov
d31de85f5f
Avoid possible spill conflict (one of the problem that caused GH-16821) (#16947) 2024-11-26 21:44:15 +03:00
Dmitry Stogov
7892a0ec8a
Fix GH-16913: 8.4 function JIT memory corruption (#16943)
with '#' will be ignored, and an empty message aborts the commit.
2024-11-26 16:59:57 +03:00
Niels Dossche
f4ca6d2794
Fix GH-16902: Set of opcache tests fail zts+aarch64 (8.4+)
Accompanying IR PR: https://github.com/dstogov/ir/pull/95

Closes GH-16924.
2024-11-25 19:51:01 +01:00
Dmitry Stogov
997431dea2
JIT: Set valid EX(opline) before calling gc_possible_root() 2024-11-18 19:31:26 +03:00
Niels Dossche
38e1b0ac8c
Fix GH-16572: Incorrect result with reflection in low-trigger JIT
When a recursive call happens with invalid arguments, the maximum valid
arguments are computed and stored in `num_args`, but the RECV entry
block we jump to is `call_num_args` instead. This can skip argument
validation checks. Fix this by using `num_args` instead.

Closes GH-16575.
2024-10-28 19:31:52 +01:00
Dmitry Stogov
8b5668efef
Fix invalid target opline with jit->reuse_ip active (#16457)
This is an alternative for #16440
2024-10-18 12:48:23 +03:00
Niels Dossche
daba40c695
Fix GH-16009: Segmentation fault with frameless functions and undefined CVs
The frameless function handlers do not update the op variables when
handling the result is undefined. In this case this causes propagating
an UNDEF value into a temporary, which results in an extra undefined
variable warning for a temporary in this case.

The original issue also reports a crash in some cases, which is also
fixed by this patch.

Closes GH-16012.
2024-09-24 21:20:35 +02: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
8f00430a2b
Fix GH-15972: Assertion failure in ext/opcache/jit/zend_jit_vm_helpers.c with function JIT (#16001) 2024-09-24 10:24:08 +03:00
Dmitry Stogov
b2eff1f2ce
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15973: Segmentation fault in JIT mode 1135 (#16006)
2024-09-23 17:13:47 +03:00
Peter Kokot
888eb370cf
Fix -Wundef/C4668 warnings (#15853)
- ZTS is either undefined or defined (to 1)
- PHP_WIN32 is either undefined or defined (to 1)
- HAVE_LIBEDIT is either undefined or defined (to 1)
2024-09-14 11:28:32 +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
Bob Weinand
25d761623c
Make internal run_time_cache a persistent allocation (#15040)
We also add zend_map_ptr_static, so that we do not incur the overhead of constantly recreating the internal run_time_cache pointers on each request.
This mechanism might be extended for mutable_data of internal classes too.
2024-09-07 01:45:26 +02:00
Levi Morrison
6435bb5ae1
Interrupt while internal frame is on the stack (#14627)
* Check VM interrupt while internal frame is on top

* Use tab instead of spaces

* fix frame used in interrupt and refactor

* remove unused failures for zend_jit_check_timeout

* Fix JIT support

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>

* Fix the missing store to vm_interrupt

* Rename new functions

* Special case zend_interrupt_function in JIT code

* refactor to use ZEND_VM_SET_OPCODE_NO_INTERRUPT

* Split atomic exchange into load + store

It is difficult to determine performance of atomics sometimes. In this
case, the separate load+store is still correct, and a load does not
cause a modification, and might be faster for some platforms than an
exchange. A load+store is slower than an exchange, but we're fine
trading the penalty to the slow path and keeping the happy path faster.

---------

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
2024-09-05 00:35:55 +02:00
Dmitry Stogov
faa1904fb6
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15652: Segmentation fault in the Zend engine when JIT enabled (#15717)
2024-09-02 21:59:14 +03:00
Arnaud Le Blanc
58aa6fc830
Lazy objects
RFC: https://wiki.php.net/rfc/lazy-objects

Closes GH-15019
2024-08-30 17:30:03 +02:00
Ilija Tovilo
8df557ac42
[RFC] Asymmetric visibility v2 (GH-15063)
Co-authored-by: Larry Garfield <larry@garfieldtech.com>
2024-08-27 02:04:48 +02: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
46ee0fb304
Disallow indirect modification on readonly properties within __clone() (#15012)
Indirect modification isn't allowed in __construct() because it allows
references to leak, so it doesn't make much sense to allow it in __clone().
2024-08-09 11:56:16 +02:00
Ilija Tovilo
7a2d5efa0f
[JIT] Avoid generating fast property assign path for readonly properties (#15260)
readonly properties will usually be IS_UNDEF on assignment, dodging the fast
path anyway. The fast path does not handle the readonly scope check. The
alternative would be handling scope there, but since there are some many
variants that might be more trouble than it's worth.
2024-08-09 11:49:40 +02:00
Dmitry Stogov
53b329e278
Fix GH-15101: _ir_RSTORE: Assertion `ctx->control' (#15153) 2024-07-29 19:17:25 +03:00
Ilija Tovilo
a0a8624346
Fix throw in IS_IDENTICAL in JIT (#15103)
We need to persist opline in case zend_is_identical() throws.
2024-07-25 13:18:47 +02:00
Ilija Tovilo
fdbe910b3b
Fix indirect readonly error messages (#14979)
$obj->ro[] = 42;, passByRef($obj->ro); and the likes should emit an indirect
modification error message. This message already existed but was used
inconsistently.
2024-07-16 23:24:07 +02: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
Peter Kokot
9e94d2b040
Autotools: Refactor builtin checks (#14835)
This creates a single M4 macro PHP_CHECK_BUILTIN and removes other
PHP_CHECK_BUILTIN_* macros. Checks are wrapped in AC_CACHE_CHECK and
PHP_HAVE_BUILTIN_* CPP macro definitions are defined to 1 if builtin
is found and undefined if not.

This also changes all PHP_HAVE_BUILTIN_ symbols to be either undefined
or defined (to value 1) and syncs all #if/ifdef/defined usages of them
in the php-src code. This way it is simpler to use them because they
don't need to be defined to value 0 on Windows, for example. This is
done as previous usages in php-src were mixed and on many places they
were only checked with ifdef.
2024-07-08 21:25:16 +02:00
Niels Dossche
fa5e29f7d0 Remove always-false if check
prop_info is NULL in this branch.
2024-07-02 02:51:18 -07:00
Niels Dossche
00691f4322 Remove always-true if check 2024-07-02 02:51:18 -07:00
Niels Dossche
00b36ce44a Remove always-false opcode check
opcode cannot be ZEND_POST_INC because of the if check above.
2024-07-02 02:51:18 -07:00
Benjamin Eberlei
72c874691b
RFC: Add #[\Deprecated] Attribute (#11293)
see https://wiki.php.net/rfc/deprecated_attribute

Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2024-07-02 09:44:25 +02:00
Peter Kokot
c44834d8ad
Trim trailing whitespace (#14721) 2024-06-29 18:41:45 +02:00