diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -182,7 +182,20 @@ 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) +option(COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH + "Library search path for blocks runtime (-lBlocksRuntime)" "") +option(COMPILER_RT_LIBDISPATCH_LIBRARY_PATH + "Library search path for libdispatch (-ldispatch)" "") +if (COMPILER_RT_INTERCEPT_LIBDISPATCH) + set(COMPILER_RT_INTERCEPT_LIBDISPATCH_CFLAGS -fblocks) + set(COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS) + append_list_if(COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH -L${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH} + COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS) + append_list_if(COMPILER_RT_LIBDISPATCH_LIBRARY_PATH -L${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH} + COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS) + list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS -lBlocksRuntime -ldispatch) +endif() if (APPLE) # Always enable on Apple platforms. set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON) endif() 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 @@ -72,10 +72,7 @@ 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() + list(APPEND TSAN_RTL_CFLAGS ${COMPILER_RT_INTERCEPT_LIBDISPATCH_CFLAGS}) endif() set(TSAN_HEADERS @@ -252,7 +249,7 @@ 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 ${COMPILER_RT_INTERCEPT_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,7 @@ else() list(APPEND LINK_FLAGS -fsanitize=thread) list(APPEND LINK_FLAGS -lm) + list(APPEND LINK_FLAGS ${COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS}) endif() set(TSAN_RTL_HEADERS)