1# This file introduces a templates for defining fuzzers. 2# 3# All parameters valid for executable() targets are valid (cflags, defines, 4# deps, include_dirs, sources, ...). In addition to that: 5# 6# dummy_main (required) 7# Path to a cpp file containing main(), used when neither 8# llvm_use_sanitize_coverage nor llvm_use_sanitize_coverage are set. 9# 10# Example of usage: 11# 12# fuzzer("llvm-opt-fuzzer") { 13# deps = [ ... ] 14# dummy_main = "DummyOptFuzzer.cpp" 15# sources = [ "llvm-opt-fuzzer.cpp" ] 16# } 17 18declare_args() { 19 # Set to the path of a static library containing a fuzzing engine, e.g. 20 # oss-fuzz's $LIB_FUZZING_ENGINE. 21 llvm_lib_fuzzing_engine = "" 22 23 # If true, pass -fsanitize=fuzzer to the compiler for fuzzer() targets. 24 # Likely only makes sense to set if you know that the host compiler is clang. 25 llvm_use_sanitize_coverage = false 26} 27 28template("fuzzer") { 29 assert(defined(invoker.dummy_main), "must set 'dummy_main' in $target_name") 30 assert(defined(invoker.sources), "must set 'sources' for $target_name") 31 executable(target_name) { 32 forward_variables_from(invoker, "*", [ "dummy_main" ]) 33 if (llvm_lib_fuzzing_engine != "") { 34 if (!defined(libs)) { 35 libs = [] 36 } 37 libs += [ llvm_lib_fuzzing_engine ] 38 not_needed(invoker, [ "dummy_main" ]) 39 } else if (llvm_use_sanitize_coverage) { 40 if (!defined(cflags)) { 41 cflags = [] 42 } 43 cflags += [ "-fsanitize=fuzzer" ] 44 not_needed(invoker, [ "dummy_main" ]) 45 } else { 46 sources += [ invoker.dummy_main ] 47 } 48 } 49} 50