Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions cargo-afl/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ pub fn object_file_path() -> Result<PathBuf> {
afl_llvm_dir().map(|path| path.join("libafl-llvm-rt.o"))
}

pub fn archive_file_path() -> Result<PathBuf> {
afl_llvm_dir().map(|path| path.join("libafl-llvm-rt.a"))
}

pub fn plugins_available() -> Result<bool> {
let afl_llvm_dir = afl_llvm_dir()?;
for result in afl_llvm_dir
Expand Down
27 changes: 3 additions & 24 deletions cargo-afl/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ use super::common;

const AFL_SRC_PATH: &str = "AFLplusplus";

// https://github.com/rust-fuzz/afl.rs/issues/148
#[cfg(target_os = "macos")]
static AR_CMD: &str = "/usr/bin/ar";
#[cfg(not(target_os = "macos"))]
static AR_CMD: &str = "ar";

#[allow(clippy::struct_excessive_bools)]
#[derive(Default, Parser)]
#[clap(after_help = "\
Expand All @@ -37,8 +31,8 @@ pub struct Args {
}

pub fn config(args: &Args) -> Result<()> {
let archive_file_path = common::archive_file_path()?;
if !args.force && archive_file_path.exists() && args.plugins == common::plugins_available()? {
let object_file_path = common::object_file_path()?;
if !args.force && object_file_path.exists() && args.plugins == common::plugins_available()? {
let version = common::afl_rustc_version()?;
bail!(
"AFL LLVM runtime was already built for Rust {version}; run `cargo afl config --build \
Expand Down Expand Up @@ -129,26 +123,11 @@ fn build_afl(args: &Args, work_dir: &Path) -> Result<()> {
Ok(())
}

fn build_afl_llvm_runtime(args: &Args, work_dir: &Path) -> Result<()> {
fn build_afl_llvm_runtime(_args: &Args, work_dir: &Path) -> Result<()> {
let object_file_path = common::object_file_path()?;
let _: u64 = std::fs::copy(work_dir.join("afl-compiler-rt.o"), &object_file_path)
.with_context(|| "could not copy object file")?;

let archive_file_path = common::archive_file_path()?;
let mut command = Command::new(AR_CMD);
command
.arg("r")
.arg(archive_file_path)
.arg(object_file_path);

if !args.verbose {
command.stdout(Stdio::null());
command.stderr(Stdio::null());
}

let success = command.status().as_ref().is_ok_and(ExitStatus::success);
ensure!(success, "could not run 'ar'");

Ok(())
}

Expand Down
7 changes: 3 additions & 4 deletions cargo-afl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn main() {
};

if !matches!(afl_args.subcmd, Some(AflSubcommand::Config(..)))
&& !common::archive_file_path().unwrap().exists()
&& !common::object_file_path().unwrap().exists()
{
let version = common::afl_rustc_version().unwrap();
eprintln!(
Expand Down Expand Up @@ -346,9 +346,8 @@ where
let mut rustdocflags = rustflags.clone();

rustflags.push_str(&format!(
"-l afl-llvm-rt \
-L {} ",
common::afl_llvm_dir().unwrap().display()
"-Clink-arg={} ",
common::object_file_path().unwrap().display()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanhauser-thc This is the change I am least certain about. Perhaps you could give this a glance.

I'm going to run some more tests, but the fact that CI is passing is a good sign.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how you would do it with an object file instead of an archive. LGTM

));

// add user provided flags
Expand Down
Loading