Commit Graph

335 Commits

Author SHA1 Message Date
Max Kellermann
d5c649b36b
zend_compiler, ...: use uint8_t instead of zend_uchar (#10621)
`zend_uchar` suggests that the value is an ASCII character, but here,
it's about very small integers.  This is misleading, so let's use a
C99 integer instead.

On all architectures currently supported by PHP, `zend_uchar` and
`uint8_t` are identical.  This change is only about code readability.
2023-02-23 14:56:54 +00:00
Ilija Tovilo
02bd52b5a8
Implement dynamic class const fetch
https://wiki.php.net/rfc/dynamic_class_constant_fetch

Closes GH-9793
2023-01-26 16:46:34 +01:00
Ilija Tovilo
3f7ec69b61
Collapse more generated files in PRs (#8754)
* The generated VM files
* tokenizer_data.c
2022-06-12 10:56:35 +02:00
Bob Weinand
b4285e5546 Ensure vm_spec_handlers exists for all opcodes <= 255 so that user defined higher opcodes do not read outside buffer
This largely has no effect in practice, but ASAN will complain then.
2022-05-25 11:28:34 +02:00
Ilija Tovilo
9a90bd7054
Deprecate ${} string interpolation
https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
2022-05-05 10:14:56 +02:00
Nikita Popov
55a4bae546 Merge branch 'PHP-8.1'
* PHP-8.1:
  Handle holes in zend_get_opcode_id()
2021-12-30 16:56:10 +01:00
Nikita Popov
b63e4cf727 Handle holes in zend_get_opcode_id()
Some opcodes may currently not be allocated.
2021-12-30 16:56:03 +01:00
Dmitry Stogov
c8dca00d15 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix clobering of operand by error handler in assignment to string offset
2021-12-02 01:22:15 +03:00
Dmitry Stogov
9786eac9a3 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix clobering of operand by error handler in assignment to string offset
2021-12-02 00:46:27 +03:00
Dmitry Stogov
09547c64c2 Fix clobering of operand by error handler in assignment to string offset
In some cases new code requires two reallocations insead of one.

Fixes oss-fuzz #31716, #36196, #39739 and #40002
2021-12-02 00:24:05 +03:00
Nikita Popov
cacafd36a7 Merge branch 'PHP-8.1'
* PHP-8.1:
  Suppress unused label warnings in SWITCH VM
2021-11-04 14:52:53 +01:00
Nikita Popov
5d2f3d45cc Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Suppress unused label warnings in SWITCH VM
2021-11-04 14:52:45 +01:00
Nikita Popov
ee37774466 Suppress unused label warnings in SWITCH VM
While we avoid emitting labels for handlers that are not referenced
from anywhere else, we do not perform a fine-grained analysis on
used specializations, so some of the specialization labels may not
be used. Use ATTRIBUTE_UNUSED_LABEL to suppress the warning. Drop
"cold" from the definition of this attribute, as it is completely
unrelated.
2021-11-04 14:50:54 +01:00
Nikita Popov
da0d246e19 Drop FREE_OP_VAR_PTR() distinction
FREE_OP_VAR_PTR() is like FREE_OP(), but only frees VAR, rather
than VARs and TMPs. I don't think this distinction makes sense
anymore, as opcodes using FREE_OP_VAR_PTR() generally only accept
VAR or CV. For the cases where other op types are accepted and
only freeing VAR is desired we already have FREE_OP_IF_VAR().

This drops FREE_OP_VAR_PTR(), leaving only FREE_OP() and
FREE_OP_IF_VAR().
2021-10-20 12:02:09 +02:00
Nikita Popov
58a0c5a2e1 Remove stale variables from zend_vm_gen.php
These "unfetched" variants no longer exist.
2021-10-19 12:27:54 +02:00
Kamil Tekiela
c3dda473cc
Fix 'can not' in test data and in code comments 2021-10-05 09:51:58 +01:00
Hao Sun
60ea2cbf74
Fix a typo in function execute_ex (#7315) 2021-07-29 13:49:31 +02:00
Dmitry Stogov
5fe2062585 Correct DWARF frame description.
Now GDB correctly shows backtraces that involves JIT-ed code for
functional/tracing JIT, HYBRID/CALL VM, x86/AArch64 CPU.
(opcache.jit_debug=0x100 should be set).
2021-05-18 18:21:08 +03:00
Dmitry Stogov
997374f41c Disable "red zone" usage (it leads to crashes). 2021-05-18 15:32:31 +03:00
Dmitry Stogov
57f2fe44c6 Use "red zone" for HYBRID VM.
Support for CALL VM and VM without global register variables.
2021-05-18 15:32:31 +03:00
Nikita Popov
57eb29f1d3 Update zend_vm_gen.php with zend_vm_opcode.c/h changes
The generated files were modified directly, resulting in mysterious
build failures depending on exact build order.
2021-04-06 11:35:05 +02:00
Max Semenik
b86dfb0e74 Fix E_DEPRECATED in zend_vm_gen.php
explode(): Passing null to parameter #2 ($string) of type string is
deprecated

Closes GH-6698.
2021-03-01 11:22:18 +01:00
Nikita Popov
de5b42219c Avoid writing zend_vm_opcodes.h if it did not change
Now that we track header changes, a change to zend_vm_opcodes.h
requires rebuilding essentially the whole tree. In most cases,
changes to zend_vm_def.h don't actually result in any header
changes though.

Avoid touching the file by first checking whether the to be written
contents are actually the same.
2021-02-17 17:18:57 +01:00
Alex Erohin
cbfdc1fd54 Coding style tweaks for zend_vm_gen.php
- fixed array style for $vm_kind_name and $op_types
- deleted unnecessary else statement for is_hot_helper function
- fixed concatenation style
- fixed style of using whitespace between "(" and switch/foreach - replaced !is_null with "!=="

Closes GH-6704.
2021-02-17 17:05:34 +01:00
Dmitry Stogov
8ad2b59e12 Disable stack reuse optimization for x86 PIC code. It may clobber local variable used for Global Offset Table. 2020-12-01 15:20:06 +03:00
Dmitry Stogov
841b00f641 Preallocate stack space for JIT in execute_ex() to eliminate JIT prologue/epilogue. 2020-11-30 17:56:08 +03:00
Sammy Kaye Powers
58d41b8c4f Provide unused retvals to observers
Make sure that the return value is available to observers, even if
it is not used by the caller.

Closes GH-6422.
2020-11-17 10:28:47 +01:00
Dmitry Stogov
855d8fa68f [Observer] Save opline before calling begin/end handlers 2020-11-11 13:06:55 +03:00
Dmitry Stogov
d5d31ea3b3 Cleanup observer API and add JIT support 2020-09-18 12:55:58 +03:00
Sammy Kaye Powers
9e94bcfdbc Remove specialization of SPEC(OBSERVER) handlers 2020-09-18 00:47:36 +03:00
Levi Morrison
66c3e900e2 Add zend_observer API
Closes GH-5857.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
Co-authored-by: Sammy Powers <sammyk@datadoghq.com>
2020-09-01 09:59:59 -06:00
Nikita Popov
42eda5160d SAVE_OPLINE in NULL_HANDLER
Let's avoid crashing before the nice error message gets printed...
2020-08-11 15:14:50 +02:00
Nikita Popov
d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00
Nikita Popov
613a56d1cb Remove FREE_UNFETCHED concept
In master normal FREE_OPs work like FREE_UNFETCHED_OP used to, so
there is no point in keeping this distinction anymore, it's just
confusing.
2020-07-09 11:58:33 +02:00
Nikita Popov
5d0687e895 Assert exception set in HANDLE_EXCEPTION()
Some code paths were checking this manually, but we can turn this
into a general assertion to avoid surprises (functions returning
failure without throwing).
2020-07-07 11:31:05 +02:00
Nikita Popov
fb91611276 Remove #undefs from vm_gen
Possibly these were needed for VM_EXPORT, but they don't serve a
purpose now.
2020-07-07 11:25:28 +02:00
Nikita Popov
002c264d07 Remove ZEND_VM_EXPORT functionality
This hasn't been used since forever and makes things more confusing
than they already are.
2020-07-07 11:23:28 +02:00
Ayesh Karunaratne
d114812faf [ci skip] Various typo fixes in stub comments and CHANGES file 2020-06-25 23:32:40 +02:00
Dmitry Stogov
f4b46314f6 Prevent CGG reordering if hanlers order is defined by zend_vm_order.txt 2020-05-22 12:37:35 +03:00
Nikita Popov
d4de3f95d6 Remove spurious const qualifier from function return type 2020-02-06 11:59:52 +01:00
Nikita Popov
169805777c Merge branch 'PHP-7.4'
* PHP-7.4:
  Apply tidy formatting
2020-02-03 13:42:08 +01:00
Nikita Popov
58b17906f5 Apply tidy formatting
Mostly reindent PHP scripts to spaces.
2020-02-03 13:41:31 +01:00
Tyson Andre
a7580899f3 Support the same handler for multiple opcodes 2019-11-15 17:37:01 +03:00
Tyson Andre
e8525c2f68 Optimize int === int/double === double
Do this by reusing the implementation used for `==`
when both arguments are ints (IS_LONG) or both are floats (IS_DOUBLE)

```php
// Before: nestedloop_ni took 0.442 seconds
// After: nestedloop_ni takes 0.401 seconds (same as nestedloop_ne)
function nestedloop_ni(int $k) {
  $x = 0;
  for ($i=0; $i < 50000000; $i++) {
    if ($i === $k) {
      $x++;
    }
  }
  print "$x\n";
}
function nestedloop_ne(int $k) {
  $x = 0;
  for ($i=0; $i < 50000000; $i++) {
    if ($i == $k) {
        $x++;
    }
  }
  print "$x\n";
}
```
2019-11-15 17:37:01 +03:00
Dmitry Stogov
f6f32f2cf0 SAMRT BRANCH improvement.
Avoid need of insertion NOP opcoes between unrelated SMART BRANCH instruction and following JMPZ/JMPNZ.
Now instead of checking the opcode of following instruction, the same information is encoded into SMART BRANH result_type.
2019-10-09 13:48:39 +03:00
Dmitry Stogov
eec04f6b56 Encapsulate all SMART BRANCH related logic inside macros. Result of SMART BRANCH may be uninitialized (on exception). 2019-10-08 16:37:21 +03:00
Nikita Popov
a66c60cce3 Throw Error when writing property of non-object
This removes object auto-vivification support.

This also means that we can remove the corresponding special
handling for typed properites: We no longer need to check that a
property is convertible to stdClass if such a conversion might
take place indirectly due to a nested property write.

Additionally OBJ_W style operations now no longer modify the
object operand, and as such we no longer need to treat op1 as a
def in SSA form.

The next step would be to actually compile the whole LHS of OBJ_W
operations in R rather than W mode, but that causes issues with
SimpleXML, whose object handlers depend on the current compilation
structure.

Part of https://wiki.php.net/rfc/engine_warnings.
2019-09-27 10:11:47 +02:00
Dmitry Stogov
470bbb8c70 Avoid code dupliction 2019-09-26 01:40:30 +03:00
Dmitry Stogov
02c83b809a ceanup 2019-09-10 15:12:42 +03:00
Dmitry Stogov
0f8bb9e37d Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove HOT attribute from some VM handlers. Comparisons almost always followed by JMPZ/JMPNZ; JMPZNZ is rare used.
  Remove --with-zlib-dir option from mysqlnd config
2019-09-05 11:43:13 +03:00