[PATCH] D48373: [Driver] Make scudo compatible with -fsanitize-minimal-runtime

2018-06-22 Thread Kostya Kortchinsky via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC335352: [Driver] Make scudo compatible with 
-fsanitize-minimal-runtime (authored by cryptoad, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48373?vs=152171=152476#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48373

Files:
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/fsanitize.c
  test/Driver/sanitizer-ld.c

Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -689,6 +689,15 @@
 // CHECK-SCUDO-LINUX: "-lpthread"
 // CHECK-SCUDO-LINUX: "-ldl"
 
+// RUN: %clang -fsanitize=scudo -fsanitize-minimal-runtime %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-linux -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SCUDO-MINIMAL-LINUX %s
+// CHECK-SCUDO-MINIMAL-LINUX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-SCUDO-MINIMAL-LINUX: "-pie"
+// CHECK-SCUDO-MINIMAL-LINUX: "--whole-archive" "{{.*}}libclang_rt.scudo_minimal-i386.a" "--no-whole-archive"
+// CHECK-SCUDO-MINIMAL-LINUX: "-lpthread"
+
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.so -shared 2>&1 \
 // RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=scudo -shared-libsan \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -674,6 +674,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=scudo,undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SCUDO-UBSAN
 // CHECK-SCUDO-UBSAN: "-fsanitize={{.*}}scudo"
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=scudo -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SCUDO-MINIMAL
+// CHECK-SCUDO-MINIMAL: "-fsanitize=scudo"
+// CHECK-SCUDO-MINIMAL: "-fsanitize-minimal-runtime"
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined,scudo -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SCUDO-UBSAN-MINIMAL
+// CHECK-SCUDO-UBSAN-MINIMAL: "-fsanitize={{.*}}scudo"
+// CHECK-SCUDO-UBSAN-MINIMAL: "-fsanitize-minimal-runtime"
+
 // RUN: %clang -target powerpc-unknown-linux -fsanitize=scudo %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SCUDO
 // CHECK-NO-SCUDO: unsupported option
 
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -45,7 +45,7 @@
   Nullability | LocalBounds | CFI,
   TrappingDefault = CFI,
   CFIClasses = CFIVCall | CFINVCall | CFIDerivedCast | CFIUnrelatedCast,
-  CompatibleWithMinimalRuntime = TrappingSupported,
+  CompatibleWithMinimalRuntime = TrappingSupported | Scudo,
 };
 
 enum CoverageFeature {
@@ -179,7 +179,8 @@
 bool SanitizerArgs::needsUbsanRt() const {
   // All of these include ubsan.
   if (needsAsanRt() || needsMsanRt() || needsHwasanRt() || needsTsanRt() ||
-  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() || needsScudoRt())
+  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() ||
+  (needsScudoRt() && !requiresMinimalRuntime()))
 return false;
 
   return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -593,14 +593,17 @@
 HelperStaticRuntimes.push_back("asan-preinit");
 }
 if (SanArgs.needsUbsanRt()) {
-  if (SanArgs.requiresMinimalRuntime()) {
+  if (SanArgs.requiresMinimalRuntime())
 SharedRuntimes.push_back("ubsan_minimal");
-  } else {
+  else
 SharedRuntimes.push_back("ubsan_standalone");
-  }
 }
-if (SanArgs.needsScudoRt())
-  SharedRuntimes.push_back("scudo");
+if (SanArgs.needsScudoRt()) {
+  if (SanArgs.requiresMinimalRuntime())
+SharedRuntimes.push_back("scudo_minimal");
+  else
+SharedRuntimes.push_back("scudo");
+}
 if (SanArgs.needsHwasanRt())
   SharedRuntimes.push_back("hwasan");
   }
@@ -666,9 +669,15 @@
   if (SanArgs.needsEsanRt())
 StaticRuntimes.push_back("esan");
   if (SanArgs.needsScudoRt()) {
-StaticRuntimes.push_back("scudo");
-if (SanArgs.linkCXXRuntimes())
-  StaticRuntimes.push_back("scudo_cxx");
+if (SanArgs.requiresMinimalRuntime()) {
+  StaticRuntimes.push_back("scudo_minimal");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx_minimal");
+} else {
+  StaticRuntimes.push_back("scudo");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx");
+}
   }
 }
 
___
cfe-commits 

[PATCH] D48373: [Driver] Make scudo compatible with -fsanitize-minimal-runtime

2018-06-20 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

Looks great, thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D48373



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


[PATCH] D48373: [Driver] Make scudo compatible with -fsanitize-minimal-runtime

2018-06-20 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad updated this revision to Diff 152171.
cryptoad added a comment.

