From 6e09bca0ef1961d0b2eb24395420349054a52ce0 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 26 Feb 2015 15:59:30 +0000 Subject: [PATCH] [msan] Change track-origins default mode from 1 to 2. Change -fsanitize-memory-track-origins to be equivalent to -fsanitize-memory-track-origins=2. Track-origins=2 provides a lot more detailed reports at the cost of some additional slowdown (ranging from none to, sometimes, 3x; ~3% average on SPEC2006). llvm-svn: 230644 --- clang/docs/MemorySanitizer.rst | 33 +++++++++++---------------------- clang/docs/UsersManual.rst | 9 +++++---- clang/lib/Driver/SanitizerArgs.cpp | 2 +- clang/test/Driver/fsanitize.c | 10 ++++++---- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/clang/docs/MemorySanitizer.rst b/clang/docs/MemorySanitizer.rst index 8841fc3..007e086 100644 --- a/clang/docs/MemorySanitizer.rst +++ b/clang/docs/MemorySanitizer.rst @@ -110,32 +110,12 @@ Origin Tracking MemorySanitizer can track origins of unitialized values, similar to Valgrind's --track-origins option. This feature is enabled by -``-fsanitize-memory-track-origins`` Clang option. With the code from +``-fsanitize-memory-track-origins=2`` (or simply +``-fsanitize-memory-track-origins``) Clang option. With the code from the example above, .. code-block:: console - % clang -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -g -O2 umr.cc - % ./a.out - WARNING: MemorySanitizer: use-of-uninitialized-value - #0 0x7f7893912f0b in main umr2.cc:6 - #1 0x7f789249b76c in __libc_start_main libc-start.c:226 - - Uninitialized value was created by a heap allocation - #0 0x7f7893901cbd in operator new[](unsigned long) msan_new_delete.cc:44 - #1 0x7f7893912e06 in main umr2.cc:4 - -Origin tracking has proved to be very useful for debugging MemorySanitizer -reports. It slows down program execution by a factor of 1.5x-2x on top -of the usual MemorySanitizer slowdown. - -MemorySanitizer can provide even more information with -``-fsanitize-memory-track-origins=2`` flag. In this mode reports -include information about intermediate stores the uninitialized value went -through. - -.. code-block:: console - % cat umr2.cc #include @@ -162,6 +142,15 @@ through. #0 0x7f7893901cbd in operator new[](unsigned long) msan_new_delete.cc:44 #1 0x7f7893912e06 in main umr2.cc:4 +By default, MemorySanitizer collects both allocation points and all +intermediate stores the uninitialized value went through. Origin +tracking has proved to be very useful for debugging MemorySanitizer +reports. It slows down program execution by a factor of 1.5x-2x on top +of the usual MemorySanitizer slowdown. + +Clang option ``-fsanitize-memory-track-origins=1`` enabled a slightly +faster mode when MemorySanitizer collects only allocation points but +not intermediate stores. Handling external code ============================ diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index d4a7b3e..1685670 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -1030,10 +1030,11 @@ are listed below. uninitialized bits came from. Slows down execution by additional 1.5x-2x. - Possible values for level are 0 (off), 1 (default), 2. Level 2 adds more - sections to MemorySanitizer reports describing the order of memory stores - the uninitialized value went through. Beware, this mode may use a lot of - extra memory. + Possible values for level are 0 (off), 1, 2 (default). Level 2 + adds more sections to MemorySanitizer reports describing the + order of memory stores the uninitialized value went + through. This mode may use extra memory in programs that copy + uninitialized memory a lot. Extra features of UndefinedBehaviorSanitizer: diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 0488abc..11b9288 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -360,7 +360,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, options::OPT_fsanitize_memory_track_origins, options::OPT_fno_sanitize_memory_track_origins)) { if (A->getOption().matches(options::OPT_fsanitize_memory_track_origins)) { - MsanTrackOrigins = 1; + MsanTrackOrigins = 2; } else if (A->getOption().matches( options::OPT_fno_sanitize_memory_track_origins)) { MsanTrackOrigins = 0; diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 8f37b02..97232e3 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -66,11 +66,13 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -pie %s -### 2>&1 // OK -// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-1 +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-2 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=1 -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-1 -// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-1 -// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fno-sanitize-memory-track-origins -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-1 -// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=0 -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-1 +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=1 -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-2 +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-2 +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fno-sanitize-memory-track-origins -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-2 +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=0 -fsanitize-memory-track-origins=1 -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-1 +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=0 -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-2 // CHECK-TRACK-ORIGINS-1: -fsanitize-memory-track-origins=1 -- 2.7.4