From 74849a8d48166043aa55adf07487592dc8bf0183 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 09:05:44 +0700 Subject: [PATCH] -fno-sanitize=undefined is enabled in zig by default, not in gcc and clang --- config/env.ini | 6 +++--- src/SPC/builder/extension/opcache.php | 11 +++++++++++ src/SPC/builder/linux/LinuxBuilder.php | 7 +++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/config/env.ini b/config/env.ini index d771ee97..5c093fc7 100644 --- a/config/env.ini +++ b/config/env.ini @@ -71,7 +71,7 @@ CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time" +SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time -fno-sanitize=undefined" SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= @@ -98,11 +98,11 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm" +SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LIBS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm" +SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index 5d9dda0a..34673a9d 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -51,4 +51,15 @@ class opcache extends Extension { return 'Zend Opcache'; } + + public function patchBeforeMake(): bool + { + if (!str_contains(getenv('CC'), 'zig')) { + return false; + } + // opcache requires -lunwind, the equivalent to -lgcc_s that gcc automatically links + $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lunwind'); + f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); + return true; + } } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index cd581a95..29eb92e6 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -103,6 +103,10 @@ class LinuxBuilder extends UnixBuilderBase $zts = ''; } $disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : ''; + $cc = trim(getenv('CC')); + if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) { + f_putenv("CC=$cc -fno-sanitize=undefined"); + } $config_file_path = $this->getOption('with-config-file-path', false) ? ('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : ''; @@ -175,6 +179,9 @@ class LinuxBuilder extends UnixBuilderBase } $this->buildEmbed(); } + if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) { + f_putenv("CC=$cc"); + } if ($enableFrankenphp) { logger()->info('building frankenphp'); $this->buildFrankenphp();