diff --git a/Cargo.lock b/Cargo.lock index 1a3f693..025dd24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,7 @@ dependencies = [ "rand", "rand_chacha", "rustc_version", + "semver", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c55c785..6a4395b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ default = ["arbitrary"] [dependencies] arbitrary = { version = "1", optional = true } rustc_version = "0.4" +semver = "1" [dev-dependencies] rand = "0.8" diff --git a/src/bin/cargo-hfuzz.rs b/src/bin/cargo-hfuzz.rs index 5635dff..de3eecd 100644 --- a/src/bin/cargo-hfuzz.rs +++ b/src/bin/cargo-hfuzz.rs @@ -1,3 +1,4 @@ +use rustc_version::Channel; use std::env; use std::fs; use std::os::unix::process::CommandExt; @@ -207,7 +208,21 @@ where let honggfuzz_target = env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| HONGGFUZZ_TARGET.into()); // HACK: temporary fix, see https://github.com/rust-lang/rust/issues/53945#issuecomment-426824324 - let use_gold_linker: bool = match Command::new("which") // check if the gold linker is available + let use_gold_linker: bool = match rustc_version::version_meta() { + Ok(version_meta) => match version_meta.channel { + Channel::Nightly | Channel::Dev => { + // old nightly + version_meta + .commit_date + .map_or(false, |date| *date < *"2025-03-08") + } + Channel::Stable | Channel::Beta => { + // old non-nightly + version_meta.semver < semver::Version::new(1, 87, 0) + } + }, + Err(_) => false, + } && match Command::new("which") // only if gold linker is available .args(&["ld.gold"]) .stdout(Stdio::null()) .stderr(Stdio::null())