diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 9c9df7b951d9..f5e80d95ed2b 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -182,7 +182,26 @@ option(COMPILER_RT_EXTERNALIZE_DEBUGINFO 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) + if (COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH) + list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS + -L${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH} + -Wl,-rpath=${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH}) + endif() + if (COMPILER_RT_LIBDISPATCH_LIBRARY_PATH) + list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS + -L${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH} + -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH}) + endif() + 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/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index c464a2c1b1d4..d91c24f2ecf5 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -595,6 +595,7 @@ macro(add_custom_libcxx name prefix) -DCMAKE_C_FLAGS=${LIBCXX_C_FLAGS} -DCMAKE_CXX_FLAGS=${LIBCXX_CXX_FLAGS} -DCMAKE_BUILD_TYPE=Release + -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY -DLLVM_PATH=${LLVM_MAIN_SRC_DIR} -DLLVM_BINARY_DIR=${prefix} -DLLVM_LIBRARY_OUTPUT_INTDIR=${prefix}/lib diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt index e547088ec185..a8a9c75a4d8b 100644 --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -72,10 +72,7 @@ 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() + list(APPEND TSAN_RTL_CFLAGS ${COMPILER_RT_INTERCEPT_LIBDISPATCH_CFLAGS}) endif() set(TSAN_HEADERS diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt index 0ad97ef3366f..43460eab2294 100644 --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -45,6 +45,7 @@ if(APPLE) 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) diff --git a/compiler-rt/test/tsan/CMakeLists.txt b/compiler-rt/test/tsan/CMakeLists.txt index 2dcf46eee4a8..f635e80c4eb1 100644 --- a/compiler-rt/test/tsan/CMakeLists.txt +++ b/compiler-rt/test/tsan/CMakeLists.txt @@ -31,6 +31,9 @@ foreach(arch ${TSAN_TEST_ARCH}) string(TOLOWER "-${arch}" TSAN_TEST_CONFIG_SUFFIX) get_test_cc_for_arch(${arch} TSAN_TEST_TARGET_CC TSAN_TEST_TARGET_CFLAGS) + string(REPLACE ";" " " LIBDISPATCH_LINK_FLAGS_STRING " ${COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS}") + string(APPEND TSAN_TEST_TARGET_CFLAGS ${LIBDISPATCH_LINK_FLAGS_STRING}) + string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME ${ARCH_UPPER_CASE}Config)