1 //===-- fuzzer_initialize.cpp - Fuzz Clang --------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// This file implements two functions: one that returns the command line 12 /// arguments for a given call to the fuzz target and one that initializes 13 /// the fuzzer with the correct command line arguments. 14 /// 15 //===----------------------------------------------------------------------===// 16 17 #include "fuzzer_initialize.h" 18 19 #include "llvm/InitializePasses.h" 20 #include "llvm/PassRegistry.h" 21 #include "llvm/Support/TargetSelect.h" 22 #include <cstring> 23 24 using namespace clang_fuzzer; 25 using namespace llvm; 26 27 28 namespace clang_fuzzer { 29 30 static std::vector<const char *> CLArgs; 31 32 const std::vector<const char *>& GetCLArgs() { 33 return CLArgs; 34 } 35 36 } 37 38 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { 39 InitializeAllTargets(); 40 InitializeAllTargetMCs(); 41 InitializeAllAsmPrinters(); 42 InitializeAllAsmParsers(); 43 44 PassRegistry &Registry = *PassRegistry::getPassRegistry(); 45 initializeCore(Registry); 46 initializeScalarOpts(Registry); 47 initializeVectorization(Registry); 48 initializeIPO(Registry); 49 initializeAnalysis(Registry); 50 initializeTransformUtils(Registry); 51 initializeInstCombine(Registry); 52 initializeAggressiveInstCombine(Registry); 53 initializeInstrumentation(Registry); 54 initializeTarget(Registry); 55 56 CLArgs.push_back("-O2"); 57 for (int I = 1; I < *argc; I++) { 58 if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) { 59 for (I++; I < *argc; I++) 60 CLArgs.push_back((*argv)[I]); 61 break; 62 } 63 } 64 return 0; 65 } 66