Revert "[Sanitizers] Error out for -static-libsan on darwin"
authorusama hameed <u_hameed@apple.com>
Thu, 2 Mar 2023 14:48:38 +0000 (19:48 +0500)
committerusama hameed <u_hameed@apple.com>
Thu, 2 Mar 2023 14:48:38 +0000 (19:48 +0500)
This reverts commit 4e7d40e0928cfe448ba947d2a67895fccaa3535f.

clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/sanitizer-ld.c

index 3b32227..4c92265 100644 (file)
@@ -220,8 +220,8 @@ def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
-def err_drv_unsupported_static_sanitizer_darwin : Error<
-  "static %0 runtime is not supported on darwin">;
+def err_drv_unsupported_static_ubsan_darwin : Error<
+  "static UndefinedBehaviorSanitizer runtime is not supported on darwin">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
index b914b1b..70882e1 100644 (file)
@@ -1215,7 +1215,7 @@ defm xl_pragma_pack : BoolFOption<"xl-pragma-pack",
 def shared_libsan : Flag<["-"], "shared-libsan">,
   HelpText<"Dynamically link the sanitizer runtime">;
 def static_libsan : Flag<["-"], "static-libsan">,
-  HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
+  HelpText<"Statically link the sanitizer runtime">;
 def : Flag<["-"], "shared-libasan">, Alias<shared_libsan>;
 def fasm : Flag<["-"], "fasm">, Group<f_Group>;
 
index 6cee9c7..b273f8b 100644 (file)
@@ -1426,42 +1426,24 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt()) {
-    const char *sanitizer = nullptr;
-    if (Sanitize.needsUbsanRt()) {
-      sanitizer = "UndefinedBehaviorSanitizer";
-    } else if (Sanitize.needsAsanRt()) {
-      sanitizer = "AddressSanitizer";
-    } else if (Sanitize.needsTsanRt()) {
-      sanitizer = "ThreadSanitizer";
-    }
-    if (sanitizer) {
-      getDriver().Diag(diag::err_drv_unsupported_static_sanitizer_darwin)
-          << sanitizer;
-      return;
-    }
+  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
+    getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
+    return;
   }
 
   if (Sanitize.linkRuntimes()) {
-    if (Sanitize.needsAsanRt()) {
-      assert(Sanitize.needsSharedRt() &&
-             "Static sanitizer runtimes not supported");
+    if (Sanitize.needsAsanRt())
       AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
-    }
     if (Sanitize.needsLsanRt())
       AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
     if (Sanitize.needsUbsanRt()) {
-      assert(Sanitize.needsSharedRt() &&
-             "Static sanitizer runtimes not supported");
-      AddLinkSanitizerLibArgs(
-          Args, CmdArgs,
-          Sanitize.requiresMinimalRuntime() ? "ubsan_minimal" : "ubsan");
+      assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
+      AddLinkSanitizerLibArgs(Args, CmdArgs,
+                              Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
+                                                                : "ubsan");
     }
-    if (Sanitize.needsTsanRt()) {
-      assert(Sanitize.needsSharedRt() &&
-             "Static sanitizer runtimes not supported");
+    if (Sanitize.needsTsanRt())
       AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
-    }
     if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
       AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
 
index 910b0ed..0ba209d 100644 (file)
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
 // CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
 
-// RUN: %clang -fsanitize=address -### %s 2>&1 \
-// RUN:     --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
-// RUN:     --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-ASAN-STATIC-DARWIN %s
-// CHECK-ASAN-STATIC-DARWIN: {{.*}}error: static AddressSanitizer runtime is not supported on darwin
-
-// RUN: %clang -fsanitize=thread -### %s 2>&1 \
-// RUN:     --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
-// RUN:     --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-TSAN-STATIC-DARWIN %s
-// CHECK-TSAN-STATIC-DARWIN: {{.*}}error: static ThreadSanitizer runtime is not supported on darwin
-
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN:     --target=i386-unknown-linux -fuse-ld=ld \
 // RUN:     -resource-dir=%S/Inputs/resource_dir \