Update PgoData to release-20180603-0040 (#18265)
[platform/upstream/coreclr.git] / enablesanitizers.sh
index 0afec5d..aedb95d 100755 (executable)
@@ -10,20 +10,23 @@ if [ $# -eq 0 ]; then
         echo " cd $(dirname $0);. enablesanitizers.sh [options]; cd -"
     fi
     echo "Usage: [asan] [ubsan] [lsan] [all] [off] [clangx.y]"
-    echo "asan: optional argument to enable Address Sanitizer."
-    echo "ubsan: optional argument to enable Undefined Behavior Sanitizer."
-    echo "lsan - optional argument to enable memory Leak Sanitizer."
-    echo "all - optional argument to enable asan, ubsan and lsan."
-    echo "off - optional argument to turn off all sanitizers."
-    echo "clangx.y - optional argument to specify clang version x.y. which is used to resolve stack traces."
+    echo " asan: optional argument to enable Address Sanitizer."
+    echo " ubsan: optional argument to enable Undefined Behavior Sanitizer."
+    echo " lsan - optional argument to enable memory Leak Sanitizer."
+    echo " all - optional argument to enable asan, ubsan and lsan."
+    echo " off - optional argument to turn off all sanitizers."
+    echo " clangx.y - optional argument to specify clang version x.y. which is used to resolve stack traces. Default is 3.6"
 else
+    # default to clang 3.6 instead of 3.5 because it supports print_stacktrace (otherwise only one stack frame)
     __ClangMajorVersion=3
-    __ClangMinorVersion=5
+    __ClangMinorVersion=6
+
     __EnableASan=0
     __EnableUBSan=0
     __EnableLSan=0
     __TurnOff=0
     __Options=
+    __ExportSymbolizerPath=1
 
     for i in "$@"
         do
@@ -58,6 +61,17 @@ else
             clang3.7)
                 __ClangMajorVersion=3
                 __ClangMinorVersion=7
+                __ExportSymbolizerPath=0
+                ;;
+            clang3.8)
+                __ClangMajorVersion=3
+                __ClangMinorVersion=8
+                __ExportSymbolizerPath=0
+                ;;
+            clang3.9)
+                __ClangMajorVersion=3
+                __ClangMinorVersion=9
+                __ExportSymbolizerPath=0
                 ;;
             *)
                 echo "Unknown arg: $i"
@@ -69,7 +83,11 @@ else
         unset DEBUG_SANITIZERS
         echo "Setting DEBUG_SANITIZERS="
     else
-        ASAN_OPTIONS="symbolize=1"
+        # for now, specify alloc_dealloc_mismatch=0 as there are too many error reports that are not an issue.
+        # Also specify use_sigaltstack=0 as coreclr uses own alternate stack for signal handlers
+        ASAN_OPTIONS="symbolize=1 alloc_dealloc_mismatch=0 use_sigaltstack=0"
+        # when Clang 3.8 available, add: suppressions=$(readlink -f sanitizersuppressions.txt)
+        UBSAN_OPTIONS="print_stacktrace=1"
 
         if [ $__EnableASan == 1 ]; then
             __Options="$__Options asan"
@@ -78,7 +96,9 @@ else
             __Options="$__Options ubsan"
         fi
         if [ $__EnableLSan == 1 ]; then
-            ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks"
+            ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks=1"
+        else
+            ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks=0"
         fi
 
         # passed to build.sh
@@ -87,14 +107,23 @@ else
         echo "Setting DEBUG_SANITIZERS=$DEBUG_SANITIZERS"
 
         # used by ASan at run-time
-        ASAN_OPTIONS="\"$ASAN_OPTIONS\""
         export ASAN_OPTIONS
-        echo "Setting ASAN_OPTIONS=$ASAN_OPTIONS"
+        echo "Setting ASAN_OPTIONS=\"$ASAN_OPTIONS\""
 
-        # used by ASan at run-time
-        ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-$__ClangMajorVersion.$__ClangMinorVersion"
-        export ASAN_SYMBOLIZER_PATH
-        echo "Setting ASAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH"
+        export UBSAN_OPTIONS
+        echo "Setting UBSAN_OPTIONS=\"$UBSAN_OPTIONS\""
+
+        # for compiler-rt > 3.6 Asan check that binary name is 'llvm-symbolizer', 'addr2line' or
+        # 'atos' (for Darwin) otherwise it returns error
+        if [ $__ExportSymbolizerPath == 1 ]; then
+            # used by ASan at run-time
+            ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-$__ClangMajorVersion.$__ClangMinorVersion"
+            export ASAN_SYMBOLIZER_PATH
+            echo "Setting ASAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH"
+        else
+            unset ASAN_SYMBOLIZER_PATH
+        fi
+        echo "Done. You can now run: build.sh Debug clang$__ClangMajorVersion.$__ClangMinorVersion"
     fi
 
     unset __ClangMajorVersion
@@ -104,4 +133,4 @@ else
     unset __EnableLSan
     unset __TurnOff
     unset __Options
-fi
\ No newline at end of file
+fi