-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2/2] support build sanitizer lit test case with libc++ #72470
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: PikachuHy (PikachuHyA) Changeswe add an option the libc++ is from the same LLVM repo, which means the option the tsan has separate logic for handling libc++. It only uses the header files but does not link against the libc++ library. https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/tsan/lit.cfg.py#L62C1-L79C1 Full diff: https://github.com/llvm/llvm-project/pull/72470.diff 9 Files Affected:
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..86b88f566a8a300 100644
--- a/compiler-rt/test/asan/lit.cfg.py
+++ b/compiler-rt/test/asan/lit.cfg.py
@@ -52,10 +52,15 @@ 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 + extra_libcxx_flags + target_cflags
clang_asan_static_cflags = (
[
"-fsanitize=address",
@@ -68,7 +73,7 @@ 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 +87,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..eec8ab54e430abe 100644
--- a/compiler-rt/test/hwasan/lit.cfg.py
+++ b/compiler-rt/test/hwasan/lit.cfg.py
@@ -42,8 +42,13 @@
"-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):
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@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 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)))
|
✅ With the latest revision this PR passed the Python code formatter. |
20f8974
to
aec0620
Compare
aec0620
to
fcc2dd8
Compare
fix #72200
this patch provide a solution for build sanitizer lit test case with libc++
we add an option
SANITIZER_LIT_USE_LIBCXX
to indicate whether to use libc++ to build lit test cases.the libc++ is from the same LLVM repo, which means
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi"
is required.the option
SANITIZER_LIT_USE_LIBCXX
works for all sanitizers (asan, hwasan, lsan, msan, ubsan) except for tsan.the tsan has separate logic for handling libc++. It only uses the header files but does not link against the libc++ library.
https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/tsan/lit.cfg.py#L62C1-L79C1
SANITIZER_LIT_USE_LIBCXX
SANITIZER_LIT_USE_LIBCXX