ready for packages

This commit is contained in:
henderkes
2026-05-05 11:16:16 +07:00
parent c5edacd8bf
commit 5f43d6a4b4
3 changed files with 28 additions and 4 deletions

View File

@@ -539,11 +539,15 @@ class Extension
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
$postStatic = PHP_OS_FAMILY === 'Darwin' ? '' : ' -Wl,--end-group ';
$extraLd = trim((string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'));
if (PHP_OS_FAMILY !== 'Darwin') {
$extraLd = trim($extraLd . ' -Wl,-Bsymbolic');
}
return [
'CFLAGS' => $config['cflags'],
'CXXFLAGS' => $config['cflags'],
'LDFLAGS' => $config['ldflags'],
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
'EXTRA_LDFLAGS' => $extraLd,
'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"),
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
];
@@ -588,7 +592,7 @@ class Extension
* of static library flags, and the second is a space-separated string
* of shared library flags
*/
protected function splitLibsIntoStaticAndShared(string $allLibs): array
protected function splitLibsIntoStaticAndShared(string $allLibs, array $excludeFromStatic = []): array
{
$staticLibString = '';
$sharedLibString = '';
@@ -598,6 +602,16 @@ class Extension
if (str_starts_with($lib, BUILD_LIB_PATH . '/lib') && str_ends_with($lib, '.a')) {
$staticLib = $lib;
}
// Libs in $excludeFromStatic are statically linked into php-cli already and re-export their
// symbols; including them as static archives in a shared extension creates a second in-process
// copy of the same library (e.g. libssl/libcrypto), causing duplicated atexit handlers and
// shared-state corruption (NULL engine_lock at exit). Drop them here so the shared extension's
// undefined refs resolve at runtime against php-cli's exported symbols instead.
$libName = str_starts_with($lib, '-l') ? substr($lib, 2) : basename($lib, '.a');
$libName = str_starts_with($libName, 'lib') ? substr($libName, 3) : $libName;
if (in_array($libName, $excludeFromStatic, true)) {
continue;
}
if ($lib === '-lphp' || !file_exists($staticLib)) {
$sharedLibString .= " {$lib}";
} else {