[compiler-rt] r207415 - [asan] split detect_odr_violation into two: =2 detects all ODR violations, =1 detects only those where the variable sizes are different. BTW, the detector seems to be working well and finding nice bugs. Early adopters are welcome.

Kostya Serebryany kcc at google.com
Mon Apr 28 05:47:59 PDT 2014


Author: kcc
Date: Mon Apr 28 07:47:58 2014
New Revision: 207415

URL: http://llvm.org/viewvc/llvm-project?rev=207415&view=rev
Log:
[asan] split detect_odr_violation into two: =2 detects all ODR violations, =1 detects only those where the variable sizes are different. BTW, the detector seems to be working well and finding nice bugs. Early adopters are welcome.

Modified:
    compiler-rt/trunk/lib/asan/asan_flags.h
    compiler-rt/trunk/lib/asan/asan_globals.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/test/asan/TestCases/Linux/odr-violation.cc

Modified: compiler-rt/trunk/lib/asan/asan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.h?rev=207415&r1=207414&r2=207415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.h (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.h Mon Apr 28 07:47:58 2014
@@ -64,7 +64,7 @@ struct Flags {
   bool start_deactivated;
   int detect_invalid_pointer_pairs;
   bool detect_container_overflow;
-  bool detect_odr_violation;
+  int detect_odr_violation;
 };
 
 extern Flags asan_flags_dont_use_directly;

Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=207415&r1=207414&r2=207415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Mon Apr 28 07:47:58 2014
@@ -99,7 +99,8 @@ static void RegisterGlobal(const Global
       // This check may not be enough: if the first global is much larger
       // the entire redzone of the second global may be within the first global.
       for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
-        if (g->beg == l->g->beg)
+        if (g->beg == l->g->beg &&
+            (flags()->detect_odr_violation >= 2 || g->size != l->g->size))
           ReportODRViolation(g, l->g);
       }
     }

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=207415&r1=207414&r2=207415&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Apr 28 07:47:58 2014
@@ -226,9 +226,10 @@ static void ParseFlagsFromString(Flags *
       "If true, honor the container overflow  annotations. "
       "See https://code.google.com/p/address-sanitizer/wiki/ContainerOverflow");
 
-  ParseFlag(str, &f->detect_odr_violation,
-      "detect_odr_violation",
-      "If true, detect violation of One-Definition-Rule (ODR) ");
+  ParseFlag(str, &f->detect_odr_violation, "detect_odr_violation",
+            "If >=2, detect violation of One-Definition-Rule (ODR); "
+            "If ==1, detect ODR-violation only if the two variables "
+            "have different sizes");
 }
 
 void InitializeFlags(Flags *f, const char *env) {

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/odr-violation.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/odr-violation.cc?rev=207415&r1=207414&r2=207415&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/odr-violation.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/odr-violation.cc Mon Apr 28 07:47:58 2014
@@ -1,8 +1,16 @@
-// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
 // RUN: %clangxx_asan %s %t.so -Wl,-R. -o %t
+//
+// Different size: detect a bug if detect_odr_violation>=1
+// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
 // RUN: ASAN_OPTIONS=detect_odr_violation=1 not %t 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %t 2>&1 | FileCheck %s
 // RUN: ASAN_OPTIONS=detect_odr_violation=0     %t 2>&1 | FileCheck %s --check-prefix=DISABLED
 // RUN:                                         %t 2>&1 | FileCheck %s --check-prefix=DISABLED
+//
+// Same size: report a bug only if detect_odr_violation>=2.
+// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -DSZ=100
+// RUN: ASAN_OPTIONS=detect_odr_violation=1     %t 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %t 2>&1 | FileCheck %s
 
 #ifndef SZ
 # define SZ 4





More information about the llvm-commits mailing list