Skip to content

Commit 093ec70

Browse files
committed
Add new EFIAPI ABI
Adds a new ABI for the EFIAPI calls. This ABI should reflect the latest version of the UEFI specification at the time of commit (UEFI spec 2.8, URL below). The specification says that for x86_64, we should follow the win64 ABI, while on all other supported platforms (ia32, itanium, arm, arm64 and risc-v), we should follow the C ABI. To simplify the implementation, we will simply follow the C ABI on all platforms except x86_64, even those technically unsupported by the UEFI specification. https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf
1 parent 8e0007f commit 093ec70

File tree

12 files changed

+182
-72
lines changed

12 files changed

+182
-72
lines changed

src/librustc/ich/impls_syntax.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi {
8080
Msp430Interrupt,
8181
X86Interrupt,
8282
AmdGpuKernel,
83+
EfiApi,
8384
Rust,
8485
C,
8586
System,

src/librustc/ty/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,7 @@ where
25962596

25972597
// It's the ABI's job to select this, not ours.
25982598
System => bug!("system abi should be selected elsewhere"),
2599+
EfiApi => bug!("eficall abi should be selected elsewhere"),
25992600

26002601
Stdcall => Conv::X86Stdcall,
26012602
Fastcall => Conv::X86Fastcall,

src/librustc_target/spec/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub enum Abi {
2121
Msp430Interrupt,
2222
X86Interrupt,
2323
AmdGpuKernel,
24+
EfiApi,
2425

2526
// Multiplatform / generic ABIs
2627
Rust,
@@ -58,6 +59,7 @@ const AbiDatas: &[AbiData] = &[
5859
AbiData {abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false },
5960
AbiData {abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false },
6061
AbiData {abi: Abi::AmdGpuKernel, name: "amdgpu-kernel", generic: false },
62+
AbiData {abi: Abi::EfiApi, name: "efiapi", generic: false },
6163

6264
// Cross-platform ABIs
6365
AbiData {abi: Abi::Rust, name: "Rust", generic: true },

src/librustc_target/spec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,13 @@ impl Target {
905905
abi
906906
}
907907
},
908+
Abi::EfiApi => {
909+
if self.arch != "x86_64" {
910+
Abi::Win64
911+
} else {
912+
Abi::C
913+
}
914+
},
908915
abi => abi
909916
}
910917
}

