summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2015-05-28 18:35:18 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2015-05-28 18:35:18 +0000
commitd804a1e36b008d00440f417b49a610b4df49bfeb (patch)
tree9c87ae684cef3562acb32c4a6c790a9623f1deec
parentabaa523e9ee3db49fabd2c58824d817ce1528293 (diff)
downloadbcm5719-llvm-d804a1e36b008d00440f417b49a610b4df49bfeb.tar.gz
bcm5719-llvm-d804a1e36b008d00440f417b49a610b4df49bfeb.zip
Add llvm-dwarfdump-fuzzer that uses LibFuzzer to fuzz llvm-dwarfdump tool.
The fuzzer is very simple, but not quite useful at the moment: it's unable to discover "interesting" examples, as LLVMObject library is terrible at error recovery, calling "report_fatal_error()" far too often. llvm-svn: 238451
-rw-r--r--llvm/tools/llvm-dwarfdump/CMakeLists.txt4
-rw-r--r--llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt14
-rw-r--r--llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp34
3 files changed, 52 insertions, 0 deletions
diff --git a/llvm/tools/llvm-dwarfdump/CMakeLists.txt b/llvm/tools/llvm-dwarfdump/CMakeLists.txt
index 086b1397461..9a2e53f5a4b 100644
--- a/llvm/tools/llvm-dwarfdump/CMakeLists.txt
+++ b/llvm/tools/llvm-dwarfdump/CMakeLists.txt
@@ -7,3 +7,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(llvm-dwarfdump
llvm-dwarfdump.cpp
)
+
+if(LLVM_USE_SANITIZE_COVERAGE)
+ add_subdirectory(fuzzer)
+endif()
diff --git a/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt b/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt
new file mode 100644
index 00000000000..1de35a3de47
--- /dev/null
+++ b/llvm/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS
+ DebugInfoDWARF
+ Object
+ Support
+ )
+
+add_llvm_executable(llvm-dwarfdump-fuzzer
+ EXCLUDE_FROM_ALL
+ llvm-dwarfdump-fuzzer.cpp
+ )
+
+target_link_libraries(llvm-dwarfdump-fuzzer
+ LLVMFuzzer
+ )
diff --git a/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp b/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp
new file mode 100644
index 00000000000..af0ac365228
--- /dev/null
+++ b/llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp
@@ -0,0 +1,34 @@
+//===-- llvm-dwarfdump-fuzzer.cpp - Fuzz the llvm-dwarfdump tool ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file implements a function that runs llvm-dwarfdump
+/// on a single input. This function is then linked into the Fuzzer library.
+///
+//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DIContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+using namespace object;
+
+extern "C" void LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+ std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
+ StringRef((const char *)data, size), "", false);
+
+ ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
+ ObjectFile::createObjectFile(Buff->getMemBufferRef());
+ if (!ObjOrErr)
+ return;
+ ObjectFile &Obj = *ObjOrErr.get();
+ std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
+ DICtx->dump(nulls(), DIDT_All);
+}
OpenPOWER on IntegriCloud