You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2019/08/16 18:48:53 UTC
[kudu] branch master updated: [llvm] back-port of fix for TSAN
issue 944
This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 250e6f1 [llvm] back-port of fix for TSAN issue 944
250e6f1 is described below
commit 250e6f14dd27d34cc88a910d27de2015b07c00ca
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Aug 15 17:54:51 2019 -0700
[llvm] back-port of fix for TSAN issue 944
See https://github.com/google/sanitizers/issues/944 for details.
Change-Id: I3992b697201ba8274a3e7ae7171c7855ed7f5e71
Reviewed-on: http://gerrit.cloudera.org:8080/14078
Tested-by: Kudu Jenkins
Reviewed-by: Grant Henke <gr...@apache.org>
---
thirdparty/download-thirdparty.sh | 5 +-
...lvm-fix-944-destruction-of-a-locked-mutex.patch | 117 +++++++++++++++++++++
2 files changed, 120 insertions(+), 2 deletions(-)
diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh
index 249fc35..d9f2a27 100755
--- a/thirdparty/download-thirdparty.sh
+++ b/thirdparty/download-thirdparty.sh
@@ -317,7 +317,7 @@ fetch_and_patch \
$PYTHON_SOURCE \
$PYTHON_PATCHLEVEL
-LLVM_PATCHLEVEL=3
+LLVM_PATCHLEVEL=4
fetch_and_patch \
llvm-${LLVM_VERSION}-iwyu-${IWYU_VERSION}.src.tar.gz \
$LLVM_SOURCE \
@@ -328,7 +328,8 @@ fetch_and_patch \
"patch -p1 < $TP_DIR/patches/llvm-iwyu-include-picker.patch" \
"patch -d tools/clang/tools/include-what-you-use -p1 < $TP_DIR/patches/llvm-iwyu-llvm-6-compat.patch" \
"patch -d projects/compiler-rt -p1 < $TP_DIR/patches/llvm-tsan-disable-trace-switching-after-multithreaded-for.patch" \
- "patch -d projects -p1 < $TP_DIR/patches/llvm-ustat-removal.patch"
+ "patch -d projects -p1 < $TP_DIR/patches/llvm-ustat-removal.patch" \
+ "patch -d projects -p1 < $TP_DIR/patches/llvm-fix-944-destruction-of-a-locked-mutex.patch"
LZ4_PATCHLEVEL=1
fetch_and_patch \
diff --git a/thirdparty/patches/llvm-fix-944-destruction-of-a-locked-mutex.patch b/thirdparty/patches/llvm-fix-944-destruction-of-a-locked-mutex.patch
new file mode 100644
index 0000000..f88debc
--- /dev/null
+++ b/thirdparty/patches/llvm-fix-944-destruction-of-a-locked-mutex.patch
@@ -0,0 +1,117 @@
+From 21dc68fe7b4cd06b2ac194a66467352ddc2c4ecb Mon Sep 17 00:00:00 2001
+From: Dmitry Vyukov <dv...@google.com>
+Date: Fri, 27 Apr 2018 08:59:35 +0000
+Subject: [PATCH] tsan: improve "destroy of a locked mutex" reports
+
+1. Allow to suppress by current stack.
+We generally allow to suppress by all main stacks.
+Current is probably the stack one wants to use to
+suppress such reports.
+
+2. Fix last lock stack restoration.
+We trimmed shadow value by storing it in u32.
+This magically worked for the test that provoked
+the report on the main thread. But this breaks
+for locks in any other threads.
+
+llvm-svn: 331023
+---
+ compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc | 4 +--
+ .../test/tsan/mutex_destroy_locked2.cc | 29 +++++++++++++++++++
+ compiler-rt/test/tsan/suppressions_mutex.cc | 19 ++++++++++++
+ .../test/tsan/suppressions_mutex.cc.supp | 2 ++
+ 4 files changed, 52 insertions(+), 2 deletions(-)
+ create mode 100644 compiler-rt/test/tsan/mutex_destroy_locked2.cc
+ create mode 100644 compiler-rt/test/tsan/suppressions_mutex.cc
+ create mode 100644 compiler-rt/test/tsan/suppressions_mutex.cc.supp
+
+diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
+index 152b965ad53..f0f4fbe7c7c 100644
+--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
++++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
+@@ -104,7 +104,7 @@ void MutexDestroy(ThreadState *thr, uptr pc, uptr addr, u32 flagz) {
+ unlock_locked = true;
+ }
+ u64 mid = s->GetId();
+- u32 last_lock = s->last_lock;
++ u64 last_lock = s->last_lock;
+ if (!unlock_locked)
+ s->Reset(thr->proc()); // must not reset it before the report is printed
+ s->mtx.Unlock();
+@@ -114,7 +114,7 @@ void MutexDestroy(ThreadState *thr, uptr pc, uptr addr, u32 flagz) {
+ rep.AddMutex(mid);
+ VarSizeStackTrace trace;
+ ObtainCurrentStack(thr, pc, &trace);
+- rep.AddStack(trace);
++ rep.AddStack(trace, true);
+ FastState last(last_lock);
+ RestoreStack(last.tid(), last.epoch(), &trace, 0);
+ rep.AddStack(trace, true);
+diff --git a/compiler-rt/test/tsan/mutex_destroy_locked2.cc b/compiler-rt/test/tsan/mutex_destroy_locked2.cc
+new file mode 100644
+index 00000000000..e29c96138a8
+--- /dev/null
++++ b/compiler-rt/test/tsan/mutex_destroy_locked2.cc
+@@ -0,0 +1,29 @@
++// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
++#include <pthread.h>
++#include <unistd.h>
++
++void *thread(void *arg) {
++ pthread_mutex_t m;
++ pthread_mutex_init(&m, 0);
++ pthread_mutex_lock(&m);
++ pthread_mutex_destroy(&m);
++ return 0;
++}
++
++int main() {
++ pthread_t th;
++ pthread_create(&th, 0, thread, 0);
++ pthread_join(th, 0);
++ return 0;
++}
++
++// CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
++// CHECK: #0 pthread_mutex_destroy
++// CHECK: #1 thread
++// CHECK: and:
++// CHECK: #0 pthread_mutex_lock
++// CHECK: #1 thread
++// CHECK: Mutex {{.*}} created at:
++// CHECK: #0 pthread_mutex_init
++// CHECK: #1 thread
++// CHECK: SUMMARY: ThreadSanitizer: destroy of a locked mutex {{.*}} in thread
+diff --git a/compiler-rt/test/tsan/suppressions_mutex.cc b/compiler-rt/test/tsan/suppressions_mutex.cc
+new file mode 100644
+index 00000000000..5d3a5d05289
+--- /dev/null
++++ b/compiler-rt/test/tsan/suppressions_mutex.cc
+@@ -0,0 +1,19 @@
++// RUN: %clang_tsan -O1 %s -o %t && %env_tsan_opts=suppressions='%s.supp' %run %t 2>&1 | FileCheck %s
++#include "test.h"
++
++void __attribute__((noinline)) suppress_this(pthread_mutex_t *mu) {
++ pthread_mutex_destroy(mu);
++}
++
++int main() {
++ pthread_mutex_t mu;
++ pthread_mutex_init(&mu, 0);
++ pthread_mutex_lock(&mu);
++ suppress_this(&mu);
++ fprintf(stderr, "DONE\n");
++ return 0;
++}
++
++// CHECK-NOT: failed to open suppressions file
++// CHECK-NOT: WARNING: ThreadSanitizer:
++// CHECK: DONE
+diff --git a/compiler-rt/test/tsan/suppressions_mutex.cc.supp b/compiler-rt/test/tsan/suppressions_mutex.cc.supp
+new file mode 100644
+index 00000000000..595febbea5c
+--- /dev/null
++++ b/compiler-rt/test/tsan/suppressions_mutex.cc.supp
+@@ -0,0 +1,2 @@
++mutex:suppress_this
++