src/libsyntax/feature_gate/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ declare_features! (
531531
/// Non-object safe trait objects safe to use but cannot be created in safe rust
532532
(active, object_safe_for_dispatch, "1.40.0", Some(43561), None),
533533

534+
/// Allows using the `efiapi` ABI.
535+
(active, abi_efiapi, "1.40.0", Some(1), None),
536+
534537
// -------------------------------------------------------------------------
535538
// feature-group-end: actual feature gates
536539
// -------------------------------------------------------------------------

src/libsyntax/feature_gate/check.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ impl<'a> PostExpansionVisitor<'a> {
234234
gate_feature_post!(&self, abi_amdgpu_kernel, span,
235235
"amdgpu-kernel ABI is experimental and subject to change");
236236
},
237+
Abi::EfiApi => {
238+
gate_feature_post!(&self, abi_efiapi, span,
239+
"efiapi ABI is experimental and subject to change");
240+
},
237241
// Stable
238242
Abi::Cdecl |
239243
Abi::Stdcall |

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ symbols! {
110110
aarch64_target_feature,
111111
abi,
112112
abi_amdgpu_kernel,
113+
abi_efiapi,
113114
abi_msp430_interrupt,
114115
abi_ptx,
115116
abi_sysv64,

src/test/codegen/abi-efiapi.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Checks if the correct annotation for the efiapi ABI is passed to llvm.
2+
3+
// compile-flags: -C no-prepopulate-passes
4+
5+
#![crate_type = "lib"]
6+
#![feature(abi_efiapi)]
7+
8+
// CHECK: define win64 i64 @has_efiapi
9+
#[no_mangle]
10+
#[cfg(target_arch = "x86_64")]
11+
pub extern "efiapi" fn has_efiapi(a: i64) -> i64 {
12+
a * 2
13+
}
14+
15+
// CHECK: define c i64 @has_efiapi
16+
#[no_mangle]
17+
#[cfg(not(target_arch = "x86_64"))]
18+
pub extern "efiapi" fn has_efiapi(a: i64) -> i64 {
19+
a * 2
20+
}

src/test/ui/codemap_tests/unicode.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `路濫狼á́́`
44
LL | extern "路濫狼á́́" fn foo() {}
55
| ^^^^^^^^^ invalid ABI
66
|
7-
= help: valid ABIs: cdecl, stdcall, fastcall, vectorcall, thiscall, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, Rust, C, system, rust-intrinsic, rust-call, platform-intrinsic, unadjusted
7+
= help: valid ABIs: cdecl, stdcall, fastcall, vectorcall, thiscall, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, Rust, C, system, rust-intrinsic, rust-call, platform-intrinsic, unadjusted
88

99
error: aborting due to previous error
1010

src/test/ui/feature-gates/feature-gate-abi.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// gate-test-abi_ptx
88
// gate-test-abi_x86_interrupt
99
// gate-test-abi_amdgpu_kernel
10+
// gate-test-abi_efiapi
1011

1112
// Functions
1213
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
@@ -20,6 +21,7 @@ extern "ptx-kernel" fn f6() {} //~ ERROR PTX ABIs are experimental and subject t
2021
extern "x86-interrupt" fn f7() {} //~ ERROR x86-interrupt ABI is experimental
2122
extern "thiscall" fn f8() {} //~ ERROR thiscall is experimental and subject to change
2223
extern "amdgpu-kernel" fn f9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
24+
extern "efiapi" fn f10() {} //~ ERROR efiapi ABI is experimental and subject to change
2325

2426
// Methods in trait definition
2527
trait Tr {
@@ -34,6 +36,7 @@ trait Tr {
3436
extern "x86-interrupt" fn m7(); //~ ERROR x86-interrupt ABI is experimental
3537
extern "thiscall" fn m8(); //~ ERROR thiscall is experimental and subject to change
3638
extern "amdgpu-kernel" fn m9(); //~ ERROR amdgpu-kernel ABI is experimental and subject to change
39+
extern "efiapi" fn m10(); //~ ERROR efiapi ABI is experimental and subject to change
3740

3841
extern "vectorcall" fn dm3() {} //~ ERROR vectorcall is experimental and subject to change
3942
extern "rust-call" fn dm4() {} //~ ERROR rust-call ABI is subject to change
@@ -42,6 +45,7 @@ trait Tr {
4245
extern "x86-interrupt" fn dm7() {} //~ ERROR x86-interrupt ABI is experimental
4346
extern "thiscall" fn dm8() {} //~ ERROR thiscall is experimental and subject to change
4447
extern "amdgpu-kernel" fn dm9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
48+
extern "efiapi" fn dm10() {} //~ ERROR efiapi ABI is experimental and subject to change
4549
}
4650

4751
struct S;
@@ -59,6 +63,7 @@ impl Tr for S {
5963
extern "x86-interrupt" fn m7() {} //~ ERROR x86-interrupt ABI is experimental
6064
extern "thiscall" fn m8() {} //~ ERROR thiscall is experimental and subject to change
6165
extern "amdgpu-kernel" fn m9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
66+
extern "efiapi" fn m10() {} //~ ERROR efiapi ABI is experimental and subject to change
6267
}
6368

6469
// Methods in inherent impl
@@ -74,6 +79,7 @@ impl S {
7479
extern "x86-interrupt" fn im7() {} //~ ERROR x86-interrupt ABI is experimental
7580
extern "thiscall" fn im8() {} //~ ERROR thiscall is experimental and subject to change
7681
extern "amdgpu-kernel" fn im9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
82+
extern "efiapi" fn im10() {} //~ ERROR efiapi ABI is experimental and subject to change
7783
}
7884

7985
// Function pointer types
@@ -86,6 +92,7 @@ type A6 = extern "ptx-kernel" fn (); //~ ERROR PTX ABIs are experimental and sub
8692
type A7 = extern "x86-interrupt" fn(); //~ ERROR x86-interrupt ABI is experimental
8793
type A8 = extern "thiscall" fn(); //~ ERROR thiscall is experimental and subject to change
8894
type A9 = extern "amdgpu-kernel" fn(); //~ ERROR amdgpu-kernel ABI is experimental and subject to change
95+
type A10 = extern "efiapi" fn(); //~ ERROR efiapi ABI is experimental and subject to change
8996

9097
// Foreign modules
9198
extern "rust-intrinsic" {} //~ ERROR intrinsics are subject to change
@@ -97,5 +104,6 @@ extern "ptx-kernel" {} //~ ERROR PTX ABIs are experimental and subject to change
97104
extern "x86-interrupt" {} //~ ERROR x86-interrupt ABI is experimental
98105
extern "thiscall" {} //~ ERROR thiscall is experimental and subject to change
99106
extern "amdgpu-kernel" {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
107+
extern "efiapi" {} //~ ERROR efiapi ABI is experimental and subject to change
100108

101109
fn main() {}

0 commit comments

Comments
 (0)