kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject kudu git commit: thirdparty: patch libcxx to fix a data race in std::once
Date Tue, 21 Feb 2017 19:11:19 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 2b0edbe31 -> d03d374ac


thirdparty: patch libcxx to fix a data race in std::once

This pulls in a patch from libcxx[1] which fixes a missing memory
barrier in std::once. This is currently causing a lot of TSAN false
positives around SSL initialization.

[1] https://github.com/llvm-mirror/libcxx/commit/4dbd4fcf8626453949625bf36976e668094cfbb1

Change-Id: I0244fdce5346b608bdad31fbd4ab2b8147733b2e
Reviewed-on: http://gerrit.cloudera.org:8080/6095
Tested-by: Todd Lipcon <todd@apache.org>
Reviewed-by: Adar Dembo <adar@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/d03d374a
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/d03d374a
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/d03d374a

Branch: refs/heads/master
Commit: d03d374ac0de84dad0a502b16a02e4040240f72b
Parents: 2b0edbe
Author: Todd Lipcon <todd@apache.org>
Authored: Tue Feb 21 09:35:41 2017 -0800
Committer: Adar Dembo <adar@cloudera.com>
Committed: Tue Feb 21 19:10:31 2017 +0000

----------------------------------------------------------------------
 thirdparty/download-thirdparty.sh               |  5 +-
 .../patches/libc++-fix-std-once-barriers.patch  | 86 ++++++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/d03d374a/thirdparty/download-thirdparty.sh
----------------------------------------------------------------------
diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh
index 252405e..77f1bb4 100755
--- a/thirdparty/download-thirdparty.sh
+++ b/thirdparty/download-thirdparty.sh
@@ -239,13 +239,16 @@ if [ ! -d $PYTHON_SOURCE ]; then
   fetch_and_expand python-${PYTHON_VERSION}.tar.gz
 fi
 
-LLVM_PATCHLEVEL=1
+LLVM_PATCHLEVEL=2
 delete_if_wrong_patchlevel $LLVM_SOURCE $LLVM_PATCHLEVEL
 if [ ! -d $LLVM_SOURCE ]; then
   fetch_and_expand llvm-${LLVM_VERSION}.src.tar.gz
 
   pushd $LLVM_SOURCE
   patch -p1 < $TP_DIR/patches/llvm-fix-amazon-linux.patch
+  pushd projects/libcxx
+  patch -p1 < $TP_DIR/patches/libc++-fix-std-once-barriers.patch
+  popd
   touch patchlevel-$LLVM_PATCHLEVEL
   popd
   echo

http://git-wip-us.apache.org/repos/asf/kudu/blob/d03d374a/thirdparty/patches/libc++-fix-std-once-barriers.patch
----------------------------------------------------------------------
diff --git a/thirdparty/patches/libc++-fix-std-once-barriers.patch b/thirdparty/patches/libc++-fix-std-once-barriers.patch
new file mode 100644
index 0000000..63939b3
--- /dev/null
+++ b/thirdparty/patches/libc++-fix-std-once-barriers.patch
@@ -0,0 +1,86 @@
+From 4dbd4fcf8626453949625bf36976e668094cfbb1 Mon Sep 17 00:00:00 2001
+From: Kuba Brecka <kuba.brecka@gmail.com>
+Date: Sun, 4 Sep 2016 09:55:12 +0000
+Subject: [PATCH] [libcxx] Fix a data race in call_once
+
+call_once is using relaxed atomic load to perform double-checked locking, which contains
a data race. The fast-path load has to be an acquire atomic load.
+
+Differential Revision: https://reviews.llvm.org/D24028
+
+
+
+git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@280621 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ include/memory | 12 ++++++++++++
+ include/mutex  |  4 ++--
+ src/mutex.cpp  |  5 +----
+ 3 files changed, 15 insertions(+), 6 deletions(-)
+
+diff --git a/include/memory b/include/memory
+index 31f58b7..8cb094e 100644
+--- a/include/memory
++++ b/include/memory
+@@ -663,6 +663,18 @@ _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
+ #endif
+ }
+ 
++template <class _ValueType>
++inline _LIBCPP_ALWAYS_INLINE
++_ValueType __libcpp_acquire_load(_ValueType const* __value) {
++#if !defined(_LIBCPP_HAS_NO_THREADS) && \
++    defined(__ATOMIC_ACQUIRE) &&        \
++    (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
++    return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
++#else
++    return *__value;
++#endif
++}
++
+ // addressof moved to <__functional_base>
+ 
+ template <class _Tp> class allocator;
+diff --git a/include/mutex b/include/mutex
+index c047cf9..79befbe 100644
+--- a/include/mutex
++++ b/include/mutex
+@@ -574,7 +574,7 @@ inline _LIBCPP_INLINE_VISIBILITY
+ void
+ call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args)
+ {
+-    if (__libcpp_relaxed_load(&__flag.__state_) != ~0ul)
++    if (__libcpp_acquire_load(&__flag.__state_) != ~0ul)
+     {
+         typedef tuple<_Callable&&, _Args&&...> _Gp;
+         _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...);
+@@ -590,7 +590,7 @@ inline _LIBCPP_INLINE_VISIBILITY
+ void
+ call_once(once_flag& __flag, _Callable& __func)
+ {
+-    if (__libcpp_relaxed_load(&__flag.__state_) != ~0ul)
++    if (__libcpp_acquire_load(&__flag.__state_) != ~0ul)
+     {
+         __call_once_param<_Callable> __p(__func);
+         __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>);
+diff --git a/src/mutex.cpp b/src/mutex.cpp
+index 9f808ca..7226abc 100644
+--- a/src/mutex.cpp
++++ b/src/mutex.cpp
+@@ -199,9 +199,6 @@ static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
+ static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
+ #endif
+ 
+-/// NOTE: Changes to flag are done via relaxed atomic stores
+-///       even though the accesses are protected by a mutex because threads
+-///       just entering 'call_once` concurrently read from flag.
+ void
+ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*))
+ {
+@@ -238,7 +235,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*))
+             __libcpp_mutex_unlock(&mut);
+             func(arg);
+             __libcpp_mutex_lock(&mut);
+-            __libcpp_relaxed_store(&flag, ~0ul);
++            __libcpp_atomic_store(&flag, ~0ul, _AO_Release);
+             __libcpp_mutex_unlock(&mut);
+             __libcpp_condvar_broadcast(&cv);
+ #ifndef _LIBCPP_NO_EXCEPTIONS


Mime
View raw message