Index: test/ubsan/CMakeLists.txt =================================================================== --- test/ubsan/CMakeLists.txt +++ test/ubsan/CMakeLists.txt @@ -3,9 +3,20 @@ set(UBSAN_TESTSUITES) set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) -macro(add_ubsan_testsuite test_mode sanitizer arch) +macro(add_ubsan_testsuite test_mode sanitizer arch lld thinlto) set(UBSAN_LIT_TEST_MODE "${test_mode}") - set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch}) + set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}) + if (${lld}) + set(CONFIG_NAME ${CONFIG_NAME}-lld) + list(APPEND UBSAN_TEST_DEPS lld) + endif() + if (${thinlto}) + set(CONFIG_NAME ${CONFIG_NAME}-thinlto) + list(APPEND UBSAN_TEST_DEPS LTO) + endif() + set(UBSAN_TEST_USE_LLD ${lld}) + set(UBSAN_TEST_USE_THINLTO ${thinlto}) + set(CONFIG_NAME ${CONFIG_NAME}-${arch}) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) @@ -15,6 +26,14 @@ endif() endmacro() +macro(add_ubsan_testsuites test_mode sanitizer arch) + add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} False False) + + if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32)) + add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} True False) + endif() +endmacro() + set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH}) if(APPLE) darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH) @@ -23,20 +42,20 @@ foreach(arch ${UBSAN_TEST_ARCH}) set(UBSAN_TEST_TARGET_ARCH ${arch}) get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS) - add_ubsan_testsuite("Standalone" ubsan ${arch}) + add_ubsan_testsuites("Standalone" ubsan ${arch}) if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};") # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready. # Disable ubsan with AddressSanitizer tests for Windows 64-bit. if(NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4) - add_ubsan_testsuite("AddressSanitizer" asan ${arch}) + add_ubsan_testsuites("AddressSanitizer" asan ${arch}) endif() endif() if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};") - add_ubsan_testsuite("MemorySanitizer" msan ${arch}) + add_ubsan_testsuites("MemorySanitizer" msan ${arch}) endif() if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID) - add_ubsan_testsuite("ThreadSanitizer" tsan ${arch}) + add_ubsan_testsuites("ThreadSanitizer" tsan ${arch}) endif() endforeach() @@ -45,7 +64,7 @@ set(UBSAN_TEST_TARGET_ARCH ${arch}) get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS) set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi") - add_ubsan_testsuite("StandaloneStatic" ubsan ${arch}) + add_ubsan_testsuites("StandaloneStatic" ubsan ${arch}) endforeach() endif() Index: test/ubsan/lit.common.cfg =================================================================== --- test/ubsan/lit.common.cfg +++ test/ubsan/lit.common.cfg @@ -11,6 +11,9 @@ "to lit.site.cfg " % attr_name) return attr_value +# Setup config name. +config.name = 'UBSan-' + config.name_suffix + # Setup source root. config.test_source_root = os.path.dirname(__file__) @@ -18,24 +21,19 @@ # Choose between standalone and UBSan+ASan modes. ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode') if ubsan_lit_test_mode == "Standalone": - config.name = 'UBSan-Standalone-' + config.target_arch config.available_features.add("ubsan-standalone") clang_ubsan_cflags = [] elif ubsan_lit_test_mode == "StandaloneStatic": - config.name = 'UBSan-StandaloneStatic-' + config.target_arch config.available_features.add("ubsan-standalone-static") clang_ubsan_cflags = ['-static-libsan'] elif ubsan_lit_test_mode == "AddressSanitizer": - config.name = 'UBSan-ASan-' + config.target_arch config.available_features.add("ubsan-asan") clang_ubsan_cflags = ["-fsanitize=address"] default_ubsan_opts += ['detect_leaks=0'] elif ubsan_lit_test_mode == "MemorySanitizer": - config.name = 'UBSan-MSan-' + config.target_arch config.available_features.add("ubsan-msan") clang_ubsan_cflags = ["-fsanitize=memory"] elif ubsan_lit_test_mode == "ThreadSanitizer": - config.name = 'UBSan-TSan-' + config.target_arch config.available_features.add("ubsan-tsan") clang_ubsan_cflags = ["-fsanitize=thread"] else: @@ -54,10 +52,23 @@ config.substitutions.append(('%env_ubsan_opts=', 'env UBSAN_OPTIONS=' + default_ubsan_opts_str)) -def build_invocation(compile_flags): - return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " " - +run_wrapper = [] target_cflags = [get_required_attr(config, "target_cflags")] + +if config.use_lld and config.has_lld: + target_cflags += ["-fuse-ld=lld"] +elif config.use_lld and (not config.has_lld): + config.unsupported = True + +if config.use_thinlto and config.lto_supported: + run_wrapper += config.lto_launch + target_cflags += config.lto_flags +elif config.use_thinlto and (not config.lto_supported): + config.unsupported = True + +def build_invocation(compile_flags): + return " " + " ".join(run_wrapper + [config.compile_wrapper, config.clang] + compile_flags) + " " + clang_ubsan_cflags += target_cflags clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags Index: test/ubsan/lit.site.cfg.in =================================================================== --- test/ubsan/lit.site.cfg.in +++ test/ubsan/lit.site.cfg.in @@ -1,9 +1,12 @@ @LIT_SITE_CFG_IN_HEADER@ # Tool-specific config options. +config.name_suffix = "@CONFIG_NAME@" config.ubsan_lit_test_mode = "@UBSAN_LIT_TEST_MODE@" config.target_cflags = "@UBSAN_TEST_TARGET_CFLAGS@" config.target_arch = "@UBSAN_TEST_TARGET_ARCH@" +config.use_lld = @UBSAN_TEST_USE_LLD@ +config.use_thinlto = @UBSAN_TEST_USE_THINLTO@ # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")