Skip to content

Commit 12583ca

Browse files
committed
chore: wip
1 parent 1d0f4d9 commit 12583ca

File tree

1 file changed

+70
-19
lines changed

1 file changed

+70
-19
lines changed

scripts/build-php.ts

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ function generateConfigureArgs(config: BuildConfig, installPrefix: string): stri
520520
...dependencyArgs,
521521
...platformDependencyArgs,
522522
'--enable-opcache=shared',
523+
'--enable-opcache-jit',
523524
'--with-readline',
524525
'--with-zip',
525526
'--enable-dtrace',
@@ -605,6 +606,7 @@ function generateCIConfigureArgs(config: BuildConfig, installPrefix: string): st
605606
ciArgs.push(
606607
'--with-kerberos',
607608
'--with-readline', // Use readline instead of libedit to avoid ncurses dependency issues
609+
'--enable-opcache-jit', // Enable JIT with inline assembly fixes
608610
)
609611
}
610612
else if (config.platform === 'linux') {
@@ -886,9 +888,9 @@ opcache.validate_timestamps = 1
886888
opcache.save_comments = 1
887889
opcache.enable_file_override = 0
888890
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
892894
893895
; Performance optimizations
894896
opcache.max_wasted_percentage = 5
@@ -978,8 +980,8 @@ opcache.fast_shutdown=1
978980
opcache.save_comments=1
979981
opcache.enable_file_override=0
980982
opcache.validate_timestamps=1
981-
opcache.jit_buffer_size=100M
982-
opcache.jit=tracing
983+
opcache.jit_buffer_size=0
984+
opcache.jit=off
983985
984986
; Phar
985987
phar.readonly = Off
@@ -1730,6 +1732,12 @@ if [ ! -f configure.patched ]; then
17301732
-e 's/have_shm_mmap_posix=no/have_shm_mmap_posix=yes/g' \\
17311733
configure
17321734
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+
17331741
# Mark as patched
17341742
touch configure.patched
17351743
fi
@@ -1887,6 +1895,12 @@ if [ ! -f configure.patched ]; then
18871895
-e 's/have_shm_mmap_posix=no/have_shm_mmap_posix=yes/g' \\
18881896
configure
18891897
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+
18901904
# Mark as patched
18911905
touch configure.patched
18921906
fi
@@ -2337,23 +2351,60 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
23372351
stdio: 'inherit',
23382352
})
23392353

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...')
23432357
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')
23542405
}
23552406
} catch (patchError) {
2356-
log(`⚠️ Failed to apply inline assembly patch: ${patchError}`)
2407+
log(`⚠️ Failed to apply comprehensive inline assembly patches: ${patchError}`)
23572408
// Continue anyway - the build might still work
23582409
}
23592410
}

0 commit comments

Comments
 (0)