diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 6fdd2e699524..6d020f3f245e 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::collections::{BTreeSet, HashMap, HashSet}; use std::iter; use std::process::Command; @@ -1011,6 +1012,13 @@ pub struct TargetCfg { // target spec). pub(crate) rustc_abi: Option, + /// ELF is the "default" binary format, so the compiler typically doesn't + /// emit a `"binary-format"` field for ELF targets. + /// + /// See `impl ToJson for Target` in `compiler/rustc_target/src/spec/json.rs`. + #[serde(default = "default_binary_format_elf")] + pub(crate) binary_format: Cow<'static, str>, + // Not present in target cfg json output, additional derived information. #[serde(skip)] /// Supported target atomic widths: e.g. `8` to `128` or `ptr`. This is derived from the builtin @@ -1032,6 +1040,10 @@ fn default_reloc_model() -> String { "pic".into() } +fn default_binary_format_elf() -> Cow<'static, str> { + Cow::Borrowed("elf") +} + #[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)] #[serde(rename_all = "kebab-case")] pub enum Endian { diff --git a/src/tools/compiletest/src/directives/cfg.rs b/src/tools/compiletest/src/directives/cfg.rs index 1735866bf2cd..531763c1b3e2 100644 --- a/src/tools/compiletest/src/directives/cfg.rs +++ b/src/tools/compiletest/src/directives/cfg.rs @@ -169,11 +169,7 @@ macro_rules! condition { condition! { name: "elf", - condition: !config.target.contains("windows") - && !config.target.contains("wasm") - && !config.target.contains("apple") - && !config.target.contains("aix") - && !config.target.contains("uefi"), + condition: target_cfg.binary_format == "elf", message: "when the target binary format is ELF" }