Fix preload auto globals handling

We need to compute the auto globals mask before EG(symbol_table)
is cleaned out.
This commit is contained in:
Nikita Popov 2019-02-15 16:34:32 +01:00
parent 0520eb8772
commit a9497cecf3
3 changed files with 29 additions and 8 deletions

View File

@ -3837,8 +3837,15 @@ static int accel_preload(const char *config)
if (ret == SUCCESS) {
zend_persistent_script *script;
zend_string *filename;
int ping_auto_globals_mask;
int i;
if (PG(auto_globals_jit)) {
ping_auto_globals_mask = zend_accel_get_auto_globals();
} else {
ping_auto_globals_mask = zend_accel_get_auto_globals_no_jit();
}
/* Release stored values to avoid dangling pointers */
zend_hash_graceful_reverse_destroy(&EG(symbol_table));
zend_hash_init(&EG(symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
@ -3859,14 +3866,7 @@ static int accel_preload(const char *config)
}
script = create_persistent_script();
/* Fill in the ping_auto_globals_mask for the new script. If jit for auto globals is enabled we
will have to ping the used auto global variables before execution */
if (PG(auto_globals_jit)) {
script->ping_auto_globals_mask = zend_accel_get_auto_globals();
} else {
script->ping_auto_globals_mask = zend_accel_get_auto_globals_no_jit();
}
script->ping_auto_globals_mask = ping_auto_globals_mask;
/* Store all functions and classes in a single pseudo-file */
filename = zend_string_init("$PRELOAD$", strlen("$PRELOAD$"), 0);

View File

@ -0,0 +1,16 @@
--TEST--
Handling of auto globals during preloading
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/preload_globals.inc
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
$x = 123;
var_dump(get_x());
?>
--EXPECT--
int(123)

View File

@ -0,0 +1,5 @@
<?php
function get_x() {
return $GLOBALS["x"];
}