[PATCH] D58935: [tsan] Support interception of libdispatch on Linux

Julian Lettner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 16:36:53 PST 2019


yln created this revision.
Herald added subscribers: llvm-commits, Sanitizers, jdoerfert, mgorny, kubamracek.
Herald added projects: Sanitizers, LLVM.
yln added reviewers: dvyukov, kcc, eugenis, delcypher, kubamracek, dcoughlin.

This is a new attempt for bringing TSan libdispatch support to Linux.
The main issue with the last patch (https://reviews.llvm.org/D53171) was
that we want to avoid building a separate library.

The updated plan is as follows:

1. Hide libdispatch support behind a flag: true on Darwin, false elsewhere. If flag is specified, assume that libdispatch header and -flbocks is available for building. This way we can directly include the libdispatch header and rely on blocks runtime for our implementation.
2. Optionally/weakly intercept libdispatch API functions.

This patch accomplishes 1). It compiles (without the flag enabled) on
Linux. Follow-up patches will provide 2) and enabling of tests on Linux.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58935

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/tsan/CMakeLists.txt
  compiler-rt/lib/tsan/rtl/tsan_libdispatch.cc
  compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc


Index: compiler-rt/lib/tsan/rtl/tsan_libdispatch.cc
===================================================================
--- compiler-rt/lib/tsan/rtl/tsan_libdispatch.cc
+++ 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 <dispatch/dispatch.h>
 #include <pthread.h>
 
-// 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
Index: compiler-rt/lib/tsan/CMakeLists.txt
===================================================================
--- compiler-rt/lib/tsan/CMakeLists.txt
+++ 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
Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58935.189227.patch
Type: text/x-patch
Size: 2772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190305/108e9102/attachment.bin>


More information about the llvm-commits mailing list