Skip to content

Commit 2d637f7

Browse files
compiler: use CanonAbi for entry_abi
makes entry_abi a lowering of the ABI string, so now it can be ```json "entry_abi": "C", "entry_abi": "win64", "entry_abi": "aapcs", ```
1 parent c04e249 commit 2d637f7

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
#[cfg(feature = "nightly")]
44
use rustc_macros::HashStable_Generic;
55

6-
use crate::{AbiFromStrErr, ExternAbi};
6+
use crate::ExternAbi;
77

88
/// Calling convention to determine codegen
99
///

compiler/rustc_target/src/spec/json.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use std::borrow::Cow;
22
use std::collections::BTreeMap;
33
use std::str::FromStr;
44

5+
use rustc_abi::ExternAbi;
56
use serde_json::Value;
67

78
use super::{Target, TargetKind, TargetOptions, TargetWarnings};
89
use crate::json::{Json, ToJson};
10+
use crate::spec::AbiMap;
911

1012
impl Target {
1113
/// Loads a target descriptor from a JSON object.
@@ -515,18 +517,6 @@ impl Target {
515517
}
516518
}
517519
} );
518-
($key_name:ident, Conv) => ( {
519-
let name = (stringify!($key_name)).replace("_", "-");
520-
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
521-
match super::Conv::from_str(s) {
522-
Ok(c) => {
523-
base.$key_name = c;
524-
Some(Ok(()))
525-
}
526-
Err(e) => Some(Err(e))
527-
}
528-
})).unwrap_or(Ok(()))
529-
} );
530520
}
531521

532522
if let Some(j) = obj.remove("target-endian") {
@@ -546,6 +536,7 @@ impl Target {
546536
incorrect_type.push("frame-pointer".into())
547537
}
548538
}
539+
549540
key!(c_int_width = "target-c-int-width");
550541
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
551542
key!(os);
@@ -659,9 +650,23 @@ impl Target {
659650
key!(supports_stack_protector, bool);
660651
key!(small_data_threshold_support, SmallDataThresholdSupport)?;
661652
key!(entry_name);
662-
key!(entry_abi, Conv)?;
663653
key!(supports_xray, bool);
664654

655+
// we're going to run `update_from_cli`, but that won't change the target's AbiMap
656+
// FIXME: better factor the Target definition so we enforce this on a type level
657+
let abi_map = AbiMap::from_target(&base);
658+
659+
if let Some(abi_str) = obj.remove("entry-abi") {
660+
if let Json::String(abi_str) = abi_str {
661+
match abi_str.parse::<ExternAbi>() {
662+
Ok(abi) => base.options.entry_abi = abi_map.canonize_abi(abi, false).unwrap(),
663+
Err(_) => return Err(format!("{abi_str} is not a valid ExternAbi")),
664+
}
665+
} else {
666+
incorrect_type.push("entry-abi".to_owned())
667+
}
668+
}
669+
665670
base.update_from_cli();
666671
base.check_consistency(TargetKind::Json)?;
667672

compiler/rustc_target/src/spec/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::str::FromStr;
4343
use std::{fmt, io};
4444

4545
use rustc_abi::{
46-
Align, Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors,
46+
Align, CanonAbi, Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors,
4747
};
4848
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
4949
use rustc_fs_util::try_canonicalize;
@@ -53,7 +53,6 @@ use rustc_span::{Symbol, kw, sym};
5353
use serde_json::Value;
5454
use tracing::debug;
5555

56-
use crate::callconv::Conv;
5756
use crate::json::{Json, ToJson};
5857
use crate::spec::crt_objects::CrtObjects;
5958

@@ -2657,9 +2656,9 @@ pub struct TargetOptions {
26572656
/// Default value is "main"
26582657
pub entry_name: StaticCow<str>,
26592658

2660-
/// The ABI of entry function.
2661-
/// Default value is `Conv::C`, i.e. C call convention
2662-
pub entry_abi: Conv,
2659+
/// The ABI of the entry function.
2660+
/// Default value is `CanonAbi::C`
2661+
pub entry_abi: CanonAbi,
26632662

26642663
/// Whether the target supports XRay instrumentation.
26652664
pub supports_xray: bool,
@@ -2890,7 +2889,7 @@ impl Default for TargetOptions {
28902889
generate_arange_section: true,
28912890
supports_stack_protector: true,
28922891
entry_name: "main".into(),
2893-
entry_abi: Conv::C,
2892+
entry_abi: CanonAbi::C,
28942893
supports_xray: false,
28952894
small_data_threshold_support: SmallDataThresholdSupport::DefaultForArch,
28962895
}

compiler/rustc_target/src/spec/targets/x86_64_unknown_uefi.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
// The win64 ABI is used. It differs from the sysv64 ABI, so we must use a windows target with
66
// LLVM. "x86_64-unknown-windows" is used to get the minimal subset of windows-specific features.
77

8-
use crate::callconv::Conv;
8+
use rustc_abi::{CanonAbi, X86Call};
9+
910
use crate::spec::{RustcAbi, Target, TargetMetadata, base};
1011

1112
pub(crate) fn target() -> Target {
1213
let mut base = base::uefi_msvc::opts();
1314
base.cpu = "x86-64".into();
1415
base.plt_by_default = false;
1516
base.max_atomic_width = Some(64);
16-
base.entry_abi = Conv::X86_64Win64;
17+
base.entry_abi = CanonAbi::X86(X86Call::Win64);
1718

1819
// We disable MMX and SSE for now, even though UEFI allows using them. Problem is, you have to
1920
// enable these CPU features explicitly before their first use, otherwise their instructions

0 commit comments

Comments
 (0)