summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Morehouse <mascasa@google.com>2018-06-05 00:11:41 +0000
committerMatt Morehouse <mascasa@google.com>2018-06-05 00:11:41 +0000
commitdb0407e1cac00368f599c8ee19cdb86390d696ff (patch)
treec4ada8b6b6f150f4a7c772b2b38e0c9a5141b15e
parent804656e720e548d443c0df7a01ef29a753572f1e (diff)
[clang-proto-fuzzer] Refactored LLVMFuzzerInitialize into its own file.
Copied and renamed some files in preparation for new loop-proto-fuzzer. Patch By: emmettneyman Differential Revision: https://reviews.llvm.org/D47666 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333969 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/clang-fuzzer/CMakeLists.txt4
-rw-r--r--tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp20
-rw-r--r--tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt3
-rw-r--r--tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp43
-rw-r--r--tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h19
5 files changed, 71 insertions, 18 deletions
diff --git a/tools/clang-fuzzer/CMakeLists.txt b/tools/clang-fuzzer/CMakeLists.txt
index 96fe1fabbf..cc9266c4db 100644
--- a/tools/clang-fuzzer/CMakeLists.txt
+++ b/tools/clang-fuzzer/CMakeLists.txt
@@ -40,6 +40,9 @@ if(CLANG_ENABLE_PROTO_FUZZER)
# Build the protobuf->C++ translation library and driver.
add_clang_subdirectory(proto-to-cxx)
+ # Build the fuzzer initialization library.
+ add_clang_subdirectory(fuzzer-initialize)
+
# Build the protobuf fuzzer
add_clang_executable(clang-proto-fuzzer
${DUMMY_MAIN}
@@ -52,6 +55,7 @@ if(CLANG_ENABLE_PROTO_FUZZER)
${PROTOBUF_LIBRARIES}
${LLVM_LIB_FUZZING_ENGINE}
clangCXXProto
+ clangFuzzerInitialize
clangHandleCXX
clangProtoToCXX
)
diff --git a/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp b/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
index 53249cafbe..159ded3ca1 100644
--- a/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ b/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -17,28 +17,12 @@
#include "cxx_proto.pb.h"
#include "handle-cxx/handle_cxx.h"
#include "proto-to-cxx/proto_to_cxx.h"
-
+#include "fuzzer-initialize/fuzzer_initialize.h"
#include "src/libfuzzer/libfuzzer_macro.h"
-#include <cstring>
-
using namespace clang_fuzzer;
-static std::vector<const char *> CLArgs;
-
-extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
- CLArgs.push_back("-O2");
- for (int I = 1; I < *argc; I++) {
- if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) {
- for (I++; I < *argc; I++)
- CLArgs.push_back((*argv)[I]);
- break;
- }
- }
- return 0;
-}
-
DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
auto S = FunctionToString(input);
- HandleCXX(S, CLArgs);
+ HandleCXX(S, GetCLArgs());
}
diff --git a/tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt b/tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
new file mode 100644
index 0000000000..c149fb3d4b
--- /dev/null
+++ b/tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
@@ -0,0 +1,3 @@
+set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} Support)
+
+add_clang_library(clangFuzzerInitialize fuzzer_initialize.cpp)
diff --git a/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp b/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
new file mode 100644
index 0000000000..08bc242b88
--- /dev/null
+++ b/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
@@ -0,0 +1,43 @@
+//===-- fuzzer_initialize.cpp - Fuzz Clang --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements two functions: one that returns the command line
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments.
+///
+//===----------------------------------------------------------------------===//
+
+#include "fuzzer_initialize.h"
+#include <cstring>
+
+using namespace clang_fuzzer;
+
+
+namespace clang_fuzzer {
+
+static std::vector<const char *> CLArgs;
+
+const std::vector<const char *>& GetCLArgs() {
+ return CLArgs;
+}
+
+}
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+ CLArgs.push_back("-O2");
+ for (int I = 1; I < *argc; I++) {
+ if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) {
+ for (I++; I < *argc; I++)
+ CLArgs.push_back((*argv)[I]);
+ break;
+ }
+ }
+ return 0;
+}
diff --git a/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h b/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
new file mode 100644
index 0000000000..83a5cf9dc5
--- /dev/null
+++ b/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
@@ -0,0 +1,19 @@
+//==-- fuzzer_initialize.h - Fuzz Clang ------------------------------------==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===----------------------------------------------------------------------===//
+
+#include <vector>
+
+namespace clang_fuzzer {
+const std::vector<const char *>& GetCLArgs();
+}