Adding tests.


Repository:
  rC Clang

https://reviews.llvm.org/D48373

Files:
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/fsanitize.c
  test/Driver/sanitizer-ld.c

Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -689,6 +689,15 @@
 // CHECK-SCUDO-LINUX: "-lpthread"
 // CHECK-SCUDO-LINUX: "-ldl"
 
+// RUN: %clang -fsanitize=scudo -fsanitize-minimal-runtime %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-linux -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SCUDO-MINIMAL-LINUX %s
+// CHECK-SCUDO-MINIMAL-LINUX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-SCUDO-MINIMAL-LINUX: "-pie"
+// CHECK-SCUDO-MINIMAL-LINUX: "--whole-archive" "{{.*}}libclang_rt.scudo_minimal-i386.a" "--no-whole-archive"
+// CHECK-SCUDO-MINIMAL-LINUX: "-lpthread"
+
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.so -shared 2>&1 \
 // RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=scudo -shared-libsan \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -674,6 +674,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=scudo,undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SCUDO-UBSAN
 // CHECK-SCUDO-UBSAN: "-fsanitize={{.*}}scudo"
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=scudo -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SCUDO-MINIMAL
+// CHECK-SCUDO-MINIMAL: "-fsanitize=scudo"
+// CHECK-SCUDO-MINIMAL: "-fsanitize-minimal-runtime"
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined,scudo -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SCUDO-UBSAN-MINIMAL
+// CHECK-SCUDO-UBSAN-MINIMAL: "-fsanitize={{.*}}scudo"
+// CHECK-SCUDO-UBSAN-MINIMAL: "-fsanitize-minimal-runtime"
+
 // RUN: %clang -target powerpc-unknown-linux -fsanitize=scudo %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SCUDO
 // CHECK-NO-SCUDO: unsupported option
 
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -593,14 +593,17 @@
 HelperStaticRuntimes.push_back("asan-preinit");
 }
 if (SanArgs.needsUbsanRt()) {
-  if (SanArgs.requiresMinimalRuntime()) {
+  if (SanArgs.requiresMinimalRuntime())
 SharedRuntimes.push_back("ubsan_minimal");
-  } else {
+  else
 SharedRuntimes.push_back("ubsan_standalone");
-  }
 }
-if (SanArgs.needsScudoRt())
-  SharedRuntimes.push_back("scudo");
+if (SanArgs.needsScudoRt()) {
+  if (SanArgs.requiresMinimalRuntime())
+SharedRuntimes.push_back("scudo_minimal");
+  else
+SharedRuntimes.push_back("scudo");
+}
 if (SanArgs.needsHwasanRt())
   SharedRuntimes.push_back("hwasan");
   }
@@ -666,9 +669,15 @@
   if (SanArgs.needsEsanRt())
 StaticRuntimes.push_back("esan");
   if (SanArgs.needsScudoRt()) {
-StaticRuntimes.push_back("scudo");
-if (SanArgs.linkCXXRuntimes())
-  StaticRuntimes.push_back("scudo_cxx");
+if (SanArgs.requiresMinimalRuntime()) {
+  StaticRuntimes.push_back("scudo_minimal");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx_minimal");
+} else {
+  StaticRuntimes.push_back("scudo");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx");
+}
   }
 }
 
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -45,7 +45,7 @@
   Nullability | LocalBounds | CFI,
   TrappingDefault = CFI,
   CFIClasses = CFIVCall | CFINVCall | CFIDerivedCast | CFIUnrelatedCast,
