Skip to content

Commit fde41bc

Browse files
danogiluuu1994
authored andcommitted
Report fatal error if JIT cannot be enabled
Closes GH-12403
1 parent e2e433a commit fde41bc

File tree

7 files changed

+31
-51
lines changed

7 files changed

+31
-51
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ MBString:
2626

2727
Opcache:
2828
. Added large shared segments support for FreeBSD. (David Carlier)
29+
. If JIT is enabled, PHP will now exit with a fatal error on startup in case
30+
of JIT startup initialization issues. (danog)
2931

3032
PDO_PGSQL:
3133
. Fixed GH-12423, DSN credentials being prioritized over the user/password

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ PHP 8.4 UPGRADE NOTES
163163
. Added mb_trim, mb_ltrim and mb_rtrim functions.
164164
RFC: https://wiki.php.net/rfc/mb_trim
165165

166+
- Opcache:
167+
. If JIT is enabled, PHP will now exit with a fatal error on startup in case
168+
of JIT startup initialization issues.
169+
166170
========================================
167171
7. New Classes and Interfaces
168172
========================================

ext/opcache/ZendAccelerator.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -3248,16 +3248,13 @@ static zend_result accel_post_startup(void)
32483248
zend_shared_alloc_lock();
32493249
#ifdef HAVE_JIT
32503250
if (JIT_G(enabled)) {
3251-
if (JIT_G(buffer_size) == 0
3252-
|| !ZSMMG(reserved)
3253-
|| zend_jit_startup(ZSMMG(reserved), jit_size, reattached) != SUCCESS) {
3251+
if (JIT_G(buffer_size) == 0) {
32543252
JIT_G(enabled) = false;
32553253
JIT_G(on) = false;
3256-
/* The JIT is implicitly disabled with opcache.jit_buffer_size=0, so we don't want to
3257-
* emit a warning here. */
3258-
if (JIT_G(buffer_size) != 0) {
3259-
zend_accel_error(ACCEL_LOG_WARNING, "Could not enable JIT!");
3260-
}
3254+
} else if (!ZSMMG(reserved)) {
3255+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not use reserved buffer!");
3256+
} else {
3257+
zend_jit_startup(ZSMMG(reserved), jit_size, reattached);
32613258
}
32623259
}
32633260
#endif

ext/opcache/jit/zend_jit.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,7 @@ ZEND_EXT_API int zend_jit_check_support(void)
34193419
return SUCCESS;
34203420
}
34213421

3422-
ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached)
3422+
ZEND_EXT_API void zend_jit_startup(void *buf, size_t size, bool reattached)
34233423
{
34243424
zend_jit_halt_op = zend_get_halt_op();
34253425
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)
34943494
}
34953495

34963496
zend_jit_unprotect();
3497-
if (zend_jit_setup() != SUCCESS) {
3498-
zend_jit_protect();
3499-
// TODO: error reporting and cleanup ???
3500-
return FAILURE;
3501-
}
3497+
zend_jit_setup();
35023498
zend_jit_protect();
35033499
zend_jit_init_handlers();
35043500

3505-
if (zend_jit_trace_startup(reattached) != SUCCESS) {
3506-
return FAILURE;
3507-
}
3501+
zend_jit_trace_startup(reattached);
35083502

35093503
zend_jit_unprotect();
35103504
/* save JIT buffer pos */
35113505
dasm_ptr[1] = dasm_ptr[0];
35123506
zend_jit_protect();
3513-
3514-
return SUCCESS;
35153507
}
35163508

35173509
ZEND_EXT_API void zend_jit_shutdown(void)

ext/opcache/jit/zend_jit.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ ZEND_EXT_API void zend_jit_init(void);
158158
ZEND_EXT_API int zend_jit_config(zend_string *jit_options, int stage);
159159
ZEND_EXT_API int zend_jit_debug_config(zend_long old_val, zend_long new_val, int stage);
160160
ZEND_EXT_API int zend_jit_check_support(void);
161-
ZEND_EXT_API int zend_jit_startup(void *jit_buffer, size_t size, bool reattached);
161+
ZEND_EXT_API void zend_jit_startup(void *jit_buffer, size_t size, bool reattached);
162162
ZEND_EXT_API void zend_jit_shutdown(void);
163163
ZEND_EXT_API void zend_jit_activate(void);
164164
ZEND_EXT_API void zend_jit_deactivate(void);

ext/opcache/jit/zend_jit_ir.c

+10-23
Original file line numberDiff line numberDiff line change
@@ -2869,7 +2869,7 @@ static void *zend_jit_ir_compile(ir_ctx *ctx, size_t *size, const char *name)
28692869
return entry;
28702870
}
28712871

2872-
static int zend_jit_setup_stubs(void)
2872+
static void zend_jit_setup_stubs(void)
28732873
{
28742874
zend_jit_ctx jit;
28752875
void *entry;
@@ -2888,7 +2888,7 @@ static int zend_jit_setup_stubs(void)
28882888
entry = zend_jit_ir_compile(&jit.ctx, &size, zend_jit_stubs[i].name);
28892889
if (!entry) {
28902890
zend_jit_free_ctx(&jit);
2891-
return 0;
2891+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile stub");
28922892
}
28932893

28942894
zend_jit_stub_handlers[i] = entry;
@@ -2920,7 +2920,6 @@ static int zend_jit_setup_stubs(void)
29202920
}
29212921
zend_jit_free_ctx(&jit);
29222922
}
2923-
return 1;
29242923
}
29252924

