1
0
mirror of https://github.com/php/php-src.git synced 2026-04-03 14:12:38 +02:00
Commit Graph

4357 Commits

Author SHA1 Message Date
Dmitry Stogov
0424ce0c15 Avoid redundand repeatable VM stack overflow checks 2021-08-26 16:50:29 +03: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
Dmitry Stogov
1c9f8eb7b9 JIT/x86: Merge load and test of EX_CALL_INFO() into single instruction 2021-08-25 14:36:06 +03:00
Dmitry Stogov
c5ded13614 JIT: Code generation for ROPE_INIT, ROPE_ADD and ROPE_END with STRING operands 2021-08-24 21:45:14 +03:00
Dmitry Stogov
116fa65482 Fixed ZEND_MAP_PTR_KIND_PTR (it is not used) 2021-08-23 14:04:02 +03:00
Dmitry Stogov
476c333a8e Reorder updates to avoid race conditions 2021-08-23 11:47:30 +03:00
Nikita Popov
ba8e5d336b Merge branch 'PHP-8.0'
* PHP-8.0:
  Test file_cache prime shm + use file combination
  Fix repeated file cache unserialization of zval string
2021-08-18 12:39:47 +02:00
Nikita Popov
de7ba3e737 Fix repeated file cache unserialization of zval string
The IS_UNSERIALIZED check here does not work if the string is
interned (serialized with file_cache_only=0) but unserialization
happens with file_cache_only=1. In this case the unserializde
string will be in the str area after mem, which is not included
in the script size, and which is also not accessible at this
point without threading through more information. Work around
the problem by checking for the serialized representation instead.
2021-08-18 12:38:27 +02:00
Nikita Popov
e86a0a905d Assert that file cache does not contain references 2021-08-17 17:13:19 +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
Dmitry Stogov
1ffbb7372a Better specialization for packed/hash arrays
- improved packed/hash inference.
- added hash guards for ASSIGN_DIM, ASSIGN_DIM_OP, FETCH_DIM_W* instructions
- more accurate invariant type guards motion
- invariant packed/hash guards motion
- rename MAY_BE_ARRAY_HASH into MAY_BE_ARRAY_NUMERIC_HASH and add MAY_BE_ARRAY_STRING_HASH
- cleanup
2021-08-13 14:30:41 +03:00
Dmitry Stogov
94b800182d Fixed conditional jump on uninitialised value (Zend/tests/match/028.phpt failure with function JIT) 2021-08-12 16:05:05 +03: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
Dmitry Stogov
c39332d740 Fixed incorrect condition 2021-08-12 11:39:08 +03:00
Nikita Popov
02b5660c0f Clear ce cache when persisting for file cache only
We should clear the ce cache before storing the interned string,
while we still have a reference to the original ce cache slot.
2021-08-12 10:34:21 +02:00
Dmitry Stogov
57e2241cbc JIT: Use zend_hash_index_lookup() instead of zend_hash_index_add_new(EG(uninitialized_zval)) 2021-08-12 09:56:13 +03:00
Dmitry Stogov
865b096890 Implement range inference for traces 2021-08-11 17:59:49 +03: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
Mike Pall
58040f257c DynASM/x86: Add missing escape in pattern. 2021-07-28 17:13:08 +03: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
8834cf013b Handle missing class when evaluating CONST_ENUM_INIT
When resolving constants on a dynamically declared class during
preloading, the enum class may not be available. Fail gracefully
in that case.

Possibly we shouldn't be trying to evaluate constants on
non-linked classes at all?
2021-07-27 14:36:38 +02:00
Nikita Popov
8675380b67 Increment refcounts in mutable data copies
For mutable_data on preloaded classes, there may be refcounted
values in the constants/properties table.
2021-07-27 12:29:46 +02:00
Nikita Popov
1bd6fafa2f Fix preloading of trait property attributes 2021-07-27 12:07:22 +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
b35418402f Allocate map_ptr for mutable_data during preloading
We need to discard objects in the class constants if they happened
to be evaluated during preloading. To allow doing so, we need to
use mutable_data, which will place the evaluated constants into
a separate table.
2021-07-27 11:16:38 +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
Nikita Popov
3eb97a4566 Always use separate static_members_table
When running without opcache, static_members_table is shared with
default_static_members_table. This is visible in reflection output,
because ReflectionProperty::getDefaultValue() will return the
current value, rather than the default value.

Address this by never sharing the table, which matches the behavior
we already see under opcache.

Fixes bug #80821.

Closes GH-7299.
2021-07-23 09:29:32 +02:00
Dmitry Stogov
e1f211f7bb Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed typo
2021-07-22 16:15:44 +03:00
Dmitry Stogov
8fbeebec34 Fixed typo 2021-07-22 16:14:26 +03:00
Dmitry Stogov
9c2b87c3cf JIT: avoid $this check in closures called from methods 2021-07-22 16:05:43 +03:00
Dmitry Stogov
713eec75f2 Merge branch 'PHP-8.0'
* PHP-8.0:
  Added test
2021-07-21 19:43:00 +03:00
Dmitry Stogov
17b5fe13e2 Added test 2021-07-21 19:29:59 +03:00
Dmitry Stogov
053c56f52e Fixed bug #81226 (Integer overflow behavior is different with JIT enabled) 2021-07-21 19:28:43 +03:00