diff options
-rw-r--r-- | cmake/Modules/CompilerRTUtils.cmake | 12 | ||||
-rw-r--r-- | cmake/config-ix.cmake | 5 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 71 |
3 files changed, 48 insertions, 40 deletions
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake index 25692974b..af5975f02 100644 --- a/cmake/Modules/CompilerRTUtils.cmake +++ b/cmake/Modules/CompilerRTUtils.cmake @@ -76,6 +76,18 @@ macro(list_intersect output input1 input2) endforeach() endmacro() +function(list_replace input_list old new) + set(replaced_list) + foreach(item ${${input_list}}) + if(${item} STREQUAL ${old}) + list(APPEND replaced_list ${new}) + else() + list(APPEND replaced_list ${item}) + endif() + endforeach() + set(${input_list} "${replaced_list}" PARENT_SCOPE) +endfunction() + # Takes ${ARGN} and puts only supported architectures in @out_var list. function(filter_available_targets out_var) set(archs ${${out_var}}) diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 92c345262..67d0c7c22 100644 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -400,6 +400,11 @@ else() set(OS_NAME "${CMAKE_SYSTEM_NAME}") endif() +set(ALL_SANITIZERS asan;dfsan;msan;profile;tsan;safestack;cfi;esan;scudo) +set(COMPILER_RT_SANITIZERS_TO_BUILD ${ALL_SANITIZERS} CACHE STRING + "sanitizers to build if supported on the target (all;${ALL_SANITIZERS})") +list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}") + if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR (OS_NAME MATCHES "Windows" AND MSVC))) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ce96fe484..4ab1e933a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -17,10 +17,27 @@ if(COMPILER_RT_BUILD_BUILTINS) add_subdirectory(builtins) endif() -if(COMPILER_RT_BUILD_SANITIZERS) - if(COMPILER_RT_HAS_INTERCEPTION) - add_subdirectory(interception) +function(compiler_rt_build_runtime runtime) + string(TOUPPER ${runtime} runtime_uppercase) + if(COMPILER_RT_HAS_${runtime_uppercase}) + add_subdirectory(${runtime}) + foreach(directory ${ARGN}) + add_subdirectory(${directory}) + endforeach() + endif() +endfunction() + +function(compiler_rt_build_sanitizer sanitizer) + string(TOUPPER ${sanitizer} sanitizer_uppercase) + string(TOLOWER ${sanitizer} sanitizer_lowercase) + list(FIND COMPILER_RT_SANITIZERS_TO_BUILD ${sanitizer_lowercase} result) + if(NOT ${result} EQUAL -1) + compiler_rt_build_runtime(${sanitizer} ${ARGN}) endif() +endfunction() + +if(COMPILER_RT_BUILD_SANITIZERS) + compiler_rt_build_runtime(interception) if(COMPILER_RT_HAS_SANITIZER_COMMON) add_subdirectory(stats) @@ -28,44 +45,18 @@ if(COMPILER_RT_BUILD_SANITIZERS) add_subdirectory(ubsan) endif() - if(COMPILER_RT_HAS_ASAN) - add_subdirectory(asan) - 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) - if(COMPILER_RT_HAS_DFSAN) - add_subdirectory(dfsan) - endif() - - if(COMPILER_RT_HAS_MSAN) - add_subdirectory(msan) - endif() - - if(COMPILER_RT_HAS_PROFILE) - add_subdirectory(profile) - endif() - - if(COMPILER_RT_HAS_TSAN) - add_subdirectory(tsan) - add_subdirectory(tsan/dd) - endif() - - if(COMPILER_RT_HAS_SAFESTACK) - add_subdirectory(safestack) - endif() - - if(COMPILER_RT_HAS_CFI) - add_subdirectory(cfi) - endif() - - if(COMPILER_RT_HAS_ESAN) - add_subdirectory(esan) - endif() - - if(COMPILER_RT_HAS_SCUDO) - add_subdirectory(scudo) - endif() + compiler_rt_build_runtime(profile) endif() -if(COMPILER_RT_BUILD_XRAY AND COMPILER_RT_HAS_XRAY) - add_subdirectory(xray) +if(COMPILER_RT_BUILD_XRAY) + compiler_rt_build_runtime(xray) endif() |