Skip to content

Commit c5d8681

Browse files
authoredOct 29, 2019
Rollup merge of rust-lang#65809 - roblabla:eficall-abi, r=nagisa
Add new EFIAPI ABI Fixes rust-lang#54527 Adds a new ABI, "efiapi", which reflects the calling convention as specified by [the current spec UEFI spec](https://uefi.org/sites/default/files/resources/UEFI%20Spec%202_7_A%20Sept%206.pdf#G6.999903). When compiling for x86_64, we should select the `win64` ABI, while on all other architectures (Itanium, x86, ARM and ARM64 and RISC-V), we should select the `C` ABI. Currently, this is done by just turning it into the C ABI everywhere except on x86_64, where it's turned into the win64 ABI. Should we prevent this ABI from being used on unsupported architectures, and if so, how would this be done?
2 parents fb73c0b + 1099826 commit c5d8681

File tree

15 files changed

+203
-82
lines changed

15 files changed

+203
-82
lines changed
 

‎src/librustc/ich/impls_syntax.rs

+1
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

+1
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

+2
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

+7
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

+3
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ declare_features! (
533533
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
534534
(active, object_safe_for_dispatch, "1.40.0", Some(43561), None),
535535

536+
/// Allows using the `efiapi` ABI.
537+
(active, abi_efiapi, "1.40.0", Some(65815), None),
538+
536539
// -------------------------------------------------------------------------
537540
// feature-group-end: actual feature gates
538541
// -------------------------------------------------------------------------

‎src/libsyntax/feature_gate/check.rs

+4
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ impl<'a> PostExpansionVisitor<'a> {
227227
gate_feature_post!(&self, abi_amdgpu_kernel, span,
228228
"amdgpu-kernel ABI is experimental and subject to change");
229229
},
230+
Abi::EfiApi => {
231+
gate_feature_post!(&self, abi_efiapi, span,
232+
"efiapi ABI is experimental and subject to change");
233+
},
230234
// Stable
231235
Abi::Cdecl |
232236
Abi::Stdcall |

‎src/libsyntax_pos/symbol.rs

+1
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

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Checks if the correct annotation for the efiapi ABI is passed to llvm.
2+
3+
// revisions:x86_64 i686 aarch64 arm riscv
4+
5+
// min-llvm-version 9.0
6+
7+
//[x86_64] compile-flags: --target x86_64-unknown-uefi
8+
//[i686] compile-flags: --target i686-unknown-linux-musl
9+
//[aarch64] compile-flags: --target aarch64-unknown-none
10+
//[arm] compile-flags: --target armv7r-none-eabi
11+
//[riscv] compile-flags: --target riscv64gc-unknown-none-elf
12+
// compile-flags: -C no-prepopulate-passes
13+
14+
#![crate_type = "lib"]
15+
#![feature(no_core, lang_items, abi_efiapi)]
16+
#![no_core]
17+
18+
#[lang="sized"]
19+
trait Sized { }
20+
#[lang="freeze"]
21+
trait Freeze { }
22+
#[lang="copy"]
23+
trait Copy { }
24+
25+
//x86_64: define win64cc void @has_efiapi
26+
//i686: define void @has_efiapi
27+
//aarch64: define void @has_efiapi
28+
//arm: define void @has_efiapi
29+
//riscv: define void @has_efiapi
30+
#[no_mangle]
31+
pub extern "efiapi" fn has_efiapi() {}

‎src/test/ui/codemap_tests/unicode.stderr

+1-1
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

+8
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)
Please sign in to comment.