mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 01:15:37 +08:00
fix aarch64 shared extensions segfault with zig 0.16.0 (#1110)
This commit is contained in:
@@ -11,6 +11,9 @@ use SPC\exception\ValidationException;
|
|||||||
use SPC\exception\WrongUsageException;
|
use SPC\exception\WrongUsageException;
|
||||||
use SPC\store\Config;
|
use SPC\store\Config;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\toolchain\ToolchainManager;
|
||||||
|
use SPC\toolchain\ZigToolchain;
|
||||||
|
use SPC\util\GlobalEnvManager;
|
||||||
use SPC\util\SPCConfigUtil;
|
use SPC\util\SPCConfigUtil;
|
||||||
use SPC\util\SPCTarget;
|
use SPC\util\SPCTarget;
|
||||||
|
|
||||||
@@ -231,7 +234,7 @@ class Extension
|
|||||||
if (preg_match('/^(.*_SHARED_LIBADD\s*=\s*)(.*)$/m', $makefileContent, $matches)) {
|
if (preg_match('/^(.*_SHARED_LIBADD\s*=\s*)(.*)$/m', $makefileContent, $matches)) {
|
||||||
$prefix = $matches[1];
|
$prefix = $matches[1];
|
||||||
$currentLibs = trim($matches[2]);
|
$currentLibs = trim($matches[2]);
|
||||||
$newLibs = trim("{$currentLibs} {$staticLibs} {$lstdcpp}");
|
$newLibs = clean_spaces("{$currentLibs} {$staticLibs} {$lstdcpp}");
|
||||||
$deduplicatedLibs = deduplicate_flags($newLibs);
|
$deduplicatedLibs = deduplicate_flags($newLibs);
|
||||||
|
|
||||||
FileSystem::replaceFileRegex(
|
FileSystem::replaceFileRegex(
|
||||||
@@ -543,6 +546,11 @@ class Extension
|
|||||||
*/
|
*/
|
||||||
protected function getSharedExtensionEnv(): array
|
protected function getSharedExtensionEnv(): array
|
||||||
{
|
{
|
||||||
|
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
|
||||||
|
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
|
||||||
|
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
|
||||||
|
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
|
||||||
|
}
|
||||||
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
|
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
|
||||||
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
||||||
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
|
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use SPC\store\Config;
|
|||||||
use SPC\store\DirDiff;
|
use SPC\store\DirDiff;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
use SPC\store\SourcePatcher;
|
use SPC\store\SourcePatcher;
|
||||||
|
use SPC\toolchain\ToolchainManager;
|
||||||
|
use SPC\toolchain\ZigToolchain;
|
||||||
use SPC\util\GlobalEnvManager;
|
use SPC\util\GlobalEnvManager;
|
||||||
use SPC\util\SPCConfigUtil;
|
use SPC\util\SPCConfigUtil;
|
||||||
use SPC\util\SPCTarget;
|
use SPC\util\SPCTarget;
|
||||||
@@ -65,7 +67,8 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
// php 8.5 contains opcache extension by default,
|
// php 8.5 contains opcache extension by default,
|
||||||
// if opcache_jit is enabled for 8.5 or opcache enabled,
|
// if opcache_jit is enabled for 8.5 or opcache enabled,
|
||||||
// we need to disable undefined behavior sanitizer.
|
// we need to disable undefined behavior sanitizer.
|
||||||
f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined');
|
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
|
||||||
|
f_putenv('SPC_COMPILER_EXTRA=' . trim($compiler_extra . ' -fno-sanitize=undefined'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getOption('enable-zts', false)) {
|
if ($this->getOption('enable-zts', false)) {
|
||||||
@@ -266,6 +269,11 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
*/
|
*/
|
||||||
protected function buildEmbed(): void
|
protected function buildEmbed(): void
|
||||||
{
|
{
|
||||||
|
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
|
||||||
|
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
|
||||||
|
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
|
||||||
|
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
|
||||||
|
}
|
||||||
$sharedExts = array_filter($this->exts, static fn ($ext) => $ext->isBuildShared());
|
$sharedExts = array_filter($this->exts, static fn ($ext) => $ext->isBuildShared());
|
||||||
$sharedExts = array_filter($sharedExts, static function ($ext) {
|
$sharedExts = array_filter($sharedExts, static function ($ext) {
|
||||||
return Config::getExt($ext->getName(), 'build-with-php') === true;
|
return Config::getExt($ext->getName(), 'build-with-php') === true;
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
#include <sapi/embed/php_embed.h>
|
#include <sapi/embed/php_embed.h>
|
||||||
|
|
||||||
int main(int argc,char **argv){
|
int main(int argc, char **argv) {
|
||||||
|
PHP_EMBED_START_BLOCK(argc, argv)
|
||||||
PHP_EMBED_START_BLOCK(argc,argv)
|
|
||||||
|
|
||||||
zend_file_handle file_handle;
|
zend_file_handle file_handle;
|
||||||
|
zend_stream_init_filename(&file_handle, "embed.php");
|
||||||
zend_stream_init_filename(&file_handle,"embed.php");
|
if(!php_execute_script(&file_handle)) {
|
||||||
|
|
||||||
if(!php_execute_script(&file_handle)){
|
|
||||||
php_printf("Failed to execute PHP script.\n");
|
php_printf("Failed to execute PHP script.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_EMBED_END_BLOCK()
|
PHP_EMBED_END_BLOCK()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user