[llvm] 5e763d3 - [gn] Add check-lsan target for Mac

Leonard Grey via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 6 10:03:49 PDT 2023


Author: Leonard Grey
Date: 2023-07-06T13:03:16-04:00
New Revision: 5e763d35e46ec5ce3b9d506ecf8690d44a98a3d7

URL: https://github.com/llvm/llvm-project/commit/5e763d35e46ec5ce3b9d506ecf8690d44a98a3d7
DIFF: https://github.com/llvm/llvm-project/commit/5e763d35e46ec5ce3b9d506ecf8690d44a98a3d7.diff

LOG: [gn] Add check-lsan target for Mac

Only supports ASAN mode right now. Standalone requires a some more plumbing so it will be a follow-up.

Mac-only but I suspect this will be fine on Linux also since it's based on the check-asan file, will follow up after testing.

Differential Revision: https://reviews.llvm.org/D153651

Added: 
    llvm/utils/gn/secondary/compiler-rt/test/lsan/BUILD.gn

Modified: 
    llvm/utils/gn/build/toolchain/target_flags.gni
    llvm/utils/gn/secondary/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni
index a8521feeee3717..09b8cfabbd6719 100644
--- a/llvm/utils/gn/build/toolchain/target_flags.gni
+++ b/llvm/utils/gn/build/toolchain/target_flags.gni
@@ -1,4 +1,5 @@
 import("//llvm/triples.gni")
+import("//llvm/utils/gn/build/mac_sdk.gni")
 import("//llvm/utils/gn/build/toolchain/compiler.gni")
 
 # Flags in this file are passed both to the compiler that's building
@@ -23,7 +24,7 @@ if (current_os == "android") {
   if (current_cpu == "arm") {
     target_flags += [ "-march=armv7-a" ]
   }
-} else if (current_os == "ios") {
+} else if (current_os == "ios" || current_os == "mac") {
   if (current_cpu == "arm64") {
     target_flags += [
       "-arch",
@@ -43,6 +44,15 @@ if (current_os == "android") {
       "x86_64",
     ]
   }
+  if (current_os == "mac") {
+    target_flags += [
+      "-isysroot",
+      mac_sdk_path,
+      # TODO(lgrey): We should be getting this from `compiler_defaults`. Why
+      # aren't we?
+    "-mmacos-version-min=10.10",
+    ]
+  }
 } else if (current_os == "baremetal") {
   target_flags += [ "--target=$llvm_current_triple" ]
 }

diff  --git a/llvm/utils/gn/secondary/BUILD.gn b/llvm/utils/gn/secondary/BUILD.gn
index 261780c3cf79af..2e8ee4332ef7c5 100644
--- a/llvm/utils/gn/secondary/BUILD.gn
+++ b/llvm/utils/gn/secondary/BUILD.gn
@@ -25,6 +25,11 @@ group("default") {
   if (current_os == "linux" || current_os == "win" || current_os=="mac") {
     deps += [ "//compiler-rt/test/asan" ]
   }
+
+  if (current_os == "mac") {
+    deps += [ "//compiler-rt/test/lsan"]
+  }
+
   if (current_os == "linux" || current_os == "android") {
     deps += [ "//compiler-rt/test/hwasan" ]
   }

diff  --git a/llvm/utils/gn/secondary/compiler-rt/test/lsan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/test/lsan/BUILD.gn
new file mode 100644
index 00000000000000..8b6ea06c7df6be
--- /dev/null
+++ b/llvm/utils/gn/secondary/compiler-rt/test/lsan/BUILD.gn
@@ -0,0 +1,79 @@
+import("//compiler-rt/target.gni")
+import("//compiler-rt/test/test.gni")
+import("//llvm/lib/Target/targets.gni")
+import("//llvm/utils/gn/build/toolchain/compiler.gni")
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+import("//llvm/version.gni")
+
+write_cmake_config("asan_mode_cfg") {
+  input = "lit.site.cfg.py.in"
+  output = "$target_gen_dir/${crt_current_target_arch}AsanConfig/lit.site.cfg.py"
+  values = [
+    "LSAN_LIT_SOURCE_DIR=" + rebase_path("."),
+    "LSAN_TEST_CONFIG_SUFFIX=$crt_current_target_suffix",
+    "LSAN_TEST_TARGET_CFLAGS=$target_flags_string",
+    # TODO(lgrey): Support standalone mode
+    "LSAN_LIT_TEST_MODE=AddressSanitizer",
+    "LSAN_TEST_TARGET_ARCH=$crt_current_target_arch",
+    "COMPILER_RT_BINARY_DIR=" + rebase_path("$root_gen_dir/compiler-rt"),
+    "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
+  ]
+}
+
+if (current_toolchain != host_toolchain) {
+  group("lsan_toolchain") {
+    deps = [
+      ":asan_mode_cfg",
+      "//compiler-rt/include($host_toolchain)",
+      "//compiler-rt/lib/asan",
+      "//compiler-rt/lib/lsan:common_sources",
+      "//compiler-rt/lib/profile",
+      "//compiler-rt/test:lit_common_configured",
+      "//llvm/tools/llvm-readobj($host_toolchain)",
+      "//llvm/tools/llvm-symbolizer($host_toolchain)",
+      "//llvm/utils/FileCheck($host_toolchain)",
+      "//llvm/utils/count($host_toolchain)",
+      "//llvm/utils/llvm-lit($host_toolchain)",
+      "//llvm/utils/not($host_toolchain)",
+    ]
+  }
+}
+
+supported_toolchains = []
+# TODO(lgrey): Test Linux
+if (host_os == "mac") {
+  supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
+}
+
+group("lsan") {
+  deps = []
+  foreach(toolchain, supported_toolchains) {
+    deps += [ ":lsan_toolchain($toolchain)" ]
+  }
+}
+
+if (supported_toolchains != []) {
+  action("check-lsan") {
+    script = "$root_build_dir/bin/llvm-lit"
+    args = [ "-sv" ]
+    foreach(toolchain, supported_toolchains) {
+      test_dir = rebase_path(
+              get_label_info(":lit_site_cfg($toolchain)", "target_gen_dir"),
+              root_build_dir)
+      args += [ 
+        test_dir + "/${crt_current_target_arch}AsanConfig",
+      ]
+    }
+    outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs
+                                             # it each time.
+
+    # Since check-lsan is always dirty, //:default doesn't depend on it so
+    # that it's not part of the default ninja target.  Hence, check-lsan
+    # shouldn't have any deps except :lsan. so that the default target is
+    # sure to build all the deps.
+    deps = [ ":lsan" ]
+    testonly = true
+
+    pool = "//:console"
+  }
+}


        


More information about the llvm-commits mailing list