llvm.org GIT mirror llvm / 5de6370
[gn build] Add fuzzers in llvm/tools that are needed for check-llvm Also add a fuzzer() template for defining fuzzers that's similar to add_llvm_fuzzer in the CMake build, and a build file for dependency llvm/lib/FuzzMutate. Also make `assert(defined(...` error strings a bit more self-consistent. Differential Revision: https://reviews.llvm.org/D56194 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350238 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 9 months ago
7 changed file(s) with 128 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
0 # This file introduces a templates for defining fuzzers.
1 #
2 # All parameters valid for executable() targets are valid (cflags, defines,
3 # deps, include_dirs, sources, ...). In addition to that:
4 #
5 # dummy_main (required)
6 # Path to a cpp file containing main(), used when neither
7 # llvm_use_sanitize_coverage nor llvm_use_sanitize_coverage are set.
8 #
9 # Example of usage:
10 #
11 # fuzzer("llvm-opt-fuzzer") {
12 # deps = [ ... ]
13 # dummy_main = "DummyOptFuzzer.cpp"
14 # sources = [ "llvm-opt-fuzzer.cpp" ]
15 # }
16
17 declare_args() {
18 # Set to the path of a static library containing a fuzzing engine, e.g.
19 # oss-fuzz's $LIB_FUZZING_ENGINE.
20 llvm_lib_fuzzing_engine = ""
21
22 # If true, pass -fsanitize=fuzzer to the compiler for fuzzer() targets.
23 # Likely only makes sense to set if you know that the host compiler is clang.
24 llvm_use_sanitize_coverage = false
25 }
26
27 template("fuzzer") {
28 assert(defined(invoker.dummy_main), "must set 'dummy_main' in $target_name")
29 assert(defined(invoker.sources), "must set 'sources' for $target_name")
30 executable(target_name) {
31 forward_variables_from(invoker, "*", [ "dummy_main" ])
32 if (llvm_lib_fuzzing_engine != "") {
33 if (!defined(libs)) {
34 libs = []
35 }
36 libs += [ llvm_lib_fuzzing_engine ]
37 not_needed(invoker, [ "dummy_main" ])
38 } else if (llvm_use_sanitize_coverage) {
39 if (!defined(cflags)) {
40 cflags = []
41 }
42 cflags += [ "-fsanitize=fuzzer" ]
43 not_needed(invoker, [ "dummy_main" ])
44 } else {
45 sources += [ invoker.dummy_main ]
46 }
47 }
48 }
1919 "//llvm/tools/llvm-dwp",
2020 "//llvm/tools/llvm-exegesis",
2121 "//llvm/tools/llvm-extract",
22 "//llvm/tools/llvm-isel-fuzzer",
2223 "//llvm/tools/llvm-link",
2324 "//llvm/tools/llvm-mca",
2425 "//llvm/tools/llvm-mt",
26 "//llvm/tools/llvm-opt-fuzzer",
2527 "//llvm/tools/llvm-opt-report",
2628 "//llvm/tools/llvm-rc",
2729 "//llvm/tools/llvm-rtdyld",
369369 # .def files used by llvm/lib/Target
370370
371371 template("write_target_def_file") {
372 assert(defined(invoker.key), "callers must set key")
373 assert(defined(invoker.value), "callers must set value")
372 assert(defined(invoker.key), "must set 'key' in $target_name")
373 assert(defined(invoker.value), "must set 'value' in $target_name")
374374
375375 action(target_name) {
376376 visibility = [ ":write_target_def_files" ]
0 static_library("FuzzMutate") {
1 output_name = "LLVMFuzzMutate"
2 deps = [
3 "//llvm/lib/Analysis",
4 "//llvm/lib/Bitcode/Reader",
5 "//llvm/lib/Bitcode/Writer",
6 "//llvm/lib/IR",
7 "//llvm/lib/Support",
8 "//llvm/lib/Target",
9 "//llvm/lib/Transforms/Scalar",
10 ]
11 sources = [
12 "FuzzerCLI.cpp",
13 "IRMutator.cpp",
14 "OpDescriptor.cpp",
15 "Operations.cpp",
16 "RandomIRBuilder.cpp",
17 ]
18 }
0 import("//llvm/utils/gn/build/fuzzer.gni")
1
2 fuzzer("llvm-isel-fuzzer") {
3 deps = [
4 "//llvm/lib/Analysis",
5 "//llvm/lib/Bitcode/Reader",
6 "//llvm/lib/Bitcode/Writer",
7 "//llvm/lib/CodeGen",
8 "//llvm/lib/CodeGen/AsmPrinter",
9 "//llvm/lib/CodeGen/SelectionDAG",
10 "//llvm/lib/FuzzMutate",
11 "//llvm/lib/IR",
12 "//llvm/lib/IRReader",
13 "//llvm/lib/MC",
14 "//llvm/lib/Support",
15 "//llvm/lib/Target",
16 "//llvm/lib/Target:TargetsToBuild",
17 "//llvm/lib/Transforms/Scalar",
18 ]
19 dummy_main = "DummyISelFuzzer.cpp"
20 sources = [
21 "llvm-isel-fuzzer.cpp",
22 ]
23 }
0 import("//llvm/utils/gn/build/fuzzer.gni")
1
2 fuzzer("llvm-opt-fuzzer") {
3 deps = [
4 "//llvm/lib/Analysis",
5 "//llvm/lib/Bitcode/Reader",
6 "//llvm/lib/Bitcode/Writer",
7 "//llvm/lib/CodeGen",
8 "//llvm/lib/FuzzMutate",
9 "//llvm/lib/IR",
10 "//llvm/lib/IRReader",
11 "//llvm/lib/MC",
12 "//llvm/lib/Passes",
13 "//llvm/lib/Support",
14 "//llvm/lib/Target",
15 "//llvm/lib/Target:TargetsToBuild",
16 "//llvm/lib/Transforms/AggressiveInstCombine",
17 "//llvm/lib/Transforms/Coroutines",
18 "//llvm/lib/Transforms/IPO",
19 "//llvm/lib/Transforms/InstCombine",
20 "//llvm/lib/Transforms/Instrumentation",
21 "//llvm/lib/Transforms/ObjCARC",
22 "//llvm/lib/Transforms/Scalar",
23 "//llvm/lib/Transforms/Utils",
24 "//llvm/lib/Transforms/Vectorize",
25 ]
26 dummy_main = "DummyOptFuzzer.cpp"
27 sources = [
28 "llvm-opt-fuzzer.cpp",
29 ]
30 }
2424 # }
2525
2626 template("tablegen") {
27 assert(defined(invoker.args), "args must be defined for $target_name")
27 assert(defined(invoker.args), "must set 'args' in $target_name")
2828
2929 config_name = "${target_name}_config"
3030 config(config_name) {