From bd64f30064937a4f99fa33392716a60c35027a25 Mon Sep 17 00:00:00 2001 From: Bruno Produit Date: Tue, 17 Oct 2023 12:02:00 +0200 Subject: [PATCH] move llvm_config to build.rs only --- cargo-afl/build.rs | 10 +++++++++- cargo-afl/src/bin/cargo-afl.rs | 10 ---------- cargo-afl/src/common.rs | 10 ---------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/cargo-afl/build.rs b/cargo-afl/build.rs index ee73f5d65..a6589dc80 100644 --- a/cargo-afl/build.rs +++ b/cargo-afl/build.rs @@ -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 @@ -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; diff --git a/cargo-afl/src/bin/cargo-afl.rs b/cargo-afl/src/bin/cargo-afl.rs index 922c42382..4c89073b7 100644 --- a/cargo-afl/src/bin/cargo-afl.rs +++ b/cargo-afl/src/bin/cargo-afl.rs @@ -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 \ diff --git a/cargo-afl/src/common.rs b/cargo-afl/src/common.rs index af0e3dec1..bbb61f677 100644 --- a/cargo-afl/src/common.rs +++ b/cargo-afl/src/common.rs @@ -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}") -}