diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-23 11:39:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-23 11:39:19 -0700 |
| commit | 6f3e9939d0389539570d4a7cad95b1e96bc8f0d4 (patch) | |
| tree | abf951c8dc19393655df93f23a6911ce6fad660d /src/zig_llvm.cpp | |
| parent | 255547d7a6a1acee9c9b65d251ec4935433b6878 (diff) | |
| parent | 61ad1be6bd7d27f79773e7da891898449a45a80e (diff) | |
| download | zig-6f3e9939d0389539570d4a7cad95b1e96bc8f0d4.tar.gz zig-6f3e9939d0389539570d4a7cad95b1e96bc8f0d4.zip | |
Merge pull request #20725 from ziglang/fuzz
initial support for integrated fuzzing
Diffstat (limited to 'src/zig_llvm.cpp')
| -rw-r--r-- | src/zig_llvm.cpp | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 72f1026617..5580b61367 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -54,6 +54,7 @@ #include <llvm/Transforms/IPO.h> #include <llvm/Transforms/IPO/AlwaysInliner.h> #include <llvm/Transforms/Instrumentation/ThreadSanitizer.h> +#include <llvm/Transforms/Instrumentation/SanitizerCoverage.h> #include <llvm/Transforms/Scalar.h> #include <llvm/Transforms/Utils.h> #include <llvm/Transforms/Utils/AddDiscriminators.h> @@ -188,9 +189,31 @@ struct TimeTracerRAII { }; } // end anonymous namespace +static SanitizerCoverageOptions getSanCovOptions(void) { + SanitizerCoverageOptions o; + o.CoverageType = SanitizerCoverageOptions::SCK_Edge; + o.IndirectCalls = true; + o.TraceBB = false; + o.TraceCmp = true; + o.TraceDiv = false; + o.TraceGep = false; + o.Use8bitCounters = false; + o.TracePC = false; + o.TracePCGuard = false; + o.Inline8bitCounters = true; + o.InlineBoolFlag = false; + o.PCTable = true; + o.NoPrune = false; + o.StackDepth = true; + o.TraceLoads = false; + o.TraceStores = false; + o.CollectControlFlow = false; + return o; +} + bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, char **error_message, bool is_debug, - bool is_small, bool time_report, bool tsan, bool lto, + bool is_small, bool time_report, bool tsan, bool sancov, bool lto, const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename, const char *bitcode_filename) { @@ -277,39 +300,38 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM pass_builder.registerCGSCCAnalyses(cgscc_am); pass_builder.registerFunctionAnalyses(function_am); pass_builder.registerLoopAnalyses(loop_am); - pass_builder.crossRegisterProxies(loop_am, function_am, - cgscc_am, module_am); - - // IR verification - if (assertions_on) { - // Verify the input - pass_builder.registerPipelineStartEPCallback( - [](ModulePassManager &module_pm, OptimizationLevel OL) { - module_pm.addPass(VerifierPass()); - }); - // Verify the output - pass_builder.registerOptimizerLastEPCallback( - [](ModulePassManager &module_pm, OptimizationLevel OL) { - module_pm.addPass(VerifierPass()); - }); - } + pass_builder.crossRegisterProxies(loop_am, function_am, cgscc_am, module_am); - // Passes specific for release build - if (!is_debug) { - pass_builder.registerPipelineStartEPCallback( - [](ModulePassManager &module_pm, OptimizationLevel OL) { - module_pm.addPass( - createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); - }); - } + pass_builder.registerPipelineStartEPCallback([&](ModulePassManager &module_pm, OptimizationLevel OL) { + // Verify the input + if (assertions_on) { + module_pm.addPass(VerifierPass()); + } + + if (!is_debug) { + module_pm.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); + } + }); + + pass_builder.registerOptimizerEarlyEPCallback([&](ModulePassManager &module_pm, OptimizationLevel OL) { + // Code coverage instrumentation. + if (sancov) { + module_pm.addPass(SanitizerCoveragePass(getSanCovOptions())); + } - // Thread sanitizer - if (tsan) { - pass_builder.registerOptimizerLastEPCallback([](ModulePassManager &module_pm, OptimizationLevel level) { + // Thread sanitizer + if (tsan) { module_pm.addPass(ModuleThreadSanitizerPass()); module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); - }); - } + } + }); + + pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) { + // Verify the output + if (assertions_on) { + module_pm.addPass(VerifierPass()); + } + }); ModulePassManager module_pm; OptimizationLevel opt_level; |
