authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-09 21:16:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-11 13:41:29-07:00
log2d005827b874f27535cda72c80b6558d9d4cd30c
tree9080004df76b836ff98416e1779bdcd85677ffd9
parent0cdccff51912359b7ec5afa57fbbd5bb69d8f3a2

make lowest stack an internal libfuzzer detail

This value is useful to help determine run uniqueness in the face of recursion, however it is not valuable to expose to the fuzzing UI.

6 files changed, 3 insertions(+), 17 deletions(-)

lib/fuzzer.zig+3-3
...@@ -28,7 +28,8 @@ fn logOverride(...@@ -28,7 +28,8 @@ fn logOverride(
28 f.writer().print(prefix1 ++ prefix2 ++ format ++ "\n", args) catch @panic("failed to write to fuzzer log");28 f.writer().print(prefix1 ++ prefix2 ++ format ++ "\n", args) catch @panic("failed to write to fuzzer log");
29}29}
3030
31export threadlocal var __sancov_lowest_stack: usize = std.math.maxInt(usize);31/// Helps determine run uniqueness in the face of recursion.
32export threadlocal var __sancov_lowest_stack: usize = 0;
3233
33export fn __sanitizer_cov_trace_const_cmp1(arg1: u8, arg2: u8) void {34export fn __sanitizer_cov_trace_const_cmp1(arg1: u8, arg2: u8) void {
34 handleCmp(@returnAddress(), arg1, arg2);35 handleCmp(@returnAddress(), arg1, arg2);
...@@ -220,7 +221,6 @@ const Fuzzer = struct {...@@ -220,7 +221,6 @@ const Fuzzer = struct {
220 .n_runs = 0,221 .n_runs = 0,
221 .unique_runs = 0,222 .unique_runs = 0,
222 .pcs_len = pcs.len,223 .pcs_len = pcs.len,
223 .lowest_stack = std.math.maxInt(usize),
224 };224 };
225 f.seen_pcs.appendSliceAssumeCapacity(std.mem.asBytes(&header));225 f.seen_pcs.appendSliceAssumeCapacity(std.mem.asBytes(&header));
226 f.seen_pcs.appendNTimesAssumeCapacity(0, n_bitset_elems * @sizeOf(usize));226 f.seen_pcs.appendNTimesAssumeCapacity(0, n_bitset_elems * @sizeOf(usize));
...@@ -261,8 +261,8 @@ const Fuzzer = struct {...@@ -261,8 +261,8 @@ const Fuzzer = struct {
261 f.input.appendSliceAssumeCapacity(run.input);261 f.input.appendSliceAssumeCapacity(run.input);
262 try f.mutate();262 try f.mutate();
263263
264 _ = @atomicRmw(usize, &header.lowest_stack, .Min, __sancov_lowest_stack, .monotonic);
265 @memset(f.pc_counters, 0);264 @memset(f.pc_counters, 0);
265 __sancov_lowest_stack = std.math.maxInt(usize);
266 f.coverage.reset();266 f.coverage.reset();
267267
268 fuzzer_one(f.input.items.ptr, f.input.items.len);268 fuzzer_one(f.input.items.ptr, f.input.items.len);
lib/fuzzer/web/index.html-1
...@@ -147,7 +147,6 @@...@@ -147,7 +147,6 @@
147 <li>Total Runs: <span id="statTotalRuns"></span></li>147 <li>Total Runs: <span id="statTotalRuns"></span></li>
148 <li>Unique Runs: <span id="statUniqueRuns"></span></li>148 <li>Unique Runs: <span id="statUniqueRuns"></span></li>
149 <li>Coverage: <span id="statCoverage"></span></li>149 <li>Coverage: <span id="statCoverage"></span></li>
150 <li>Lowest Stack: <span id="statLowestStack"></span></li>
151 <li>Entry Points: <ul id="entryPointsList"></ul></li>150 <li>Entry Points: <ul id="entryPointsList"></ul></li>
152 </ul>151 </ul>
153 </div>152 </div>
lib/fuzzer/web/main.js-2
...@@ -6,7 +6,6 @@...@@ -6,7 +6,6 @@
6 const domStatTotalRuns = document.getElementById("statTotalRuns");6 const domStatTotalRuns = document.getElementById("statTotalRuns");
7 const domStatUniqueRuns = document.getElementById("statUniqueRuns");7 const domStatUniqueRuns = document.getElementById("statUniqueRuns");
8 const domStatCoverage = document.getElementById("statCoverage");8 const domStatCoverage = document.getElementById("statCoverage");
9 const domStatLowestStack = document.getElementById("statLowestStack");
10 const domEntryPointsList = document.getElementById("entryPointsList");9 const domEntryPointsList = document.getElementById("entryPointsList");
1110
12 let wasm_promise = fetch("main.wasm");11 let wasm_promise = fetch("main.wasm");
...@@ -158,7 +157,6 @@...@@ -158,7 +157,6 @@
158 domStatTotalRuns.innerText = totalRuns;157 domStatTotalRuns.innerText = totalRuns;
159 domStatUniqueRuns.innerText = uniqueRuns + " (" + percent(uniqueRuns, totalRuns) + "%)";158 domStatUniqueRuns.innerText = uniqueRuns + " (" + percent(uniqueRuns, totalRuns) + "%)";
160 domStatCoverage.innerText = coveredSourceLocations + " / " + totalSourceLocations + " (" + percent(coveredSourceLocations, totalSourceLocations) + "%)";159 domStatCoverage.innerText = coveredSourceLocations + " / " + totalSourceLocations + " (" + percent(coveredSourceLocations, totalSourceLocations) + "%)";
161 domStatLowestStack.innerText = unwrapString(wasm_exports.lowestStack());
162160
163 const entryPoints = unwrapInt32Array(wasm_exports.entryPoints());161 const entryPoints = unwrapInt32Array(wasm_exports.entryPoints());
164 resizeDomList(domEntryPointsList, entryPoints.length, "<li></li>");162 resizeDomList(domEntryPointsList, entryPoints.length, "<li></li>");
lib/fuzzer/web/main.zig-7
...@@ -106,13 +106,6 @@ export fn decl_source_html(decl_index: Decl.Index) String {...@@ -106,13 +106,6 @@ export fn decl_source_html(decl_index: Decl.Index) String {
106 return String.init(string_result.items);106 return String.init(string_result.items);
107}107}
108108
109export fn lowestStack() String {
110 const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]);
111 string_result.clearRetainingCapacity();
112 string_result.writer(gpa).print("0x{d}", .{header.lowest_stack}) catch @panic("OOM");
113 return String.init(string_result.items);
114}
115
116export fn totalSourceLocations() usize {109export fn totalSourceLocations() usize {
117 return coverage_source_locations.items.len;110 return coverage_source_locations.items.len;
118}111}
lib/std/Build/Fuzz/WebServer.zig-2
...@@ -406,7 +406,6 @@ fn sendCoverageContext(...@@ -406,7 +406,6 @@ fn sendCoverageContext(
406 const seen_pcs = cov_header.seenBits();406 const seen_pcs = cov_header.seenBits();
407 const n_runs = @atomicLoad(usize, &cov_header.n_runs, .monotonic);407 const n_runs = @atomicLoad(usize, &cov_header.n_runs, .monotonic);
408 const unique_runs = @atomicLoad(usize, &cov_header.unique_runs, .monotonic);408 const unique_runs = @atomicLoad(usize, &cov_header.unique_runs, .monotonic);
409 const lowest_stack = @atomicLoad(usize, &cov_header.lowest_stack, .monotonic);
410 if (prev_unique_runs.* != unique_runs) {409 if (prev_unique_runs.* != unique_runs) {
411 // There has been an update.410 // There has been an update.
412 if (prev_unique_runs.* == 0) {411 if (prev_unique_runs.* == 0) {
...@@ -431,7 +430,6 @@ fn sendCoverageContext(...@@ -431,7 +430,6 @@ fn sendCoverageContext(
431 const header: abi.CoverageUpdateHeader = .{430 const header: abi.CoverageUpdateHeader = .{
432 .n_runs = n_runs,431 .n_runs = n_runs,
433 .unique_runs = unique_runs,432 .unique_runs = unique_runs,
434 .lowest_stack = lowest_stack,
435 };433 };
436 const iovecs: [2]std.posix.iovec_const = .{434 const iovecs: [2]std.posix.iovec_const = .{
437 makeIov(std.mem.asBytes(&header)),435 makeIov(std.mem.asBytes(&header)),
lib/std/Build/Fuzz/abi.zig-2
...@@ -13,7 +13,6 @@ pub const SeenPcsHeader = extern struct {...@@ -13,7 +13,6 @@ pub const SeenPcsHeader = extern struct {
13 n_runs: usize,13 n_runs: usize,
14 unique_runs: usize,14 unique_runs: usize,
15 pcs_len: usize,15 pcs_len: usize,
16 lowest_stack: usize,
1716
18 /// Used for comptime assertions. Provides a mechanism for strategically17 /// Used for comptime assertions. Provides a mechanism for strategically
19 /// causing compile errors.18 /// causing compile errors.
...@@ -79,7 +78,6 @@ pub const CoverageUpdateHeader = extern struct {...@@ -79,7 +78,6 @@ pub const CoverageUpdateHeader = extern struct {
79 flags: Flags = .{},78 flags: Flags = .{},
80 n_runs: u64,79 n_runs: u64,
81 unique_runs: u64,80 unique_runs: u64,
82 lowest_stack: u64,
8381
84 pub const Flags = packed struct(u64) {82 pub const Flags = packed struct(u64) {
85 tag: ToClientTag = .coverage_update,83 tag: ToClientTag = .coverage_update,