Skip to content

Commit

Permalink
Add support for more llvm instrumentations; fix not working `disable_…
Browse files Browse the repository at this point in the history
…branch_folding`
  • Loading branch information
0xdeafbeef committed Feb 22, 2025
1 parent 95f7737 commit 5256b76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ pub struct BuildOptions {
/// available.
pub no_trace_compares: bool,

#[arg(long)]
/// Enables `sanitizer-coverage-trace-divs` LLVM instrumentation
///
/// When set to `true`, the compiler will instrument integer division instructions
/// to capture the right argument of division.
pub trace_div: bool,

#[arg(long)]
/// Enables `sanitizer-coverage-trace-geps` LLVM instrumentation
///
/// When set to `true`, instruments GetElementPtr (GEP) instructions to track
/// pointer arithmetic operations to capture array indices.
pub trace_gep: bool,

#[arg(long)]
/// Disable transformation of if-statements into `cmov` instructions (when this
/// happens, we get no coverage feedback for that branch). Default setting is true.
Expand Down Expand Up @@ -165,7 +179,7 @@ pub struct BuildOptions {
/// Note, that in the second program, there are now 2 new coverage feedback points,
/// and the fuzzer can store an input to the corpus at each condition that it passes;
/// giving it a better chance of producing an input that reaches `res = 2;`.
pub disable_branch_folding: Option<bool>,
pub disable_branch_folding: bool,

#[arg(long)]
/// Disable the inclusion of the `/include:main` MSVC linker argument
Expand Down
12 changes: 10 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ impl FuzzProject {
rustflags.push_str(" -Cllvm-args=-sanitizer-coverage-trace-compares");
}

if build.disable_branch_folding.unwrap_or(true) {
rustflags.push_str(" -Cllvm-args=-simplifycfg-branch-fold-threshold=0");
if build.trace_div {
rustflags.push_str(" -Cllvm-args=-sanitizer-coverage-trace-divs");
}

if build.trace_gep {
rustflags.push_str(" -Cllvm-args=-sanitizer-coverage-trace-geps");
}

if !build.no_cfg_fuzzing {
Expand All @@ -194,6 +198,10 @@ impl FuzzProject {
rustflags.push_str(" -Clink-dead-code");
}

if build.disable_branch_folding {
rustflags.push_str(" -Cllvm-args=-simplifycfg-branch-fold-threshold=0");
}

if build.coverage {
rustflags.push_str(" -Cinstrument-coverage");
}
Expand Down

0 comments on commit 5256b76

Please sign in to comment.