Index: llvm/trunk/utils/gn/build/fuzzer.gni =================================================================== --- llvm/trunk/utils/gn/build/fuzzer.gni +++ llvm/trunk/utils/gn/build/fuzzer.gni @@ -0,0 +1,49 @@ +# This file introduces a templates for defining fuzzers. +# +# All parameters valid for executable() targets are valid (cflags, defines, +# deps, include_dirs, sources, ...). In addition to that: +# +# dummy_main (required) +# Path to a cpp file containing main(), used when neither +# llvm_use_sanitize_coverage nor llvm_use_sanitize_coverage are set. +# +# Example of usage: +# +# fuzzer("llvm-opt-fuzzer") { +# deps = [ ... ] +# dummy_main = "DummyOptFuzzer.cpp" +# sources = [ "llvm-opt-fuzzer.cpp" ] +# } + +declare_args() { + # Set to the path of a static library containing a fuzzing engine, e.g. + # oss-fuzz's $LIB_FUZZING_ENGINE. + llvm_lib_fuzzing_engine = "" + + # If true, pass -fsanitize=fuzzer to the compiler for fuzzer() targets. + # Likely only makes sense to set if you know that the host compiler is clang. + llvm_use_sanitize_coverage = false +} + +template("fuzzer") { + assert(defined(invoker.dummy_main), "must set 'dummy_main' in $target_name") + assert(defined(invoker.sources), "must set 'sources' for $target_name") + executable(target_name) { + forward_variables_from(invoker, "*", [ "dummy_main" ]) + if (llvm_lib_fuzzing_engine != "") { + if (!defined(libs)) { + libs = [] + } + libs += [ llvm_lib_fuzzing_engine ] + not_needed(invoker, [ "dummy_main" ]) + } else if (llvm_use_sanitize_coverage) { + if (!defined(cflags)) { + cflags = [] + } + cflags += [ "-fsanitize=fuzzer" ] + not_needed(invoker, [ "dummy_main" ]) + } else { + sources += [ invoker.dummy_main ] + } + } +} Index: llvm/trunk/utils/gn/secondary/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/BUILD.gn +++ llvm/trunk/utils/gn/secondary/BUILD.gn @@ -20,9 +20,11 @@ "//llvm/tools/llvm-dwp", "//llvm/tools/llvm-exegesis", "//llvm/tools/llvm-extract", + "//llvm/tools/llvm-isel-fuzzer", "//llvm/tools/llvm-link", "//llvm/tools/llvm-mca", "//llvm/tools/llvm-mt", + "//llvm/tools/llvm-opt-fuzzer", "//llvm/tools/llvm-opt-report", "//llvm/tools/llvm-rc", "//llvm/tools/llvm-rtdyld", Index: llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn +++ llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn @@ -370,8 +370,8 @@ # .def files used by llvm/lib/Target template("write_target_def_file") { - assert(defined(invoker.key), "callers must set key") - assert(defined(invoker.value), "callers must set value") + assert(defined(invoker.key), "must set 'key' in $target_name") + assert(defined(invoker.value), "must set 'value' in $target_name") action(target_name) { visibility = [ ":write_target_def_files" ] Index: llvm/trunk/utils/gn/secondary/llvm/lib/FuzzMutate/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/lib/FuzzMutate/BUILD.gn +++ llvm/trunk/utils/gn/secondary/llvm/lib/FuzzMutate/BUILD.gn @@ -0,0 +1,19 @@ +static_library("FuzzMutate") { + output_name = "LLVMFuzzMutate" + deps = [ + "//llvm/lib/Analysis", + "//llvm/lib/Bitcode/Reader", + "//llvm/lib/Bitcode/Writer", + "//llvm/lib/IR", + "//llvm/lib/Support", + "//llvm/lib/Target", + "//llvm/lib/Transforms/Scalar", + ] + sources = [ + "FuzzerCLI.cpp", + "IRMutator.cpp", + "OpDescriptor.cpp", + "Operations.cpp", + "RandomIRBuilder.cpp", + ] +} Index: llvm/trunk/utils/gn/secondary/llvm/tools/llvm-isel-fuzzer/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/tools/llvm-isel-fuzzer/BUILD.gn +++ llvm/trunk/utils/gn/secondary/llvm/tools/llvm-isel-fuzzer/BUILD.gn @@ -0,0 +1,24 @@ +import("//llvm/utils/gn/build/fuzzer.gni") + +fuzzer("llvm-isel-fuzzer") { + deps = [ + "//llvm/lib/Analysis", + "//llvm/lib/Bitcode/Reader", + "//llvm/lib/Bitcode/Writer", + "//llvm/lib/CodeGen", + "//llvm/lib/CodeGen/AsmPrinter", + "//llvm/lib/CodeGen/SelectionDAG", + "//llvm/lib/FuzzMutate", + "//llvm/lib/IR", + "//llvm/lib/IRReader", + "//llvm/lib/MC", + "//llvm/lib/Support", + "//llvm/lib/Target", + "//llvm/lib/Target:TargetsToBuild", + "//llvm/lib/Transforms/Scalar", + ] + dummy_main = "DummyISelFuzzer.cpp" + sources = [ + "llvm-isel-fuzzer.cpp", + ] +} Index: llvm/trunk/utils/gn/secondary/llvm/tools/llvm-opt-fuzzer/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/tools/llvm-opt-fuzzer/BUILD.gn +++ llvm/trunk/utils/gn/secondary/llvm/tools/llvm-opt-fuzzer/BUILD.gn @@ -0,0 +1,31 @@ +import("//llvm/utils/gn/build/fuzzer.gni") + +fuzzer("llvm-opt-fuzzer") { + deps = [ + "//llvm/lib/Analysis", + "//llvm/lib/Bitcode/Reader", + "//llvm/lib/Bitcode/Writer", + "//llvm/lib/CodeGen", + "//llvm/lib/FuzzMutate", + "//llvm/lib/IR", + "//llvm/lib/IRReader", + "//llvm/lib/MC", + "//llvm/lib/Passes", + "//llvm/lib/Support", + "//llvm/lib/Target", + "//llvm/lib/Target:TargetsToBuild", + "//llvm/lib/Transforms/AggressiveInstCombine", + "//llvm/lib/Transforms/Coroutines", + "//llvm/lib/Transforms/IPO", + "//llvm/lib/Transforms/InstCombine", + "//llvm/lib/Transforms/Instrumentation", + "//llvm/lib/Transforms/ObjCARC", + "//llvm/lib/Transforms/Scalar", + "//llvm/lib/Transforms/Utils", + "//llvm/lib/Transforms/Vectorize", + ] + dummy_main = "DummyOptFuzzer.cpp" + sources = [ + "llvm-opt-fuzzer.cpp", + ] +} Index: llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni +++ llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni @@ -25,7 +25,7 @@ # } template("tablegen") { - assert(defined(invoker.args), "args must be defined for $target_name") + assert(defined(invoker.args), "must set 'args' in $target_name") config_name = "${target_name}_config" config(config_name) {