From: Alexey Samsonov Date: Wed, 17 Dec 2014 23:14:01 +0000 (+0000) Subject: [ASan] Always build shared ASan runtime on Linux. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=969902b43b0c028d49dba8ee0b443351fa0453cb;p=platform%2Fupstream%2Fllvm.git [ASan] Always build shared ASan runtime on Linux. This commit changes the strategy for building shared ASan runtime and the way we test it: - COMPILER_RT_BUILD_SHARED_ASAN CMake option is removed. We now always build shared ASan runtime (it is the default on Android, Windows and Mac, and not the default on Linux and FreeBSD). - Platforms, which use static runtime by default now have "check-asan-dynamic" testsuite. This testsuite contains instrumented unit tests, and ASan lit tests, and runs them with shared ASan runtime. This testsuite is *not* a part of "check-asan" and *not* a part of "check-all", as adding 1000 more test cases, which duplicate existing ones is costly. However, you're welcome to add this command to your buildbot. llvm-svn: 224470 --- diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index a6a4ed9..0757a50 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -199,14 +199,6 @@ option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF) # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in. pythonize_bool(COMPILER_RT_DEBUG) -# We have to support both static and dynamic/shared runtime on Windows. -# Android only works with dynamic runtime. -if(WIN32 OR ANDROID) -option(COMPILER_RT_BUILD_SHARED_ASAN "Build shared version of AddressSanitizer runtime" ON) -else() -option(COMPILER_RT_BUILD_SHARED_ASAN "Build shared version of AddressSanitizer runtime" OFF) -endif() - #================================ # Setup Compiler Flags #================================ diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index 3edd854f..f080fa7 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -156,12 +156,17 @@ endif() # using specified link flags. Make executable a part of provided # test_suite. # add_compiler_rt_test( +# SUBDIR # OBJECTS # DEPS # LINK_FLAGS ) macro(add_compiler_rt_test test_suite test_name) - parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) - set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") + parse_arguments(TEST "SUBDIR;OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) + if(TEST_SUBDIR) + set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SUBDIR}/${test_name}") + else() + set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}") + endif() # Use host compiler in a standalone build, and just-built Clang otherwise. if(NOT COMPILER_RT_STANDALONE_BUILD) list(APPEND TEST_DEPS clang) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index e405f25..c32f624 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -205,6 +205,12 @@ else() set(COMPILER_RT_HAS_ASAN FALSE) endif() +if (OS_NAME MATCHES "Linux|FreeBSD") + set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE) +else() + set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE) +endif() + # TODO: Add builtins support. if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index 85d2b9a..79510f9 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -79,12 +79,10 @@ else() add_compiler_rt_object_library(RTAsan_preinit ${arch} SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS} DEFS ${ASAN_COMMON_DEFINITIONS}) - if (COMPILER_RT_BUILD_SHARED_ASAN) - add_compiler_rt_object_library(RTAsan_dynamic ${arch} - SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} - CFLAGS ${ASAN_DYNAMIC_CFLAGS} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) - endif() + add_compiler_rt_object_library(RTAsan_dynamic ${arch} + SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) endforeach() endif() @@ -129,28 +127,25 @@ else() DEFS ${ASAN_COMMON_DEFINITIONS}) add_dependencies(asan clang_rt.asan_cxx-${arch}) - if (COMPILER_RT_BUILD_SHARED_ASAN) - add_compiler_rt_runtime(clang_rt.asan-preinit-${arch} ${arch} STATIC - SOURCES $ - CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_dependencies(asan clang_rt.asan-preinit-${arch}) - - if (WIN32) - set(SHARED_ASAN_NAME clang_rt.asan_dynamic-${arch}${COMPILER_RT_OS_SUFFIX}) - else() - set(SHARED_ASAN_NAME clang_rt.asan-${arch}${COMPILER_RT_OS_SUFFIX}) - endif() - - add_compiler_rt_runtime(clang_rt.asan-dynamic-${arch} ${arch} SHARED - OUTPUT_NAME ${SHARED_ASAN_NAME} - SOURCES $ - ${ASAN_COMMON_RUNTIME_OBJECTS} - CFLAGS ${ASAN_DYNAMIC_CFLAGS} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) - target_link_libraries(clang_rt.asan-dynamic-${arch} ${ASAN_DYNAMIC_LIBS}) - add_dependencies(asan clang_rt.asan-dynamic-${arch}) + add_compiler_rt_runtime(clang_rt.asan-preinit-${arch} ${arch} STATIC + SOURCES $ + CFLAGS ${ASAN_CFLAGS} + DEFS ${ASAN_COMMON_DEFINITIONS}) + add_dependencies(asan clang_rt.asan-preinit-${arch}) + + if (WIN32) + set(SHARED_ASAN_NAME clang_rt.asan_dynamic-${arch}${COMPILER_RT_OS_SUFFIX}) + else() + set(SHARED_ASAN_NAME clang_rt.asan-${arch}${COMPILER_RT_OS_SUFFIX}) endif() + add_compiler_rt_runtime(clang_rt.asan-dynamic-${arch} ${arch} SHARED + OUTPUT_NAME ${SHARED_ASAN_NAME} + SOURCES $ + ${ASAN_COMMON_RUNTIME_OBJECTS} + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) + target_link_libraries(clang_rt.asan-dynamic-${arch} ${ASAN_DYNAMIC_LIBS}) + add_dependencies(asan clang_rt.asan-dynamic-${arch}) if (UNIX AND NOT ${arch} STREQUAL "i386" AND NOT ${arch} STREQUAL "i686") add_sanitizer_rt_symbols(clang_rt.asan_cxx-${arch}) diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt index 7b36371..b1e34c7 100644 --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -117,7 +117,7 @@ endmacro() # Link ASan unit test for a given architecture from a set # of objects in with given linker flags. macro(add_asan_test test_suite test_name arch kind) - parse_arguments(TEST "OBJECTS;LINKFLAGS" "WITH_TEST_RUNTIME" ${ARGN}) + parse_arguments(TEST "OBJECTS;LINKFLAGS;SUBDIR" "WITH_TEST_RUNTIME" ${ARGN}) get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) set(TEST_DEPS ${TEST_OBJECTS}) if(NOT COMPILER_RT_STANDALONE_BUILD) @@ -132,6 +132,7 @@ macro(add_asan_test test_suite test_name arch kind) endif() endif() add_compiler_rt_test(${test_suite} ${test_name} + SUBDIR ${TEST_SUBDIR} OBJECTS ${TEST_OBJECTS} DEPS ${TEST_DEPS} LINK_FLAGS ${TEST_LINKFLAGS} @@ -141,6 +142,11 @@ endmacro() # Main AddressSanitizer unit tests. add_custom_target(AsanUnitTests) set_target_properties(AsanUnitTests PROPERTIES FOLDER "ASan unit tests") +# AddressSanitizer unit tests with dynamic runtime (on platforms where it's +# not the default). +add_custom_target(AsanDynamicUnitTests) +set_target_properties(AsanDynamicUnitTests + PROPERTIES FOLDER "ASan unit tests with dynamic runtime") # ASan benchmarks (not actively used now). add_custom_target(AsanBenchmarks) set_target_properties(AsanBenchmarks PROPERTIES FOLDER "Asan benchmarks") @@ -182,11 +188,15 @@ macro(add_asan_tests_for_arch_and_kind arch kind) asan_compile(ASAN_INST_TEST_OBJECTS asan_mac_test_helpers.mm ${arch} ${kind} ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -ObjC ${ARGN}) endif() - add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Test" ${arch} ${kind} + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default") + add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Test" + ${arch} ${kind} SUBDIR "default" OBJECTS ${ASAN_INST_TEST_OBJECTS} LINKFLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) - if(COMPILER_RT_BUILD_SHARED_ASAN) - add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Dynamic-Test" ${arch} ${kind} + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic") + add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test" + ${arch} ${kind} SUBDIR "dynamic" OBJECTS ${ASAN_INST_TEST_OBJECTS} LINKFLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS}) endif() @@ -220,7 +230,8 @@ macro(add_asan_tests_for_arch_and_kind arch kind) asan_compile(ASAN_NOINST_TEST_OBJECTS ${src} ${arch} ${kind} ${ASAN_UNITTEST_COMMON_CFLAGS} ${ARGN}) endforeach() - add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Noinst-Test" ${arch} ${kind} + add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Noinst-Test" + ${arch} ${kind} SUBDIR "default" OBJECTS ${ASAN_NOINST_TEST_OBJECTS} LINKFLAGS ${ASAN_UNITTEST_NOINST_LINKFLAGS} WITH_TEST_RUNTIME) @@ -231,14 +242,10 @@ macro(add_asan_tests_for_arch_and_kind arch kind) asan_compile(ASAN_BENCHMARKS_OBJECTS ${src} ${arch} ${kind} ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${ARGN}) endforeach() - add_asan_test(AsanBenchmarks "Asan-${arch}${kind}-Benchmark" ${arch} ${kind} + add_asan_test(AsanBenchmarks "Asan-${arch}${kind}-Benchmark" + ${arch} ${kind} SUBDIR "default" OBJECTS ${ASAN_BENCHMARKS_OBJECTS} LINKFLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) - if(COMPILER_RT_BUILD_SHARED_ASAN) - add_asan_test(AsanBenchmarks "Asan-${arch}${kind}-Dynamic-Benchmark" ${arch} ${kind} - OBJECTS ${ASAN_BENCHMARKS_OBJECTS} - LINKFLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS}) - endif() endmacro() if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID) diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt index 14f7f50..78725d4 100644 --- a/compiler-rt/test/asan/CMakeLists.txt +++ b/compiler-rt/test/asan/CMakeLists.txt @@ -1,6 +1,7 @@ set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(ASAN_TESTSUITES) +set(ASAN_DYNAMIC_TESTSUITES) macro(get_bits_for_arch arch bits) if (${arch} STREQUAL "arm" OR @@ -78,13 +79,14 @@ else() # Not Android ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig/lit.site.cfg ) list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig) - if(COMPILER_RT_BUILD_SHARED_ASAN) + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) set(ASAN_TEST_CONFIG_SUFFIX "64-Dynamic") set(ASAN_TEST_DYNAMIC True) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic/lit.site.cfg) - list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic) + list(APPEND ASAN_DYNAMIC_TESTSUITES + ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic) endif() endif() @@ -99,13 +101,14 @@ else() # Not Android ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg ) list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig) - if(COMPILER_RT_BUILD_SHARED_ASAN) + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic") set(ASAN_TEST_DYNAMIC True) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg) - list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic) + list(APPEND ASAN_DYNAMIC_TESTSUITES + ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic) endif() endif() @@ -119,23 +122,18 @@ else() # Not Android ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg ) list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig) - if(COMPILER_RT_BUILD_SHARED_ASAN) + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic") set(ASAN_TEST_DYNAMIC True) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg) - list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic) + list(APPEND ASAN_DYNAMIC_TESTSUITES + ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic) endif() endif() endif() # Not Android -if(COMPILER_RT_INCLUDE_TESTS) - configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg) -endif() - set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) if(COMPILER_RT_STANDALONE_BUILD) add_executable(FileCheck IMPORTED GLOBAL) @@ -144,13 +142,44 @@ if(COMPILER_RT_STANDALONE_BUILD) else() list(APPEND ASAN_TEST_DEPS asan) endif() +set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS}) -# FIXME: support unit test in the android test runner -if(COMPILER_RT_INCLUDE_TESTS AND NOT ANDROID) - list(APPEND ASAN_TEST_DEPS AsanUnitTests) - list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) +# Add unit tests. +if(COMPILER_RT_INCLUDE_TESTS) + set(ASAN_TEST_DYNAMIC False) + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg) + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) + set(ASAN_TEST_DYNAMIC True) + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg) + endif() + # FIXME: support unit test in the android test runner + if (NOT ANDROID) + list(APPEND ASAN_TEST_DEPS AsanUnitTests) + list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) + list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests) + list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic) + endif() + endif() endif() + add_lit_testsuite(check-asan "Running the AddressSanitizer tests" ${ASAN_TESTSUITES} DEPENDS ${ASAN_TEST_DEPS}) set_target_properties(check-asan PROPERTIES FOLDER "ASan tests") + +if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) + # Add check-dynamic-asan target (not included in check-all) + set(EXCLUDE_FROM_ALL TRUE) + add_lit_testsuite(check-asan-dynamic + "Running the AddressSanitizer tests with dynamic runtime" + ${ASAN_DYNAMIC_TESTSUITES} + DEPENDS ${ASAN_DYNAMIC_TEST_DEPS}) + set_target_properties(check-asan-dynamic + PROPERTIES FOLDER "ASan dynamic tests") + set(EXCLUDE_FROM_ALL FALSE) +endif() diff --git a/compiler-rt/test/asan/Unit/lit.site.cfg.in b/compiler-rt/test/asan/Unit/lit.site.cfg.in index 1791b6b..a354975 100644 --- a/compiler-rt/test/asan/Unit/lit.site.cfg.in +++ b/compiler-rt/test/asan/Unit/lit.site.cfg.in @@ -17,7 +17,13 @@ config.name = 'AddressSanitizer-Unit' # Setup test source and exec root. For unit tests, we define # it as build directory with ASan unit tests. # FIXME: De-hardcode this path. -config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/asan/tests" +if @ASAN_TEST_DYNAMIC@: + test_dir = "dynamic" +else: + test_dir = "default" +config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@", + "lib", "asan", "tests", test_dir) + config.test_source_root = config.test_exec_root # Set LD_LIBRARY_PATH to pick dynamic runtime up properly.