Index: cfe/trunk/include/clang/Basic/Sanitizers.def =================================================================== --- cfe/trunk/include/clang/Basic/Sanitizers.def +++ cfe/trunk/include/clang/Basic/Sanitizers.def @@ -50,6 +50,9 @@ // libFuzzer SANITIZER("fuzzer", Fuzzer) +// libFuzzer-required instrumentation, no linking. +SANITIZER("fuzzer-no-link", FuzzerNoLink) + // ThreadSanitizer SANITIZER("thread", Thread) Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp =================================================================== --- cfe/trunk/lib/Driver/SanitizerArgs.cpp +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp @@ -32,7 +32,7 @@ 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 @@ 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: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp @@ -2018,6 +2018,7 @@ Res |= SanitizerKind::Address; Res |= SanitizerKind::Leak; Res |= SanitizerKind::Fuzzer; + Res |= SanitizerKind::FuzzerNoLink; if (isTargetMacOS()) { if (!isMacosxVersionLT(10, 9)) Res |= SanitizerKind::Vptr; Index: cfe/trunk/lib/Driver/ToolChains/Linux.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains/Linux.cpp +++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp @@ -828,6 +828,7 @@ SanitizerMask Res = ToolChain::getSupportedSanitizers(); Res |= SanitizerKind::Address; Res |= SanitizerKind::Fuzzer; + Res |= SanitizerKind::FuzzerNoLink; Res |= SanitizerKind::KernelAddress; Res |= SanitizerKind::Vptr; Res |= SanitizerKind::SafeStack; Index: cfe/trunk/test/Driver/fuzzer.c =================================================================== --- cfe/trunk/test/Driver/fuzzer.c +++ cfe/trunk/test/Driver/fuzzer.c @@ -21,6 +21,11 @@ // 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