8189800: Add support for AddressSanitizer
authorasmotrak
Tue, 31 Oct 2017 17:03:02 +0300
changeset 47479 77a5f2ef1807
parent 47478 438e0c9f2f17
child 47480 a3b9cabfaed8
8189800: Add support for AddressSanitizer Reviewed-by: ihse, dholmes
make/autoconf/basics.m4
make/autoconf/configure.ac
make/autoconf/generated-configure.sh
make/autoconf/jdk-options.m4
make/autoconf/spec.gmk.in
test/TestCommon.gmk
--- a/make/autoconf/basics.m4	Mon Oct 30 17:49:33 2017 -0700
+++ b/make/autoconf/basics.m4	Tue Oct 31 17:03:02 2017 +0300
@@ -639,6 +639,14 @@
         elif test -d "$DEVKIT_ROOT/$host/sys-root"; then
           SYSROOT="$DEVKIT_ROOT/$host/sys-root"
         fi
+
+        if test "x$DEVKIT_ROOT" != x; then
+          DEVKIT_LIB_DIR="$DEVKIT_ROOT/lib"
+          if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
+            DEVKIT_LIB_DIR="$DEVKIT_ROOT/lib64"
+          fi
+          AC_SUBST(DEVKIT_LIB_DIR)
+        fi
       ]
   )
 
--- a/make/autoconf/configure.ac	Mon Oct 30 17:49:33 2017 -0700
+++ b/make/autoconf/configure.ac	Tue Oct 31 17:03:02 2017 +0300
@@ -1,5 +1,5 @@
 SRC#
-# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -203,6 +203,9 @@
 JDKOPT_SETUP_DEBUG_SYMBOLS
 JDKOPT_SETUP_CODE_COVERAGE
 
+# AddressSanitizer
+JDKOPT_SETUP_ADDRESS_SANITIZER
+
 # Need toolchain to setup dtrace
 HOTSPOT_SETUP_DTRACE
 HOTSPOT_ENABLE_DISABLE_AOT
--- a/make/autoconf/generated-configure.sh	Mon Oct 30 17:49:33 2017 -0700
+++ b/make/autoconf/generated-configure.sh	Tue Oct 31 17:03:02 2017 +0300
@@ -704,6 +704,7 @@
 BUILD_GTEST
 ENABLE_CDS
 ENABLE_AOT
+ASAN_ENABLED
 GCOV_ENABLED
 ZIP_EXTERNAL_DEBUG_SYMBOLS
 COPY_DEBUG_SYMBOLS
@@ -958,6 +959,7 @@
 SPEC
 SDKROOT
 XCODEBUILD
+DEVKIT_LIB_DIR
 JVM_VARIANT_MAIN
 VALID_JVM_VARIANTS
 JVM_VARIANTS
@@ -1171,6 +1173,7 @@
 enable_debug_symbols
 enable_zip_debug_info
 enable_native_coverage
+enable_asan
 enable_dtrace
 enable_aot
 enable_cds
@@ -1976,6 +1979,7 @@
   --enable-native-coverage
                           enable native compilation with code coverage
                           data[disabled]
+  --enable-asan           enable AddressSanitizer if possible [disabled]
   --enable-dtrace[=yes/no/auto]
                           enable dtrace. Default is auto, where dtrace is
                           enabled if all dependencies are present.
@@ -4403,6 +4407,12 @@
 #
 
 
+###############################################################################
+#
+# AddressSanitizer
+#
+
+
 ################################################################################
 #
 # Static build support.  When enabled will generate static
@@ -5115,7 +5125,7 @@
 #CUSTOM_AUTOCONF_INCLUDE
 
 # Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1509013542
+DATE_WHEN_GENERATED=1509128484
 
 ###############################################################################
 #
@@ -17273,6 +17283,14 @@
           SYSROOT="$DEVKIT_ROOT/$host/sys-root"
         fi
 
+        if test "x$DEVKIT_ROOT" != x; then
+          DEVKIT_LIB_DIR="$DEVKIT_ROOT/lib"
+          if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
+            DEVKIT_LIB_DIR="$DEVKIT_ROOT/lib64"
+          fi
+
+        fi
+
 
 fi
 
@@ -54169,6 +54187,49 @@
 
 
 
