Commit graph

776 commits

Author SHA1 Message Date
Dmitry Stogov
1a6863c6af Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Preloading: don't remove INCLUDE_OE_EVAL nstructions with used result
2021-12-14 11:37:25 +03:00
Dmitry Stogov
cd8e6f5f7b Preloading: don't remove INCLUDE_OE_EVAL nstructions with used result 2021-12-14 11:36:33 +03:00
Dmitry Stogov
0e1c7243f6 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed a crash becaeuse of race condition in inheritance cache
2021-11-18 14:22:39 +03:00
Dmitry Stogov
5ab2749263 Fixed a crash becaeuse of race condition in inheritance cache
zend_inheritance_cache_entry.[num_]warnings must be updated before this entry is made visible to other processes
2021-11-18 14:17:36 +03:00
Dmitry Stogov
d56ec0a624 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81607 (CE_CACHE allocation with concurrent access)
2021-11-17 18:25:00 +03:00
Dmitry Stogov
76548e5093 Fixed bug #81607 (CE_CACHE allocation with concurrent access) 2021-11-17 18:23:36 +03:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
a35f72f51e Reduce indentation 2021-10-14 16:20:02 +02:00
Dmitry Stogov
0bfd87e886 Merge branch 'PHP-8.1'
* PHP-8.1:
  Flush error messages emitted during preloading
2021-10-08 12:35:50 +03:00
Dmitry Stogov
b2c43a4efb Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Flush error messages emitted during preloading
2021-10-08 12:35:38 +03:00
Dmitry Stogov
45b127ad4a Flush error messages emitted during preloading 2021-10-08 12:34:25 +03:00
Kamil Tekiela
10f102d790
Fix 'can not' in error messages 2021-10-05 09:51:58 +01:00
Nikita Popov
c19977d054 Fix delayed early binding with optimization
It's possible for delayed early binding opcodes to get optimized
away if they are "unreachable". However, we still need to attempt
early binding for them. (In some cases we also corrupt the early
binding list outright during optimization, which is how I got here.)

Fix this by storing information about delayed early binding
independently of DECLARE_CLASS_DELAYED opcodes, so early binding is
performed even after the opcode has been dropped.
2021-09-29 18:00:20 +02:00
Nikita Popov
1ea58832e2 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix bug #81472: Support large device major/minor number
2021-09-24 09:58:29 +02:00
Nikita Popov
2b0288b220 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix bug #81472: Support large device major/minor number
2021-09-24 09:58:22 +02:00
Lin Yang
9ad8fadcbb Fix bug #81472: Support large device major/minor number
Latest linux kernel use large number (12 bits for major device, 20
bits for minor device). Current code only supports previous standard
(5 chars), which means 8 bits for major and 8 bits for minor device.
It will fail if device number is out of that range. So this patch
increases device number read from /proc/self/maps file.

Closes GH-7512.
2021-09-24 09:57:32 +02:00
George Peter Banyard
f345f6d529 Voidify zend_optimize_script()
It always returned 1

As a consequence voidify preload_optimize()
2021-09-21 11:35:53 +01:00
Nikita Popov
cd4243dde9 Add fuzzer for function JIT
This is a basic fuzzer for the function JIT, which looks for
crashes and sanitizer violations only, and does not try to detect
differing behavior yet.
2021-09-15 17:12:39 +02:00
Nikita Popov
86d470f3e0 Reset CE cache slots on opcache reset
Permanent opcache interned strings could have ce_cache pointing to
non-permanent map_ptr slots. On reset, those would be left dangling.
Clear any non-permanent ce_cache slots when the interned string
state is reset.

This was fun to debug...
2021-09-13 15:20:34 +02:00
Nikita Popov
6434c93a27 Explicitly store real map ptr base
If we only store the biased pointer, the map ptr region will not
be recognized as reachable memory by leak checkers. This is
primarily problematic for fuzzing, because this is persistent
memory that may be reallocated during the request, without being
an actual leak.

Avoid this by simply storing both the real base pointer of the
allocation, as well as the biased base pointer used for accesses.
2021-08-26 12:29:44 +02:00
Nikita Popov
97b6a364b3 Fix __COMPILER_HALT_OFFSET__ preservation during preloading
The shutdown refactoring has moved the destruction of constants
earlier, so also move the halt compiler offset backup earlier.

