Skip to content

Commit

Permalink
move llvm_config to build.rs only
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoproduit committed Oct 17, 2023
1 parent 10d57b6 commit bd64f30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
10 changes: 9 additions & 1 deletion cargo-afl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() {
}

fn build_afl(work_dir: &Path, base: Option<&Path>) {
let llvm_config = common::get_llvm_config();
let llvm_config = get_llvm_config();

if cfg!(feature = "cmplog") {
// Make sure we are on nightly for the -Z flags
Expand Down Expand Up @@ -140,6 +140,14 @@ fn copy_afl_llvm_plugins(work_dir: &Path, base: Option<&Path>) {
}
}

fn get_llvm_config() -> String {
// Fetch the llvm version of the rust toolchain and set the LLVM_CONFIG environement variable to the same version
// This is needed to compile the llvm plugins (needed for cmplog) from afl with the right LLVM version
let version_meta = rustc_version::version_meta().unwrap();
let llvm_version = version_meta.llvm_version.unwrap().major.to_string();
format!("llvm-config-{llvm_version}")
}

#[cfg(unix)]
mod sys {
use std::fs::File;
Expand Down
10 changes: 0 additions & 10 deletions cargo-afl/src/bin/cargo-afl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,6 @@ where
"cargo-afl must be compiled with nightly for the cmplog feature"
);

let llvm_config = common::get_llvm_config();

// check if llvm tools are installed and with the good version for the plugin compilation
let mut command = Command::new(llvm_config.clone());
command.args(["--version"]);
let status = command
.status()
.unwrap_or_else(|_| panic!("could not run {llvm_config} --version"));
assert!(status.success());

rustflags.push_str(&format!(
"-Z llvm-plugins={p}/cmplog-instructions-pass.so \
-Z llvm-plugins={p}/cmplog-routines-pass.so \
Expand Down
10 changes: 0 additions & 10 deletions cargo-afl/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,3 @@ pub fn object_file_path(base: Option<&Path>) -> PathBuf {
pub fn archive_file_path(base: Option<&Path>) -> PathBuf {
afl_llvm_dir(base).join("libafl-llvm-rt.a")
}

#[allow(dead_code)]
#[must_use]
pub fn get_llvm_config() -> String {
// Fetch the llvm version of the rust toolchain and set the LLVM_CONFIG environement variable to the same version
// This is needed to compile the llvm plugins (needed for cmplog) from afl with the right LLVM version
let version_meta = rustc_version::version_meta().unwrap();
let llvm_version = version_meta.llvm_version.unwrap().major.to_string();
format!("llvm-config-{llvm_version}")
}

0 comments on commit bd64f30

Please sign in to comment.