8302599: Extend ASan support to Microsoft Visual C++

Reviewed-by: erikj, stuefe, ihse
This commit is contained in:
Justin King 2023-02-20 18:37:16 +00:00
parent c7517b3dec
commit 0bf3a53e01
2 changed files with 24 additions and 7 deletions

View file

@ -415,7 +415,8 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
CHECK_AVAILABLE: [
AC_MSG_CHECKING([if AddressSanitizer (asan) is available])
if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
test "x$TOOLCHAIN_TYPE" = "xclang"; then
test "x$TOOLCHAIN_TYPE" = "xclang" ||
test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
@ -423,11 +424,19 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
fi
],
IF_ENABLED: [
# ASan is simply incompatible with gcc -Wstringop-truncation. See
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85650
# It's harmless to be suppressed in clang as well.
ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
ASAN_LDFLAGS="-fsanitize=address"
if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
test "x$TOOLCHAIN_TYPE" = "xclang"; then
# ASan is simply incompatible with gcc -Wstringop-truncation. See
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85650
# It's harmless to be suppressed in clang as well.
ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
ASAN_LDFLAGS="-fsanitize=address"
elif test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
# -Oy- is equivalent to -fno-omit-frame-pointer in GCC/Clang.
ASAN_CFLAGS="-fsanitize=address -Oy- -DADDRESS_SANITIZER"
# MSVC produces a warning if you pass -fsanitize=address to the linker.
ASAN_LDFLAGS=""
fi
JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
CFLAGS_JDKLIB="$CFLAGS_JDKLIB $ASAN_CFLAGS"