diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -182,11 +182,21 @@ pythonize_bool(COMPILER_RT_DEBUG) option(COMPILER_RT_INTERCEPT_LIBDISPATCH - "Support interception of libdispatch (GCD). Requires '-fblocks'." OFF) + "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF) if (APPLE) # Always enable on Apple platforms. set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON) endif() pythonize_bool(COMPILER_RT_INTERCEPT_LIBDISPATCH) +option(COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH + "Library search path for blocks runtime (-lBlocksRuntime)" "") +if (COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH) + set(COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH_LINK_FLAG -L${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH}) +endif() +option(COMPILER_RT_LIBDISPATCH_LIBRARY_PATH + "Library search path for libdispatch (-ldispatch)" "") +if (COMPILER_RT_LIBDISPATCH_LIBRARY_PATH) + set(COMPILER_RT_LIBDISPATCH_LIBRARY_PATH_LINK_FLAG -L${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH}) +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 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 @@ -246,13 +246,18 @@ COMPILER_RT_LIBCXXABI_PATH AND COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang" AND NOT ANDROID) + if(COMPILER_RT_INTERCEPT_LIBDISPATCH AND NOT APPLE) + set(libdispatch_link_flags + ${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH_LINK_FLAG} -lBlocksRuntime + ${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH_LINK_FLAG} -ldispatch) + endif() set(libcxx_tsan_deps) foreach(arch ${TSAN_SUPPORTED_ARCH}) get_target_flags_for_arch(${arch} TARGET_CFLAGS) set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan_${arch}) add_custom_libcxx(libcxx_tsan_${arch} ${LIBCXX_PREFIX} DEPS ${TSAN_RUNTIME_LIBRARIES} - CFLAGS ${TARGET_CFLAGS} -fsanitize=thread + CFLAGS ${TARGET_CFLAGS} -fsanitize=thread ${libdispatch_link_flags} USE_TOOLCHAIN) list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-build) endforeach() diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -45,6 +45,11 @@ else() list(APPEND LINK_FLAGS -fsanitize=thread) list(APPEND LINK_FLAGS -lm) + if (COMPILER_RT_INTERCEPT_LIBDISPATCH) + list(APPEND LINK_FLAGS + ${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH_LINK_FLAG} -lBlocksRuntime + ${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH_LINK_FLAG} -ldispatch) + endif() endif() set(TSAN_RTL_HEADERS)