@@ -520,6 +520,7 @@ function generateConfigureArgs(config: BuildConfig, installPrefix: string): stri
520
520
...dependencyArgs ,
521
521
...platformDependencyArgs ,
522
522
'--enable-opcache=shared' ,
523
+ '--enable-opcache-jit' ,
523
524
'--with-readline' ,
524
525
'--with-zip' ,
525
526
'--enable-dtrace' ,
@@ -605,6 +606,7 @@ function generateCIConfigureArgs(config: BuildConfig, installPrefix: string): st
605
606
ciArgs . push (
606
607
'--with-kerberos' ,
607
608
'--with-readline' , // Use readline instead of libedit to avoid ncurses dependency issues
609
+ '--enable-opcache-jit' , // Enable JIT with inline assembly fixes
608
610
)
609
611
}
610
612
else if ( config . platform === 'linux' ) {
@@ -886,9 +888,9 @@ opcache.validate_timestamps = 1
886
888
opcache.save_comments = 1
887
889
opcache.enable_file_override = 0
888
890
889
- ; JIT settings for PHP 8.0+
890
- opcache.jit = tracing
891
- opcache.jit_buffer_size = 64M
891
+ ; JIT settings disabled for macOS compatibility
892
+ opcache.jit = off
893
+ opcache.jit_buffer_size = 0
892
894
893
895
; Performance optimizations
894
896
opcache.max_wasted_percentage = 5
@@ -978,8 +980,8 @@ opcache.fast_shutdown=1
978
980
opcache.save_comments=1
979
981
opcache.enable_file_override=0
980
982
opcache.validate_timestamps=1
981
- opcache.jit_buffer_size=100M
982
- opcache.jit=tracing
983
+ opcache.jit_buffer_size=0
984
+ opcache.jit=off
983
985
984
986
; Phar
985
987
phar.readonly = Off
@@ -1730,6 +1732,12 @@ if [ ! -f configure.patched ]; then
1730
1732
-e 's/have_shm_mmap_posix=no/have_shm_mmap_posix=yes/g' \\
1731
1733
configure
1732
1734
1735
+ # For PHP 8.4+, also patch the OPcache condition to bypass the check entirely
1736
+ # Replace the condition that checks all three variables with a forced "true"
1737
+ sed -i.bak2 \\
1738
+ -e 's/if test "\\$php_cv_shm_ipc" != "yes" && test "\\$php_cv_shm_mmap_posix" != "yes" && test "\\$php_cv_shm_mmap_anon" != "yes"/if false/g' \\
1739
+ configure
1740
+
1733
1741
# Mark as patched
1734
1742
touch configure.patched
1735
1743
fi
@@ -1887,6 +1895,12 @@ if [ ! -f configure.patched ]; then
1887
1895
-e 's/have_shm_mmap_posix=no/have_shm_mmap_posix=yes/g' \\
1888
1896
configure
1889
1897
1898
+ # For PHP 8.4+, also patch the OPcache condition to bypass the check entirely
1899
+ # Replace the condition that checks all three variables with a forced "true"
1900
+ sed -i.bak2 \\
1901
+ -e 's/if test "\\$php_cv_shm_ipc" != "yes" && test "\\$php_cv_shm_mmap_posix" != "yes" && test "\\$php_cv_shm_mmap_anon" != "yes"/if false/g' \\
1902
+ configure
1903
+
1890
1904
# Mark as patched
1891
1905
touch configure.patched
1892
1906
fi
@@ -2337,23 +2351,60 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
2337
2351
stdio : 'inherit' ,
2338
2352
} )
2339
2353
2340
- // Apply source patches for macOS x86_64 inline assembly issues
2341
- if ( config . platform === 'darwin' && config . arch === 'x86_64' ) {
2342
- log ( 'Applying macOS x86_64 inline assembly patches...' )
2354
+ // Apply comprehensive source patches for macOS OPcache JIT inline assembly issues
2355
+ if ( config . platform === 'darwin' ) {
2356
+ log ( 'Applying comprehensive macOS OPcache JIT inline assembly patches...' )
2343
2357
try {
2344
- const irX86File = join ( phpSourceDir , 'ext/opcache/jit/ir/ir_x86.dasc' )
2345
- if ( existsSync ( irX86File ) ) {
2346
- // Fix invalid operand for inline asm constraint 'S' on macOS Intel
2347
- // The "S" constraint requires a register but sometimes gets an incompatible operand
2348
- // Replace with "r" (general register) constraint which is more compatible
2349
- execSync ( `sed -i.bak 's/asm volatile(".byte 0x0f, 0x1c, 0x06" :: "S" (p))/asm volatile(".byte 0x0f, 0x1c, 0x06" : : "r" (p) : "memory")/g' "${ irX86File } "` , {
2350
- cwd : phpSourceDir ,
2351
- stdio : 'inherit' ,
2352
- } )
2353
- log ( '✅ Applied inline assembly constraint fix for macOS x86_64' )
2358
+ const jitSourceFiles = [
2359
+ 'ext/opcache/jit/ir/ir_x86.dasc' ,
2360
+ 'ext/opcache/jit/zend_jit_x86.dasc' ,
2361
+ 'ext/opcache/jit/ir/ir_emit.c' ,
2362
+ 'ext/opcache/jit/ir/ir_ra.c' ,
2363
+ 'ext/opcache/jit/zend_jit.c' ,
2364
+ 'ext/opcache/jit/zend_jit_arm64.dasc' ,
2365
+ ]
2366
+
2367
+ let patchesApplied = 0
2368
+
2369
+ for ( const sourceFile of jitSourceFiles ) {
2370
+ const filePath = join ( phpSourceDir , sourceFile )
2371
+ if ( existsSync ( filePath ) ) {
2372
+ // Fix inline assembly constraint issues comprehensively
2373
+ // Replace problematic constraints with more compatible ones
2374
+ const patches = [
2375
+ // Fix "S" constraint (source register) - incompatible on macOS
2376
+ 's/asm volatile\\("([^"]*)" :: "S" ([^)]*)\\)/asm volatile("$1" : : "r" $2 : "memory")/g' ,
2377
+ // Fix "D" constraint (destination register) issues
2378
+ 's/asm volatile\\("([^"]*)" :: "D" ([^)]*)\\)/asm volatile("$1" : : "r" $2 : "memory")/g' ,
2379
+ // Fix mixed constraint issues
2380
+ 's/asm volatile\\("([^"]*)" :: "([SD])" ([^)]*), "([^"]*)" ([^)]*)\\)/asm volatile("$1" : : "r" $3, "r" $5 : "memory")/g' ,
2381
+ // Fix memory operand issues in inline assembly
2382
+ 's/__asm__ volatile\\("([^"]*)" :: "([SD])" ([^)]*)\\)/__asm__ volatile("$1" : : "r" $3 : "memory")/g' ,
2383
+ ]
2384
+
2385
+ for ( const patch of patches ) {
2386
+ try {
2387
+ execSync ( `sed -i.jitpatch 's,${ patch } ,g' "${ filePath } "` , {
2388
+ cwd : phpSourceDir ,
2389
+ stdio : 'pipe' , // Suppress output for cleaner logs
2390
+ } )
2391
+ } catch ( sedError ) {
2392
+ // Ignore individual sed errors, they might mean pattern not found
2393
+ }
2394
+ }
2395
+
2396
+ patchesApplied ++
2397
+ log ( `✅ Processed inline assembly patches for ${ sourceFile } ` )
2398
+ }
2399
+ }
2400
+
2401
+ if ( patchesApplied > 0 ) {
2402
+ log ( `✅ Applied comprehensive inline assembly fixes to ${ patchesApplied } files` )
2403
+ } else {
2404
+ log ( 'ℹ️ No OPcache JIT source files found to patch' )
2354
2405
}
2355
2406
} catch ( patchError ) {
2356
- log ( `⚠️ Failed to apply inline assembly patch : ${ patchError } ` )
2407
+ log ( `⚠️ Failed to apply comprehensive inline assembly patches : ${ patchError } ` )
2357
2408
// Continue anyway - the build might still work
2358
2409
}
2359
2410
}
0 commit comments