Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -436,6 +436,7 @@ list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}") if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND + (COMPILER_RT_BUILD_SANITIZERS OR COMPILER_RT_BUILD_XRAY) AND (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR (OS_NAME MATCHES "Windows" AND (NOT MINGW AND NOT CYGWIN)))) set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE) @@ -443,13 +444,15 @@ set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE) endif() -if (COMPILER_RT_HAS_SANITIZER_COMMON) +if (COMPILER_RT_HAS_SANITIZER_COMMON AND + COMPILER_RT_BUILD_SANITIZERS) set(COMPILER_RT_HAS_INTERCEPTION TRUE) else() set(COMPILER_RT_HAS_INTERCEPTION FALSE) endif() -if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH) +if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS) set(COMPILER_RT_HAS_ASAN TRUE) else() set(COMPILER_RT_HAS_ASAN FALSE) @@ -464,6 +467,7 @@ # TODO: Add builtins support. if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_DFSAN TRUE) else() @@ -471,6 +475,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Linux|FreeBSD") set(COMPILER_RT_HAS_LSAN TRUE) else() @@ -485,6 +490,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_MSAN TRUE) else() @@ -492,6 +498,7 @@ endif() if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android") set(COMPILER_RT_HAS_PROFILE TRUE) else() @@ -499,6 +506,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Darwin|Linux|FreeBSD|Android") set(COMPILER_RT_HAS_TSAN TRUE) else() @@ -506,6 +514,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android") set(COMPILER_RT_HAS_UBSAN TRUE) else() @@ -513,6 +522,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Darwin|Linux|FreeBSD") set(COMPILER_RT_HAS_SAFESTACK TRUE) else() @@ -520,6 +530,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND CFI_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_CFI TRUE) else() @@ -527,6 +538,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND ESAN_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_ESAN TRUE) else() @@ -534,6 +546,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND SCUDO_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_SANITIZERS AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_SCUDO TRUE) else() @@ -541,6 +554,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND + COMPILER_RT_BUILD_XRAY AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_XRAY TRUE) else() Index: include/CMakeLists.txt =================================================================== --- include/CMakeLists.txt +++ include/CMakeLists.txt @@ -1,19 +1,43 @@ -set(SANITIZER_HEADERS - sanitizer/allocator_interface.h - sanitizer/asan_interface.h - sanitizer/common_interface_defs.h - sanitizer/coverage_interface.h - sanitizer/dfsan_interface.h - sanitizer/esan_interface.h - sanitizer/linux_syscall_hooks.h - sanitizer/lsan_interface.h - sanitizer/msan_interface.h - sanitizer/tsan_interface.h - sanitizer/tsan_interface_atomic.h) +set(SANITIZER_HEADERS) +if(COMPILER_RT_HAS_SANITIZER_COMMON) + list(APPEND SANITIZER_HEADERS + sanitizer/allocator_interface.h + sanitizer/common_interface_defs.h + sanitizer/coverage_interface.h + sanitizer/linux_syscall_hooks.h) +endif() +if(COMPILER_RT_HAS_ASAN) + list(APPEND SANITIZER_HEADERS + sanitizer/asan_interface.h) +endif() +if(COMPILER_RT_HAS_DFSAN) + list(APPEND SANITIZER_HEADERS + sanitizer/dfsan_interface.h) +endif() +if(COMPILER_RT_HAS_ESAN) + list(APPEND SANITIZER_HEADERS + sanitizer/esan_interface.h) +endif() +if(COMPILER_RT_HAS_LSAN) + list(APPEND SANITIZER_HEADERS + sanitizer/lsan_interface.h) +endif() +if(COMPILER_RT_HAS_MSAN) + list(APPEND SANITIZER_HEADERS + sanitizer/msan_interface.h) +endif() +if(COMPILER_RT_HAS_TSAN) + list(APPEND SANITIZER_HEADERS + sanitizer/tsan_interface.h + sanitizer/tsan_interface_atomic.h) +endif() -set(XRAY_HEADERS - xray/xray_interface.h - xray/xray_log_interface.h) +set(XRAY_HEADERS) +if(COMPILER_RT_BUILD_XRAY) + list(APPEND XRAY_HEADERS + xray/xray_interface.h + xray/xray_log_interface.h) +endif() set(COMPILER_RT_HEADERS ${SANITIZER_HEADERS} Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -8,8 +8,7 @@ # sanitizers or xray (or both). # #TODO: Refactor sanitizer_common into smaller pieces (e.g. flag parsing, utils). -if (COMPILER_RT_HAS_SANITIZER_COMMON AND - (COMPILER_RT_BUILD_SANITIZERS OR COMPILER_RT_BUILD_XRAY)) +if (COMPILER_RT_HAS_SANITIZER_COMMON) add_subdirectory(sanitizer_common) endif() @@ -36,27 +35,27 @@ endif() endfunction() -if(COMPILER_RT_BUILD_SANITIZERS) - compiler_rt_build_runtime(interception) +# the following set is conditional to COMPILER_RT_BUILD_SANITIZERS +# (via COMPILER_RT_HAS_* in config-ix.cmake) +compiler_rt_build_runtime(interception) - if(COMPILER_RT_HAS_SANITIZER_COMMON) - add_subdirectory(stats) - add_subdirectory(lsan) - add_subdirectory(ubsan) - endif() +if(COMPILER_RT_BUILD_SANITIZERS AND COMPILER_RT_HAS_SANITIZER_COMMON) + add_subdirectory(stats) + add_subdirectory(lsan) + add_subdirectory(ubsan) +endif() - compiler_rt_build_sanitizer(asan) - compiler_rt_build_sanitizer(dfsan) - compiler_rt_build_sanitizer(msan) - compiler_rt_build_sanitizer(tsan tsan/dd) - compiler_rt_build_sanitizer(safestack) - compiler_rt_build_sanitizer(cfi) - compiler_rt_build_sanitizer(esan) - compiler_rt_build_sanitizer(scudo) +compiler_rt_build_sanitizer(asan) +compiler_rt_build_sanitizer(dfsan) +compiler_rt_build_sanitizer(msan) +compiler_rt_build_sanitizer(tsan tsan/dd) +compiler_rt_build_sanitizer(safestack) +compiler_rt_build_sanitizer(cfi) +compiler_rt_build_sanitizer(esan) +compiler_rt_build_sanitizer(scudo) - compiler_rt_build_runtime(profile) -endif() +compiler_rt_build_runtime(profile) -if(COMPILER_RT_BUILD_XRAY) - compiler_rt_build_runtime(xray) -endif() +# the following set is conditional to COMPILER_RT_BUILD_XRAY +# (via COMPILER_RT_HAS_* in config-ix.cmake) +compiler_rt_build_runtime(xray) Index: test/sanitizer_common/CMakeLists.txt =================================================================== --- test/sanitizer_common/CMakeLists.txt +++ test/sanitizer_common/CMakeLists.txt @@ -4,13 +4,20 @@ set(SANITIZER_COMMON_TESTSUITES) set(SUPPORTED_TOOLS) -if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD" AND NOT ANDROID) +if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD" AND NOT ANDROID AND + COMPILER_RT_HAS_ASAN) list(APPEND SUPPORTED_TOOLS asan) endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID) - list(APPEND SUPPORTED_TOOLS tsan) - list(APPEND SUPPORTED_TOOLS msan) - list(APPEND SUPPORTED_TOOLS lsan) + if(COMPILER_RT_HAS_TSAN) + list(APPEND SUPPORTED_TOOLS tsan) + endif() + if(COMPILER_RT_HAS_MSAN) + list(APPEND SUPPORTED_TOOLS msan) + endif() + if(COMPILER_RT_HAS_LSAN) + list(APPEND SUPPORTED_TOOLS lsan) + endif() endif() # Create a separate config for each tool we support.