Skip to content

Commit e2ea8fb

Browse files
committed
Add ASan support for VS
As of VS 16.9, there is native support for ASan in the MSVC toolchain. Although it is already possible to enable that by adding the respective option to `CFLAGS`, we make it available via the configure option `--enable-sanitizer` which is only used for clang builds on Windows so far. We also disable the manual inclusion of ASan headers, since these are available by default. We use the more general `__SANITIZE_ADDRESS__` for detection of ASan, to avoid a bogus warning, when `_setmaxstdio()` is called.
1 parent e0b947a commit e2ea8fb

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

Zend/zend_fibers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# include <limits.h>
4040
#endif
4141

42-
#ifdef __SANITIZE_ADDRESS__
42+
#if defined(__SANITIZE_ADDRESS__) && !defined(_MSC_VER)
4343
# include <sanitizer/common_interface_defs.h>
4444
#endif
4545

ext/exif/exif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/* needed for ssize_t definition */
4949
#include <sys/types.h>
5050

51-
#ifdef __SANITIZE_ADDRESS__
51+
#if defined(__SANITIZE_ADDRESS__) && !defined(_MSC_VER)
5252
# include <sanitizer/asan_interface.h>
5353
#endif
5454

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3090,7 +3090,7 @@ static int accel_startup(zend_extension *extension)
30903090
#endif
30913091

30923092
#ifdef ZEND_WIN32
3093-
# if !defined(__has_feature) || !__has_feature(address_sanitizer)
3093+
# ifndef __SANITIZE_ADDRESS__
30943094
_setmaxstdio(2048); /* The default configuration is limited to 512 stdio files */
30953095
# endif
30963096
#endif

win32/build/confutils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,8 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir)
12411241
if (PHP_SANITIZER == "yes") {
12421242
if (CLANG_TOOLSET) {
12431243
add_asan_opts("CFLAGS_" + SAPI, "LIBS_" + SAPI, (is_lib ? "ARFLAGS_" : "LDFLAGS_") + SAPI);
1244+
} else if (VS_TOOLSET) {
1245+
ADD_FLAG("CFLAGS", "/fsanitize=address");
12441246
}
12451247
}
12461248

0 commit comments

Comments
 (0)