[TSan][libdispatch] Enable linking and running of tests on Linux

When COMPILER_RT_INTERCEPT_LIBDISPATCH is ON the TSan runtime library
now has a dependency on the blocks runtime and libdispatch. Make sure we
set all the required linking options.

Also add cmake options for specifying additional library paths to
instruct the linker where to search for libdispatch and the blocks
runtime. This allows us to build TSan runtime with libdispatch support
without installing those libraries into default linker library paths.

`CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY` is necessary to avoid
aborting the build due to failing the link step in CMake's
check_c_compiler test.

Reviewed By: dvyukov, kubamracek

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

llvm-svn: 356281
This commit is contained in:
Julian Lettner 2019-03-15 17:52:27 +00:00
parent d238bf7855
commit 764c2165e8
5 changed files with 26 additions and 5 deletions

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)