Skip to content

Add ASan support for MSVC #6964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/zend_fibers.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# endif
#endif

#ifdef __SANITIZE_ADDRESS__
#if defined(__SANITIZE_ADDRESS__) && !defined(_MSC_VER)
# include <sanitizer/common_interface_defs.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/* needed for ssize_t definition */
#include <sys/types.h>

#ifdef __SANITIZE_ADDRESS__
#if defined(__SANITIZE_ADDRESS__) && !defined(_MSC_VER)
# include <sanitizer/asan_interface.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3093,7 +3093,7 @@ static int accel_startup(zend_extension *extension)
#endif

#ifdef ZEND_WIN32
# if !defined(__has_feature) || !__has_feature(address_sanitizer)
# ifndef __SANITIZE_ADDRESS__
_setmaxstdio(2048); /* The default configuration is limited to 512 stdio files */
# endif
#endif
Expand Down
9 changes: 7 additions & 2 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function main(): void
$temp_source, $temp_target, $test_cnt, $test_dirs,
$test_files, $test_idx, $test_list, $test_results, $testfile,
$user_tests, $valgrind, $sum_results, $shuffle, $file_cache, $num_repeats,
$bless;
$bless, $asan;
// Parallel testing
global $workers, $workerID;
global $context_line_count;
Expand Down Expand Up @@ -363,6 +363,7 @@ function main(): void
$workers = null;
$context_line_count = 3;
$num_repeats = 1;
$asan = false;

$cfgtypes = ['show', 'keep'];
$cfgfiles = ['skip', 'php', 'clean', 'out', 'diff', 'exp', 'mem'];
Expand Down Expand Up @@ -567,6 +568,7 @@ function main(): void
break;
case '--asan':
case '--msan':
$asan = true;
$environment['USE_ZEND_ALLOC'] = 0;
$environment['USE_TRACKED_ALLOC'] = 1;
$environment['SKIP_ASAN'] = 1;
Expand Down Expand Up @@ -1312,7 +1314,10 @@ function system_with_timeout(
$data .= "\nTermsig=" . ($stat["exitcode"] - 128) . "\n";
} else if (defined('PHP_WINDOWS_VERSION_MAJOR') && (($stat["exitcode"] >> 28) & 0b1111) === 0b1100) {
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781
$data .= "\nTermsig=" . $stat["exitcode"] . "\n";
// ignore STATUS_BAD_STACK exit codes under ASan for now
if (!$asan || $stat["exitcode"] !== -1073741784) {
$data .= "\nTermsig=" . $stat["exitcode"] . "\n";
}
}

proc_close($proc);
Expand Down
2 changes: 2 additions & 0 deletions win32/build/confutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,8 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir)
if (PHP_SANITIZER == "yes") {
if (CLANG_TOOLSET) {
add_asan_opts("CFLAGS_" + SAPI, "LIBS_" + SAPI, (is_lib ? "ARFLAGS_" : "LDFLAGS_") + SAPI);
} else if (VS_TOOLSET) {
ADD_FLAG("CFLAGS", "/fsanitize=address");
}
}

Expand Down