]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/uefi_msvc_base.rs
rustc_target: Remove some useless imports
[rust.git] / src / librustc_target / spec / uefi_msvc_base.rs
1 // This defines a base target-configuration for native UEFI systems. The UEFI specification has
2 // quite detailed sections on the ABI of all the supported target architectures. In almost all
3 // cases it simply follows what Microsoft Windows does. Hence, whenever in doubt, see the MSDN
4 // documentation.
5 // UEFI uses COFF/PE32+ format for binaries. All binaries must be statically linked. No dynamic
6 // linker is supported. As native to COFF, binaries are position-dependent, but will be relocated
7 // by the loader if the pre-chosen memory location is already in use.
8 // UEFI forbids running code on anything but the boot-CPU. No interrupts are allowed other than
9 // the timer-interrupt. Device-drivers are required to use polling-based models. Furthermore, all
10 // code runs in the same environment, no process separation is supported.
11
12 use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions};
13
14 pub fn opts() -> TargetOptions {
15     let pre_link_args_msvc = vec![
16         // Suppress the verbose logo and authorship debugging output, which would needlessly
17         // clog any log files.
18         "/NOLOGO".to_string(),
19         // UEFI is fully compatible to non-executable data pages. Tell the compiler that
20         // non-code sections can be marked as non-executable, including stack pages. In fact,
21         // firmware might enforce this, so we better let the linker know about this, so it
22         // will fail if the compiler ever tries placing code on the stack (e.g., trampoline
23         // constructs and alike).
24         "/NXCOMPAT".to_string(),
25         // Non-standard subsystems have no default entry-point in PE+ files. We have to define
26         // one. "efi_main" seems to be a common choice amongst other implementations and the
27         // spec.
28         "/entry:efi_main".to_string(),
29         // COFF images have a "Subsystem" field in their header, which defines what kind of
30         // program it is. UEFI has 3 fields reserved, which are EFI_APPLICATION,
31         // EFI_BOOT_SERVICE_DRIVER, and EFI_RUNTIME_DRIVER. We default to EFI_APPLICATION,
32         // which is very likely the most common option. Individual projects can override this
33         // with custom linker flags.
34         // The subsystem-type only has minor effects on the application. It defines the memory
35         // regions the application is loaded into (runtime-drivers need to be put into
36         // reserved areas), as well as whether a return from the entry-point is treated as
37         // exit (default for applications).
38         "/subsystem:efi_application".to_string(),
39     ];
40     let mut pre_link_args = LinkArgs::new();
41     pre_link_args.insert(LinkerFlavor::Msvc, pre_link_args_msvc.clone());
42     pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Link), pre_link_args_msvc);
43
44     TargetOptions {
45         dynamic_linking: false,
46         executables: true,
47         disable_redzone: true,
48         exe_suffix: ".efi".to_string(),
49         allows_weak_linkage: false,
50         panic_strategy: PanicStrategy::Abort,
51         stack_probes: true,
52         singlethread: true,
53         emit_debug_gdb_scripts: false,
54
55         linker: Some("rust-lld".to_string()),
56         lld_flavor: LldFlavor::Link,
57         pre_link_args,
58
59         ..Default::default()
60     }
61 }