From a9497cecf3a76b3264ed0807023cd59e9bcf6f23 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 15 Feb 2019 16:34:32 +0100 Subject: [PATCH] Fix preload auto globals handling We need to compute the auto globals mask before EG(symbol_table) is cleaned out. --- ext/opcache/ZendAccelerator.c | 16 ++++++++-------- ext/opcache/tests/preload_005.phpt | 16 ++++++++++++++++ ext/opcache/tests/preload_globals.inc | 5 +++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 ext/opcache/tests/preload_005.phpt create mode 100644 ext/opcache/tests/preload_globals.inc diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 985c66c32e6..f30b6759593 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -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); diff --git a/ext/opcache/tests/preload_005.phpt b/ext/opcache/tests/preload_005.phpt new file mode 100644 index 00000000000..1bcfae4d799 --- /dev/null +++ b/ext/opcache/tests/preload_005.phpt @@ -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-- + +--FILE-- + +--EXPECT-- +int(123) diff --git a/ext/opcache/tests/preload_globals.inc b/ext/opcache/tests/preload_globals.inc new file mode 100644 index 00000000000..213dc60fabb --- /dev/null +++ b/ext/opcache/tests/preload_globals.inc @@ -0,0 +1,5 @@ +