diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -181,6 +181,12 @@ # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in. pythonize_bool(COMPILER_RT_DEBUG) +option(COMPILER_RT_INTERCEPT_LIBDISPATCH + "Support interception of libdispatch (GCD). Requires '-fblocks'." OFF) +if (APPLE) # Always enable on Apple platforms. + set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON) +endif() + if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9") # Mac OS X prior to 10.9 had problems with exporting symbols from # libc++/libc++abi. diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -61,7 +61,6 @@ if(APPLE) list(APPEND TSAN_SOURCES rtl/tsan_interceptors_mac.cc - rtl/tsan_libdispatch_mac.cc rtl/tsan_platform_mac.cc rtl/tsan_platform_posix.cc) elseif(UNIX) @@ -71,6 +70,14 @@ rtl/tsan_platform_posix.cc) endif() +if(COMPILER_RT_INTERCEPT_LIBDISPATCH) + list(APPEND TSAN_SOURCES rtl/tsan_libdispatch.cc) + # Libdispatch support for non-Apple platforms requires '-fblocks'. + if (NOT APPLE) + list(APPEND TSAN_RTL_CFLAGS "-fblocks") + endif() +endif() + set(TSAN_HEADERS rtl/tsan_clock.h rtl/tsan_defs.h diff --git a/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_libdispatch.cc rename from compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc rename to compiler-rt/lib/tsan/rtl/tsan_libdispatch.cc --- a/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_libdispatch.cc @@ -1,4 +1,4 @@ -//===-- tsan_libdispatch_mac.cc -------------------------------------------===// +//===-- tsan_libdispatch.cc -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,11 +8,10 @@ // // This file is a part of ThreadSanitizer (TSan), a race detector. // -// Mac-specific libdispatch (GCD) support. +// Support for intercepting libdispatch (GCD). //===----------------------------------------------------------------------===// #include "sanitizer_common/sanitizer_platform.h" -#if SANITIZER_MAC #include "sanitizer_common/sanitizer_common.h" #include "interception/interception.h" @@ -24,7 +23,7 @@ #include #include -// DISPATCH_NOESCAPE is not defined prior to XCode 8. +// DISPATCH_NOESCAPE is only defined on Apple platforms with at least Xcode 8. #ifndef DISPATCH_NOESCAPE #define DISPATCH_NOESCAPE #endif @@ -722,5 +721,3 @@ } } // namespace __tsan - -#endif // SANITIZER_MAC