Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce AFLRS_REQUIRE_PLUGINS & AFL_OPT_LEVEL #540

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cargo-afl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,30 +272,41 @@ where
"sancov"
};

let opt_level = env::var("AFL_OPT_LEVEL").unwrap_or("3".to_string());
let require_plugins = env::var("AFLRS_REQUIRE_PLUGINS").is_ok();

// `-C codegen-units=1` is needed to work around link errors
// https://github.com/rust-fuzz/afl.rs/pull/193#issuecomment-933550430

let binding = common::afl_llvm_dir().unwrap();
let p = binding.display();

let mut rustflags = String::from(
let mut rustflags = format!(
"-C debug-assertions \
-C overflow_checks \
-C codegen-units=1 \
-C opt-level=3 \
-C opt-level={opt_level} \
-C target-cpu=native ",
);
let mut environment_variables = HashMap::<&str, String>::new();
environment_variables.insert("ASAN_OPTIONS", asan_options);
environment_variables.insert("TSAN_OPTIONS", tsan_options);

if common::plugins_available().unwrap() {
let has_plugins = common::plugins_available().unwrap();
if require_plugins || has_plugins {
// Make sure we are on nightly for the -Z flags
assert!(
rustc_version::version_meta().unwrap().channel == rustc_version::Channel::Nightly,
"cargo-afl must be compiled with nightly for CMPLOG and other advanced AFL++ features"
);

if require_plugins {
assert!(
has_plugins,
"AFL++ plugins are not available; run `cargo afl config --build --force --plugins`"
);
}

rustflags.push_str(&format!(
"-Z llvm-plugins={p}/cmplog-instructions-pass.so \
-Z llvm-plugins={p}/cmplog-routines-pass.so \
Expand Down
Loading