[compiler-rt] r175040 - [msan] don't check shadow inside interceptors if we are inside symbolizer; add weak function __msan_default_options that overrides default options

Kostya Serebryany kcc at google.com
Tue Feb 12 23:19:47 PST 2013


Author: kcc
Date: Wed Feb 13 01:19:47 2013
New Revision: 175040

URL: http://llvm.org/viewvc/llvm-project?rev=175040&view=rev
Log:
[msan] don't check shadow inside interceptors if we are inside symbolizer; add weak function __msan_default_options that overrides default options

Modified:
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan.h
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/msan/msan_interface_internal.h
    compiler-rt/trunk/lib/msan/msan_report.cc

Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=175040&r1=175039&r2=175040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Wed Feb 13 01:19:47 2013
@@ -58,6 +58,8 @@ static THREADLOCAL struct {
   uptr stack_top, stack_bottom;
 } __msan_stack_bounds;
 
+static THREADLOCAL bool is_in_symbolizer;
+
 extern "C" const int __msan_track_origins;
 int __msan_get_track_origins() {
   return __msan_track_origins;
@@ -81,6 +83,10 @@ static bool IsRunningUnderDr() {
   return result;
 }
 
+void EnterSymbolizer() { is_in_symbolizer = true; }
+void ExitSymbolizer()  { is_in_symbolizer = false; }
+bool IsInSymbolizer() { return is_in_symbolizer; }
+
 static Flags msan_flags;
 
 Flags *flags() {
@@ -126,6 +132,9 @@ static void InitializeFlags(Flags *f, co
   f->verbosity = 0;
   f->strip_path_prefix = "";
 
+  // Override from user-specified string.
+  if (__msan_default_options)
+    ParseFlagsFromString(f, __msan_default_options());
   ParseFlagsFromString(f, options);
 }
 
@@ -417,3 +426,11 @@ u32 __msan_get_origin(void *a) {
 u32 __msan_get_umr_origin() {
   return __msan_origin_tls;
 }
+
+#if !SANITIZER_SUPPORTS_WEAK_HOOKS
+extern "C" {
+SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
+const char* __msan_default_options() { return ""; }
+}  // extern "C"
+#endif
+

Modified: compiler-rt/trunk/lib/msan/msan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=175040&r1=175039&r2=175040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.h (original)
+++ compiler-rt/trunk/lib/msan/msan.h Wed Feb 13 01:19:47 2013
@@ -46,6 +46,10 @@ void InstallTrapHandler();
 void InstallAtExitHandler();
 void ReplaceOperatorsNewAndDelete();
 
+void EnterSymbolizer();
+void ExitSymbolizer();
+bool IsInSymbolizer();
+
 void MsanDie();
 void PrintWarning(uptr pc, uptr bp);
 void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin);

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=175040&r1=175039&r2=175040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Wed Feb 13 01:19:47 2013
@@ -41,6 +41,7 @@ using namespace __msan;
 #define CHECK_UNPOISONED(x, n) \
   do { \
     sptr offset = __msan_test_shadow(x, n);                 \
+    if (__msan::IsInSymbolizer()) break;                    \
     if (offset >= 0 && flags()->report_umrs) {              \
       GET_CALLER_PC_BP_SP;                                  \
       (void)sp;                                             \

Modified: compiler-rt/trunk/lib/msan/msan_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=175040&r1=175039&r2=175040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (original)
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Wed Feb 13 01:19:47 2013
@@ -85,6 +85,9 @@ void __msan_set_exit_code(int exit_code)
 SANITIZER_INTERFACE_ATTRIBUTE
 int __msan_set_poison_in_malloc(int do_poison);
 
+SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
+/* OPTIONAL */ const char* __msan_default_options();
+
 // For testing.
 SANITIZER_INTERFACE_ATTRIBUTE
 void __msan_set_expect_umr(int expect_umr);

Modified: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=175040&r1=175039&r2=175040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Wed Feb 13 01:19:47 2013
@@ -44,6 +44,16 @@ class Decorator: private __sanitizer::An
   const char *End()    { return Default(); }
 };
 
+struct SymbolizerScope {
+  SymbolizerScope() { EnterSymbolizer(); }
+  ~SymbolizerScope() { ExitSymbolizer(); }
+};
+
+static void PrintStack(const uptr *trace, uptr size) {
+  SymbolizerScope sym_scope;
+  StackTrace::PrintStack(trace, size, true, flags()->strip_path_prefix, 0);
+}
+
 static void DescribeOrigin(u32 origin) {
   Decorator d;
   if (flags()->verbosity)
@@ -64,7 +74,7 @@ static void DescribeOrigin(u32 origin) {
     const uptr *trace = StackDepotGet(origin, &size);
     Printf("  %sUninitialized value was created by a heap allocation%s\n",
            d.Origin(), d.End());
-    StackTrace::PrintStack(trace, size, true, flags()->strip_path_prefix, 0);
+    PrintStack(trace, size);
   }
 }
 
@@ -72,7 +82,10 @@ static void ReportSummary(const char *er
   if (!stack->size || !IsSymbolizerAvailable()) return;
   AddressInfo ai;
   uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
-  SymbolizeCode(pc, &ai, 1);
+  {
+    SymbolizerScope sym_scope;
+    SymbolizeCode(pc, &ai, 1);
+  }
   ReportErrorSummary(error_type,
                      StripPathPrefix(ai.file, flags()->strip_path_prefix),
                      ai.line, ai.function);
@@ -87,8 +100,7 @@ void ReportUMR(StackTrace *stack, u32 or
   Printf("%s", d.Warning());
   Report(" WARNING: Use of uninitialized value\n");
   Printf("%s", d.End());
-  StackTrace::PrintStack(stack->trace, stack->size, true,
-                         flags()->strip_path_prefix, 0);
+  PrintStack(stack->trace, stack->size);
   if (origin) {
     DescribeOrigin(origin);
   }
@@ -99,8 +111,7 @@ void ReportExpectedUMRNotFound(StackTrac
   GenericScopedLock<StaticSpinMutex> lock(&report_mu);
 
   Printf(" WARNING: Expected use of uninitialized value not found\n");
-  StackTrace::PrintStack(stack->trace, stack->size, true,
-                         flags()->strip_path_prefix, 0);
+  PrintStack(stack->trace, stack->size);
 }
 
 void ReportAtExitStatistics() {





More information about the llvm-commits mailing list