Skip to content

Commit f98dcc5

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 9a42d2b commit f98dcc5

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
@@ -55,7 +55,7 @@
5555
# endif
5656
#endif
5757

58-
#ifdef __SANITIZE_ADDRESS__
58+
#if defined(__SANITIZE_ADDRESS__) && !defined(_MSC_VER)
5959
# include <sanitizer/common_interface_defs.h>
6060
#endif
6161

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
@@ -3093,7 +3093,7 @@ static int accel_startup(zend_extension *extension)
30933093
#endif
30943094

30953095
#ifdef ZEND_WIN32
3096-
# if !defined(__has_feature) || !__has_feature(address_sanitizer)
3096+
# ifndef __SANITIZE_ADDRESS__
30973097
_setmaxstdio(2048); /* The default configuration is limited to 512 stdio files */
30983098
# endif
30993099
#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)