[llvm] r238451 - Add llvm-dwarfdump-fuzzer that uses LibFuzzer to fuzz llvm-dwarfdump tool.
Alexey Samsonov
vonosmas at gmail.com
Thu May 28 11:35:18 PDT 2015
Author: samsonov
Date: Thu May 28 13:35:18 2015
New Revision: 238451
URL: http://llvm.org/viewvc/llvm-project?rev=238451&view=rev
Log:
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.
Added:
llvm/trunk/tools/llvm-dwarfdump/fuzzer/
llvm/trunk/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt
llvm/trunk/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp
Modified:
llvm/trunk/tools/llvm-dwarfdump/CMakeLists.txt
Modified: llvm/trunk/tools/llvm-dwarfdump/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/CMakeLists.txt?rev=238451&r1=238450&r2=238451&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-dwarfdump/CMakeLists.txt Thu May 28 13:35:18 2015
@@ -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()
Added: llvm/trunk/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt?rev=238451&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt (added)
+++ llvm/trunk/tools/llvm-dwarfdump/fuzzer/CMakeLists.txt Thu May 28 13:35:18 2015
@@ -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
+ )
Added: llvm/trunk/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp?rev=238451&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp (added)
+++ llvm/trunk/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp Thu May 28 13:35:18 2015
@@ -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);
+}
More information about the llvm-commits
mailing list