LLVM  15.0.0git
FuzzerCLI.h
Go to the documentation of this file.
1 //===-- FuzzerCLI.h - Common logic for CLIs of fuzzers ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Common logic needed to implement LLVM's fuzz targets' CLIs - including LLVM
10 // concepts like cl::opt and libFuzzer concepts like -ignore_remaining_args=1.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_FUZZMUTATE_FUZZERCLI_H
15 #define LLVM_FUZZMUTATE_FUZZERCLI_H
16 
17 #include "llvm/Support/DataTypes.h"
18 #include <stddef.h>
19 
20 namespace llvm {
21 
22 class StringRef;
23 
24 /// Parse cl::opts from a fuzz target commandline.
25 ///
26 /// This handles all arguments after -ignore_remaining_args=1 as cl::opts.
27 void parseFuzzerCLOpts(int ArgC, char *ArgV[]);
28 
29 /// Handle backend options that are encoded in the executable name.
30 ///
31 /// Parses some common backend options out of a specially crafted executable
32 /// name (argv[0]). For example, a name like llvm-foo-fuzzer--aarch64-gisel
33 /// might set up an AArch64 triple and the Global ISel selector. This should be
34 /// called *before* parseFuzzerCLOpts if calling both.
35 ///
36 /// This is meant to be used for environments like OSS-Fuzz that aren't capable
37 /// of passing in command line arguments in the normal way.
38 void handleExecNameEncodedBEOpts(StringRef ExecName);
39 
40 /// Handle optimizer options which are encoded in the executable name.
41 /// Same semantics as in 'handleExecNameEncodedBEOpts'.
42 void handleExecNameEncodedOptimizerOpts(StringRef ExecName);
43 
44 using FuzzerTestFun = int (*)(const uint8_t *Data, size_t Size);
45 using FuzzerInitFun = int (*)(int *argc, char ***argv);
46 
47 /// Runs a fuzz target on the inputs specified on the command line.
48 ///
49 /// Useful for testing fuzz targets without linking to libFuzzer. Finds inputs
50 /// in the argument list in a libFuzzer compatible way.
51 int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
52  FuzzerInitFun Init = [](int *, char ***) { return 0; });
53 
54 } // namespace llvm
55 
56 #endif // LLVM_FUZZMUTATE_FUZZERCLI_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::handleExecNameEncodedOptimizerOpts
void handleExecNameEncodedOptimizerOpts(StringRef ExecName)
Handle optimizer options which are encoded in the executable name.
Definition: FuzzerCLI.cpp:68
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::FuzzerInitFun
int(*)(int *argc, char ***argv) FuzzerInitFun
Definition: FuzzerCLI.h:45
llvm::handleExecNameEncodedBEOpts
void handleExecNameEncodedBEOpts(StringRef ExecName)
Handle backend options that are encoded in the executable name.
Definition: FuzzerCLI.cpp:32
llvm::Init
Definition: Record.h:281
llvm::parseFuzzerCLOpts
void parseFuzzerCLOpts(int ArgC, char *ArgV[])
Parse cl::opts from a fuzz target commandline.
Definition: FuzzerCLI.cpp:18
llvm::FuzzerTestFun
int(*)(const uint8_t *Data, size_t Size) FuzzerTestFun
Definition: FuzzerCLI.h:44
DataTypes.h
llvm::runFuzzerOnInputs
int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne, FuzzerInitFun Init=[](int *, char ***) { return 0;})
Runs a fuzz target on the inputs specified on the command line.
Definition: FuzzerCLI.cpp:132