[compiler-rt] r255170 - [CMake] Provide options for toggling on and off various runtime libraries.
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 9 16:06:42 PST 2015
Chris Bieneman via llvm-commits <llvm-commits at lists.llvm.org> writes:
> Author: cbieneman
> Date: Wed Dec 9 16:45:03 2015
> New Revision: 255170
>
> URL: http://llvm.org/viewvc/llvm-project?rev=255170&view=rev
> Log:
> [CMake] Provide options for toggling on and off various runtime libraries.
>
> Summary:
> Rather than having to add new "experimental" options each time someone
> wants to work on bringing a sanitizer to a new platform, this patch
> makes options for all of them.
>
> The default values for the options are set by the platform checks that
> would have enabled them, but they can be overridden on or off.
>
> Reviewers: kubabrecka, samsonov
>
> Subscribers: llvm-commits
>
> Differential Revision: http://reviews.llvm.org/D14846
>
> Added:
> compiler-rt/trunk/test/interception/
> compiler-rt/trunk/test/interception/CMakeLists.txt
> Modified:
> compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
> compiler-rt/trunk/cmake/config-ix.cmake
> compiler-rt/trunk/lib/CMakeLists.txt
> compiler-rt/trunk/lib/lsan/CMakeLists.txt
> compiler-rt/trunk/lib/tsan/CMakeLists.txt
> compiler-rt/trunk/lib/ubsan/CMakeLists.txt
> compiler-rt/trunk/test/CMakeLists.txt
> compiler-rt/trunk/test/cfi/CMakeLists.txt
> compiler-rt/trunk/test/ubsan/CMakeLists.txt
>
> Modified: compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake (original)
> +++ compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake Wed Dec 9 16:45:03 2015
> @@ -36,6 +36,16 @@ macro(append_list_if condition value)
> endif()
> endmacro()
>
> +# Appends values to list if it isn't already there
> +macro(append_list_unique list)
> + foreach(val ${ARGN})
> + list(FIND ${list} ${val} idx)
> + if(idx EQUAL -1)
> + list(APPEND ${list} ${val})
> + endif()
> + endforeach()
> +endmacro()
> +
> # Appends value to all strings in ARGN, if the condition is true.
> macro(append_string_if condition value)
> if(${condition})
> @@ -67,3 +77,12 @@ macro(list_union output input1 input2)
> endif()
> endforeach()
> endmacro()
> +
> +macro(check_list_contains outvar list input)
> + list(FIND ${list} ${input} idx)
> + if(idx GREATER -1)
> + set(${outvar} True)
> + else()
> + set(${outvar} False)
> + endif()
> +endmacro()
>
> Modified: compiler-rt/trunk/cmake/config-ix.cmake
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/cmake/config-ix.cmake (original)
> +++ compiler-rt/trunk/cmake/config-ix.cmake Wed Dec 9 16:45:03 2015
> @@ -505,78 +505,82 @@ endif()
> 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)))
> - set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
> -else()
> - set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
> + list(APPEND DEFAULT_RUNTIMES sanitizer_common)
> endif()
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND
> - (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4))
> - set(COMPILER_RT_HAS_INTERCEPTION TRUE)
> -else()
> - set(COMPILER_RT_HAS_INTERCEPTION FALSE)
> +if (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4)
> + list(APPEND DEFAULT_RUNTIMES interception)
> + list(APPEND REQUIRES_COMMON interception)
> endif()
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND
> +if (ASAN_SUPPORTED_ARCH AND
> (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4))
> - set(COMPILER_RT_HAS_ASAN TRUE)
> -else()
> - set(COMPILER_RT_HAS_ASAN FALSE)
> + list(APPEND DEFAULT_RUNTIMES asan)
> + list(APPEND REQUIRES_COMMON asan)
> endif()
>
> if (OS_NAME MATCHES "Linux|FreeBSD|Windows")
> - set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
> -else()
> - set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
> + set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME On)
> endif()
>
> # TODO: Add builtins support.
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
> +if (DFSAN_SUPPORTED_ARCH AND
> OS_NAME MATCHES "Linux")
> - set(COMPILER_RT_HAS_DFSAN TRUE)
> -else()
> - set(COMPILER_RT_HAS_DFSAN FALSE)
> + list(APPEND DEFAULT_RUNTIMES dfsan)
> + list(APPEND REQUIRES_COMMON dfsan)
> endif()
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
> - OS_NAME MATCHES "Linux|FreeBSD")
> - set(COMPILER_RT_HAS_LSAN TRUE)
> -else()
> - set(COMPILER_RT_HAS_LSAN FALSE)
> +if (LSAN_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux|FreeBSD")
> + list(APPEND DEFAULT_RUNTIMES lsan)
> + list(APPEND REQUIRES_COMMON lsan)
> endif()
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
> +if (MSAN_SUPPORTED_ARCH AND
> OS_NAME MATCHES "Linux")
> - set(COMPILER_RT_HAS_MSAN TRUE)
> -else()
> - set(COMPILER_RT_HAS_MSAN FALSE)
> + list(APPEND DEFAULT_RUNTIMES msan)
> + list(APPEND REQUIRES_COMMON msan)
> endif()
>
> if (PROFILE_SUPPORTED_ARCH AND
> OS_NAME MATCHES "Darwin|Linux|FreeBSD")
> - set(COMPILER_RT_HAS_PROFILE TRUE)
> -else()
> - set(COMPILER_RT_HAS_PROFILE FALSE)
> + list(APPEND DEFAULT_RUNTIMES profile)
> endif()
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
> +if (TSAN_SUPPORTED_ARCH AND
> OS_NAME MATCHES "Darwin|Linux|FreeBSD")
> - set(COMPILER_RT_HAS_TSAN TRUE)
> -else()
> - set(COMPILER_RT_HAS_TSAN FALSE)
> + list(APPEND DEFAULT_RUNTIMES tsan)
> + list(APPEND REQUIRES_COMMON tsan)
> endif()
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
> +if (UBSAN_SUPPORTED_ARCH AND
> OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows")
> - set(COMPILER_RT_HAS_UBSAN TRUE)
> -else()
> - set(COMPILER_RT_HAS_UBSAN FALSE)
> + list(APPEND DEFAULT_RUNTIMES ubsan)
> + list(APPEND REQUIRES_COMMON ubsan)
> endif()
> +list(APPEND DEFAULT_RUNTIMES cfi)
>
> -if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
> +if (SAFESTACK_SUPPORTED_ARCH AND
> OS_NAME MATCHES "Darwin|Linux|FreeBSD")
> - set(COMPILER_RT_HAS_SAFESTACK TRUE)
> -else()
> - set(COMPILER_RT_HAS_SAFESTACK FALSE)
> + list(APPEND DEFAULT_RUNTIMES safestack)
> + list(APPEND REQUIRES_COMMON safestack)
> +endif()
> +
> +set(COMPILER_RT_RUNTIMES_TO_BUILD "all"
> + CACHE STRING "Semicolon-separated list of runtimes to build, or \"all\".")
> +
> +if(COMPILER_RT_RUNTIMES_TO_BUILD STREQUAL "all")
> + set(COMPILER_RT_RUNTIMES_TO_BUILD ${DEFAULT_RUNTIMES})
> +endif()
Would it be better to have COMPILER_RT_RUNTIMES_TO_BUILD be "default"
for the default runtimes? It seems strange that "all" doesn't actually
mean "build all of them".
> +
> +# Several of the runtimes produce object libraries that are consumed by other
> +# runtimes (i.e. asan relies on ubsan). If you're building a library that relies
> +# on common bits we need to build this full set of libraries.
> +list_union(SHOULD_BUILD_COMMON REQUIRES_COMMON COMPILER_RT_RUNTIMES_TO_BUILD)
Does this work correctly if I manually specify something non-default in
COMPILER_RT_RUNTIMES_TO_BUILD that would normally require common? That
is, if I'm on Darwin and set COMPILER_RT_RUNTIMES_TO_BUILD=msan, I don't
think sanitizer_common will be added to the list with the current code.
> +
> +if(SHOULD_BUILD_COMMON)
> + append_list_unique(COMPILER_RT_RUNTIMES_TO_BUILD sanitizer_common)
> + append_list_unique(COMPILER_RT_RUNTIMES_TO_BUILD lsan)
> + append_list_unique(COMPILER_RT_RUNTIMES_TO_BUILD ubsan)
> + append_list_unique(COMPILER_RT_RUNTIMES_TO_BUILD interception)
> endif()
>
> Modified: compiler-rt/trunk/lib/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -9,40 +9,9 @@ if(COMPILER_RT_BUILD_BUILTINS)
> endif()
>
> if(COMPILER_RT_BUILD_SANITIZERS)
> - if(COMPILER_RT_HAS_INTERCEPTION)
> - add_subdirectory(interception)
> - endif()
> -
> - if(COMPILER_RT_HAS_SANITIZER_COMMON)
> - add_subdirectory(sanitizer_common)
> - add_subdirectory(lsan)
> - add_subdirectory(ubsan)
> - endif()
> -
> - add_subdirectory(cfi)
> -
> - if(COMPILER_RT_HAS_ASAN)
> - add_subdirectory(asan)
> - endif()
> -
> - 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()
> + message(STATUS "Adding runtimes...")
> + foreach(runtime ${COMPILER_RT_RUNTIMES_TO_BUILD})
> + message(STATUS "Adding runtime: ${runtime}")
> + add_subdirectory(${runtime})
> + endforeach()
> endif()
>
> Modified: compiler-rt/trunk/lib/lsan/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/lsan/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -24,6 +24,7 @@ add_compiler_rt_object_libraries(RTLSanC
> SOURCES ${LSAN_COMMON_SOURCES}
> CFLAGS ${LSAN_CFLAGS})
>
> +check_list_contains(COMPILER_RT_HAS_LSAN COMPILER_RT_RUNTIMES_TO_BUILD lsan)
> if(COMPILER_RT_HAS_LSAN)
> foreach(arch ${LSAN_SUPPORTED_ARCH})
> add_compiler_rt_runtime(clang_rt.lsan
>
> Modified: compiler-rt/trunk/lib/tsan/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/tsan/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -213,3 +213,5 @@ endif()
> if(COMPILER_RT_INCLUDE_TESTS)
> add_subdirectory(tests)
> endif()
> +
> +add_subdirectory(dd)
>
> Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -1,5 +1,7 @@
> # Build for the undefined behavior sanitizer runtime support library.
>
> +check_list_contains(COMPILER_RT_HAS_UBSAN COMPILER_RT_RUNTIMES_TO_BUILD ubsan)
> +
> set(UBSAN_SOURCES
> ubsan_diag.cc
> ubsan_init.cc
>
> Modified: compiler-rt/trunk/test/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/CMakeLists.txt (original)
> +++ compiler-rt/trunk/test/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -36,37 +36,9 @@ endif()
> # Run sanitizer tests only if we're sure that clang would produce
> # working binaries.
> if(COMPILER_RT_CAN_EXECUTE_TESTS)
> - if(COMPILER_RT_HAS_ASAN)
> - add_subdirectory(asan)
> - endif()
> - if(COMPILER_RT_HAS_DFSAN)
> - add_subdirectory(dfsan)
> - endif()
> - if(COMPILER_RT_HAS_LSAN)
> - add_subdirectory(lsan)
> - endif()
> - if(COMPILER_RT_HAS_MSAN)
> - add_subdirectory(msan)
> - endif()
> - if(COMPILER_RT_HAS_PROFILE)
> - add_subdirectory(profile)
> - endif()
> - if(COMPILER_RT_HAS_SANITIZER_COMMON)
> - add_subdirectory(sanitizer_common)
> - endif()
> - if(COMPILER_RT_HAS_TSAN)
> - add_subdirectory(tsan)
> - endif()
> - if(COMPILER_RT_HAS_UBSAN)
> - add_subdirectory(ubsan)
> - endif()
> - # CFI tests require diagnostic mode, which is implemented in UBSan.
> - if(COMPILER_RT_HAS_UBSAN)
> - add_subdirectory(cfi)
> - endif()
> - if(COMPILER_RT_HAS_SAFESTACK)
> - add_subdirectory(safestack)
> - endif()
> + foreach(runtime ${COMPILER_RT_RUNTIMES_TO_BUILD})
> + add_subdirectory(${runtime})
> + endforeach()
> endif()
>
> if(COMPILER_RT_STANDALONE_BUILD)
> @@ -79,3 +51,4 @@ if(COMPILER_RT_STANDALONE_BUILD)
> ${LLVM_LIT_TESTSUITES}
> DEPENDS ${LLVM_LIT_DEPENDS})
> endif()
> +
>
> Modified: compiler-rt/trunk/test/cfi/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/cfi/CMakeLists.txt (original)
> +++ compiler-rt/trunk/test/cfi/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -1,3 +1,9 @@
> +check_list_contains(HAS_UBSAN COMPILER_RT_RUNTIMES_TO_BUILD ubsan)
> +# CFI tests require diagnostic mode, which is implemented in UBSan.
> +if(NOT HAS_UBSAN)
> + return()
> +endif()
> +
> configure_lit_site_cfg(
> ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
> ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
>
> Added: compiler-rt/trunk/test/interception/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/interception/CMakeLists.txt?rev=255170&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/interception/CMakeLists.txt (added)
> +++ compiler-rt/trunk/test/interception/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -0,0 +1 @@
> +# Placeholder to avoid special casing.
>
> Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=255170&r1=255169&r2=255170&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
> +++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Wed Dec 9 16:45:03 2015
> @@ -20,6 +20,10 @@ if(APPLE)
> darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
> endif()
>
> +check_list_contains(HAS_ASAN COMPILER_RT_RUNTIMES_TO_BUILD asan)
> +check_list_contains(HAS_MSAN COMPILER_RT_RUNTIMES_TO_BUILD msan)
> +check_list_contains(HAS_TSAN COMPILER_RT_RUNTIMES_TO_BUILD tsan)
> +
> foreach(arch ${UBSAN_TEST_ARCH})
> set(UBSAN_TEST_TARGET_ARCH ${arch})
> if(${arch} MATCHES "arm|aarch64")
> @@ -31,13 +35,17 @@ foreach(arch ${UBSAN_TEST_ARCH})
> endif()
> add_ubsan_testsuite("Standalone" ubsan ${arch})
>
> - if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
> + check_list_contains(ASAN_HAS_ARCH ASAN_SUPPORTED_ARCH ${arch})
> + check_list_contains(MSAN_HAS_ARCH MSAN_SUPPORTED_ARCH ${arch})
> + check_list_contains(TSAN_HAS_ARCH TSAN_SUPPORTED_ARCH ${arch})
> +
> + if(HAS_ASAN AND ASAN_HAS_ARCH)
> add_ubsan_testsuite("AddressSanitizer" asan ${arch})
> endif()
> - if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
> + if(HAS_MSAN AND MSAN_HAS_ARCH)
> add_ubsan_testsuite("MemorySanitizer" msan ${arch})
> endif()
> - if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
> + if(HAS_TSAN AND TSAN_HAS_ARCH)
> add_ubsan_testsuite("ThreadSanitizer" tsan ${arch})
> endif()
> endforeach()
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list