-fno-sanitize=undefined is enabled in zig by default, not in gcc and clang

This commit is contained in:
DubbleClick 2025-06-24 09:05:44 +07:00
parent ee0de6933f
commit 74849a8d48
3 changed files with 21 additions and 3 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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();