Skip to content

Commit 1230507

Browse files
compiler: use CanonAbi for entry_abi
1 parent 6ab5d6a commit 1230507

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

compiler/rustc_target/src/json.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,9 @@ impl ToJson for rustc_abi::Endian {
140140
self.as_str().to_json()
141141
}
142142
}
143+
144+
impl ToJson for rustc_abi::CanonAbi {
145+
fn to_json(&self) -> Json {
146+
self.to_string().trim_matches('"').to_json()
147+
}
148+
}

compiler/rustc_target/src/spec/json.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,6 @@ impl Target {
557557
}
558558
}
559559
} );
560-
($key_name:ident, Conv) => ( {
561-
let name = (stringify!($key_name)).replace("_", "-");
562-
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
563-
match super::Conv::from_str(s) {
564-
Ok(c) => {
565-
base.$key_name = c;
566-
Some(Ok(()))
567-
}
568-
Err(e) => Some(Err(e))
569-
}
570-
})).unwrap_or(Ok(()))
571-
} );
572560
}
573561

574562
if let Some(j) = obj.remove("target-endian") {
@@ -588,6 +576,21 @@ impl Target {
588576
incorrect_type.push("frame-pointer".into())
589577
}
590578
}
579+
580+
if let Some(abi_str) = obj.remove("entry-abi") {
581+
if let Json::String(abi_str) = abi_str {
582+
match abi_str.parse() {
583+
Ok(canon_abi) => base.options.entry_abi = canon_abi,
584+
Err(_) => bad_kv.push((
585+
"entry-abi".to_owned(),
586+
format!("{abi_str} is not a valid CanonAbi"),
587+
)),
588+
}
589+
} else {
590+
incorrect_type.push("entry-abi".to_owned())
591+
}
592+
}
593+
591594
key!(c_int_width = "target-c-int-width");
592595
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
593596
key!(os);
@@ -701,7 +704,6 @@ impl Target {
701704
key!(supports_stack_protector, bool);
702705
key!(small_data_threshold_support, SmallDataThresholdSupport)?;
703706
key!(entry_name);
704-
key!(entry_abi, Conv)?;
705707
key!(supports_xray, bool);
706708

707709
base.update_from_cli();

compiler/rustc_target/src/spec/mod.rs

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

4545
use rustc_abi::{
46-
AbiMap, Align, Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors,
46+
AbiMap, Align, CanonAbi, Endian, ExternAbi, Integer, Size, TargetDataLayout,
47+
TargetDataLayoutErrors,
4748
};
4849
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
4950
use rustc_fs_util::try_canonicalize;
@@ -53,7 +54,6 @@ use rustc_span::{Symbol, kw, sym};
5354
use serde_json::Value;
5455
use tracing::debug;
5556

56-
use crate::callconv::Conv;
5757
use crate::json::{Json, ToJson};
5858
use crate::spec::crt_objects::CrtObjects;
5959

@@ -2657,9 +2657,9 @@ pub struct TargetOptions {
26572657
/// Default value is "main"
26582658
pub entry_name: StaticCow<str>,
26592659

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

26642664
/// Whether the target supports XRay instrumentation.
26652665
pub supports_xray: bool,
@@ -2891,7 +2891,7 @@ impl Default for TargetOptions {
28912891
generate_arange_section: true,
28922892
supports_stack_protector: true,
28932893
entry_name: "main".into(),
2894-
entry_abi: Conv::C,
2894+
entry_abi: CanonAbi::C,
28952895
supports_xray: false,
28962896
small_data_threshold_support: SmallDataThresholdSupport::DefaultForArch,
28972897
}

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)