]> granicus.if.org Git - clang/commitdiff
Add -fsanitize=fuzzer-no-link flag to the driver.
authorGeorge Karpenkov <ekarpenkov@apple.com>
Fri, 11 Aug 2017 17:22:58 +0000 (17:22 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Fri, 11 Aug 2017 17:22:58 +0000 (17:22 +0000)
The flag will perform instrumentation necessary to the fuzzing,
but will NOT link libLLVMFuzzer.a library.
Necessary when modifying CFLAGS for projects which may produce
executables as well as a fuzzable target.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310733 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Sanitizers.def
lib/Driver/SanitizerArgs.cpp
lib/Driver/ToolChains/Darwin.cpp
lib/Driver/ToolChains/Linux.cpp
test/Driver/fuzzer.c

index 28a92abf00b743973893b8ea9d29070c40be094b..d6df6171729a8339389d2923904856a124eabcfe 100644 (file)
@@ -50,6 +50,9 @@ SANITIZER("memory", Memory)
 // libFuzzer
 SANITIZER("fuzzer", Fuzzer)
 
+// libFuzzer-required instrumentation, no linking.
+SANITIZER("fuzzer-no-link", FuzzerNoLink)
+
 // ThreadSanitizer
 SANITIZER("thread", Thread)
 
index 2f12c6d4a5f22533d9a9b2b8d6b64192c785d7d6..e411629ca425e0fec51255d8f0b97fb2bb04d440 100644 (file)
@@ -32,7 +32,7 @@ enum : SanitizerMask {
   RequiresPIE = DataFlow,
   NeedsUnwindTables = Address | Thread | Memory | DataFlow,
   SupportsCoverage = Address | KernelAddress | Memory | Leak | Undefined |
-                     Integer | Nullability | DataFlow | Fuzzer,
+                     Integer | Nullability | DataFlow | Fuzzer | FuzzerNoLink,
   RecoverableByDefault = Undefined | Integer | Nullability,
   Unrecoverable = Unreachable | Return,
   LegacyFsanitizeRecoverMask = Undefined | Integer,
@@ -286,8 +286,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
       Add &= ~InvalidTrappingKinds;
       Add &= Supported;
 
-      // Enable coverage if the fuzzing flag is set.
       if (Add & Fuzzer)
+        Add |= FuzzerNoLink;
+
+      // Enable coverage if the fuzzing flag is set.
+      if (Add & FuzzerNoLink)
         CoverageFeatures |= CoverageTracePCGuard | CoverageIndirCall |
                             CoverageTraceCmp | CoveragePCTable;
 
index 7f55d3ed7f3d6f903fad9df14df8a8390d7023d3..f67e36ef635e40404ca6f570a9e94693b8c0c510 100644 (file)
@@ -2018,6 +2018,7 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Leak;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   if (isTargetMacOS()) {
     if (!isMacosxVersionLT(10, 9))
       Res |= SanitizerKind::Vptr;
index 08a27fa7fed10df9bde0d908badf4693ddcaae41..1adf9f7070d170102c4aac664f209d5354b2deeb 100644 (file)
@@ -828,6 +828,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
index 62ee06435c2fcd16750585ca1909ea5f69f885ee..c0fc4b6f661f934e5f9e2ec1e6f7e75593421333 100644 (file)
 // RUN: %clang -fsanitize=fuzzer %s -shared -o %t.so -### 2>&1 | FileCheck --check-prefixes=CHECK-NOLIB-SO %s
 // CHECK-NOLIB-SO-NOT: libLLVMFuzzer.a
 
+// Check that we don't link in libFuzzer when compiling with -fsanitize=fuzzer-no-link.
+// RUN: %clang -fsanitize=fuzzer-no-link %s -target x86_64-apple-darwin14 -### 2>&1 | FileCheck --check-prefixes=CHECK-NOLIB,CHECK-COV %s
+// CHECK-NOLIB-NOT: libLLVMFuzzer.a
+// CHECK-COV: -fsanitize-coverage-trace-pc-guard
+
 // RUN: %clang -fsanitize=fuzzer -fsanitize-coverage=trace-pc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-MSG %s
 // CHECK-MSG-NOT: argument unused during compilation