diff --git a/Makefile b/Makefile index ccca3ac5ef..d8b540fcff 100644 --- a/Makefile +++ b/Makefile @@ -256,8 +256,8 @@ endif ifdef COMPILE_WITH_TSAN DISABLE_JEMALLOC=1 EXEC_LDFLAGS += -fsanitize=thread - PLATFORM_CCFLAGS += -fsanitize=thread -fPIC - PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC + PLATFORM_CCFLAGS += -fsanitize=thread -fPIC -DFOLLY_SANITIZE_THREAD + PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC -DFOLLY_SANITIZE_THREAD # Turn off -pg when enabling TSAN testing, because that induces # a link failure. TODO: find the root cause PROFILING_FLAGS = @@ -1285,7 +1285,7 @@ db_merge_operator_test: db/db_merge_operator_test.o db/db_test_util.o $(LIBOBJEC db_merge_operand_test: db/db_merge_operand_test.o db/db_test_util.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) - + db_options_test: db/db_options_test.o db/db_test_util.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) diff --git a/third-party/folly/folly/CPortability.h b/third-party/folly/folly/CPortability.h index 3ce3a7785a..56cb6b1a58 100644 --- a/third-party/folly/folly/CPortability.h +++ b/third-party/folly/folly/CPortability.h @@ -13,3 +13,15 @@ #else #define FOLLY_EXPORT #endif + +#if defined(__has_feature) +#define FOLLY_HAS_FEATURE(...) __has_feature(__VA_ARGS__) +#else +#define FOLLY_HAS_FEATURE(...) 0 +#endif + +#if FOLLY_HAS_FEATURE(thread_sanitizer) || __SANITIZE_THREAD__ +#ifndef FOLLY_SANITIZE_THREAD +#define FOLLY_SANITIZE_THREAD 1 +#endif +#endif diff --git a/third-party/folly/folly/Portability.h b/third-party/folly/folly/Portability.h index 2c6544c196..61c05ff225 100644 --- a/third-party/folly/folly/Portability.h +++ b/third-party/folly/folly/Portability.h @@ -5,6 +5,8 @@ #pragma once +#include + #if defined(__arm__) #define FOLLY_ARM 1 #else @@ -72,3 +74,11 @@ constexpr bool kIsMsvc = true; constexpr bool kIsMsvc = false; #endif } // namespace folly + +namespace folly { +#if FOLLY_SANITIZE_THREAD +constexpr bool kIsSanitizeThread = true; +#else +constexpr bool kIsSanitizeThread = false; +#endif +} // namespace folly diff --git a/third-party/folly/folly/synchronization/AtomicUtil-inl.h b/third-party/folly/folly/synchronization/AtomicUtil-inl.h index 6adba2b31a..4c10d84510 100644 --- a/third-party/folly/folly/synchronization/AtomicUtil-inl.h +++ b/third-party/folly/folly/synchronization/AtomicUtil-inl.h @@ -230,8 +230,9 @@ bool atomic_fetch_set(Atomic& atomic, std::size_t bit, std::memory_order mo) { static_assert(!std::is_const{}, ""); assert(bit < (sizeof(Integer) * 8)); - if (folly::kIsArchAmd64) { - // do the optimized thing on x86 builds + // do the optimized thing on x86 builds. Also, some versions of TSAN do not + // properly instrument the inline assembly, so avoid it when TSAN is enabled + if (folly::kIsArchAmd64 && !folly::kIsSanitizeThread) { return detail::atomic_fetch_set_x86(atomic, bit, mo); } else { // otherwise default to the default implementation using fetch_or() @@ -246,8 +247,9 @@ bool atomic_fetch_reset(Atomic& atomic, std::size_t bit, std::memory_order mo) { static_assert(!std::is_const{}, ""); assert(bit < (sizeof(Integer) * 8)); - if (folly::kIsArchAmd64) { - // do the optimized thing on x86 builds + // do the optimized thing on x86 builds. Also, some versions of TSAN do not + // properly instrument the inline assembly, so avoid it when TSAN is enabled + if (folly::kIsArchAmd64 && !folly::kIsSanitizeThread) { return detail::atomic_fetch_reset_x86(atomic, bit, mo); } else { // otherwise default to the default implementation using fetch_and() diff --git a/third-party/folly/folly/synchronization/test/DistributedMutexTest.cpp b/third-party/folly/folly/synchronization/test/DistributedMutexTest.cpp index b83fdda712..e75d0f35c6 100644 --- a/third-party/folly/folly/synchronization/test/DistributedMutexTest.cpp +++ b/third-party/folly/folly/synchronization/test/DistributedMutexTest.cpp @@ -981,6 +981,12 @@ template