29262925
#define REGISTER_HELPER(n) \
@@ -3121,7 +3120,7 @@ static void zend_jit_setup_disasm(void)
31213120
#endif
31223121
}
31233122

3124-
static int zend_jit_calc_trace_prologue_size(void)
3123+
static void zend_jit_calc_trace_prologue_size(void)
31253124
{
31263125
zend_jit_ctx jit_ctx;
31273126
zend_jit_ctx *jit = &jit_ctx;
@@ -3142,11 +3141,10 @@ static int zend_jit_calc_trace_prologue_size(void)
31423141
zend_jit_free_ctx(jit);
31433142

31443143
if (!entry) {
3145-
return 0;
3144+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile prologue");
31463145
}
31473146

31483147
zend_jit_trace_prologue_size = size;
3149-
return 1;
31503148
}
31513149

31523150
#if !ZEND_WIN32 && !defined(IR_TARGET_AARCH64)
@@ -3197,12 +3195,11 @@ static zend_never_inline void zend_jit_set_sp_adj_vm(void)
31973195
}
31983196
#endif
31993197

3200-
static int zend_jit_setup(void)
3198+
static void zend_jit_setup(void)
32013199
{
32023200
#if defined(IR_TARGET_X86)
32033201
if (!zend_cpu_supports_sse2()) {
3204-
zend_error(E_CORE_ERROR, "CPU doesn't support SSE2");
3205-
return FAILURE;
3202+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: CPU doesn't support SSE2");
32063203
}
32073204
#endif
32083205
#if defined(IR_TARGET_X86) || defined(IR_TARGET_X64)
@@ -3235,8 +3232,7 @@ static int zend_jit_setup(void)
32353232
offset += sizeof(void*);
32363233
}
32373234
if (offset >= size) {
3238-
// TODO: error message ???
3239-
return FAILURE;
3235+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: offset >= size");
32403236
}
32413237
} while(0);
32423238
# elif ZEND_WIN32
@@ -3259,8 +3255,7 @@ static int zend_jit_setup(void)
32593255
offset += sizeof(void*);
32603256
}
32613257
if (offset >= size) {
3262-
// TODO: error message ???
3263-
return FAILURE;
3258+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: offset >= size");
32643259
}
32653260
} while(0);
32663261
# elif defined(__APPLE__) && defined(__x86_64__)
@@ -3345,17 +3340,9 @@ static int zend_jit_setup(void)
33453340
ZEND_JIT_DEBUG_IR_AFTER_SCCP|ZEND_JIT_DEBUG_IR_AFTER_SCHEDULE|ZEND_JIT_DEBUG_IR_AFTER_REGS);
33463341
}
33473342

3348-
if (!zend_jit_calc_trace_prologue_size()) {
3349-
JIT_G(debug) = debug;
3350-
return FAILURE;
3351-
}
3352-
if (!zend_jit_setup_stubs()) {
3353-
JIT_G(debug) = debug;
3354-
return FAILURE;
3355-
}
3343+
zend_jit_calc_trace_prologue_size();
3344+
zend_jit_setup_stubs();
33563345
JIT_G(debug) = debug;
3357-
3358-
return SUCCESS;
33593346
}
33603347

33613348
static void zend_jit_shutdown_ir(void)

ext/opcache/jit/zend_jit_trace.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_fla
4646
}
4747
}
4848

49-
static int zend_jit_trace_startup(bool reattached)
49+
static void zend_jit_trace_startup(bool reattached)
5050
{
5151
if (!reattached) {
5252
zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * JIT_G(max_root_traces));
5353
if (!zend_jit_traces) {
54-
return FAILURE;
54+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not allocate JIT root traces buffer!");
5555
}
5656
zend_jit_exit_groups = (const void**)zend_shared_alloc(sizeof(void*) * (ZEND_JIT_TRACE_MAX_EXITS/ZEND_JIT_EXIT_POINTS_PER_GROUP));
5757
if (!zend_jit_exit_groups) {
58-
return FAILURE;
58+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not allocate JIT exit groups buffer!");
5959
}
6060
ZEND_JIT_TRACE_NUM = 1;
6161
ZEND_JIT_COUNTER_NUM = 0;
@@ -67,11 +67,11 @@ static int zend_jit_trace_startup(bool reattached)
6767
} else {
6868
zend_jit_traces = ZCSG(jit_traces);
6969
if (!zend_jit_traces) {
70-
return FAILURE;
70+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not obtain JIT traces buffer!");
7171
}
7272
zend_jit_exit_groups = ZCSG(jit_exit_groups);
7373
if (!zend_jit_exit_groups) {
74-
return FAILURE;
74+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not obtain JIT exit groups buffer!");
7575
}
7676
}
7777

@@ -80,10 +80,8 @@ static int zend_jit_trace_startup(bool reattached)
8080

8181
JIT_G(exit_counters) = calloc(JIT_G(max_exit_counters), 1);
8282
if (JIT_G(exit_counters) == NULL) {
83-
return FAILURE;
83+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not allocate JIT exit counters buffer!");
8484
}
85-
86-
return SUCCESS;
8785
}
8886

8987
static const void *zend_jit_trace_allocate_exit_point(uint32_t n)

0 commit comments

Comments
 (0)