diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 1a46f5b334806..4d0d7fb35fd5e 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -182,6 +182,8 @@ else() set(cxxabi_supported ON) endif() +option(SANITIZER_LIT_USE_LIBCXX "Build sanitizer lit test case with libc++" OFF) + option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON) set(SANITIZER_CAN_USE_CXXABI OFF) @@ -633,8 +635,10 @@ if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++") list(APPEND SANITIZER_TEST_CXX_CFLAGS "$<$:$,/imsvc,-isystem>$,$$,/imsvc,-isystem>>>") if (SANITIZER_USE_STATIC_TEST_CXX) list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$") + list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$") else() list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$,cxx_shared,cxx_static>>") + list(APPEND SANITIZER_TEST_CXX_LIBRARIES "-L $") endif() # We are using the in tree libc++ so avoid including the default one. append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_UNITTEST_CFLAGS) diff --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt index f9b01b15b0e62..7b4c934fbc69e 100644 --- a/compiler-rt/test/CMakeLists.txt +++ b/compiler-rt/test/CMakeLists.txt @@ -17,7 +17,9 @@ pythonize_bool(ZLIB_FOUND) pythonize_bool(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC) pythonize_bool(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER) - +if (SANITIZER_LIT_USE_LIBCXX) + set (LLVM_LIBCXX_USED 1) +endif () configure_compiler_rt_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.common.configured.in ${CMAKE_CURRENT_BINARY_DIR}/lit.common.configured) diff --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py index d930346602125..c4944eb25b4ab 100644 --- a/compiler-rt/test/asan/lit.cfg.py +++ b/compiler-rt/test/asan/lit.cfg.py @@ -52,10 +52,17 @@ def get_required_attr(config, attr_name): else: extra_link_flags = [] +if config.libcxx_used == "1": + extra_libcxx_flags = config.libcxx_flags +else: + extra_libcxx_flags = [] + # Setup default compiler flags used with -fsanitize=address option. # FIXME: Review the set of required flags and check if it can be reduced. target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags -target_cxxflags = config.cxx_mode_flags + target_cflags +target_cxxflags = config.cxx_mode_flags +target_cxxflags += extra_libcxx_flags + target_cflags + clang_asan_static_cflags = ( [ "-fsanitize=address", @@ -68,7 +75,9 @@ def get_required_attr(config, attr_name): ) if config.target_arch == "s390x": clang_asan_static_cflags.append("-mbackchain") -clang_asan_static_cxxflags = config.cxx_mode_flags + clang_asan_static_cflags +clang_asan_static_cxxflags = ( + config.cxx_mode_flags + extra_libcxx_flags + clang_asan_static_cflags +) target_is_msvc = bool(re.match(r".*-windows-msvc$", config.target_triple)) @@ -82,7 +91,7 @@ def get_required_attr(config, attr_name): "-D_DLL", "-Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames", ] - elif platform.system() == "FreeBSD": + elif platform.system() == "FreeBSD" or config.libcxx_used: # On FreeBSD, we need to add -pthread to ensure pthread functions are available. asan_dynamic_flags += ["-pthread"] config.available_features.add("asan-dynamic-runtime") diff --git a/compiler-rt/test/hwasan/lit.cfg.py b/compiler-rt/test/hwasan/lit.cfg.py index 594f3294a84ac..8a64ad2082aaa 100644 --- a/compiler-rt/test/hwasan/lit.cfg.py +++ b/compiler-rt/test/hwasan/lit.cfg.py @@ -42,9 +42,15 @@ "-hwasan-instrument-personality-functions=0", ] -clang_hwasan_cxxflags = config.cxx_mode_flags + clang_hwasan_cflags -clang_hwasan_oldrt_cxxflags = config.cxx_mode_flags + clang_hwasan_oldrt_cflags +if config.libcxx_used == "1": + extra_libcxx_flags = config.libcxx_flags +else: + extra_libcxx_flags = [] +clang_hwasan_cxxflags = config.cxx_mode_flags + extra_libcxx_flags + clang_hwasan_cflags +clang_hwasan_oldrt_cxxflags = ( + config.cxx_mode_flags + extra_libcxx_flags + clang_hwasan_oldrt_cflags +) def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in index 7c2d53520099a..9ca52d496776d 100644 --- a/compiler-rt/test/lit.common.configured.in +++ b/compiler-rt/test/lit.common.configured.in @@ -69,7 +69,9 @@ else: set_default("have_internal_symbolizer", @COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER_PYBOOL@) set_default("have_zlib", @ZLIB_FOUND_PYBOOL@) set_default("libcxx_used", "@LLVM_LIBCXX_USED@") - +set_default("libcxx_flags", ["-nostdinc++ -nostdlib++ " + \ + "-isystem @LLVM_BINARY_DIR@/include/c++/v1 -L @LLVM_BINARY_DIR@/lib@LLVM_LIBDIR_SUFFIX@ " + \ + "-Wl,-rpath,@LLVM_BINARY_DIR@/lib@LLVM_LIBDIR_SUFFIX@ -lc++"]) # LLVM tools dir can be passed in lit parameters, so try to # apply substitution. config.llvm_tools_dir = lit_config.substitute(config.llvm_tools_dir) diff --git a/compiler-rt/test/lsan/lit.common.cfg.py b/compiler-rt/test/lsan/lit.common.cfg.py index e9b974955730d..cb6e81677bdf6 100644 --- a/compiler-rt/test/lsan/lit.common.cfg.py +++ b/compiler-rt/test/lsan/lit.common.cfg.py @@ -71,7 +71,13 @@ def get_required_attr(config, attr_name): clang_cflags = ["-O0", config.target_cflags] + config.debug_info_flags if config.android: clang_cflags = clang_cflags + ["-fno-emulated-tls"] -clang_cxxflags = config.cxx_mode_flags + clang_cflags + +if config.libcxx_used == "1": + extra_libcxx_flags = config.libcxx_flags +else: + extra_libcxx_flags = [] + +clang_cxxflags = config.cxx_mode_flags + extra_libcxx_flags + clang_cflags lsan_incdir = config.test_source_root + "/../" clang_lsan_cflags = clang_cflags + lsan_cflags + ["-I%s" % lsan_incdir] clang_lsan_cxxflags = clang_cxxflags + lsan_cflags + ["-I%s" % lsan_incdir] diff --git a/compiler-rt/test/msan/lit.cfg.py b/compiler-rt/test/msan/lit.cfg.py index 361be79e2557e..9883d788890fa 100644 --- a/compiler-rt/test/msan/lit.cfg.py +++ b/compiler-rt/test/msan/lit.cfg.py @@ -25,7 +25,13 @@ # On SystemZ we need -mbackchain to make the fast unwinder work. if config.target_arch == "s390x": clang_msan_cflags.append("-mbackchain") -clang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags + +if config.libcxx_used == "1": + extra_libcxx_flags = config.libcxx_flags +else: + extra_libcxx_flags = [] + +clang_msan_cxxflags = config.cxx_mode_flags + extra_libcxx_flags + clang_msan_cflags # Flags for KMSAN invocation. This is C-only, we're not interested in C++. clang_kmsan_cflags = ( diff --git a/compiler-rt/test/ubsan/lit.common.cfg.py b/compiler-rt/test/ubsan/lit.common.cfg.py index 61f6818cce064..ab7bd6d984d91 100644 --- a/compiler-rt/test/ubsan/lit.common.cfg.py +++ b/compiler-rt/test/ubsan/lit.common.cfg.py @@ -61,9 +61,14 @@ def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " +if config.libcxx_used == "1": + extra_libcxx_flags = config.libcxx_flags +else: + extra_libcxx_flags = [] + target_cflags = [get_required_attr(config, "target_cflags")] clang_ubsan_cflags += target_cflags -clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags +clang_ubsan_cxxflags = config.cxx_mode_flags + extra_libcxx_flags + clang_ubsan_cflags # Define %clang and %clangxx substitutions to use in test RUN lines. config.substitutions.append(("%clang ", build_invocation(clang_ubsan_cflags))) diff --git a/compiler-rt/test/ubsan_minimal/lit.common.cfg.py b/compiler-rt/test/ubsan_minimal/lit.common.cfg.py index d398d3a0a8162..74e901281215e 100644 --- a/compiler-rt/test/ubsan_minimal/lit.common.cfg.py +++ b/compiler-rt/test/ubsan_minimal/lit.common.cfg.py @@ -23,9 +23,14 @@ def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " +if config.libcxx_used == "1": + extra_libcxx_flags = config.libcxx_flags +else: + extra_libcxx_flags = [] + target_cflags = [get_required_attr(config, "target_cflags")] clang_ubsan_cflags = ["-fsanitize-minimal-runtime"] + target_cflags -clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags +clang_ubsan_cxxflags = config.cxx_mode_flags + extra_libcxx_flags + clang_ubsan_cflags # Define %clang and %clangxx substitutions to use in test RUN lines. config.substitutions.append(("%clang ", build_invocation(clang_ubsan_cflags)))