authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-28 14:36:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-28 18:07:13-07:00
log88bba4c15463796c0b89a4d097366b11bdb7679c
tree7d2ce0cb17531525470f110fc6a5516ea1da65a3
parentb8d99a332395ec0a1b9ed1a8e18f0db8db131b3c

LLVM: enable sancov pass partially

It's useful to have TraceCmp based on the results of LLVM optimizations, while the code coverage bits were emitted by Zig manually, allowing more careful correlation to points of interest in the source code. This re-enables the sancov pass in `-ffuzz` mode, but only TraceCmp. Notably, IndirectCalls is off, which needs to be implemented manually in the LLVM backend, and StackDepth remains off, because it is not used by libfuzzer or AFL either. If stack depth is re-introduced, it can be done with better performance characteristics by being function call graph aware, and only lowered in call graph cycles, where its heuristic properties come in useful. Fixes the fuzzing regression.

1 files changed, 7 insertions(+), 6 deletions(-)

src/codegen/llvm.zig+7-6
......@@ -1275,7 +1275,7 @@ pub const Object = struct {
12751275 .is_small = options.is_small,
12761276 .time_report = options.time_report,
12771277 .tsan = options.sanitize_thread,
1278 .sancov = sanCovPassEnabled(comp.config.san_cov_trace_pc_guard),
1278 .sancov = options.fuzz,
12791279 .lto = options.lto,
12801280 .asm_filename = null,
12811281 .bin_filename = options.bin_path,
......@@ -1283,16 +1283,21 @@ pub const Object = struct {
12831283 .bitcode_filename = null,
12841284 .coverage = .{
12851285 .CoverageType = .Edge,
1286 // Works in tandem with Inline8bitCounters or InlineBoolFlag.
1287 // Zig does not yet implement its own version of this but it
1288 // needs to for better fuzzing logic.
12861289 .IndirectCalls = false,
12871290 .TraceBB = false,
1288 .TraceCmp = false,
1291 .TraceCmp = true,
12891292 .TraceDiv = false,
12901293 .TraceGep = false,
12911294 .Use8bitCounters = false,
12921295 .TracePC = false,
12931296 .TracePCGuard = comp.config.san_cov_trace_pc_guard,
1297 // Zig emits its own inline 8-bit counters instrumentation.
12941298 .Inline8bitCounters = false,
12951299 .InlineBoolFlag = false,
1300 // Zig emits its own PC table instrumentation.
12961301 .PCTable = false,
12971302 .NoPrune = false,
12981303 .StackDepth = false,
......@@ -12273,7 +12278,3 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
1227312278 => unreachable,
1227412279 }
1227512280}
12276
12277fn sanCovPassEnabled(trace_pc_guard: bool) bool {
12278 return trace_pc_guard;
12279}