fix -fsanitize-coverage-trace-pc-guard and fuzzer support for C compile units

- allow `-fsanitize-coverage-trace-pc-guard` to be used on its own without enabling the fuzzer.
   (note that previouly, while the flag was only active when fuzzing, the fuzzer itself doesn't use it, and the code will not link as is.)

 - add stub functions in the fuzzer to link with instrumented C code (previously fuzzed tests failed to link if they were calling into C):
   while the zig compile unit uses a custom `EmitOptions.Coverage` with features disabled,
   the C code is built calling into the clang driver with "-fsanitize=fuzzer-no-link" that automatically enables the default features.
	(see de06978ebc/clang/lib/Driver/SanitizerArgs.cpp (L587))

 - emit `-fsanitize-coverage=trace-pc-guard` instead of `-Xclang -fsanitize-coverage-trace-pc-guard` so that edge coverrage is enabled by clang driver. (previously, it was enabled only because the fuzzer was)
This commit is contained in:
Xavier Bouchoux
2025-02-17 08:52:13 +01:00
committed by Alex Rønne Petersen
parent aa5c6c027c
commit 84ece5624a
3 changed files with 19 additions and 5 deletions

View File

@@ -83,6 +83,18 @@ export fn __sanitizer_cov_trace_pc_indir(callee: usize) void {
//fuzzer.traceValue(pc ^ callee);
//std.log.debug("0x{x}: indirect call to 0x{x}", .{ pc, callee });
}
export fn __sanitizer_cov_8bit_counters_init(start: usize, end: usize) void {
// clang will emit a call to this function when compiling with code coverage instrumentation.
// however fuzzer_init() does not need this information, since it directly reads from the symbol table.
_ = start;
_ = end;
}
export fn __sanitizer_cov_pcs_init(start: usize, end: usize) void {
// clang will emit a call to this function when compiling with code coverage instrumentation.
// however fuzzer_init() does not need this information, since it directly reads from the symbol table.
_ = start;
_ = end;
}
fn handleCmp(pc: usize, arg1: u64, arg2: u64) void {
fuzzer.traceValue(pc ^ arg1 ^ arg2);