[compiler-rt] r245776 - [TSan] Support __sanitizer_set_death_callback().

Alexey Samsonov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 18:07:03 PDT 2015


Author: samsonov
Date: Fri Aug 21 20:07:02 2015
New Revision: 245776

URL: http://llvm.org/viewvc/llvm-project?rev=245776&view=rev
Log:
[TSan] Support __sanitizer_set_death_callback().

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/sanitizer_set_death_callback_test.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=245776&r1=245775&r2=245776&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Aug 21 20:07:02 2015
@@ -2449,7 +2449,7 @@ static void finalize(void *arg) {
   // Make sure the output is not lost.
   FlushStreams();
   if (status)
-    REAL(_exit)(status);
+    Die();
 }
 
 static void unreachable() {

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=245776&r1=245775&r2=245776&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Fri Aug 21 20:07:02 2015
@@ -514,7 +514,7 @@ bool OutputReport(ThreadState *thr, cons
   PrintReport(rep);
   ctx->nreported++;
   if (flags()->halt_on_error)
-    internal__exit(common_flags()->exitcode);
+    Die();
   return true;
 }
 

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/sanitizer_set_death_callback_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/sanitizer_set_death_callback_test.cc?rev=245776&r1=245775&r2=245776&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/sanitizer_set_death_callback_test.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/sanitizer_set_death_callback_test.cc Fri Aug 21 20:07:02 2015
@@ -1,10 +1,7 @@
 // RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
-// Check __sanitizer_set_death_callback. Not all sanitizers implement it yet.
-// XFAIL: tsan
 
 #include <sanitizer/common_interface_defs.h>
 #include <stdio.h>
-#include <pthread.h>
 
 volatile char *zero = 0;
 
@@ -13,14 +10,9 @@ void Death() {
 }
 // CHECK: DEATH CALLBACK EXECUTED
 
-int global[10];
+char global;
 volatile char *sink;
 
-void *Thread(void *x) {
-  global[0]++;
-  return x;
-}
-
 __attribute__((noinline))
 void MaybeInit(int *uninitialized) {
   if (zero)
@@ -37,12 +29,10 @@ int main(int argc, char **argv) {
   __sanitizer_set_death_callback(Death);
   MaybeInit(&uninitialized);
   if (uninitialized)  // trigger msan report.
-    global[0] = 77;
-  pthread_t t;
-  pthread_create(&t, 0, Thread, 0);
-  global[0]++;           // trigger tsan report.
-  pthread_join(t, 0);
-  global[argc + 10]++;   // trigger asan report.
+    global = 77;
+  sink = new char[100];
+  delete[] sink;
+  global = sink[0];  // use-after-free: trigger asan/tsan report.
   Leak();
   sink = 0;
 }




More information about the llvm-commits mailing list