summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-isel-fuzzer
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2017-09-01 17:02:22 +0000
committerJustin Bogner <mail@justinbogner.com>2017-09-01 17:02:22 +0000
commitc3b67fbda73b5fd6a7d3eb1cf8382ab2e5133fe2 (patch)
tree375e629a498c66e91fbb8f2054935044fbb71e68 /llvm/tools/llvm-isel-fuzzer
parent75c98c365b8b4c42e9ba84351b0aef8f73f69019 (diff)
downloadbcm5719-llvm-c3b67fbda73b5fd6a7d3eb1cf8382ab2e5133fe2.tar.gz
bcm5719-llvm-c3b67fbda73b5fd6a7d3eb1cf8382ab2e5133fe2.zip
llvm-isel-fuzzer: Make buildable and testable without libFuzzer
This adds a dummy main so we can build and run the llvm-isel-fuzzer functionality when we aren't building LLVM with coverage. The approach here should serve as a template to stop in-tree fuzzers from bitrotting (See llvm.org/pr34314). Note that I'll probably move most of the logic in DummyISelFuzzer's `main` to a library so it's easy to reuse it in other fuzz targets, but I'm planning on doing that in a follow up that also consolidates argument handling in our LLVMFuzzerInitialize implementations. llvm-svn: 312338
Diffstat (limited to 'llvm/tools/llvm-isel-fuzzer')
-rw-r--r--llvm/tools/llvm-isel-fuzzer/CMakeLists.txt3
-rw-r--r--llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp56
2 files changed, 58 insertions, 1 deletions
diff --git a/llvm/tools/llvm-isel-fuzzer/CMakeLists.txt b/llvm/tools/llvm-isel-fuzzer/CMakeLists.txt
index 474bcf928eb..4bd4420bade 100644
--- a/llvm/tools/llvm-isel-fuzzer/CMakeLists.txt
+++ b/llvm/tools/llvm-isel-fuzzer/CMakeLists.txt
@@ -12,4 +12,5 @@ set(LLVM_LINK_COMPONENTS
Support
Target
)
-add_llvm_fuzzer(llvm-isel-fuzzer llvm-isel-fuzzer.cpp)
+add_llvm_fuzzer(llvm-isel-fuzzer llvm-isel-fuzzer.cpp
+ DUMMY_MAIN DummyISelFuzzer.cpp)
diff --git a/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp b/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp
new file mode 100644
index 00000000000..929a63a541d
--- /dev/null
+++ b/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp
@@ -0,0 +1,56 @@
+//===--- DummyFuzzerMain.cpp - Entry point to sanity check the fuzzer -----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of main so we can build and test without linking libFuzzer.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+extern "C" LLVM_ATTRIBUTE_WEAK int LLVMFuzzerInitialize(int *argc,
+ char ***argv) {
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ errs() << "*** This tool was not linked to libFuzzer.\n"
+ << "*** No fuzzing will be performed.\n";
+ if (int RC = LLVMFuzzerInitialize(&argc, &argv)) {
+ errs() << "Initialization failed\n";
+ return RC;
+ }
+
+ for (int I = 1; I < argc; ++I) {
+ StringRef Arg(argv[I]);
+ if (Arg.startswith("-")) {
+ if (Arg.equals("-ignore_remaining_args=1"))
+ break;
+ continue;
+ }
+
+ auto BufOrErr = MemoryBuffer::getFile(Arg, /*FileSize-*/ -1,
+ /*RequiresNullTerminator=*/false);
+ if (std::error_code EC = BufOrErr.getError()) {
+ errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n";
+ return 1;
+ }
+ std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());
+ errs() << "Running: " << Arg << " (" << Buf->getBufferSize() << " bytes)\n";
+ LLVMFuzzerTestOneInput(
+ reinterpret_cast<const uint8_t *>(Buf->getBufferStart()),
+ Buf->getBufferSize());
+ }
+}
OpenPOWER on IntegriCloud