Skip to content

Commit

Permalink
[CMake] Track TSan's dependency on C++ headers
Browse files Browse the repository at this point in the history
TSan relies on C++ headers, so when libc++ is being built as part of
the runtimes build, include an explicit dependency on cxx-headers which
is the same approach that's already used for other sanitizers.

Differential Revision: https://reviews.llvm.org/D88912
  • Loading branch information
petrhosek committed Oct 6, 2020
1 parent 9eff07a commit 4540d66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ endmacro()
# CFLAGS <compile flags>
# LINK_FLAGS <linker flags>
# DEFS <compile definitions>
# DEPS <dependencies>
# LINK_LIBS <linked libraries> (only for shared library)
# OBJECT_LIBS <object libraries to use as sources>
# PARENT_TARGET <convenience parent target>
Expand All @@ -152,7 +153,7 @@ function(add_compiler_rt_runtime name type)
cmake_parse_arguments(LIB
""
"PARENT_TARGET"
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS"
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS"
${ARGN})
set(libnames)
# Until we support this some other way, build compiler-rt runtime without LTO
Expand Down Expand Up @@ -329,6 +330,9 @@ function(add_compiler_rt_runtime name type)
RUNTIME DESTINATION ${install_dir_${libname}}
${COMPONENT_OPTION})
endif()
if(LIB_DEPS)
add_dependencies(${libname} ${LIB_DEPS})
endif()
set_target_properties(${libname} PROPERTIES
OUTPUT_NAME ${output_name_${libname}})
set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime")
Expand Down
10 changes: 9 additions & 1 deletion compiler-rt/lib/tsan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=530
append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
TSAN_RTL_CFLAGS)

if (TARGET cxx-headers OR HAVE_LIBCXX)
set(TSAN_DEPS cxx-headers)
endif()

set(TSAN_SOURCES
rtl/tsan_clock.cpp
rtl/tsan_debugging.cpp
Expand Down Expand Up @@ -142,6 +146,7 @@ if(APPLE)
RTSanitizerCommonSymbolizer
RTUbsan
CFLAGS ${TSAN_RTL_CFLAGS}
DEPS ${TSAN_DEPS}
LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
LINK_LIBS ${TSAN_LINK_LIBS} objc
PARENT_TARGET tsan)
Expand All @@ -150,7 +155,8 @@ if(APPLE)
ARCHS ${TSAN_SUPPORTED_ARCH}
SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
ADDITIONAL_HEADERS ${TSAN_HEADERS}
CFLAGS ${TSAN_RTL_CFLAGS})
CFLAGS ${TSAN_RTL_CFLAGS}
DEPS ${TSAN_DEPS})

# Build and check Go runtime.
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
Expand Down Expand Up @@ -214,6 +220,7 @@ else()
$<TARGET_OBJECTS:RTUbsan.${arch}>
ADDITIONAL_HEADERS ${TSAN_HEADERS}
CFLAGS ${TSAN_RTL_CFLAGS}
DEPS ${TSAN_DEPS}
PARENT_TARGET tsan)
add_compiler_rt_runtime(clang_rt.tsan_cxx
STATIC
Expand All @@ -222,6 +229,7 @@ else()
$<TARGET_OBJECTS:RTUbsan_cxx.${arch}>
ADDITIONAL_HEADERS ${TSAN_HEADERS}
CFLAGS ${TSAN_RTL_CFLAGS}
DEPS ${TSAN_DEPS}
PARENT_TARGET tsan)
list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
clang_rt.tsan_cxx-${arch})
Expand Down

0 comments on commit 4540d66

Please sign in to comment.