Skip to content

Commit 74849a8

Browse files
committed
-fno-sanitize=undefined is enabled in zig by default, not in gcc and clang
1 parent ee0de69 commit 74849a8

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

config/env.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ CXX=${SPC_LINUX_DEFAULT_CXX}
7171
AR=${SPC_LINUX_DEFAULT_AR}
7272
LD=${SPC_LINUX_DEFAULT_LD}
7373
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
74-
SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time"
74+
SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time -fno-sanitize=undefined"
7575
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
7676
; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated)
7777
SPC_EXTRA_LIBS=
@@ -98,11 +98,11 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}"
9898
; LDFLAGS for configuring php
9999
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
100100
; LIBS for configuring php
101-
SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm"
101+
SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil"
102102
; EXTRA_CFLAGS for `make` php
103103
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
104104
; EXTRA_LIBS for `make` php
105-
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm"
105+
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil"
106106
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
107107
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
108108
; EXTRA_LDFLAGS_PROGRAM for `make` php

src/SPC/builder/extension/opcache.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,15 @@ public function getDistName(): string
5151
{
5252
return 'Zend Opcache';
5353
}
54+
55+
public function patchBeforeMake(): bool
56+
{
57+
if (!str_contains(getenv('CC'), 'zig')) {
58+
return false;
59+
}
60+
// opcache requires -lunwind, the equivalent to -lgcc_s that gcc automatically links
61+
$extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lunwind');
62+
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
63+
return true;
64+
}
5465
}

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
103103
$zts = '';
104104
}
105105
$disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : '';
106+
$cc = trim(getenv('CC'));
107+
if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) {
108+
f_putenv("CC=$cc -fno-sanitize=undefined");
109+
}
106110

107111
$config_file_path = $this->getOption('with-config-file-path', false) ?
108112
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
@@ -175,6 +179,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
175179
}
176180
$this->buildEmbed();
177181
}
182+
if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) {
183+
f_putenv("CC=$cc");
184+
}
178185
if ($enableFrankenphp) {
179186
logger()->info('building frankenphp');
180187
$this->buildFrankenphp();

0 commit comments

Comments
 (0)