LLVM 24.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/ADT/ArrayRef.h"
20#include <stddef.h>
21
22namespace llvm {
23
24class StringRef;
25namespace cl {
26class LibraryOptions;
28}
29
30/// Parse cl::opts from a fuzz target commandline.
31///
32/// This handles all arguments after -ignore_remaining_args=1 as cl::opts.
33LLVM_ABI void
35 ArrayRef<const cl::LibraryOptions *> ToolOptions, int ArgC,
36 char *ArgV[]);
37
38/// Handle backend options that are encoded in the executable name.
39///
40/// Parses some common backend options out of a specially crafted executable
41/// name (argv[0]). For example, a name like llvm-foo-fuzzer--aarch64-gisel
42/// might set up an AArch64 triple and the Global ISel selector. This should be
43/// called *before* parseFuzzerCLOpts if calling both.
44///
45/// This is meant to be used for environments like OSS-Fuzz that aren't capable
46/// of passing in command line arguments in the normal way.
47LLVM_ABI void
49 StringRef ExecName);
50
51/// Handle optimizer options which are encoded in the executable name.
52/// Same semantics as in 'handleExecNameEncodedBEOpts'.
53LLVM_ABI void
55 StringRef ExecName);
56
57using FuzzerTestFun = int (*)(const uint8_t *Data, size_t Size);
58using FuzzerInitFun = int (*)(int *argc, char ***argv);
59
60/// Runs a fuzz target on the inputs specified on the command line.
61///
62/// Useful for testing fuzz targets without linking to libFuzzer. Finds inputs
63/// in the argument list in a libFuzzer compatible way.
65 int ArgC, char *ArgV[], FuzzerTestFun TestOne,
66 FuzzerInitFun Init = [](int *, char ***) { return 0; });
67
68} // namespace llvm
69
70#endif // LLVM_FUZZMUTATE_FUZZERCLI_H
#define LLVM_ABI
Definition Compiler.h:211
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The options of a library that declares them in TableGen rather than as cl::opt (see llvm/Option/Libra...
This namespace contains all of the command line option processing machinery.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void parseFuzzerCLOpts(cl::LibraryOptionsContext &LibraryOptions, ArrayRef< const cl::LibraryOptions * > ToolOptions, int ArgC, char *ArgV[])
Parse cl::opts from a fuzz target commandline.
Definition FuzzerCLI.cpp:18
LLVM_ABI void handleExecNameEncodedOptimizerOpts(cl::LibraryOptionsContext &LibraryOptions, StringRef ExecName)
Handle optimizer options which are encoded in the executable name.
Definition FuzzerCLI.cpp:71
int(*)(const uint8_t *Data, size_t Size) FuzzerTestFun
Definition FuzzerCLI.h:57
LLVM_ABI 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.
LLVM_ABI void handleExecNameEncodedBEOpts(cl::LibraryOptionsContext &LibraryOptions, StringRef ExecName)
Handle backend options that are encoded in the executable name.
Definition FuzzerCLI.cpp:34
int(*)(int *argc, char ***argv) FuzzerInitFun
Definition FuzzerCLI.h:58