fixes for thin lto

This commit is contained in:
henderkes
2026-05-06 09:35:20 +07:00
parent 410f1d2fc8
commit 712beff2f5
5 changed files with 29 additions and 2 deletions

View File

@@ -10,13 +10,26 @@ use SPC\util\SPCTarget;
trait ncurses
{
public function patchBeforeBuild(): bool
{
// MKlib_gen.sh feeds preprocessor stdout through a sed/awk pipeline into lib_gen.c.
// zig-cc/clang leaks the "N warning(s) generated." summary onto stdout (not stderr),
// and that line ends up as invalid C in the generated source. Filter it out of the pipe.
FileSystem::replaceFileStr(
$this->source_dir . '/ncurses/base/MKlib_gen.sh',
'$preprocessor $TMP 2>/dev/null \\',
"\$preprocessor \$TMP 2>/dev/null \\\n| grep -v ' generated\\.\$' \\",
);
return true;
}
protected function build(): void
{
$filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
UnixAutoconfExecutor::create($this)
->appendEnv([
'CFLAGS' => '-std=c17',
'CFLAGS' => '-std=c17 -w',
'LDFLAGS' => SPCTarget::isStatic() ? '-static' : '',
])
->configure(

View File

@@ -21,6 +21,14 @@ trait unixodbc
'Linux' => '/etc',
default => throw new WrongUsageException('Unsupported OS: ' . PHP_OS_FAMILY),
};
// libltdl is incompatible with -flto (https://bugs.gentoo.org/532672)
$stripLto = static fn ($s) => preg_replace('/(^|\s)-flto(=\S+)?(?=\s|$)/', ' ', (string) $s);
$origC = $this->builder->arch_c_flags;
$origCxx = $this->builder->arch_cxx_flags;
$origLd = $this->builder->arch_ld_flags;
$this->builder->arch_c_flags = clean_spaces($stripLto($origC));
$this->builder->arch_cxx_flags = clean_spaces($stripLto($origCxx));
$this->builder->arch_ld_flags = clean_spaces($stripLto($origLd));
$make = UnixAutoconfExecutor::create($this)
->configure(
'--disable-debug',
@@ -37,6 +45,10 @@ trait unixodbc
);
$make->make();
$this->builder->arch_c_flags = $origC;
$this->builder->arch_cxx_flags = $origCxx;
$this->builder->arch_ld_flags = $origLd;
$pkgConfigs = ['odbc.pc', 'odbccr.pc', 'odbcinst.pc'];
$this->patchPkgconfPrefix($pkgConfigs);
foreach ($pkgConfigs as $file) {