Skip to content

Commit f2ed9a4

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

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

scripts/build-php.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,56 @@ exec ./configure "$@"
19741974
}
19751975
}
19761976

1977+
// Apply comprehensive source patching for macOS OPcache JIT inline assembly issues
1978+
if (config.platform === 'darwin') {
1979+
log('Applying comprehensive macOS OPcache JIT inline assembly patches...')
1980+
try {
1981+
const jitSourceFiles = [
1982+
'ext/opcache/jit/ir/ir_x86.dasc',
1983+
'ext/opcache/jit/zend_jit_x86.dasc',
1984+
'ext/opcache/jit/ir/ir_emit.c',
1985+
'ext/opcache/jit/ir/ir_ra.c',
1986+
'ext/opcache/jit/zend_jit.c',
1987+
'ext/opcache/jit/zend_jit_arm64.dasc',
1988+
]
1989+
1990+
const patches = [
1991+
// Fix "S" constraint (source register) - incompatible on macOS
1992+
's/asm volatile("([^"]*)" :: "S" ([^)]*))/asm volatile("$1" : : "r" $2 : "memory")/g',
1993+
// Fix "D" constraint (destination register) issues
1994+
's/asm volatile("([^"]*)" :: "D" ([^)]*))/asm volatile("$1" : : "r" $2 : "memory")/g',
1995+
// Fix mixed constraint issues
1996+
's/asm volatile("([^"]*)" :: "([SD])" ([^)]*), "([^"]*)" ([^)]*))/asm volatile("$1" : : "r" $3, "r" $5 : "memory")/g',
1997+
// Fix memory operand issues in inline assembly
1998+
's/__asm__ volatile("([^"]*)" :: "([SD])" ([^)]*))/asm volatile("$1" : : "r" $3 : "memory")/g',
1999+
]
2000+
2001+
for (const filePath of jitSourceFiles) {
2002+
const fullFilePath = join(phpSourceDir, filePath)
2003+
if (existsSync(fullFilePath)) {
2004+
log(`Patching ${filePath}...`)
2005+
for (const patch of patches) {
2006+
try {
2007+
execSync(`sed -i.jitpatch '${patch}' "${fullFilePath}"`, {
2008+
cwd: phpSourceDir,
2009+
stdio: 'pipe'
2010+
})
2011+
} catch (sedError) {
2012+
// Ignore sed errors for patterns that don't match - this is expected
2013+
log(`Note: Pattern '${patch}' not found in ${filePath} (this is normal)`)
2014+
}
2015+
}
2016+
} else {
2017+
log(`Note: File ${filePath} not found (normal for this PHP version)`)
2018+
}
2019+
}
2020+
log('✅ OPcache JIT inline assembly patches applied successfully')
2021+
} catch (patchError: any) {
2022+
log('⚠️ Warning: Failed to apply some OPcache JIT patches:', patchError.message)
2023+
log('Continuing with build - patches may not be needed for this PHP version')
2024+
}
2025+
}
2026+
19772027
log('Building PHP...')
19782028
const jobs = execSync('nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2', { encoding: 'utf8' }).trim()
19792029

0 commit comments

Comments
 (0)