[compiler-rt] [2/2] support build sanitizer lit test case with libc++ (PR #72470)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 22:31:27 PST 2023
https://github.com/PikachuHyA updated https://github.com/llvm/llvm-project/pull/72470
>From aec06204e858928c5e191d385e9fc972a59c189c Mon Sep 17 00:00:00 2001
From: PikachuHy <pikachuhy at linux.alibaba.com>
Date: Thu, 16 Nov 2023 11:06:51 +0800
Subject: [PATCH] support build sanitizer lit test case with libc++
---
compiler-rt/CMakeLists.txt | 4 ++++
compiler-rt/test/CMakeLists.txt | 4 +++-
compiler-rt/test/asan/lit.cfg.py | 14 +++++++++++---
compiler-rt/test/hwasan/lit.cfg.py | 10 ++++++++--
compiler-rt/test/lit.common.configured.in | 4 +++-
compiler-rt/test/lsan/lit.common.cfg.py | 8 +++++++-
compiler-rt/test/msan/lit.cfg.py | 8 +++++++-
compiler-rt/test/ubsan/lit.common.cfg.py | 7 ++++++-
compiler-rt/test/ubsan_minimal/lit.common.cfg.py | 7 ++++++-
9 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 1a46f5b33480694..4d0d7fb35fd5ee9 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 "$<$<TARGET_EXISTS:cxx-headers>:$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>$<JOIN:$<TARGET_PROPERTY:cxx-headers,INTERFACE_INCLUDE_DIRECTORIES>,$<SEMICOLON>$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>>>")
if (SANITIZER_USE_STATIC_TEST_CXX)
list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:cxx_static>")
+ list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:cxxabi_static>")
else()
list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:cxx_shared>,cxx_shared,cxx_static>>")
+ list(APPEND SANITIZER_TEST_CXX_LIBRARIES "-L $<TARGET_LINKER_FILE_DIR:cxxabi_shared>")
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 f9b01b15b0e62c6..7b4c934fbc69e8d 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 d93034660212509..7e559c58f15b21a 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,8 @@ 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
+clang_asan_static_cxxflags += extra_libcxx_flags + clang_asan_static_cflags
target_is_msvc = bool(re.match(r".*-windows-msvc$", config.target_triple))
@@ -82,7 +90,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 594f3294a84ac17..8a64ad2082aaab9 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 7c2d53520099a19..9ca52d496776d1e 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 at LLVM_LIBDIR_SUFFIX@ " + \
+ "-Wl,-rpath, at LLVM_BINARY_DIR@/lib at 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 e9b974955730d32..cb6e81677bdf6ed 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 361be79e2557ed4..9883d788890fa19 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 61f6818cce064ff..ab7bd6d984d9135 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 d398d3a0a81626e..74e901281215ecb 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)))
More information about the llvm-commits
mailing list