[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 3 15:10:27 PDT 2024
================
@@ -0,0 +1,67 @@
+import os
+
+# Setup config name.
+config.name = "RTSAN" + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Setup default compiler flags use with -frtsan-instrument option.
+clang_rtsan_cflags = ["-frtsan-instrument", config.target_cflags]
+
+# If libc++ was used to build rtsan libraries, libc++ is needed. Fix applied
+# to Linux only since -rpath may not be portable. This can be extended to
+# other platforms.
+if config.libcxx_used == "1" and config.host_os == "Linux":
+ clang_rtsan_cflags = clang_rtsan_cflags + (
+ ["-L%s -lc++ -Wl,-rpath=%s" % (config.llvm_shlib_dir, config.llvm_shlib_dir)]
+ )
+
+clang_rtsan_cxxflags = config.cxx_mode_flags + clang_rtsan_cflags
+
+
+def build_invocation(compile_flags):
+ return " " + " ".join([config.clang] + compile_flags) + " "
+
+
+# Assume that llvm-rtsan is in the config.llvm_tools_dir.
+llvm_rtsan = os.path.join(config.llvm_tools_dir, "llvm-rtsan")
+
+# Setup substitutions.
+if config.host_os == "Linux":
+ libdl_flag = "-ldl"
+else:
+ libdl_flag = ""
+
+config.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
+config.substitutions.append(
+ ("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
+)
+config.substitutions.append(("%clang_rtsan ", build_invocation(clang_rtsan_cflags)))
+config.substitutions.append(("%clangxx_rtsan", build_invocation(clang_rtsan_cxxflags)))
+config.substitutions.append(("%llvm_rtsan", llvm_rtsan))
+config.substitutions.append(
+ (
+ "%rtsanlib",
+ (
+ "-lm -lpthread %s -lrt -L%s "
+ "-Wl,-whole-archive -lclang_rt.rtsan%s -Wl,-no-whole-archive"
----------------
MaskRay wrote:
clangdriver shall pass these arguments to the linker. lit.cfg.py should not need to do it.
https://github.com/llvm/llvm-project/pull/92460
More information about the cfe-commits
mailing list