annotate include/llvm/FuzzMutate/FuzzerCLI.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===-- FuzzerCLI.h - Common logic for CLIs of fuzzers ----------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 // Common logic needed to implement LLVM's fuzz targets' CLIs - including LLVM
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 // concepts like cl::opt and libFuzzer concepts like -ignore_remaining_args=1.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #ifndef LLVM_FUZZMUTATE_FUZZER_CLI_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #define LLVM_FUZZMUTATE_FUZZER_CLI_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/ADT/StringRef.h"
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
18 #include "llvm/IR/LLVMContext.h"
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/Support/DataTypes.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 /// Parse cl::opts from a fuzz target commandline.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 /// This handles all arguments after -ignore_remaining_args=1 as cl::opts.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 void parseFuzzerCLOpts(int ArgC, char *ArgV[]);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 /// Handle backend options that are encoded in the executable name.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 /// Parses some common backend options out of a specially crafted executable
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 /// name (argv[0]). For example, a name like llvm-foo-fuzzer--aarch64-gisel
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 /// might set up an AArch64 triple and the Global ISel selector. This should be
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 /// called *before* parseFuzzerCLOpts if calling both.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 /// This is meant to be used for environments like OSS-Fuzz that aren't capable
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 /// of passing in command line arguments in the normal way.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 void handleExecNameEncodedBEOpts(StringRef ExecName);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
39 /// Handle optimizer options which are encoded in the executable name.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
40 /// Same semantics as in 'handleExecNameEncodedBEOpts'.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
41 void handleExecNameEncodedOptimizerOpts(StringRef ExecName);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
42
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 using FuzzerTestFun = int (*)(const uint8_t *Data, size_t Size);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 using FuzzerInitFun = int (*)(int *argc, char ***argv);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 /// Runs a fuzz target on the inputs specified on the command line.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 /// Useful for testing fuzz targets without linking to libFuzzer. Finds inputs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 /// in the argument list in a libFuzzer compatible way.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 FuzzerInitFun Init = [](int *, char ***) { return 0; });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
53 /// Fuzzer friendly interface for the llvm bitcode parser.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
54 ///
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
55 /// \param Data Bitcode we are going to parse
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
56 /// \param Size Size of the 'Data' in bytes
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
57 /// \return New module or nullptr in case of error
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
58 std::unique_ptr<Module> parseModule(const uint8_t *Data, size_t Size,
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
59 LLVMContext &Context);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
60
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
61 /// Fuzzer friendly interface for the llvm bitcode printer.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
62 ///
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
63 /// \param M Module to print
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
64 /// \param Dest Location to store serialized module
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
65 /// \param MaxSize Size of the destination buffer
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
66 /// \return Number of bytes that were written. When module size exceeds MaxSize
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
67 /// returns 0 and leaves Dest unchanged.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
68 size_t writeModule(const Module &M, uint8_t *Dest, size_t MaxSize);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
69
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
70 /// Try to parse module and verify it. May output verification errors to the
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
71 /// errs().
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
72 /// \return New module or nullptr in case of error.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
73 std::unique_ptr<Module> parseAndVerify(const uint8_t *Data, size_t Size,
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
74 LLVMContext &Context);
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
75
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 } // end llvm namespace
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 #endif // LLVM_FUZZMUTATE_FUZZER_CLI_H