-  CompatibleWithMinimalRuntime = TrappingSupported,
+  CompatibleWithMinimalRuntime = TrappingSupported | Scudo,
 };
 
 enum CoverageFeature {
@@ -179,7 +179,8 @@
 bool SanitizerArgs::needsUbsanRt() const {
   // All of these include ubsan.
   if (needsAsanRt() || needsMsanRt() || needsHwasanRt() || needsTsanRt() ||
-  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() || needsScudoRt())
+  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() ||
+  (needsScudoRt() && !requiresMinimalRuntime()))
 return false;
 
   return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48373: [Driver] Make scudo compatible with -fsanitize-minimal-runtime

2018-06-20 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis requested changes to this revision.
eugenis added a comment.
This revision now requires changes to proceed.

Please add a test.


Repository:
  rC Clang

https://reviews.llvm.org/D48373



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


[PATCH] D48373: [Driver] Make scudo compatible with -fsanitize-minimal-runtime

2018-06-20 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad created this revision.
cryptoad added a reviewer: eugenis.
Herald added a subscriber: cfe-commits.

This is the clang side of the change, there is a compiler-rt counterpart.

Scudo works with UBSan using `-fsanitize=scudo,integer` for example, and to do
so it embeds UBSan runtime. This makes it not compatible with the UBSan minimal
runtime, but this is something we want for production purposes.

The idea is to have a Scudo minimal runtime on the compiler-rt side that will
not embed UBSan. This is basically the runtime that is currently in use for
Fuchsia, without coverage, stacktraces or symbolization. With this, Scudo
becomes compatible with `-fsanitize-minimal-runtime`.

If this approach is suitable, I'll add the tests as well, otherwise I am open
to other options.


Repository:
  rC Clang

https://reviews.llvm.org/D48373

Files:
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/CommonArgs.cpp


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -593,14 +593,17 @@
 HelperStaticRuntimes.push_back("asan-preinit");
 }
 if (SanArgs.needsUbsanRt()) {
-  if (SanArgs.requiresMinimalRuntime()) {
+  if (SanArgs.requiresMinimalRuntime())
 SharedRuntimes.push_back("ubsan_minimal");
-  } else {
+  else
 SharedRuntimes.push_back("ubsan_standalone");
-  }
 }
-if (SanArgs.needsScudoRt())
-  SharedRuntimes.push_back("scudo");
+if (SanArgs.needsScudoRt()) {
+  if (SanArgs.requiresMinimalRuntime())
+SharedRuntimes.push_back("scudo_minimal");
+  else
+SharedRuntimes.push_back("scudo");
+}
 if (SanArgs.needsHwasanRt())
   SharedRuntimes.push_back("hwasan");
   }
@@ -666,9 +669,15 @@
   if (SanArgs.needsEsanRt())
 StaticRuntimes.push_back("esan");
   if (SanArgs.needsScudoRt()) {
-StaticRuntimes.push_back("scudo");
-if (SanArgs.linkCXXRuntimes())
-  StaticRuntimes.push_back("scudo_cxx");
+if (SanArgs.requiresMinimalRuntime()) {
+  StaticRuntimes.push_back("scudo_minimal");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx_minimal");
+} else {
+  StaticRuntimes.push_back("scudo");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx");
+}
   }
 }
 
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -45,7 +45,7 @@
   Nullability | LocalBounds | CFI,
   TrappingDefault = CFI,
   CFIClasses = CFIVCall | CFINVCall | CFIDerivedCast | CFIUnrelatedCast,
-  CompatibleWithMinimalRuntime = TrappingSupported,
+  CompatibleWithMinimalRuntime = TrappingSupported | Scudo,
 };
 
 enum CoverageFeature {
@@ -179,7 +179,8 @@
 bool SanitizerArgs::needsUbsanRt() const {
   // All of these include ubsan.
   if (needsAsanRt() || needsMsanRt() || needsHwasanRt() || needsTsanRt() ||
-  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() || needsScudoRt())
+  needsDfsanRt() || needsLsanRt() || needsCfiDiagRt() ||
+  (needsScudoRt() && !requiresMinimalRuntime()))
 return false;
 
   return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -593,14 +593,17 @@
 HelperStaticRuntimes.push_back("asan-preinit");
 }
 if (SanArgs.needsUbsanRt()) {
-  if (SanArgs.requiresMinimalRuntime()) {
+  if (SanArgs.requiresMinimalRuntime())
 SharedRuntimes.push_back("ubsan_minimal");
-  } else {
+  else
 SharedRuntimes.push_back("ubsan_standalone");
-  }
 }
-if (SanArgs.needsScudoRt())
-  SharedRuntimes.push_back("scudo");
+if (SanArgs.needsScudoRt()) {
+  if (SanArgs.requiresMinimalRuntime())
+SharedRuntimes.push_back("scudo_minimal");
+  else
+SharedRuntimes.push_back("scudo");
+}
 if (SanArgs.needsHwasanRt())
   SharedRuntimes.push_back("hwasan");
   }
@@ -666,9 +669,15 @@
   if (SanArgs.needsEsanRt())
 StaticRuntimes.push_back("esan");
   if (SanArgs.needsScudoRt()) {
-StaticRuntimes.push_back("scudo");
-if (SanArgs.linkCXXRuntimes())
-  StaticRuntimes.push_back("scudo_cxx");
+if (SanArgs.requiresMinimalRuntime()) {
+  StaticRuntimes.push_back("scudo_minimal");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx_minimal");
+} else {
+  StaticRuntimes.push_back("scudo");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("scudo_cxx");
+}
   }
 }
 
Index: lib/Driver/SanitizerArgs.cpp
===
---