This fixes phar tests under --preload.
2021-08-17 10:03:22 +02:00
Nikita Popov
cecea72a10 Reuse parts of normal executor shutdown for preloading
preloading currently reimplements parts of shutdown_executor(),
so it's easy for that code to go out of sync.

Extract this into an zend_shutdown_executor_values() API function
and use it as part of the preloading pre-shutdown.
2021-08-16 16:20:03 +02:00
Nikita Popov
4bb66ddc76 Set EG(active)=0 during preloading shutdown
Just like during normal shutdown, we should set EG(active)=0
during the partial preloading shutdown, to make sure that no
user code can run.

We need to slightly tweak inheritance class loading to still
pick the right code path.
2021-08-16 15:53:12 +02:00
Nikita Popov
99ddc806dc Discard constants before preload_load()
We don't preload constants, so we should also not cache
constant evaluations based on them, as a different value may be
defined at runtime.
2021-08-16 15:47:18 +02:00
Nikita Popov
af50e687a8 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #81353
2021-08-16 15:05:32 +02:00
Nikita Popov
47ccdecf00 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #81353
2021-08-16 15:04:57 +02:00
Nikita Popov
d1e956ff31 Fixed bug #81353
A user-defined error handler should not be invoked for preload
warnings. We are in a partially shut-down state at that point.
2021-08-16 15:04:17 +02:00
Nikita Popov
4a4ae45a0b Fix bug #81142 by adding zend_string_init_existing_interned()
Add a new interned string handler that fetches an interned string
if it exists, but does not create one if it does not (and instead
returns a non-interned string).

This fixes bug #81142, by preventing the creating of new interned
strings for unserialized array keys.

