Skip to content

Commit

Permalink
Limit efiapi calling convention to supported arches
Browse files Browse the repository at this point in the history
Supported architectures in UEFI are described here:
https://uefi.org/specs/UEFI/2.10/02_Overview.html#calling-conventions

Changes to tests modeled on 8240e7a.

rust-lang#65815
  • Loading branch information
nicholasbishop committed Nov 6, 2022
1 parent 7eef946 commit 16edaa5
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 100 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,8 +1941,10 @@ impl Target {
| PlatformIntrinsic
| Unadjusted
| Cdecl { .. }
| EfiApi
| RustCold => true,
EfiApi => {
["arm", "aarch64", "riscv32", "riscv64", "x86", "x86_64"].contains(&&self.arch[..])
}
X86Interrupt => ["x86", "x86_64"].contains(&&self.arch[..]),
Aapcs { .. } => "arm" == self.arch,
CCmseNonSecureCall => ["arm", "aarch64"].contains(&&self.arch[..]),
Expand Down
33 changes: 33 additions & 0 deletions src/test/ui/feature-gates/feature-gate-abi-efiapi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// needs-llvm-components: x86
// compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib
#![no_core]
#![feature(no_core, lang_items)]
#[lang="sized"]
trait Sized { }

// Functions
extern "efiapi" fn f1() {} //~ ERROR efiapi ABI is experimental

// Methods in trait defintion
trait Tr {
extern "efiapi" fn f2(); //~ ERROR efiapi ABI is experimental
extern "efiapi" fn f3() {} //~ ERROR efiapi ABI is experimental
}

struct S;

// Methods in trait impl
impl Tr for S {
extern "efiapi" fn f2() {} //~ ERROR efiapi ABI is experimental
}

// Methods in inherent impl
impl S {
extern "efiapi" fn f4() {} //~ ERROR efiapi ABI is experimental
}

// Function pointer types
type A = extern "efiapi" fn(); //~ ERROR efiapi ABI is experimental

// Foreign modules
extern "efiapi" {} //~ ERROR efiapi ABI is experimental
66 changes: 66 additions & 0 deletions src/test/ui/feature-gates/feature-gate-abi-efiapi.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:9:8
|
LL | extern "efiapi" fn f1() {}
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:13:12
|
LL | extern "efiapi" fn f2();
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:14:12
|
LL | extern "efiapi" fn f3() {}
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:21:12
|
LL | extern "efiapi" fn f2() {}
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:26:12
|
LL | extern "efiapi" fn f4() {}
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:30:17
|
LL | type A = extern "efiapi" fn();
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error[E0658]: efiapi ABI is experimental and subject to change
--> $DIR/feature-gate-abi-efiapi.rs:33:8
|
LL | extern "efiapi" {}
| ^^^^^^^^
|
= note: see issue #65815 <https://github.com/rust-lang/rust/issues/65815> for more information
= help: add `#![feature(abi_efiapi)]` to the crate attributes to enable

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0658`.
8 changes: 0 additions & 8 deletions src/test/ui/feature-gates/feature-gate-abi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// gate-test-intrinsics
// gate-test-platform_intrinsics
// gate-test-abi_efiapi
// compile-flags: --crate-type=rlib

#![feature(no_core, lang_items)]
Expand All @@ -18,7 +17,6 @@ extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "rust-call" fn f4(_: ()) {} //~ ERROR rust-call ABI is subject to change
extern "efiapi" fn f10() {} //~ ERROR efiapi ABI is experimental and subject to change

// Methods in trait definition
trait Tr {
Expand All @@ -27,10 +25,8 @@ trait Tr {
extern "platform-intrinsic" fn m2(); //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "rust-call" fn m4(_: ()); //~ ERROR rust-call ABI is subject to change
extern "efiapi" fn m10(); //~ ERROR efiapi ABI is experimental and subject to change

extern "rust-call" fn dm4(_: ()) {} //~ ERROR rust-call ABI is subject to change
extern "efiapi" fn dm10() {} //~ ERROR efiapi ABI is experimental and subject to change
}

struct S;
Expand All @@ -42,7 +38,6 @@ impl Tr for S {
extern "platform-intrinsic" fn m2() {} //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "rust-call" fn m4(_: ()) {} //~ ERROR rust-call ABI is subject to change
extern "efiapi" fn m10() {} //~ ERROR efiapi ABI is experimental and subject to change
}

// Methods in inherent impl
Expand All @@ -52,17 +47,14 @@ impl S {
extern "platform-intrinsic" fn im2() {} //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "rust-call" fn im4(_: ()) {} //~ ERROR rust-call ABI is subject to change
extern "efiapi" fn im10() {} //~ ERROR efiapi ABI is experimental and subject to change
}

// Function pointer types
type A1 = extern "rust-intrinsic" fn(); //~ ERROR intrinsics are subject to change
type A2 = extern "platform-intrinsic" fn(); //~ ERROR platform intrinsics are experimental
type A4 = extern "rust-call" fn(_: ()); //~ ERROR rust-call ABI is subject to change
type A10 = extern "efiapi" fn(); //~ ERROR efiapi ABI is experimental and subject to change

// Foreign modules
extern "rust-intrinsic" {} //~ ERROR intrinsics are subject to change
extern "platform-intrinsic" {} //~ ERROR platform intrinsics are experimental
extern "rust-call" {} //~ ERROR rust-call ABI is subject to change
extern "efiapi" {} //~ ERROR efiapi ABI is experimental and subject to change
Loading

0 comments on commit 16edaa5

Please sign in to comment.