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