annotate include/llvm/FuzzMutate/FuzzerCLI.h @ 134:3a76565eade5 LLVM5.0.1

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