diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-08-28 23:20:21 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-28 23:20:21 -0700 |
| commit | e9a00ba7f4ef2546cd0c98559002431c749374fe (patch) | |
| tree | 18102a8fd19ea54f1049ba6a0be522391a2bb7c7 /lib/std/Build | |
| parent | 6a21875ddbe0f509122fbd220f1abb015cc7bac7 (diff) | |
| parent | 13b5cee4cce2be7b5d1423fcd59b00ff1807142e (diff) | |
| download | zig-e9a00ba7f4ef2546cd0c98559002431c749374fe.tar.gz zig-e9a00ba7f4ef2546cd0c98559002431c749374fe.zip | |
Merge pull request #21236 from ziglang/fuzz
exclude unreachable code paths from having coverage instrumentation
Diffstat (limited to 'lib/std/Build')
| -rw-r--r-- | lib/std/Build/Fuzz/WebServer.zig | 17 | ||||
| -rw-r--r-- | lib/std/Build/Step/Compile.zig | 16 |
2 files changed, 22 insertions, 11 deletions
diff --git a/lib/std/Build/Fuzz/WebServer.zig b/lib/std/Build/Fuzz/WebServer.zig index 26b25b83d9..a0ab018cf5 100644 --- a/lib/std/Build/Fuzz/WebServer.zig +++ b/lib/std/Build/Fuzz/WebServer.zig @@ -664,11 +664,16 @@ fn addEntryPoint(ws: *WebServer, coverage_id: u64, addr: u64) error{ AlreadyRepo const coverage_map = ws.coverage_files.getPtr(coverage_id).?; const header: *const abi.SeenPcsHeader = @ptrCast(coverage_map.mapped_memory[0..@sizeOf(abi.SeenPcsHeader)]); const pcs = header.pcAddrs(); - const index = std.sort.upperBound(usize, pcs, addr, struct { - fn order(context: usize, item: usize) std.math.Order { - return std.math.order(item, context); + // Since this pcs list is unsorted, we must linear scan for the best index. + const index = i: { + var best: usize = 0; + for (pcs[1..], 1..) |elem_addr, i| { + if (elem_addr == addr) break :i i; + if (elem_addr > addr) continue; + if (elem_addr > pcs[best]) best = i; } - }.order); + break :i best; + }; if (index >= pcs.len) { log.err("unable to find unit test entry address 0x{x} in source locations (range: 0x{x} to 0x{x})", .{ addr, pcs[0], pcs[pcs.len - 1], @@ -678,8 +683,8 @@ fn addEntryPoint(ws: *WebServer, coverage_id: u64, addr: u64) error{ AlreadyRepo if (false) { const sl = coverage_map.source_locations[index]; const file_name = coverage_map.coverage.stringAt(coverage_map.coverage.fileAt(sl.file).basename); - log.debug("server found entry point for 0x{x} at {s}:{d}:{d}", .{ - addr, file_name, sl.line, sl.column, + log.debug("server found entry point for 0x{x} at {s}:{d}:{d} - index {d} between {x} and {x}", .{ + addr, file_name, sl.line, sl.column, index, pcs[index - 1], pcs[index + 1], }); } const gpa = ws.gpa; diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 1aeebbb55b..922d64c728 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -218,12 +218,18 @@ no_builtin: bool = false, /// Managed by the build runner, not user build script. zig_process: ?*Step.ZigProcess, -/// Enables deprecated coverage instrumentation that is only useful if you -/// are using third party fuzzers that depend on it. Otherwise, slows down -/// the instrumented binary with unnecessary function calls. +/// Enables coverage instrumentation that is only useful if you are using third +/// party fuzzers that depend on it. Otherwise, slows down the instrumented +/// binary with unnecessary function calls. /// -/// To enable fuzz testing instrumentation on a compilation, see the `fuzz` -/// flag in `Module`. +/// This kind of coverage instrumentation is used by AFLplusplus v4.21c, +/// however, modern fuzzers - including Zig - have switched to using "inline +/// 8-bit counters" or "inline bool flag" which incurs only a single +/// instruction for coverage, along with "trace cmp" which instruments +/// comparisons and reports the operands. +/// +/// To instead enable fuzz testing instrumentation on a compilation using Zig's +/// builtin fuzzer, see the `fuzz` flag in `Module`. sanitize_coverage_trace_pc_guard: ?bool = null, pub const ExpectedCompileErrors = union(enum) { |
