r310733 - Add -fsanitize=fuzzer-no-link flag to the driver.
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 11 10:22:58 PDT 2017
Author: george.karpenkov
Date: Fri Aug 11 10:22:58 2017
New Revision: 310733
URL: http://llvm.org/viewvc/llvm-project?rev=310733&view=rev
Log:
Add -fsanitize=fuzzer-no-link flag to the driver.
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
Modified:
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/test/Driver/fuzzer.c
Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=310733&r1=310732&r2=310733&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Fri Aug 11 10:22:58 2017
@@ -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)
Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=310733&r1=310732&r2=310733&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Fri Aug 11 10:22:58 2017
@@ -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 ToolC
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;
Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=310733&r1=310732&r2=310733&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Fri Aug 11 10:22:58 2017
@@ -2018,6 +2018,7 @@ SanitizerMask Darwin::getSupportedSaniti
Res |= SanitizerKind::Address;
Res |= SanitizerKind::Leak;
Res |= SanitizerKind::Fuzzer;
+ Res |= SanitizerKind::FuzzerNoLink;
if (isTargetMacOS()) {
if (!isMacosxVersionLT(10, 9))
Res |= SanitizerKind::Vptr;
Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=310733&r1=310732&r2=310733&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Fri Aug 11 10:22:58 2017
@@ -828,6 +828,7 @@ SanitizerMask Linux::getSupportedSanitiz
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::Fuzzer;
+ Res |= SanitizerKind::FuzzerNoLink;
Res |= SanitizerKind::KernelAddress;
Res |= SanitizerKind::Vptr;
Res |= SanitizerKind::SafeStack;
Modified: cfe/trunk/test/Driver/fuzzer.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuzzer.c?rev=310733&r1=310732&r2=310733&view=diff
==============================================================================
--- cfe/trunk/test/Driver/fuzzer.c (original)
+++ cfe/trunk/test/Driver/fuzzer.c Fri Aug 11 10:22:58 2017
@@ -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
More information about the cfe-commits
mailing list