Skip to content

Commit ca02125

Browse files
committed
test/codegen: add UEFI cross-compilation test
Add a new codegen test which cross-compiles a UEFI program and verifies that an entry-point is emitted. The UEFI code-generation has broken in nightly before, see for instance: commit c1b2fd2 Merge: faccb0f 6e77729 Author: Dylan DPC <[email protected]> Date: Tue May 5 01:49:44 2020 +0200 Rollup merge of rust-lang#71881 - IsaacWoods:master, r=petrochenkov Correctly handle UEFI targets as Windows-like when emitting sections for LLVM bitcode This commit adds a very simple UEFI program and verifies that cross-compilation with the built-in `x86_64-unknown-uefi` target works. No runtime testing, nor any elaborate code-validation is done. This simply serves as base test that verifies compilation works and an entry point is emitted. Usually, you would use `libcore`, but in this test we do not want to trigger re-compilation of `libcore` for `x86_64-unknown-uefi`. Hence, we pull in just enough of `libcore` to make the test compile. This UEFI program is fully functional and returns success (i.e., 0). You can run it from your UEFI BootManager or from EfiShell. The imported UEFI definitions are explicitly kept simple. For more elaborate use-cases you would want the full UEFI specification (see the `r_efi` crate for a standalone import of the base UEFI specification).
1 parent 10c2316 commit ca02125

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Checks whether UEFI targets cross-compile successfully.
2+
//
3+
// This test contains a simple UEFI program that simply exits with return code
4+
// 0. It can be easily run from the UEFI shell (but any other UEFI environment
5+
// works as well). This program is not run as part of the test. The test merely
6+
// verifies the cross-compilation does not fail and an entry-point is emitted.
7+
//
8+
// The imported definitions from the UEFI specification are intentionally left
9+
// incomplete. Only the bits that are actually used by this test are defined.
10+
11+
// min-llvm-version 9.0
12+
13+
// compile-flags: --target x86_64-unknown-uefi
14+
15+
#![feature(abi_efiapi, lang_items, no_core)]
16+
#![no_core]
17+
#![no_main]
18+
19+
#[lang = "sized"]
20+
pub trait Sized {}
21+
#[lang = "freeze"]
22+
pub trait Freeze {}
23+
#[lang = "copy"]
24+
pub trait Copy {}
25+
26+
// CHECK: define win64cc i64 @efi_main{{.*}}
27+
#[export_name = "efi_main"]
28+
pub extern "efiapi" fn main(_h: *mut usize, _st: *mut usize) -> usize {
29+
return 0;
30+
}

0 commit comments

Comments
 (0)