Closes GH-7360.
2021-08-12 11:57:50 +02:00
Nikita Popov
315f40942b
Always use CE_CACHE, remove TYPE_HAS_CE (#7336)
Currently, CE_CACHE on strings is only used with opcache interned strings. This
patch extends usage to non-opcache interned strings as well. This means that
most type strings can now make use of CE_CACHE even if opcache is not loaded,
which allows us to remove TYPE_HAS_CE kind, and fix some discrepancies
depending on whether a type stores a resolved or non-resolved name.

There are two cases where CE_CACHE will not be used:

 * When opcache is not used and a permanent interned string (that is not an
   internal class name) is used as a type name during the request. In this case
   we can't allocate a map_ptr index for the permanent string, as it would be
   not be in the permanent map_ptr index space.
 * When opcache is used but the script is not cached (e.g. eval'd code or
   opcache full). If opcache is used, we can't allocate additional map_ptr
   indexes at runtime, because they may conflict with indexes allocated by
   opcache.

In these two cases we would end up not using CE caching for property types
(argument/return types still have the separate cache slot).
2021-08-11 10:28:52 +02:00
Nikita Popov
5e997ec3ce
Remove special self/parent handling in get_class_name_map_ptr() (#7330)
zend_accel_get_class_name_map_ptr() for "self" and "parent" will
currently try to determine which class these refer to, and then
initialize the CE_CACHE on those strings.

However, this shouldn't be necessary: We already initialize
CE_CACHE on all class declaration names, so it should be covered
through that already.
2021-08-10 10:29:20 +02:00
Nikita Popov
9fe3aab7c5 Remove declares inside functions as well 2021-08-02 10:41:27 +02:00
Nikita Popov
8356da600b Remove dynamic defs from methods as well
We need to remove DECLARE_FUNCTION + dynamic_defs for functions
defined in methods as well, not just for those declared in the
main script.
2021-08-02 10:29:58 +02:00
Nikita Popov
9ee9393784 Skip shebang on preload script 2021-07-30 16:11:47 +02:00
Nikita Popov
67b5d8fcdc Don't reverse class order during preloading
We don't guarantee any particular order, but this reduces test
failures under --preload that are sensitive to class order.

Add some ZEND_HASH_FOREACH_*_FROM macros to allow skipping the
persistent classes while iterating in forward direction.
2021-07-30 15:14:17 +02:00
Nikita Popov
d836046ab8 Perform preloading attempt on copied class
It is very hard to determine in advance whether class linking will
fail due to missing dependencies in variance checks (#7314 attempts
this). This patch takes an alternative approach where we try to
perform inheritance on a copy of the class (zend_lazy_class_load)
and then restore the original class if inheritance fails. The fatal
error in that case is recorded and thrown as a warning later.

Closes GH-7319.
2021-07-30 15:09:49 +02:00
Nikita Popov
b1b0c81e39 Don't print preload warning for non-top-level classes
Dynamically declared classes categorically do not get linked during
preloading, even if all their dependencies are known. The warning
is misleading in this case, and there isn't anything the user can
do to address it.
2021-07-30 10:27:51 +02:00
Nikita Popov
29aed2a6c8 Clean up dependency resolution during preloading
Combine the code for checking whether all dependencies are
available and reporting an error if they are not. Actually store
the loaded deps and then use those when checking for type
availability, instead of looking up the same classes again and
again.
2021-07-28 16:55:06 +02:00
Nikita Popov
e011952576
Preload unlinked classes, remove preload autoload (#7311)
Currently, classes that can't be linked get moved back into the original script
and are not preloaded. As such classes may be referenced from functions that
did get preloaded, there is a preload autoload mechanism to load them at
runtime.

Since PHP 8.1, we can safely preload unlinked classes, which will then go
through usual lazy loading. This means that we no longer need the preload
autoload mechanism. However, we need to be careful not to modify any hash
table buckets in-place, and should create new buckets for lazy loaded classes.
2021-07-28 14:27:58 +02:00
Nikita Popov
380e705fc2 Use consistent line numbers for early binding errors
Non-early-bound classes report inheritance errors at the first line
of the class, if no better line information is available (we should
really store line numbers for properties at least...) Early bound
classes report it at the last line of the class instead.

Make the error reporting consistent by always reporting at the
first line.
2021-07-28 12:35:20 +02:00
Nikita Popov
5a7e1a7aa8 Don't use IMMUTABLE flag to decide whether mutable_data is used
mutable_data may be used for IMMUTABLE classes, internal classes
and to-be-preloaded classes. Check whether the mutable_data
map_ptr is set rather than only the IMMUTABLE flag.
2021-07-27 11:44:01 +02:00
Nikita Popov
c1959e63e5 Fix preloading of enums
We should not store constants that resolve to objects.
2021-07-27 11:01:44 +02:00
Nikita Popov
703e92c121 Don't force constant resolution for include preloading
Same as with property types, we no longer require that all constants
are resolved for preloading to work, it's just an optimization. As
such, drop the forced resolution for include-based preloading and
just keep the optimization.
2021-07-27 10:50:31 +02:00
Nikita Popov
70195c3561 Don't force property type resolution for include preloading
Having all property types resolved is no longer a hard requirement
for preloading, resolving the types is just an optimization. As
such, drop the special logic that forced loading of property
types when include-based preloading is used. Instead only keep
the code that resolves types based on actually preloaded classes.

Also drop the ZEND_ACC_PROPERTY_TYPES_RESOLVED flag, which is now
nearly useless and takes up flag space...
2021-07-27 10:36:21 +02:00
Dmitry Stogov
1e4095f03d Fixed bug #81256 (Assertion `zv != ((void *)0)' failed for "preload" with JIT) 2021-07-20 15:27:43 +03:00
Christoph M. Becker
0ce1cd1370
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #81206: Multiple PHP processes crash with JIT enabled
2021-07-19 23:52:51 +02:00
Christoph M. Becker
ef77d3c89f
Fix #81206: Multiple PHP processes crash with JIT enabled
We need to avoid resetting the JIT for all SAPIs, but we need to
initialize the JIT handlers even when only reattaching on Windows.

Closes GH-7208.
2021-07-19 23:45:37 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Dmitry Stogov
8ae06582c6 Fixed incorrect map_ptr slots counting 2021-06-16 11:33:43 +03:00
twosee
795efd7613
Add zend_getpagesize() and reuse it in accelerator and fiber (#7057) 2021-05-27 18:27:18 +08:00
Nikita Popov
f31c531960 Merge branch 'PHP-8.0'
* PHP-8.0:
  Move preload_autoload assignment into preload_load()
2021-05-19 12:56:28 +02:00