@@ -3534,9 +3534,44 @@ static void preload_remove_empty_includes(void)
35343534
35353535static int preload_optimize (zend_persistent_script * script )
35363536{
3537+ zend_class_entry * ce ;
3538+ zend_op_array * op_array ;
3539+
3540+ zend_shared_alloc_init_xlat_table ();
3541+
3542+ ZEND_HASH_FOREACH_PTR (& script -> script .class_table , ce ) {
3543+ if (ce -> ce_flags & ZEND_ACC_TRAIT ) {
3544+ ZEND_HASH_FOREACH_PTR (& ce -> function_table , op_array ) {
3545+ if (!(op_array -> fn_flags & ZEND_ACC_TRAIT_CLONE )) {
3546+ zend_shared_alloc_register_xlat_entry (op_array -> opcodes , op_array );
3547+ }
3548+ } ZEND_HASH_FOREACH_END ();
3549+ }
3550+ } ZEND_HASH_FOREACH_END ();
3551+
35373552 if (!zend_optimize_script (& script -> script , ZCG (accel_directives ).optimization_level , ZCG (accel_directives ).opt_debug_level )) {
35383553 return FAILURE ;
35393554 }
3555+
3556+ ZEND_HASH_FOREACH_PTR (& script -> script .class_table , ce ) {
3557+ if (ce -> ce_flags & ZEND_ACC_IMPLEMENT_TRAITS ) {
3558+ ZEND_HASH_FOREACH_PTR (& ce -> function_table , op_array ) {
3559+ if (op_array -> fn_flags & ZEND_ACC_TRAIT_CLONE ) {
3560+ zend_op_array * orig_op_array = zend_shared_alloc_get_xlat_entry (op_array -> opcodes );
3561+ uint32_t fn_flags = op_array -> fn_flags ;
3562+ zend_function * prototype = op_array -> prototype ;
3563+ HashTable * ht = op_array -> static_variables ;
3564+ * op_array = * orig_op_array ;
3565+ op_array -> fn_flags = fn_flags ;
3566+ op_array -> prototype = prototype ;
3567+ op_array -> static_variables = ht ;
3568+ }
3569+ } ZEND_HASH_FOREACH_END ();
3570+ }
3571+ } ZEND_HASH_FOREACH_END ();
3572+
3573+ zend_shared_alloc_destroy_xlat_table ();
3574+
35403575 ZEND_HASH_FOREACH_PTR (preload_scripts , script ) {
35413576 if (!zend_optimize_script (& script -> script , ZCG (accel_directives ).optimization_level , ZCG (accel_directives ).opt_debug_level )) {
35423577 return FAILURE ;
@@ -3729,8 +3764,6 @@ static int accel_preload(const char *config)
37293764 script -> ping_auto_globals_mask = zend_accel_get_auto_globals_no_jit ();
37303765 }
37313766
3732- zend_shared_alloc_init_xlat_table ();
3733-
37343767 /* Store all functions and classes in a single pseudo-file */
37353768 filename = zend_string_init ("$PRELOAD$" , strlen ("$PRELOAD$" ), 0 );
37363769#if ZEND_USE_ABS_CONST_ADDR
@@ -3767,6 +3800,8 @@ static int accel_preload(const char *config)
37673800 return FAILURE ;
37683801 }
37693802
3803+ zend_shared_alloc_init_xlat_table ();
3804+
37703805 HANDLE_BLOCK_INTERRUPTIONS ();
37713806 SHM_UNPROTECT ();
37723807
0 commit comments