+# AddressSanitizer
+
+  # Check whether --enable-asan was given.
+if test "${enable_asan+set}" = set; then :
+  enableval=$enable_asan;
+fi
+
+  ASAN_ENABLED="no"
+  if test "x$enable_asan" = "xyes"; then
+    case $TOOLCHAIN_TYPE in
+      gcc | clang)
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking if asan is enabled" >&5
+$as_echo_n "checking if asan is enabled... " >&6; }
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+        ASAN_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
+        ASAN_LDFLAGS="-fsanitize=address"
+        JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
+        JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
+        CFLAGS_JDKLIB="$CFLAGS_JDKLIB $ASAN_CFLAGS"
+        CFLAGS_JDKEXE="$CFLAGS_JDKEXE $ASAN_CFLAGS"
+        CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $ASAN_CFLAGS"
+        CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $ASAN_CFLAGS"
+        LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $ASAN_LDFLAGS"
+        LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $ASAN_LDFLAGS"
+        ASAN_ENABLED="yes"
+        ;;
+      *)
+        as_fn_error $? "--enable-asan only works with toolchain type gcc or clang" "$LINENO" 5
+        ;;
+    esac
+  elif test "x$enable_asan" = "xno"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if asan is enabled" >&5
+$as_echo_n "checking if asan is enabled... " >&6; }
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  elif test "x$enable_asan" != "x"; then
+    as_fn_error $? "--enable-asan can only be assigned \"yes\" or \"no\"" "$LINENO" 5
+  fi
+
+
+
+
 # Need toolchain to setup dtrace
 
   # Test for dtrace dependencies
--- a/make/autoconf/jdk-options.m4	Mon Oct 30 17:49:33 2017 -0700
+++ b/make/autoconf/jdk-options.m4	Tue Oct 31 17:03:02 2017 +0300
@@ -399,6 +399,46 @@
   AC_SUBST(GCOV_ENABLED)
 ])
 
+###############################################################################
+#
+# AddressSanitizer
+#
+AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
+[
+  AC_ARG_ENABLE(asan, [AS_HELP_STRING([--enable-asan],
+      [enable AddressSanitizer if possible @<:@disabled@:>@])])
+  ASAN_ENABLED="no"
+  if test "x$enable_asan" = "xyes"; then
+    case $TOOLCHAIN_TYPE in
+      gcc | clang)
+        AC_MSG_CHECKING([if asan is enabled])
+        AC_MSG_RESULT([yes])
+        ASAN_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
+        ASAN_LDFLAGS="-fsanitize=address"
+        JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
+        JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
+        CFLAGS_JDKLIB="$CFLAGS_JDKLIB $ASAN_CFLAGS"
+        CFLAGS_JDKEXE="$CFLAGS_JDKEXE $ASAN_CFLAGS"
+        CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $ASAN_CFLAGS"
+        CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $ASAN_CFLAGS"
+        LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $ASAN_LDFLAGS"
+        LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $ASAN_LDFLAGS"
+        ASAN_ENABLED="yes"
+        ;;
+      *)
+        AC_MSG_ERROR([--enable-asan only works with toolchain type gcc or clang])
+        ;;
+    esac
+  elif test "x$enable_asan" = "xno"; then
+    AC_MSG_CHECKING([if asan is enabled])
+    AC_MSG_RESULT([no])
+  elif test "x$enable_asan" != "x"; then
+    AC_MSG_ERROR([--enable-asan can only be assigned "yes" or "no"])
+  fi
+
+  AC_SUBST(ASAN_ENABLED)
+])
+
 ################################################################################
 #
 # Static build support.  When enabled will generate static
--- a/make/autoconf/spec.gmk.in	Mon Oct 30 17:49:33 2017 -0700
+++ b/make/autoconf/spec.gmk.in	Tue Oct 31 17:03:02 2017 +0300
@@ -312,6 +312,16 @@
 
 GCOV_ENABLED=@GCOV_ENABLED@
 
+# AddressSanitizer
+export ASAN_ENABLED:=@ASAN_ENABLED@
+export DEVKIT_LIB_DIR:=@DEVKIT_LIB_DIR@
+ifeq ($(ASAN_ENABLED), yes)
+  export ASAN_OPTIONS="handle_segv=0 detect_leaks=0"
+  ifneq ($(DEVKIT_LIB_DIR),)
+    export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):$(DEVKIT_LIB_DIR)
+  endif
+endif
+
 # Necessary additional compiler flags to compile X11
 X_CFLAGS:=@X_CFLAGS@
 X_LIBS:=@X_LIBS@
--- a/test/TestCommon.gmk	Mon Oct 30 17:49:33 2017 -0700
+++ b/test/TestCommon.gmk	Tue Oct 31 17:03:02 2017 +0300
@@ -188,6 +188,16 @@
   CLEAN_ARCHIVE_BUNDLE = @$(RM) $(ARCHIVE_BUNDLE)
 endif
 
+# AddressSanitizer
+ifeq ($(ASAN_ENABLED), yes)
+  export ASAN_OPTIONS="handle_segv=0 detect_leaks=0"
+  JTREG_BASIC_OPTIONS += -e:ASAN_OPTIONS=$(ASAN_OPTIONS)
+  ifneq ($(DEVKIT_LIB_DIR),)
+    export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):$(DEVKIT_LIB_DIR)
+    JTREG_BASIC_OPTIONS += -e:LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)
+  endif
+endif
+
 # important results files
 SUMMARY_TXT = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTreport/text/summary.txt")
 STATS_TXT_NAME = Stats.txt