Coverage Analysis
Coverage analysis is essential for understanding which parts of your code are exercised during fuzzing. It helps identify fuzzing blockers like magic value checks and tracks the effectiveness of harness improvements over time.
Overview
Code coverage during fuzzing serves two critical purposes:
- Assessing harness effectiveness: Understand which parts of your application are actually executed by your fuzzing harnesses
- Tracking fuzzing progress: Monitor how coverage changes when updating harnesses, fuzzers, or the system under test (SUT)
Coverage is a proxy for fuzzer capability and performance. While coverage is not ideal for measuring fuzzer performance in absolute terms, it reliably indicates whether your harness works effectively in a given setup.
Key Concepts
When to Apply
Apply this technique when:
- Starting a new fuzzing campaign to establish a baseline
- Fuzzer appears to plateau without finding new paths
- After harness modifications to verify improvements
- When migrating between different fuzzers
- Identifying areas requiring dictionary entries or seed inputs
- Debugging why certain code paths aren't reached
Skip this technique when:
- Fuzzing campaign is actively finding crashes
- Coverage infrastructure isn't set up yet
- Working with extremely large codebases where full coverage reports are impractical
- Fuzzer's internal coverage metrics are sufficient for your needs
Quick Reference
Ideal Coverage Workflow
The following workflow represents best practices for integrating coverage analysis into your fuzzing campaigns:
Key principle: Use the corpus generated after each fuzzing campaign to calculate coverage, rather than real-time fuzzer statistics. This approach provides reproducible, comparable measurements across different fuzzing tools.
Step-by-Step
Step 1: Build with Coverage Instrumentation
Choose your instrumentation method based on toolchain:
LLVM/Clang (C/C++):
GCC (C/C++):
Rust:
Step 2: Create Execution Runtime (C/C++ only)
For C/C++ projects, create a runtime that executes your corpus:
Step 3: Execute on Corpus
LLVM (C/C++):
GCC (C/C++):
Rust:
Coverage data is automatically generated when running cargo fuzz coverage.
Step 4: Process Coverage Data
LLVM:
GCC with gcovr:
Rust:
Step 5: Analyze Results
Review the coverage report to identify:
- Uncovered code blocks: Areas that may need better seed inputs or dictionary entries
- Magic value checks: Conditional statements with hardcoded values that block progress
- Dead code: Functions that may not be reachable through your harness
- Coverage changes: Compare against baseline to track improvements or regressions
Common Patterns
Pattern: Identifying Magic Values
Problem: Fuzzer cannot discover paths guarded by magic value checks.
Coverage reveals:
Solution: Add magic values to dictionary file:
Pattern: Handling Crashing Inputs
Problem: Coverage generation fails when corpus contains crashing inputs.
Before:
After:
Pattern: CMake Integration
Use Case: Adding coverage builds to CMake projects.
Build:
Advanced Usage
Tips and Tricks
Incremental Coverage Updates
GCC's gcov instrumentation incrementally updates .gcda files across multiple runs. This is useful for tracking coverage as you add test cases:
Handling Large Codebases
For projects with hundreds of source files:
-
Filter by prefix: Only generate reports for relevant directories
-
Use directory coverage: Group by directory to reduce clutter (LLVM 18+)
-
Generate JSON for programmatic analysis:
Differential Coverage
Compare coverage between two fuzzing campaigns:
Anti-Patterns
Tool-Specific Guidance
libFuzzer
libFuzzer uses LLVM's SanitizerCoverage by default for guiding fuzzing, but you need separate instrumentation for generating reports.
Build for coverage:
Execute corpus and generate report:
Integration tips:
- Don't use
-fsanitize=fuzzerfor coverage builds (it conflicts with profile instrumentation) - Reuse the same harness function (
LLVMFuzzerTestOneInput) with a different main function - Use the
-ignore-filename-regexflag to exclude harness code from coverage reports - Consider using llvm-cov's
-show-instantiationflag for template-heavy C++ code
AFL++
AFL++ provides its own coverage feedback mechanism, but for detailed reports use standard LLVM/GCC tools.
Build for coverage with LLVM:
Build for coverage with GCC:
Execute and generate report:
Integration tips:
- Don't use AFL++'s instrumentation (
afl-clang-fast) for coverage builds - Use standard compilers with coverage flags instead
- AFL++'s
queue/directory contains your corpus - AFL++'s built-in coverage statistics are useful for real-time monitoring but not for detailed analysis
cargo-fuzz (Rust)
cargo-fuzz provides built-in coverage generation using LLVM tools.
Install prerequisites:
Generate coverage data:
Create HTML report script:
Generate report:
Integration tips:
- Always use the nightly toolchain for coverage
- The
-Xdemangler=rustfiltflag makes function names readable - Filter by source files (e.g.,
src/lib.rs) to focus on crate code - Use
-show-line-counts-or-regionsand-show-instantiationsfor better Rust-specific output - Corpus is located in
fuzz/corpus/<target>/
honggfuzz
honggfuzz works with standard LLVM/GCC coverage instrumentation.
Build for coverage:
Execute corpus:
Integration tips:
- Don't use
hfuzz-clangfor coverage builds - honggfuzz corpus is typically in a workspace directory
- Use the same LLVM workflow as libFuzzer
Troubleshooting
Related Skills
Tools That Use This Technique
Related Techniques
Resources
Key External Resources
LLVM Source-Based Code Coverage Comprehensive guide to LLVM's profile instrumentation, including advanced features like branch coverage, region coverage, and integration with existing build systems. Covers compiler flags, runtime behavior, and profile data formats.
llvm-cov Command Guide
Detailed CLI reference for llvm-cov commands including show, report, and export. Documents all filtering options, output formats, and integration with llvm-profdata.
gcovr Documentation Complete guide to gcovr tool for generating coverage reports from gcov data. Covers HTML themes, filtering options, multi-directory projects, and CI/CD integration patterns.
SanitizerCoverage Documentation Low-level documentation for LLVM's SanitizerCoverage instrumentation. Explains inline 8-bit counters, PC tables, and how fuzzers use coverage feedback for guidance.
On the Evaluation of Fuzzer Performance Research paper examining limitations of coverage as a fuzzing performance metric. Argues for more nuanced evaluation methods beyond simple code coverage percentages.
Video Resources
Not applicable - coverage analysis is primarily a tooling and workflow topic best learned through documentation and hands-on practice.

