From: Kostya Kortchinsky Date: Fri, 22 Jun 2018 14:31:30 +0000 (+0000) Subject: [Driver] Make scudo compatible with -fsanitize-minimal-runtime X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b8a6fded3d3ff541e9553a623666553bbb095de;p=clang [Driver] Make scudo compatible with -fsanitize-minimal-runtime Summary: 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. Reviewers: eugenis Reviewed By: eugenis Subscribers: llvm-commits, cfe-commits Differential Revision: https://reviews.llvm.org/D48373 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335352 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index 4eee52c779..743e042a79 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -45,7 +45,7 @@ enum : SanitizerMask { Nullability | LocalBounds | CFI, TrappingDefault = CFI, CFIClasses = CFIVCall | CFINVCall | CFIDerivedCast | CFIUnrelatedCast, - CompatibleWithMinimalRuntime = TrappingSupported, + CompatibleWithMinimalRuntime = TrappingSupported | Scudo, }; enum CoverageFeature { @@ -179,7 +179,8 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D, 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) || diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index 4f3d46e246..5bd012a6d8 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -593,14 +593,17 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, 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 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, 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"); + } } } diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 5f66e24075..3e3b13e8c2 100644 --- a/test/Driver/fsanitize.c +++ b/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 diff --git a/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c index 93df586e30..e85a828b33 100644 --- a/test/Driver/sanitizer-ld.c +++ b/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 \