Skip to content

Commit e69b08e

Browse files
committed
Add documentation for libafl_targets features
1 parent e9301d3 commit e69b08e

File tree

3 files changed

+149
-24
lines changed

3 files changed

+149
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/libafl_targets/Cargo.toml

Lines changed: 147 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ categories = [
1919
]
2020

2121
[package.metadata.docs.rs]
22+
features = ["document-features"]
2223
all-features = true
2324

25+
2426
[features]
2527
default = [
2628
"std",
@@ -31,52 +33,173 @@ default = [
3133
"coverage",
3234
"common",
3335
]
36+
37+
#! # Feature Flags
38+
#! ### General Features
39+
40+
## Enables features that need rust's `std` lib to work, like print, env, ... support
3441
std = ["libafl/std"]
42+
43+
## Collects performance statistics of the fuzzing pipeline and displays it on `Monitor` components
3544
introspection = ["libafl/introspection"]
36-
libfuzzer = ["std", "common"]
37-
libfuzzer_no_link_main = ["libfuzzer"]
38-
libfuzzer_define_run_driver = ["libfuzzer"]
39-
libfuzzer_interceptors = ["libfuzzer", "sancov_cmplog"]
40-
libfuzzer_oom = ["libfuzzer"]
41-
sanitizers_flags = []
42-
pointer_maps = []
45+
46+
## Support for the `sancov` 8-bit counters.
47+
## This feature enables the `8-bit-counters` runtime for `LibAFL`, which uses a global `COUNTERS_MAPS` to store coverage maps.
48+
## It is compatible with LLVM's `SanitizerCoverage` 8-bit counters instrumentation.
49+
sancov_8bit = []
50+
51+
## Support for `sancov` pcguard edge coverage.
52+
## This feature enables the `pcguard` runtime for `LibAFL`, specifically for edge coverage.
53+
## It instruments edges by writing a `1` to the coverage map at the corresponding index.
54+
## This is non-colliding coverage.
55+
## Mutually exclusive with `sancov_pcguard_hitcounts`.
4356
sancov_pcguard_edges = ["coverage"]
57+
58+
## Support for `sancov` pcguard hitcounts coverage.
59+
## This feature enables the `pcguard` runtime for `LibAFL`, specifically for hitcounts coverage.
60+
## It instruments edges by incrementing the counter in the coverage map at the corresponding index.
61+
## This is non-colliding coverage.
62+
## Mutually exclusive with `sancov_pcguard_edges`.
4463
sancov_pcguard_hitcounts = ["coverage"]
64+
65+
## Support for `sancov` value profile.
66+
## This feature enables value profiling in the `sancov` runtime.
67+
## It compiles `sancov_cmp.c` with `SANCOV_VALUE_PROFILE` defined, enabling tracing of comparisons.
4568
sancov_value_profile = ["common"]
46-
sancov_8bit = []
69+
70+
## Support for `sancov` ngram4 coverage.
71+
## This feature enables NGRAM-4 instrumentation in the `sancov` runtime.
72+
## It maintains a history of the last 4 locations to provide context-sensitive coverage.
4773
sancov_ngram4 = ["coverage"]
74+
75+
## Support for `sancov` ngram8 coverage.
76+
## This feature enables NGRAM-8 instrumentation in the `sancov` runtime.
77+
## It maintains a history of the last 8 locations to provide context-sensitive coverage.
4878
sancov_ngram8 = ["coverage"]
79+
80+
## Support for `sancov` context coverage.
81+
## This feature enables context-sensitive coverage in the `sancov` runtime.
82+
## It XORs the current position with the previous context ID to distinguish paths based on calling context.
4983
sancov_ctx = ["coverage"]
84+
85+
## Support for `sancov`-based cmplog.
86+
## This feature enables comparison logging using the LLVM `sancov` runtime.
87+
## It compiles `sancov_cmp.c` with `SANCOV_CMPLOG` defined and links against weak symbols for comparison hooks.
88+
## This allows tracing of comparison operands for advanced fuzzing techniques like RedQueen.
5089
sancov_cmplog = [
5190
"common",
5291
] # Defines cmp and __sanitizer_weak_hook functions. Use libfuzzer_interceptors to define interceptors (only compatible with Linux)
92+
93+
## Support for `sancov` pcguard.
94+
## This is an alias for `sancov_pcguard_hitcounts`, enabling hitcounts coverage by default.
5395
sancov_pcguard = ["sancov_pcguard_hitcounts"]
54-
sanitizer_interfaces = []
55-
clippy = [] # Ignore compiler warnings during clippy
56-
observers = ["meminterval"]
57-
common = [
58-
] # Compile common C code defining sanitizer options and cross-platform intrinsics
59-
coverage = ["common"] # Compile C code definining coverage maps
60-
cmplog = ["common"] # Compile C code defining cmp log maps
61-
forkserver = [
62-
"common",
63-
"nix",
64-
"libafl/std",
65-
"libafl/fork",
66-
] # Compile C code for forkserver support
67-
windows_asan = ["common"] # Compile C code for ASAN on Windows
68-
whole_archive = [] # use +whole-archive to ensure the presence of weak symbols
96+
97+
## Compile common C code defining sanitizer options and cross-platform intrinsics.
98+
## This feature compiles `common.c` and `common.h`, which are used by many other features.
99+
common = []
100+
101+
## Compile C code definining coverage maps.
102+
## This feature compiles `coverage.c`, which defines the edge coverage map (`EDGES_MAP`) and related variables.
103+
coverage = ["common"]
104+
105+
## Compile C code defining cmp log maps.
106+
## This feature compiles `cmplog.c` and `cmplog.h`, which define the comparison logging map and related structures.
107+
cmplog = ["common"]
108+
109+
## Compile C code for forkserver support.
110+
## This feature compiles `forkserver.rs` and enables the forkserver protocol for communicating with the fuzzer.
111+
## It allows the target to be spawned and controlled by a parent fuzzer process.
112+
forkserver = ["common", "nix", "libafl/std", "libafl/fork"]
113+
114+
## Compile C code for ASan on Windows.
115+
## This feature compiles `windows_asan.c` and `windows_asan.rs` to provide AddressSanitizer support on Windows.
116+
windows_asan = ["common"]
117+
118+
## use +whole-archive to ensure the presence of weak symbols.
119+
## This feature adds the `+whole-archive` modifier to linked libraries in `build.rs`.
120+
## This is important for ensuring that weak symbols (like sanitizer hooks) are included in the final binary.
121+
whole_archive = []
122+
123+
## Support for `aflpp`-style `CmpLog` maps.
124+
## This feature enables extended `CmpLog` instrumentation, compatible with `AFL++`.
125+
## It compiles `cmplog.c` with `CMPLOG_EXTENDED` defined.
69126
cmplog_extended_instrumentation = [
70127
"cmplog", # without `cmplog`, extended instrumentation won't compile
71-
] # support for aflpp cmplog map, we will remove this once aflpp and libafl cmplog shares the same LLVM passes.
128+
]
129+
130+
## Support for function logging.
131+
## This feature enables the `call` module, which provides hooks for function calls.
132+
## It allows tracing function entries and exits.
72133
function-logging = ["common", "std"]
134+
135+
## Tracks the Feedbacks and the Objectives that were interesting for a Testcase.
136+
## This feature enables tracking of hit feedbacks in the `libfuzzer` OOM observer.
73137
track_hit_feedbacks = ["libafl/track_hit_feedbacks"]
138+
139+
#! ### Libfuzzer-compatibility Features
140+
141+
## Libfuzzer compatibility mode.
142+
## This feature compiles `libfuzzer.c` and enables Libfuzzer compatibility.
143+
## It allows `LibAFL` to be used as a drop-in replacement for Libfuzzer.
144+
libfuzzer = ["std", "common"]
145+
146+
## Libfuzzer mode without linking main.
147+
## This feature defines `FUZZER_NO_LINK_MAIN` when compiling `libfuzzer.c`.
148+
## It prevents the definition of a `main` function, which is useful when the target already has a `main`.
149+
libfuzzer_no_link_main = ["libfuzzer"]
150+
151+
## Libfuzzer mode defining run driver.
152+
## This feature defines `FUZZER_DEFINE_RUN_DRIVER` when compiling `libfuzzer.c`.
153+
## It defines the `run_driver` symbol, which is used by some Libfuzzer targets.
154+
libfuzzer_define_run_driver = ["libfuzzer"]
155+
156+
## Libfuzzer interceptors.
157+
## This feature compiles `FuzzerInterceptors.cpp`, which defines interceptors for common library functions (e.g., `malloc`, `free`).
158+
## It is used to track memory allocations and other events in Libfuzzer compatibility mode.
159+
libfuzzer_interceptors = ["libfuzzer", "sancov_cmplog"]
160+
161+
## Libfuzzer OOM handling.
162+
## This feature enables Out-Of-Memory (OOM) handling in Libfuzzer compatibility mode.
163+
## It registers a handler to catch OOM errors and report them to the fuzzer.
164+
libfuzzer_oom = ["libfuzzer"]
165+
166+
#! ### Sanitizer Features
167+
168+
## Sanitizer flags.
169+
## This feature defines `DEFAULT_SANITIZERS_OPTIONS` in `common.c`.
170+
## It sets default options for sanitizers (e.g., ASAN, MSAN) to be compatible with fuzzing.
171+
sanitizers_flags = []
172+
173+
## Pointer maps.
174+
## This feature changes the way coverage maps are accessed.
175+
## Instead of using fixed-size arrays, it uses pointers to access the maps.
176+
## This is useful when the map location is not known at compile time or when using shared memory.
177+
pointer_maps = []
178+
179+
## Sanitizer interfaces.
180+
## This feature generates Rust bindings for sanitizer interface headers (`sanitizer_interfaces.h`).
181+
## It allows accessing sanitizer functions and structures from Rust code.
182+
sanitizer_interfaces = []
183+
184+
## Ignore compiler warnings during clippy.
185+
## This feature suppresses clippy warnings in generated code or specific modules.
186+
clippy = []
187+
188+
## Observers.
189+
## This feature enables observer implementations in `sancov_8bit` and `cmps`.
190+
## It allows using these observers to track coverage and comparison values.
191+
observers = ["meminterval"]
192+
193+
## Document all features of this crate (for `cargo doc`)
194+
document-features = ["dep:document-features"]
195+
74196
[build-dependencies]
75197
bindgen = "0.72.1"
76198
cc = { version = "1.2.48", features = ["parallel"] }
77199
rustversion = "1.0.22"
78200

79201
[dependencies]
202+
document-features = { workspace = true, optional = true }
80203
libafl = { workspace = true, features = [], default-features = false }
81204
libafl_bolts = { workspace = true, features = [] }
82205
libafl_core = { workspace = true, features = [] }

crates/libafl_targets/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! `libafl_targets` contains runtime code, injected in the target itself during compilation.
22
#![doc = include_str!("../README.md")]
3+
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
34
#![no_std]
45
// For `std::simd`
56
#![cfg_attr(nightly, feature(portable_simd))]

0 commit comments

Comments
 (0)