From 94f7b8c07623398460227576a84c3e249868feff Mon Sep 17 00:00:00 2001 From: jonboh Date: Tue, 2 Jan 2024 18:45:04 +0100 Subject: [PATCH] add llvm-path option this allows the usage of an already installed llvm-profdata binary --- src/options/coverage.rs | 6 ++++++ src/project.rs | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/options/coverage.rs b/src/options/coverage.rs index bf66e38..4c416c8 100644 --- a/src/options/coverage.rs +++ b/src/options/coverage.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::{ options::{BuildOptions, FuzzDirWrapper}, project::FuzzProject, @@ -14,6 +16,10 @@ pub struct Coverage { #[command(flatten)] pub fuzz_dir_wrapper: FuzzDirWrapper, + /// Sets the path to the LLVM bin directory. By default, it will use the one installed with rustc + #[arg(long)] + pub llvm_path: Option, + /// Name of the fuzz target pub target: String, diff --git a/src/project.rs b/src/project.rs index 61a9649..306df37 100644 --- a/src/project.rs +++ b/src/project.rs @@ -699,7 +699,14 @@ impl FuzzProject { .context("Failed to generage coverage data")?; } } - self.merge_coverage(&coverage_out_raw_dir, &coverage_out_file)?; + + let mut profdata_bin_path = coverage.llvm_path.clone().unwrap_or(rustlib()?); + profdata_bin_path.push(format!("llvm-profdata{}", env::consts::EXE_SUFFIX)); + self.merge_coverage( + &profdata_bin_path, + &coverage_out_raw_dir, + &coverage_out_file, + )?; Ok(()) } @@ -749,10 +756,13 @@ impl FuzzProject { Ok((cmd, dummy_corpus)) } - fn merge_coverage(&self, profdata_raw_path: &Path, profdata_out_path: &Path) -> Result<()> { - let mut profdata_path = rustlib()?; - profdata_path.push(format!("llvm-profdata{}", env::consts::EXE_SUFFIX)); - let mut merge_cmd = Command::new(profdata_path); + fn merge_coverage( + &self, + profdata_bin_path: &Path, + profdata_raw_path: &Path, + profdata_out_path: &Path, + ) -> Result<()> { + let mut merge_cmd = Command::new(profdata_bin_path); merge_cmd.arg("merge").arg("-sparse"); merge_cmd.arg(profdata_raw_path); merge_cmd.arg("-o").arg(profdata_out_path);