Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AFLplusplus/AFLplusplus/llms.txt
Use this file to discover all available pages before exploring further.
Overview
LLVM mode provides true compiler-level instrumentation instead of assembly-level rewriting. It works with LLVM versions 14-21 (18+ recommended) and offers significant performance improvements and better compatibility.LLVM mode replaces the
AFL_INST_RATIO variable with more effective PCGUARD analysis.Key Benefits
- Performance: Up to 2x faster for CPU-bound programs, ~10% faster for fast binaries
- CPU-independent: Works on non-x86 architectures (build with
AFL_NO_X86=1) - Better multi-threading support: Handles multi-threaded targets more effectively
- Compiler optimizations: Leverages LLVM’s optimization capabilities
Building LLVM Mode
Quick Start
Rebuild AFL++ with theLLVM_CONFIG variable set to your desired clang version:
Custom LLVM Build
For a custom-compiled LLVM version, specify the full path:Troubleshooting Old Linux Systems
If you encounter C++ library issues on older systems, switch to gcc/g++:Usage
Basic Compilation
Once built, you can instrument programs usingafl-clang-fast:
Alternative: Using afl-cc
You can also useafl-cc/afl-c++ and direct it to use LLVM instrumentation:
Instrumentation Options
Coverage Modes
- Default (PCGUARD)
- LTO Mode
- N-Gram Coverage
- Context Sensitive
Standard edge coverage instrumentation using LLVM’s PCGUARD.
Environment Variables
Set the instrumentation mode. Options:
NGRAM-{2-16}: N-gram branch coverageCTX: Context sensitive coverageCALLER: Caller branch coveragellvm-codecov: Source code coverage mode
Enable thread-safe counters for multi-threaded applications. Provides better precision at the cost of slightly higher overhead.
Enable NeverZero counters for LLVM < 9 or when using thread-safe counters. Prevents counter overflow wrapping to zero.
Disable NeverZero counters on LLVM 9+ for a small performance boost (only if target has no extensive loops).
Extract constant string comparison parameters to a dictionary file during compilation.
Skip parsing
main() when extracting dictionary (avoids command-line parsing strings).Advanced Features
Context Sensitive Branch Coverage
Every function gets its own ID, and edge coverage is augmented with the calling context:Caller Branch Coverage
Lighter alternative to context-sensitive coverage - augments edge coverage with just the called function ID:N-Gram Branch Coverage
Based on the paper “Be Sensitive and Collaborative: Analyzing Impact of Coverage Metrics in Greybox Fuzzing”. Remembers N previous branches:NeverZero Counters
Prevents edge coverage counters from wrapping to zero, improving path discovery:- Automatic on LLVM 9+: Enabled by default
- Manual enable: Set
AFL_LLVM_NOT_ZERO=1for LLVM < 9 or thread-safe counters - Disable: Set
AFL_LLVM_SKIP_NEVERZERO=1for small performance boost
Dictionary Extraction (dict2file)
Automatically extract string comparison constants during compilation:main() to avoid command-line parsing strings:
Supported Environment Variables
LLVM mode supports the following AFL++ environment variables:AFL_USE_ASAN- Enable AddressSanitizerAFL_HARDEN- Enable hardening optionsAFL_DONT_OPTIMIZE- Disable optimization
AFL_INST_RATIO is NOT honored as PCGUARD analysis is more effective.Performance Comparison
| Binary Type | Performance Gain |
|---|---|
| CPU-bound programs | Up to 2x faster |
| Fast binaries | ~10% faster |
| With LTO mode | 10-25% additional gain |
Next Steps
Persistent Mode
Achieve 10-20x speed improvements with persistent mode fuzzing
LTO Mode
Use collision-free instrumentation for even better coverage
CmpLog
Enable Redqueen-style mutations for complex comparisons
LAF-Intel
Split complex comparisons to improve path discovery

