diff --git a/NEWS b/NEWS index ab95aab660b07..e321e593c6a13 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ Intl: Opcache: . Added large shared segments support for FreeBSD. (David Carlier) + . If JIT is enabled, PHP will now exit with a fatal error on startup + in case of JIT startup initialization issues. (danog) PDO_PGSQL: . Fixed GH-12423, DSN credentials being prioritized over the user/password diff --git a/UPGRADING b/UPGRADING index a43cbf1fcacf0..3118a024f2015 100644 --- a/UPGRADING +++ b/UPGRADING @@ -153,6 +153,10 @@ PHP 8.4 UPGRADE NOTES 9. Other Changes to Extensions ======================================== +- Opcache: + . If JIT is enabled, PHP will now exit with a fatal error on startup + in case of JIT startup initialization issues. + - Intl: . The class constants are typed now. diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index a21c640d916c9..7201e2e91dfdc 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3248,16 +3248,13 @@ static zend_result accel_post_startup(void) zend_shared_alloc_lock(); #ifdef HAVE_JIT if (JIT_G(enabled)) { - if (JIT_G(buffer_size) == 0 - || !ZSMMG(reserved) - || zend_jit_startup(ZSMMG(reserved), jit_size, reattached) != SUCCESS) { + if (JIT_G(buffer_size) == 0) { JIT_G(enabled) = false; JIT_G(on) = false; - /* The JIT is implicitly disabled with opcache.jit_buffer_size=0, so we don't want to - * emit a warning here. */ - if (JIT_G(buffer_size) != 0) { - zend_accel_error(ACCEL_LOG_WARNING, "Could not enable JIT!"); - } + } else if (!ZSMMG(reserved)) { + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not use reserved buffer!"); + } else { + zend_jit_startup(ZSMMG(reserved), jit_size, reattached); } } #endif diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index bef5d2fd9962d..ac91fdcbb862a 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -3419,7 +3419,7 @@ ZEND_EXT_API int zend_jit_check_support(void) return SUCCESS; } -ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached) +ZEND_EXT_API void zend_jit_startup(void *buf, size_t size, bool reattached) { zend_jit_halt_op = zend_get_halt_op(); zend_jit_profile_counter_rid = zend_get_op_array_extension_handle(ACCELERATOR_PRODUCT_NAME); @@ -3494,24 +3494,16 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached) } zend_jit_unprotect(); - if (zend_jit_setup() != SUCCESS) { - zend_jit_protect(); - // TODO: error reporting and cleanup ??? - return FAILURE; - } + zend_jit_setup(); zend_jit_protect(); zend_jit_init_handlers(); - if (zend_jit_trace_startup(reattached) != SUCCESS) { - return FAILURE; - } + zend_jit_trace_startup(reattached); zend_jit_unprotect(); /* save JIT buffer pos */ dasm_ptr[1] = dasm_ptr[0]; zend_jit_protect(); - - return SUCCESS; } ZEND_EXT_API void zend_jit_shutdown(void) diff --git a/ext/opcache/jit/zend_jit.h b/ext/opcache/jit/zend_jit.h index d9f0f72a4b69e..06e91bb63c982 100644 --- a/ext/opcache/jit/zend_jit.h +++ b/ext/opcache/jit/zend_jit.h @@ -158,7 +158,7 @@ ZEND_EXT_API void zend_jit_init(void); ZEND_EXT_API int zend_jit_config(zend_string *jit_options, int stage); ZEND_EXT_API int zend_jit_debug_config(zend_long old_val, zend_long new_val, int stage); ZEND_EXT_API int zend_jit_check_support(void); -ZEND_EXT_API int zend_jit_startup(void *jit_buffer, size_t size, bool reattached); +ZEND_EXT_API void zend_jit_startup(void *jit_buffer, size_t size, bool reattached); ZEND_EXT_API void zend_jit_shutdown(void); ZEND_EXT_API void zend_jit_activate(void); ZEND_EXT_API void zend_jit_deactivate(void); diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c index fa1dc3073dad9..177a084ece154 100644 --- a/ext/opcache/jit/zend_jit_ir.c +++ b/ext/opcache/jit/zend_jit_ir.c @@ -2867,7 +2867,7 @@ static void *zend_jit_ir_compile(ir_ctx *ctx, size_t *size, const char *name) return entry; } -static int zend_jit_setup_stubs(void) +static void zend_jit_setup_stubs(void) { zend_jit_ctx jit; void *entry; @@ -2886,7 +2886,7 @@ static int zend_jit_setup_stubs(void) entry = zend_jit_ir_compile(&jit.ctx, &size, zend_jit_stubs[i].name); if (!entry) { zend_jit_free_ctx(&jit); - return 0; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile stub"); } zend_jit_stub_handlers[i] = entry; @@ -2918,7 +2918,6 @@ static int zend_jit_setup_stubs(void) } zend_jit_free_ctx(&jit); } - return 1; } #define REGISTER_HELPER(n) \ @@ -3119,7 +3118,7 @@ static void zend_jit_setup_disasm(void) #endif } -static int zend_jit_calc_trace_prologue_size(void) +static void zend_jit_calc_trace_prologue_size(void) { zend_jit_ctx jit_ctx; zend_jit_ctx *jit = &jit_ctx; @@ -3140,11 +3139,10 @@ static int zend_jit_calc_trace_prologue_size(void) zend_jit_free_ctx(jit); if (!entry) { - return 0; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile prologue"); } zend_jit_trace_prologue_size = size; - return 1; } #if !ZEND_WIN32 && !defined(IR_TARGET_AARCH64) @@ -3195,12 +3193,11 @@ static zend_never_inline void zend_jit_set_sp_adj_vm(void) } #endif -static int zend_jit_setup(void) +static void zend_jit_setup(void) { #if defined(IR_TARGET_X86) if (!zend_cpu_supports_sse2()) { - zend_error(E_CORE_ERROR, "CPU doesn't support SSE2"); - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: CPU doesn't support SSE2"); } #endif #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) @@ -3233,8 +3230,7 @@ static int zend_jit_setup(void) offset += sizeof(void*); } if (offset >= size) { - // TODO: error message ??? - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: offset >= size"); } } while(0); # elif ZEND_WIN32 @@ -3257,8 +3253,7 @@ static int zend_jit_setup(void) offset += sizeof(void*); } if (offset >= size) { - // TODO: error message ??? - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: offset >= size"); } } while(0); # elif defined(__APPLE__) && defined(__x86_64__) @@ -3343,17 +3338,9 @@ static int zend_jit_setup(void) ZEND_JIT_DEBUG_IR_AFTER_SCCP|ZEND_JIT_DEBUG_IR_AFTER_SCHEDULE|ZEND_JIT_DEBUG_IR_AFTER_REGS); } - if (!zend_jit_calc_trace_prologue_size()) { - JIT_G(debug) = debug; - return FAILURE; - } - if (!zend_jit_setup_stubs()) { - JIT_G(debug) = debug; - return FAILURE; - } + zend_jit_calc_trace_prologue_size(); + zend_jit_setup_stubs(); JIT_G(debug) = debug; - - return SUCCESS; } static void zend_jit_shutdown_ir(void) diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 26f69b19d081d..a69786fe7c63f 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -46,16 +46,16 @@ static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_fla } } -static int zend_jit_trace_startup(bool reattached) +static void zend_jit_trace_startup(bool reattached) { if (!reattached) { zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * JIT_G(max_root_traces)); if (!zend_jit_traces) { - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not allocate JIT root traces buffer!"); } zend_jit_exit_groups = (const void**)zend_shared_alloc(sizeof(void*) * (ZEND_JIT_TRACE_MAX_EXITS/ZEND_JIT_EXIT_POINTS_PER_GROUP)); if (!zend_jit_exit_groups) { - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not allocate JIT exit groups buffer!"); } ZEND_JIT_TRACE_NUM = 1; ZEND_JIT_COUNTER_NUM = 0; @@ -67,11 +67,11 @@ static int zend_jit_trace_startup(bool reattached) } else { zend_jit_traces = ZCSG(jit_traces); if (!zend_jit_traces) { - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not obtain JIT traces buffer!"); } zend_jit_exit_groups = ZCSG(jit_exit_groups); if (!zend_jit_exit_groups) { - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not obtain JIT exit groups buffer!"); } } @@ -80,10 +80,8 @@ static int zend_jit_trace_startup(bool reattached) JIT_G(exit_counters) = calloc(JIT_G(max_exit_counters), 1); if (JIT_G(exit_counters) == NULL) { - return FAILURE; + zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not allocate JIT exit counters buffer!"); } - - return SUCCESS; } static const void *zend_jit_trace_allocate_exit_point(uint32_t n)