Skip to content

Commit 0bf3a53

Browse files
committed
8302599: Extend ASan support to Microsoft Visual C++
Reviewed-by: erikj, stuefe, ihse
1 parent c7517b3 commit 0bf3a53

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

make/autoconf/jdk-options.m4

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,19 +415,28 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
415415
CHECK_AVAILABLE: [
416416
AC_MSG_CHECKING([if AddressSanitizer (asan) is available])
417417
if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
418-
test "x$TOOLCHAIN_TYPE" = "xclang"; then
418+
test "x$TOOLCHAIN_TYPE" = "xclang" ||
419+
test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
419420
AC_MSG_RESULT([yes])
420421
else
421422
AC_MSG_RESULT([no])
422423
AVAILABLE=false
423424
fi
424425
],
425426
IF_ENABLED: [
426-
# ASan is simply incompatible with gcc -Wstringop-truncation. See
427-
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85650
428-
# It's harmless to be suppressed in clang as well.
429-
ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
430-
ASAN_LDFLAGS="-fsanitize=address"
427+
if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
428+
test "x$TOOLCHAIN_TYPE" = "xclang"; then
429+
# ASan is simply incompatible with gcc -Wstringop-truncation. See
430+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85650
431+
# It's harmless to be suppressed in clang as well.
432+
ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
433+
ASAN_LDFLAGS="-fsanitize=address"
434+
elif test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
435+
# -Oy- is equivalent to -fno-omit-frame-pointer in GCC/Clang.
436+
ASAN_CFLAGS="-fsanitize=address -Oy- -DADDRESS_SANITIZER"
437+
# MSVC produces a warning if you pass -fsanitize=address to the linker.
438+
ASAN_LDFLAGS=""
439+
fi
431440
JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
432441
JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
433442
CFLAGS_JDKLIB="$CFLAGS_JDKLIB $ASAN_CFLAGS"

make/data/asan/asan_default_options.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
#if (defined(__GNUC__) && !defined(__clang__)) || __has_attribute(visibility)
3535
#define ATTRIBUTE_DEFAULT_VISIBILITY __attribute__((visibility("default")))
36+
#elif defined(_MSC_VER)
37+
#define ATTRIBUTE_DEFAULT_VISIBILITY __declspec(dllexport)
3638
#else
3739
#define ATTRIBUTE_DEFAULT_VISIBILITY
3840
#endif
@@ -43,12 +45,18 @@
4345
#define ATTRIBUTE_USED
4446
#endif
4547

48+
#if defined(_MSC_VER)
49+
#define CDECL __cdecl
50+
#else
51+
#define CDECL
52+
#endif
53+
4654
// Override weak symbol exposed by ASan to override default options. This is called by ASan
4755
// extremely early during library loading, before main is called. We need to override the default
4856
// options because LSan is enabled by default and Hotspot is not yet compatible with it.
4957
// Additionally we need to prevent ASan from handling SIGSEGV, so that Hotspot's crash handler is
5058
// used. You can override these options by setting the environment variable ASAN_OPTIONS.
51-
ATTRIBUTE_DEFAULT_VISIBILITY ATTRIBUTE_USED const char* __asan_default_options() {
59+
ATTRIBUTE_DEFAULT_VISIBILITY ATTRIBUTE_USED const char* CDECL __asan_default_options() {
5260
return
5361
#ifdef LEAK_SANITIZER
5462
"leak_check_at_exit=0,"

0 commit comments

Comments
 (0)