Skip to content

Commit 9161547

Browse files
committed
Report fatal error if JIT cannot be enabled
1 parent 7bcfac9 commit 9161547

File tree

7 files changed

+31
-51
lines changed

7 files changed

+31
-51
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Intl:
2020

2121
Opcache:
2222
. Added large shared segments support for FreeBSD. (David Carlier)
23+
. If JIT is enabled, PHP will now exit with a fatal error on startup
24+
in case of JIT startup initialization issues. (danog)
2325

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

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ PHP 8.4 UPGRADE NOTES
153153
9. Other Changes to Extensions
154154
========================================
155155

156+
- Opcache:
157+
. If JIT is enabled, PHP will now exit with a fatal error on startup
158+
in case of JIT startup initialization issues.
159+
156160
- Intl:
157161
. The class constants are typed now.
158162

ext/opcache/ZendAccelerator.c

Lines changed: 5 additions & 8 deletions
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

Lines changed: 3 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,7 @@ static void *zend_jit_ir_compile(ir_ctx *ctx, size_t *size, const char *name)
28672867
return entry;
28682868
}
28692869

2870-
static int zend_jit_setup_stubs(void)
2870+
static void zend_jit_setup_stubs(void)
28712871
{
28722872
zend_jit_ctx jit;
28732873
void *entry;
@@ -2886,7 +2886,7 @@ static int zend_jit_setup_stubs(void)
28862886
entry = zend_jit_ir_compile(&jit.ctx, &size, zend_jit_stubs[i].name);
28872887
if (!entry) {
28882888
zend_jit_free_ctx(&jit);
2889-
return 0;
2889+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile stub");
28902890
}
28912891

28922892
zend_jit_stub_handlers[i] = entry;
@@ -2918,7 +2918,6 @@ static int zend_jit_setup_stubs(void)
29182918
}
29192919
zend_jit_free_ctx(&jit);
29202920
}
2921-
return 1;
29222921
}
29232922

29242923
#define REGISTER_HELPER(n) \
@@ -3119,7 +3118,7 @@ static void zend_jit_setup_disasm(void)
31193118
#endif
31203119
}
31213120

3122-
static int zend_jit_calc_trace_prologue_size(void)
3121+
static void zend_jit_calc_trace_prologue_size(void)
31233122
{
31243123
zend_jit_ctx jit_ctx;
31253124
zend_jit_ctx *jit = &jit_ctx;
@@ -3140,11 +3139,10 @@ static int zend_jit_calc_trace_prologue_size(void)
31403139
zend_jit_free_ctx(jit);
31413140

31423141
if (!entry) {
3143-
return 0;
3142+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile prologue");
31443143
}
31453144

31463145
zend_jit_trace_prologue_size = size;
3147-
return 1;
31483146
}
31493147

31503148
#if !ZEND_WIN32 && !defined(IR_TARGET_AARCH64)
@@ -3195,12 +3193,11 @@ static zend_never_inline void zend_jit_set_sp_adj_vm(void)
31953193
}
31963194
#endif
31973195

3198-
static int zend_jit_setup(void)
3196+
static void zend_jit_setup(void)
31993197
{
32003198
#if defined(IR_TARGET_X86)
32013199
if (!zend_cpu_supports_sse2()) {
3202-
zend_error(E_CORE_ERROR, "CPU doesn't support SSE2");
3203-
return FAILURE;
3200+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: CPU doesn't support SSE2");
32043201
}
32053202
#endif
32063203
#if defined(IR_TARGET_X86) || defined(IR_TARGET_X64)
@@ -3233,8 +3230,7 @@ static int zend_jit_setup(void)
32333230
offset += sizeof(void*);
32343231
}
32353232
if (offset >= size) {
3236-
// TODO: error message ???
3237-
return FAILURE;
3233+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: offset >= size");
32383234
}
32393235
} while(0);
32403236
# elif ZEND_WIN32
@@ -3257,8 +3253,7 @@ static int zend_jit_setup(void)
32573253
offset += sizeof(void*);
32583254
}
32593255
if (offset >= size) {
3260-
// TODO: error message ???
3261-
return FAILURE;
3256+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: offset >= size");
32623257
}
32633258
} while(0);
32643259
# elif defined(__APPLE__) && defined(__x86_64__)
@@ -3343,17 +3338,9 @@ static int zend_jit_setup(void)
33433338
ZEND_JIT_DEBUG_IR_AFTER_SCCP|ZEND_JIT_DEBUG_IR_AFTER_SCHEDULE|ZEND_JIT_DEBUG_IR_AFTER_REGS);
33443339
}
33453340

3346-
if (!zend_jit_calc_trace_prologue_size()) {
3347-
JIT_G(debug) = debug;
3348-
return FAILURE;
3349-
}
3350-
if (!zend_jit_setup_stubs()) {
3351-
JIT_G(debug) = debug;
3352-
return FAILURE;
3353-
}
3341+
zend_jit_calc_trace_prologue_size();
3342+
zend_jit_setup_stubs();
33543343
JIT_G(debug) = debug;
3355-
3356-
return SUCCESS;
33573344
}
33583345

33593346
static void zend_jit_shutdown_ir(void)

ext/opcache/jit/zend_jit_trace.c

Lines changed: 6 additions & 8 deletions
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)