annotate docs/FuzzingLLVM.rst @ 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 ================================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 Fuzzing LLVM libraries and tools
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 ================================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 .. contents::
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 :local:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 :depth: 2
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 Introduction
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 ============
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 The LLVM tree includes a number of fuzzers for various components. These are
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 built on top of :doc:`LibFuzzer <LibFuzzer>`.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 Available Fuzzers
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 =================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 clang-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 ------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 A |generic fuzzer| that tries to compile textual input as C++ code. Some of the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 bugs this fuzzer has reported are `on bugzilla`__ and `on OSS Fuzz's
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 tracker`__.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 __ https://llvm.org/pr23057
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 __ https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj-llvm+clang-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 clang-proto-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 ------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 A |protobuf fuzzer| that compiles valid C++ programs generated from a protobuf
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 class that describes a subset of the C++ language.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 This fuzzer accepts clang command line options after `ignore_remaining_args=1`.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 For example, the following command will fuzz clang with a higher optimization
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 level:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 .. code-block:: shell
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 % bin/clang-proto-fuzzer <corpus-dir> -ignore_remaining_args=1 -O3
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 clang-format-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 -------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 A |generic fuzzer| that runs clang-format_ on C++ text fragments. Some of the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 bugs this fuzzer has reported are `on bugzilla`__
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 and `on OSS Fuzz's tracker`__.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 .. _clang-format: https://clang.llvm.org/docs/ClangFormat.html
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 __ https://llvm.org/pr23052
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 __ https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj-llvm+clang-format-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 llvm-as-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 --------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 A |generic fuzzer| that tries to parse text as :doc:`LLVM assembly <LangRef>`.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 Some of the bugs this fuzzer has reported are `on bugzilla`__.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 __ https://llvm.org/pr24639
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 llvm-dwarfdump-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 ---------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 A |generic fuzzer| that interprets inputs as object files and runs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 :doc:`llvm-dwarfdump <CommandGuide/llvm-dwarfdump>` on them. Some of the bugs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 this fuzzer has reported are `on OSS Fuzz's tracker`__
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 __ https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj-llvm+llvm-dwarfdump-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 llvm-demangle-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 ---------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 A |generic fuzzer| for the Itanium demangler used in various LLVM tools. We've
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 fuzzed __cxa_demangle to death, why not fuzz LLVM's implementation of the same
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 function!
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 llvm-isel-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 ----------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 A |LLVM IR fuzzer| aimed at finding bugs in instruction selection.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 This fuzzer accepts flags after `ignore_remaining_args=1`. The flags match
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 those of :doc:`llc <CommandGuide/llc>` and the triple is required. For example,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 the following command would fuzz AArch64 with :doc:`GlobalISel`:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 .. code-block:: shell
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 % bin/llvm-isel-fuzzer <corpus-dir> -ignore_remaining_args=1 -mtriple aarch64 -global-isel -O0
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 Some flags can also be specified in the binary name itself in order to support
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 OSS Fuzz, which has trouble with required arguments. To do this, you can copy
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 or move ``llvm-isel-fuzzer`` to ``llvm-isel-fuzzer--x-y-z``, separating options
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 from the binary name using "--". The valid options are architecture names
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 (``aarch64``, ``x86_64``), optimization levels (``O0``, ``O2``), or specific
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 keywords, like ``gisel`` for enabling global instruction selection. In this
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 mode, the same example could be run like so:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 .. code-block:: shell
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 % bin/llvm-isel-fuzzer--aarch64-O0-gisel <corpus-dir>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
103 llvm-opt-fuzzer
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
104 ---------------
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
105
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
106 A |LLVM IR fuzzer| aimed at finding bugs in optimization passes.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
107
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
108 It receives optimzation pipeline and runs it for each fuzzer input.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
109
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
110 Interface of this fuzzer almost directly mirrors ``llvm-isel-fuzzer``. Both
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
111 ``mtriple`` and ``passes`` arguments are required. Passes are specified in a
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
112 format suitable for the new pass manager.
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
113
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
114 .. code-block:: shell
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
115
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
116 % bin/llvm-opt-fuzzer <corpus-dir> -ignore_remaining_args=1 -mtriple x86_64 -passes instcombine
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
117
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
118 Similarly to the ``llvm-isel-fuzzer`` arguments in some predefined configurations
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
119 might be embedded directly into the binary file name:
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
120
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
121 .. code-block:: shell
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
122
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
123 % bin/llvm-opt-fuzzer--x86_64-instcombine <corpus-dir>
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
124
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 llvm-mc-assemble-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 -----------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 A |generic fuzzer| that fuzzes the MC layer's assemblers by treating inputs as
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 target specific assembly.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 Note that this fuzzer has an unusual command line interface which is not fully
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 compatible with all of libFuzzer's features. Fuzzer arguments must be passed
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 after ``--fuzzer-args``, and any ``llc`` flags must use two dashes. For
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 example, to fuzz the AArch64 assembler you might use the following command:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 .. code-block:: console
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 llvm-mc-fuzzer --triple=aarch64-linux-gnu --fuzzer-args -max_len=4
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 This scheme will likely change in the future.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 llvm-mc-disassemble-fuzzer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 --------------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 A |generic fuzzer| that fuzzes the MC layer's disassemblers by treating inputs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 as assembled binary data.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 Note that this fuzzer has an unusual command line interface which is not fully
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149 compatible with all of libFuzzer's features. See the notes above about
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 ``llvm-mc-assemble-fuzzer`` for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 .. |generic fuzzer| replace:: :ref:`generic fuzzer <fuzzing-llvm-generic>`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 .. |protobuf fuzzer|
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 replace:: :ref:`libprotobuf-mutator based fuzzer <fuzzing-llvm-protobuf>`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 .. |LLVM IR fuzzer|
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 replace:: :ref:`structured LLVM IR fuzzer <fuzzing-llvm-ir>`
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 Mutators and Input Generators
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 =============================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 The inputs for a fuzz target are generated via random mutations of a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 :ref:`corpus <libfuzzer-corpus>`. There are a few options for the kinds of
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 mutations that a fuzzer in LLVM might want.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 .. _fuzzing-llvm-generic:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 Generic Random Fuzzing
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 ----------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 The most basic form of input mutation is to use the built in mutators of
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 LibFuzzer. These simply treat the input corpus as a bag of bits and make random
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 mutations. This type of fuzzer is good for stressing the surface layers of a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 program, and is good at testing things like lexers, parsers, or binary
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176 protocols.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 Some of the in-tree fuzzers that use this type of mutator are `clang-fuzzer`_,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179 `clang-format-fuzzer`_, `llvm-as-fuzzer`_, `llvm-dwarfdump-fuzzer`_,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 `llvm-mc-assemble-fuzzer`_, and `llvm-mc-disassemble-fuzzer`_.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
182 .. _fuzzing-llvm-protobuf:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184 Structured Fuzzing using ``libprotobuf-mutator``
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185 ------------------------------------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187 We can use libprotobuf-mutator_ in order to perform structured fuzzing and
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188 stress deeper layers of programs. This works by defining a protobuf class that
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189 translates arbitrary data into structurally interesting input. Specifically, we
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190 use this to work with a subset of the C++ language and perform mutations that
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 produce valid C++ programs in order to exercise parts of clang that are more
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 interesting than parser error handling.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 To build this kind of fuzzer you need `protobuf`_ and its dependencies
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195 installed, and you need to specify some extra flags when configuring the build
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 with :doc:`CMake <CMake>`. For example, `clang-proto-fuzzer`_ can be enabled by
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197 adding ``-DCLANG_ENABLE_PROTO_FUZZER=ON`` to the flags described in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 :ref:`building-fuzzers`.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200 The only in-tree fuzzer that uses ``libprotobuf-mutator`` today is
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201 `clang-proto-fuzzer`_.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203 .. _libprotobuf-mutator: https://github.com/google/libprotobuf-mutator
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 .. _protobuf: https://github.com/google/protobuf
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 .. _fuzzing-llvm-ir:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 Structured Fuzzing of LLVM IR
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209 -----------------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211 We also use a more direct form of structured fuzzing for fuzzers that take
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212 :doc:`LLVM IR <LangRef>` as input. This is achieved through the ``FuzzMutate``
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213 library, which was `discussed at EuroLLVM 2017`_.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
215 The ``FuzzMutate`` library is used to structurally fuzz backends in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 `llvm-isel-fuzzer`_.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218 .. _discussed at EuroLLVM 2017: https://www.youtube.com/watch?v=UBbQ_s6hNgg
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
220
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
221 Building and Running
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 ====================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
223
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
224 .. _building-fuzzers:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
225
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
226 Configuring LLVM to Build Fuzzers
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
227 ---------------------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
228
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
229 Fuzzers will be built and linked to libFuzzer by default as long as you build
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
230 LLVM with sanitizer coverage enabled. You would typically also enable at least
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
231 one sanitizer to find bugs faster. The most common way to build the fuzzers is
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
232 by adding the following two flags to your CMake invocation:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
233 ``-DLLVM_USE_SANITIZER=Address -DLLVM_USE_SANITIZE_COVERAGE=On``.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
234
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
235 .. note:: If you have ``compiler-rt`` checked out in an LLVM tree when building
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
236 with sanitizers, you'll want to specify ``-DLLVM_BUILD_RUNTIME=Off``
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
237 to avoid building the sanitizers themselves with sanitizers enabled.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
238
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
239 Continuously Running and Finding Bugs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
240 -------------------------------------
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
241
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
242 There used to be a public buildbot running LLVM fuzzers continuously, and while
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
243 this did find issues, it didn't have a very good way to report problems in an
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
244 actionable way. Because of this, we're moving towards using `OSS Fuzz`_ more
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
245 instead.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
246
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
247 You can browse the `LLVM project issue list`_ for the bugs found by
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
248 `LLVM on OSS Fuzz`_. These are also mailed to the `llvm-bugs mailing
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
249 list`_.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
250
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
251 .. _OSS Fuzz: https://github.com/google/oss-fuzz
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
252 .. _LLVM project issue list:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
253 https://bugs.chromium.org/p/oss-fuzz/issues/list?q=Proj-llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
254 .. _LLVM on OSS Fuzz:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
255 https://github.com/google/oss-fuzz/blob/master/projects/llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
256 .. _llvm-bugs mailing list:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
257 http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
258
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
259
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
260 Utilities for Writing Fuzzers
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
261 =============================
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
262
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
263 There are some utilities available for writing fuzzers in LLVM.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
264
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
265 Some helpers for handling the command line interface are available in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
266 ``include/llvm/FuzzMutate/FuzzerCLI.h``, including functions to parse command
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
267 line options in a consistent way and to implement standalone main functions so
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
268 your fuzzer can be built and tested when not built against libFuzzer.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
269
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
270 There is also some handling of the CMake config for fuzzers, where you should
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
271 use the ``add_llvm_fuzzer`` to set up fuzzer targets. This function works
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
272 similarly to functions such as ``add_llvm_tool``, but they take care of linking
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
273 to LibFuzzer when appropriate and can be passed the ``DUMMY_MAIN`` argument to
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
274 enable standalone testing.