fix lto crash

This commit is contained in:
henderkes
2026-07-07 19:08:26 +07:00
parent 435d2c07b0
commit 3823631a58
2 changed files with 24 additions and 3 deletions

View File

@@ -165,15 +165,14 @@ class Zig extends CustomPackage
$zig = "{$zig_bin_dir}/zig";
$verLine = trim((string) shell_exec(escapeshellarg($zig) . ' cc --version 2>/dev/null'));
if (!preg_match('/clang version (\d+\.\d+\.\d+)/', $verLine, $m)) {
logger()->warning('[zig] could not detect bundled clang version; skipping runtime bit build (--pgo + shared libs without __dso_handle)');
return;
throw new \RuntimeException('[zig] could not detect bundled clang version; cannot build clang runtime bits (--pgo, __dso_handle, __cpu_model)');
}
$llvmVersion = $m[1];
logger()->info("Building clang runtime bits for LLVM {$llvmVersion} (zig's bundled clang)");
$srcRoot = $this->fetchCompilerRtSource($llvmVersion);
if ($srcRoot === null) {
return;
throw new \RuntimeException("[zig] failed to fetch compiler-rt {$llvmVersion} sources; cannot build clang runtime bits (--pgo, __dso_handle, __cpu_model)");
}
f_mkdir($libDir, recursive: true);
@@ -187,6 +186,19 @@ class Zig extends CustomPackage
$this->buildCpuModelBuiltins($zig, $srcRoot, $cpuModelLib);
}
FileSystem::removeDir($srcRoot);
// A zig install missing any of these degrades silently at build time
// (no .profraw with --pgo, no __dso_handle in shared libs, unresolved
// __cpu_model for __builtin_cpu_supports — the last one even changes
// which code paths PHP's configure picks, making builds
// machine-dependent). Fail the install instead.
$missing = array_filter(
[$profileLib, $crtBegin, $crtEnd, $cpuModelLib],
fn ($f) => !file_exists($f)
);
if ($missing !== []) {
throw new \RuntimeException('[zig] failed to build clang runtime bits: missing ' . implode(', ', array_map('basename', $missing)) . ' (see warnings above)');
}
}
private function buildCpuModelBuiltins(string $zig, string $srcRoot, string $libPath): void

View File

@@ -50,6 +50,15 @@ class ZigToolchain implements ToolchainInterface
$extra_vars = getenv('SPC_EXTRA_PHP_VARS') ?: '';
GlobalEnvManager::putenv("SPC_EXTRA_PHP_VARS=php_cv_have_avx512=no php_cv_have_avx512vbmi=no {$extra_vars}");
}
// An __attribute__((ifunc)) in LTO bitcode crashes zig 0.16's lld (LLVM 21)
// during thin-link symbol resolution
$all_flags = $cflags . ' ' . (getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: '') . ' ' . (getenv('SPC_DEFAULT_LD_FLAGS') ?: '');
if (str_contains($all_flags, '-flto')) {
$extra_vars = getenv('SPC_EXTRA_PHP_VARS') ?: '';
if (!str_contains($extra_vars, 'ax_cv_have_func_attribute_ifunc')) {
GlobalEnvManager::putenv("SPC_EXTRA_PHP_VARS={$extra_vars} ax_cv_have_func_attribute_ifunc=no");
}
}
}
public function getCompilerInfo(): ?string