[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-06 Thread Usama Hameed via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG665e32ee0ffd: [Sanitizers] Error out for -static-libsan on 
darwin (authored by usama54321).

Changed prior to commit:
  https://reviews.llvm.org/D144672?vs=502474=502569#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/asan/TestCases/replaceable_new_delete.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp

Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
@@ -1,11 +1,13 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using static-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
 // the new/delete interceptors as "weak" using those workarounds as well.
 // UNSUPPORTED: target={{.*windows.*}}
 
-// RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
+// darwin only supports `shared-libsan`.
+// REQUIRES: asan-static-runtime
+
 // RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
@@ -1,4 +1,4 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using shared-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
@@ -6,7 +6,6 @@
 // UNSUPPORTED: target={{.*windows.*}}
 
 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
 #include 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // 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 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs  = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  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.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-05 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 502474.
dmaclach added a comment.

Moved to `REQUIRES: asan-static-runtime`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/asan/TestCases/replaceable_new_delete.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp

Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
===
--- /dev/null
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
@@ -0,0 +1,35 @@
+// Ensure that operator new/delete are still replaceable using static-libsan.
+
+// FIXME: Weak symbols aren't supported on Windows, although some code in
+// compiler-rt already exists to solve this problem. We should probably define
+// the new/delete interceptors as "weak" using those workarounds as well.
+// UNSUPPORTED: target={{.*windows.*}}
+
+// darwin only supports `shared-libsan`.
+// REQUIRES: asan-static-runtime
+
+// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
+
+#include 
+#include 
+#include 
+
+void *operator new[](size_t size) {
+  fprintf(stderr, "replaced new\n");
+  return malloc(size);
+}
+
+void operator delete[](void *ptr) noexcept {
+  fprintf(stderr, "replaced delete\n");
+  return free(ptr);
+}
+
+int main(int argc, char **argv) {
+  // CHECK: replaced new
+  char *x = new char[5];
+  // CHECK: replaced delete
+  delete[] x;
+  // CHECK: ERROR: AddressSanitizer
+  *x = 13;
+  return 0;
+}
Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
@@ -1,4 +1,4 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using shared-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
@@ -6,7 +6,6 @@
 // UNSUPPORTED: target={{.*windows.*}}
 
 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
 #include 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // 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 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs  = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  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.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Julian Lettner via Phabricator via cfe-commits
yln accepted this revision.
yln added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

usama54321 wrote:
> yln wrote:
> > usama54321 wrote:
> > > yln wrote:
> > > > zixuw wrote:
> > > > > dmaclach wrote:
> > > > > > yln wrote:
> > > > > > > This should work, right?
> > > > > > No.. darwin should fail with the `-static-libsan` flag. This is the 
> > > > > > test that was failing and caused the rollback.
> > > > > I think @yln is suggesting using `REQUIRES: asan-static-runtime` 
> > > > > instead of `XFAIL: darwin`. I wasn't aware of that conditional but 
> > > > > yeah that should be better if it works.
> > > > I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: 
> > > > darwin` since it seems that we already have a lit feature for it.
> > > I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
> > > understands that REQUIRES: asan-static-runtime should result in skipping 
> > > the test on Darwin as it does not know about this dependency.
> > > I don't think lit understands that REQUIRES: asan-static-runtime should 
> > > result in skipping the test on Darwin as it does not know about this 
> > > dependency.
> > 
> > Actually, this was exactly my point.  We have other tests already marked 
> > with `REQUIRES: asan-static-runtime` and we should double check our changes 
> > don't affect these as well.
> > 
> > If LIT doesn't model this dependency yet, then we should make sure it does! 
> >  And this test can act as a good "canary in the coal mine".
> > 
> > Please use `REQUIRES: asan-static-runtime` and make sure we understand and 
> > deal with any fallout.
> Sorry for my earlier comment. @yln is correct, and we should use REQUIRES: 
> asan-static-runtime. I double checked, and this already works as expected on 
> darwin, i.e. these tests are unsupported on darwin. So you should not need to 
> do anything apart from adding the REQUIRES in the test.
> [...] I double checked, and this already works as expected on darwin, i.e. 
> these tests are unsupported on darwin.

Thanks Usama!

Patch LGTM assuming we switch to using `REQUIRES: asan-static-runtime`.  Thanks 
for seeing this through! :)




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> usama54321 wrote:
> > yln wrote:
> > > zixuw wrote:
> > > > dmaclach wrote:
> > > > > yln wrote:
> > > > > > This should work, right?
> > > > > No.. darwin should fail with the `-static-libsan` flag. This is the 
> > > > > test that was failing and caused the rollback.
> > > > I think @yln is suggesting using `REQUIRES: asan-static-runtime` 
> > > > instead of `XFAIL: darwin`. I wasn't aware of that conditional but yeah 
> > > > that should be better if it works.
> > > I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: 
> > > darwin` since it seems that we already have a lit feature for it.
> > I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
> > understands that REQUIRES: asan-static-runtime should result in skipping 
> > the test on Darwin as it does not know about this dependency.
> > I don't think lit understands that REQUIRES: asan-static-runtime should 
> > result in skipping the test on Darwin as it does not know about this 
> > dependency.
> 
> Actually, this was exactly my point.  We have other tests already marked with 
> `REQUIRES: asan-static-runtime` and we should double check our changes don't 
> affect these as well.
> 
> If LIT doesn't model this dependency yet, then we should make sure it does!  
> And this test can act as a good "canary in the coal mine".
> 
> Please use `REQUIRES: asan-static-runtime` and make sure we understand and 
> deal with any fallout.
Sorry for my earlier comment. @yln is correct, and we should use REQUIRES: 
asan-static-runtime. I double checked, and this already works as expected on 
darwin, i.e. these tests are unsupported on darwin. So you should not need to 
do anything apart from adding the REQUIRES in the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Julian Lettner via Phabricator via cfe-commits
yln added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

usama54321 wrote:
> yln wrote:
> > zixuw wrote:
> > > dmaclach wrote:
> > > > yln wrote:
> > > > > This should work, right?
> > > > No.. darwin should fail with the `-static-libsan` flag. This is the 
> > > > test that was failing and caused the rollback.
> > > I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead 
> > > of `XFAIL: darwin`. I wasn't aware of that conditional but yeah that 
> > > should be better if it works.
> > I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: 
> > darwin` since it seems that we already have a lit feature for it.
> I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
> understands that REQUIRES: asan-static-runtime should result in skipping the 
> test on Darwin as it does not know about this dependency.
> I don't think lit understands that REQUIRES: asan-static-runtime should 
> result in skipping the test on Darwin as it does not know about this 
> dependency.

Actually, this was exactly my point.  We have other tests already marked with 
`REQUIRES: asan-static-runtime` and we should double check our changes don't 
affect these as well.

If LIT doesn't model this dependency yet, then we should make sure it does!  
And this test can act as a good "canary in the coal mine".

Please use `REQUIRES: asan-static-runtime` and make sure we understand and deal 
with any fallout.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

Went with unsupported.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 502138.
dmaclach marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/asan/TestCases/replaceable_new_delete.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp

Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
===
--- /dev/null
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
@@ -0,0 +1,35 @@
+// Ensure that operator new/delete are still replaceable using static-libsan.
+
+// FIXME: Weak symbols aren't supported on Windows, although some code in
+// compiler-rt already exists to solve this problem. We should probably define
+// the new/delete interceptors as "weak" using those workarounds as well.
+// UNSUPPORTED: target={{.*windows.*}}
+
+// darwin only supports `shared-libsan`.
+// UNSUPPORTED: darwin
+
+// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
+
+#include 
+#include 
+#include 
+
+void *operator new[](size_t size) {
+  fprintf(stderr, "replaced new\n");
+  return malloc(size);
+}
+
+void operator delete[](void *ptr) noexcept {
+  fprintf(stderr, "replaced delete\n");
+  return free(ptr);
+}
+
+int main(int argc, char **argv) {
+  // CHECK: replaced new
+  char *x = new char[5];
+  // CHECK: replaced delete
+  delete[] x;
+  // CHECK: ERROR: AddressSanitizer
+  *x = 13;
+  return 0;
+}
Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
@@ -1,4 +1,4 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using shared-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
@@ -6,7 +6,6 @@
 // UNSUPPORTED: target={{.*windows.*}}
 
 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
 #include 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // 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 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs  = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  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.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer 

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> zixuw wrote:
> > dmaclach wrote:
> > > yln wrote:
> > > > This should work, right?
> > > No.. darwin should fail with the `-static-libsan` flag. This is the test 
> > > that was failing and caused the rollback.
> > I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead of 
> > `XFAIL: darwin`. I wasn't aware of that conditional but yeah that should be 
> > better if it works.
> I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: darwin` 
> since it seems that we already have a lit feature for it.
I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
understands that REQUIRES: asan-static-runtime should result in skipping the 
test on Darwin as it does not know about this dependency.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Julian Lettner via Phabricator via cfe-commits
yln added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

zixuw wrote:
> dmaclach wrote:
> > yln wrote:
> > > This should work, right?
> > No.. darwin should fail with the `-static-libsan` flag. This is the test 
> > that was failing and caused the rollback.
> I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead of 
> `XFAIL: darwin`. I wasn't aware of that conditional but yeah that should be 
> better if it works.
I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: darwin` 
since it seems that we already have a lit feature for it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

dmaclach wrote:
> yln wrote:
> > This should work, right?
> No.. darwin should fail with the `-static-libsan` flag. This is the test that 
> was failing and caused the rollback.
I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead of 
`XFAIL: darwin`. I wasn't aware of that conditional but yeah that should be 
better if it works.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> This should work, right?
No.. darwin should fail with the `-static-libsan` flag. This is the test that 
was failing and caused the rollback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Julian Lettner via Phabricator via cfe-commits
yln added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

This should work, right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 501899.
dmaclach added a comment.
Herald added subscribers: Sanitizers, Enna1.

Updated with fixed tests for `replaceable_new_delete.cpp`.

Split `replaceable_new_delete.cpp` into `replaceable_new_delete_shared.cpp` and 
`replaceable_new_delete_static.cpp`.
Static is marked as failing on darwin.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/asan/TestCases/replaceable_new_delete.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp

Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
===
--- /dev/null
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
@@ -0,0 +1,35 @@
+// Ensure that operator new/delete are still replaceable using static-libsan.
+
+// FIXME: Weak symbols aren't supported on Windows, although some code in
+// compiler-rt already exists to solve this problem. We should probably define
+// the new/delete interceptors as "weak" using those workarounds as well.
+// UNSUPPORTED: target={{.*windows.*}}
+
+// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 
+#include 
+#include 
+#include 
+
+void *operator new[](size_t size) {
+  fprintf(stderr, "replaced new\n");
+  return malloc(size);
+}
+
+void operator delete[](void *ptr) noexcept {
+  fprintf(stderr, "replaced delete\n");
+  return free(ptr);
+}
+
+int main(int argc, char **argv) {
+  // CHECK: replaced new
+  char *x = new char[5];
+  // CHECK: replaced delete
+  delete[] x;
+  // CHECK: ERROR: AddressSanitizer
+  *x = 13;
+  return 0;
+}
Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
@@ -1,4 +1,4 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using shared-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
@@ -6,7 +6,6 @@
 // UNSUPPORTED: target={{.*windows.*}}
 
 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
 #include 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // 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 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs  = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  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) {
+  

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added a comment.

I have reverted the commit for now


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

Yep. Apologies. Been a long time since I committed anything to LLVM. I'll try 
and take a look tonight/first thing tomorrow.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 reopened this revision.
usama54321 added a comment.
This revision is now accepted and ready to land.

@dmaclach Can you please take a look and fix this? Thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

Hi! This broke the asan replaceable_new_delete.cpp test on Darwin because it 
has a run line using `-static-libsan`. Could you take a look? Probably need to 
separate that check out and mark as unsupported on Darwin


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Usama Hameed via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e7d40e0928c: [Sanitizers] Error out for -static-libsan on 
darwin (authored by usama54321).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  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: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // 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 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs  = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  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.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   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())
+if (Sanitize.needsTsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
+}
 if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
   AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1215,7 +1215,7 @@
 def shared_libsan : Flag<["-"], "shared-libsan">,
   HelpText<"Dynamically link the sanitizer runtime">;
 def static_libsan : Flag<["-"], "static-libsan">,
-  HelpText<"Statically link the sanitizer runtime">;
+  HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
 def : Flag<["-"], "shared-libasan">, Alias;
 def fasm : Flag<["-"], "fasm">, Group;
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -220,8 +220,8 @@
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

@usama54321 or @yln are you able to commit for me?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-02-28 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 accepted this revision.
usama54321 added a comment.
This revision is now accepted and ready to land.

I was verifying that static versions of these libraries are not present on 
darwin. Sorry for the delay.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-02-27 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

Updated with buildable patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-02-27 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 500942.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  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: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // 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 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs  = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  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.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   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())
+if (Sanitize.needsTsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
+}
 if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
   AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1215,7 +1215,7 @@
 def shared_libsan : Flag<["-"], "shared-libsan">,
   HelpText<"Dynamically link the sanitizer runtime">;
 def static_libsan : Flag<["-"], "static-libsan">,
-  HelpText<"Statically link the sanitizer runtime">;
+  HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
 def : Flag<["-"], "shared-libasan">, Alias;
 def fasm : Flag<["-"], "fasm">, Group;
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -220,8 +220,8 @@
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
-def err_drv_unsupported_static_ubsan_darwin : Error<
-  "static