diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -163,6 +163,13 @@ function(add_asan_tests arch test_runtime) cmake_parse_arguments(TEST "" "KIND" "CFLAGS" ${ARGN}) + # The Lit files are configured once per architecture and static/dynamic + # selection. Each configuration expects the test binaries in a corresponding + # subdirectory. Generate subdirectory names based on the architecture name. + string(TOUPPER ${arch} ARCH_UPPER_CASE) + set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) + set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig) + # Closure to keep the values. function(generate_asan_tests test_objects test_suite testname) generate_compiler_rt_tests(${test_objects} ${test_suite} ${testname} ${arch} @@ -177,7 +184,7 @@ set(ASAN_INST_TEST_OBJECTS) generate_asan_tests(ASAN_INST_TEST_OBJECTS AsanUnitTests "Asan-${arch}${TEST_KIND}-Test" - SUBDIR "default" + SUBDIR "${CONFIG_NAME}" LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS} SOURCES ${ASAN_INST_TEST_SOURCES} CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${TEST_CFLAGS}) @@ -191,7 +198,7 @@ set(ASAN_DYNAMIC_TEST_OBJECTS) generate_asan_tests(ASAN_DYNAMIC_TEST_OBJECTS AsanDynamicUnitTests "${dynamic_test_name}" - SUBDIR "dynamic" + SUBDIR "${CONFIG_NAME_DYNAMIC}" CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -D_MT -D_DLL SOURCES ${ASAN_INST_TEST_SOURCES} LINK_FLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS} @@ -201,7 +208,7 @@ # Otherwise, reuse ASAN_INST_TEST_OBJECTS. add_compiler_rt_test(AsanDynamicUnitTests "${dynamic_test_name}" "${arch}" - SUBDIR "dynamic" + SUBDIR "${CONFIG_NAME_DYNAMIC}" OBJECTS ${ASAN_INST_TEST_OBJECTS} DEPS asan ${ASAN_INST_TEST_OBJECTS} LINK_FLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS} @@ -213,7 +220,7 @@ set(ASAN_NOINST_TEST_OBJECTS) generate_asan_tests(ASAN_NOINST_TEST_OBJECTS AsanUnitTests "Asan-${arch}${TEST_KIND}-Noinst-Test" - SUBDIR "default" + SUBDIR "${CONFIG_NAME}" CFLAGS ${ASAN_UNITTEST_COMMON_CFLAGS} LINK_FLAGS ${ASAN_UNITTEST_NOINST_LINK_FLAGS} SOURCES ${ASAN_NOINST_TEST_SOURCES} @@ -222,7 +229,7 @@ set(ASAN_BENCHMARK_OBJECTS) generate_asan_tests(ASAN_BENCHMARK_OBJECTS AsanBenchmarks "Asan-${arch}${TEST_KIND}-Benchmark" - SUBDIR "default" + SUBDIR "${CONFIG_NAME}" CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} SOURCES ${ASAN_BENCHMARKS_SOURCES} LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS}) diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt --- a/compiler-rt/test/asan/CMakeLists.txt +++ b/compiler-rt/test/asan/CMakeLists.txt @@ -127,25 +127,31 @@ # 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.py.in - ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py) - if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) - set(ASAN_TEST_DYNAMIC True) + foreach(arch ${ASAN_TEST_ARCH}) + string(TOUPPER ${arch} ARCH_UPPER_CASE) + set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) + set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig) + + set(ASAN_TEST_DYNAMIC False) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in - ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py) - 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) + ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py) 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) + set(ASAN_TEST_DYNAMIC True) + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}/lit.site.cfg.py) endif() - 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/${CONFIG_NAME}) + if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) + list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests) + list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}) + endif() + endif() + endforeach() endif() if (SHADOW_MAPPING_UNRELIABLE) diff --git a/compiler-rt/test/asan/Unit/lit.site.cfg.py.in b/compiler-rt/test/asan/Unit/lit.site.cfg.py.in --- a/compiler-rt/test/asan/Unit/lit.site.cfg.py.in +++ b/compiler-rt/test/asan/Unit/lit.site.cfg.py.in @@ -2,6 +2,8 @@ import os import platform +import re +import shlex # Load common config for all compiler-rt unit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured") @@ -28,18 +30,35 @@ # Setup config name. config.name = 'AddressSanitizer-Unit' +# Load target architecture information. Note config.target_triple can be +# incorrect since it is populated with the default target. This unit test suite +# may run for multiple targets. The dynamic suite needs the correct target for +# library path selection. +config.target_arch = "@arch@" + # Setup test source and exec root. For unit tests, we define # it as build directory with ASan unit tests. # FIXME: De-hardcode this path. if @ASAN_TEST_DYNAMIC@: - test_dir = "dynamic" + test_dir = "@CONFIG_NAME_DYNAMIC@" else: - test_dir = "default" + test_dir = "@CONFIG_NAME@" config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@", "lib", "asan", "tests", test_dir) config.test_source_root = config.test_exec_root +# When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of +# config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the +# host triple as the trailing path component. The value is incorrect for i386 +# tests on x86_64 hosts and vice versa. Adjust config.compiler_rt_libdir +# accordingly. +if config.enable_per_target_runtime_dir and config.target_arch != config.host_arch: + if config.target_arch == 'i386': + config.compiler_rt_libdir = re.sub(r'/x86_64(?=-[^/]+$)', '/i386', config.compiler_rt_libdir) + elif config.target_arch == 'x86_64': + config.compiler_rt_libdir = re.sub(r'/i386(?=-[^/]+$)', '/x86_64', config.compiler_rt_libdir) + # Set LD_LIBRARY_PATH to pick dynamic runtime up properly. push_ld_library_path(config, config.compiler_rt_libdir) diff --git a/compiler-rt/unittests/lit.common.unit.configured.in b/compiler-rt/unittests/lit.common.unit.configured.in --- a/compiler-rt/unittests/lit.common.unit.configured.in +++ b/compiler-rt/unittests/lit.common.unit.configured.in @@ -7,6 +7,7 @@ config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@" config.compiler_rt_libdir = "@COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR@" +config.enable_per_target_runtime_dir = @LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_PYBOOL@ config.llvm_build_mode = "@LLVM_BUILD_MODE@" config.host_arch = "@HOST_ARCH@" config.host_os = "@HOST_OS@"