Skip to content

Commit

Permalink
Fix __COMPILER_HALT_OFFSET__ preservation during preloading
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Aug 17, 2021
1 parent fc6f3d1 commit 97b6a36
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4439,6 +4439,24 @@ static int accel_preload(const char *config, bool in_child)
ping_auto_globals_mask = zend_accel_get_auto_globals();
}

if (EG(zend_constants)) {
/* Remember __COMPILER_HALT_OFFSET__(s). Do this early,
* as zend_shutdown_executor_values() destroys constants. */
ZEND_HASH_FOREACH_PTR(preload_scripts, script) {
zend_execute_data *orig_execute_data = EG(current_execute_data);
zend_execute_data fake_execute_data;
zval *offset;

memset(&fake_execute_data, 0, sizeof(fake_execute_data));
fake_execute_data.func = (zend_function*)&script->script.main_op_array;
EG(current_execute_data) = &fake_execute_data;
if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1)) != NULL) {
script->compiler_halt_offset = Z_LVAL_P(offset);
}
EG(current_execute_data) = orig_execute_data;
} ZEND_HASH_FOREACH_END();
}

/* Cleanup executor */
EG(flags) |= EG_FLAGS_IN_SHUTDOWN;

Expand All @@ -4450,6 +4468,10 @@ static int accel_preload(const char *config, bool in_child)
/* Release stored values to avoid dangling pointers */
zend_shutdown_executor_values(/* fast_shutdown */ false);

/* We don't want to preload constants.
* Check that zend_shutdown_executor_values() also destroys constants. */
ZEND_ASSERT(zend_hash_num_elements(EG(zend_constants)) == EG(persistent_constants_count));

zend_hash_init(&EG(symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);

CG(map_ptr_last) = orig_map_ptr_last;
Expand All @@ -4460,36 +4482,6 @@ static int accel_preload(const char *config, bool in_child)
goto finish;
}

/* Don't preload constants */
if (EG(zend_constants)) {
zend_string *key;
zval *zv;

/* Remember __COMPILER_HALT_OFFSET__(s) */
ZEND_HASH_FOREACH_PTR(preload_scripts, script) {
zend_execute_data *orig_execute_data = EG(current_execute_data);
zend_execute_data fake_execute_data;
zval *offset;

memset(&fake_execute_data, 0, sizeof(fake_execute_data));
fake_execute_data.func = (zend_function*)&script->script.main_op_array;
EG(current_execute_data) = &fake_execute_data;
if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1)) != NULL) {
script->compiler_halt_offset = Z_LVAL_P(offset);
}
EG(current_execute_data) = orig_execute_data;
} ZEND_HASH_FOREACH_END();

ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(zend_constants), key, zv) {
zend_constant *c = Z_PTR_P(zv);
if (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT) {
break;
}
EG(zend_constants)->pDestructor(zv);
zend_string_release(key);
} ZEND_HASH_FOREACH_END_DEL();
}

/* Inheritance errors may be thrown during linking */
zend_try {
preload_link();
Expand Down

0 comments on commit 97b6a36

Please sign in to comment.