diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 751903070051..f3a4d5833649 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -29,6 +29,7 @@ check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INIT check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) check_cxx_compiler_flag(-msse3 COMPILER_RT_HAS_MSSE3_FLAG) check_cxx_compiler_flag(-std=c99 COMPILER_RT_HAS_STD_C99_FLAG) +check_cxx_compiler_flag(--sysroot=. COMPILER_RT_HAS_SYSROOT_FLAG) if(NOT WIN32 AND NOT CYGWIN) # MinGW warns if -fvisibility-inlines-hidden is used. diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt index 34f6e30dee6c..5e480d9abbde 100644 --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -21,7 +21,6 @@ append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=512 TSAN_RTL_CFLAGS) append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors TSAN_RTL_CFLAGS) -# FIXME: Add support for --sysroot=. compile flag: set(TSAN_SOURCES rtl/tsan_clock.cc @@ -187,6 +186,18 @@ endif() add_dependencies(compiler-rt tsan) +# Make sure that non-platform-specific files don't include any system headers. +if(COMPILER_RT_HAS_SYSROOT_FLAG) + file(GLOB _tsan_generic_sources rtl/tsan*) + file(GLOB _tsan_platform_sources rtl/tsan*posix* rtl/tsan*mac* + rtl/tsan*linux*) + list(REMOVE_ITEM _tsan_generic_sources ${_tsan_platform_sources}) + message(STATUS "platform: ${_tsan_platform_sources}") + message(STATUS "generic: ${_tsan_generic_sources}") + set_source_files_properties(${_tsan_generic_sources} + PROPERTIES COMPILE_FLAGS "--sysroot=.") +endif() + # Build libcxx instrumented with TSan. if(COMPILER_RT_HAS_LIBCXX_SOURCES AND COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang")