[tsan] Support interception of libdispatch on Linux

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.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D58935

llvm-svn: 355538
This commit is contained in:
Julian Lettner 2019-03-06 19:25:09 +00:00
parent 318028f00f
commit 96ef52ccf0
3 changed files with 17 additions and 7 deletions

View File

@ -181,6 +181,12 @@ option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
# 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.

View File

@ -61,7 +61,6 @@ set(TSAN_CXX_SOURCES
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 @@ elseif(UNIX)
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

View File

@ -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 @@ TSAN_INTERCEPTOR(void, dispatch_resume, dispatch_object_t o) {
}
} // namespace __tsan
#endif // SANITIZER_MAC