|
| 1 | +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// This defines a base target-configuration for native UEFI systems. The UEFI specification has |
| 12 | +// quite detailed sections on the ABI of all the supported target architectures. In almost all |
| 13 | +// cases it simply follows what Microsoft Windows does. Hence, whenever in doubt, see the MSDN |
| 14 | +// documentation. |
| 15 | +// UEFI uses COFF/PE32+ format for binaries. All binaries must be statically linked. No dynamic |
| 16 | +// linker is supported. As native to COFF, binaries are position-dependent, but will be relocated |
| 17 | +// by the loader if the pre-chosen memory location is already in use. |
| 18 | +// UEFI forbids running code on anything but the boot-CPU. Not interrupts are allowed other than |
| 19 | +// the timer-interrupt. Device-drivers are required to use polling-based models. Furthermore, all |
| 20 | +// code runs in the same environment, no process separation is supported. |
| 21 | + |
| 22 | +use spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions}; |
| 23 | +use std::default::Default; |
| 24 | + |
| 25 | +pub fn opts() -> TargetOptions { |
| 26 | + let mut pre_link_args = LinkArgs::new(); |
| 27 | + |
| 28 | + pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Link), vec![ |
| 29 | + // Suppress the verbose logo and authorship debugging output, which would needlessly |
| 30 | + // clog any log files. |
| 31 | + "/NOLOGO".to_string(), |
| 32 | + |
| 33 | + // UEFI is fully compatible to non-executable data pages. Tell the compiler that |
| 34 | + // non-code sections can be marked as non-executable, including stack pages. |
| 35 | + "/NXCOMPAT".to_string(), |
| 36 | + |
| 37 | + // There is no runtime for UEFI targets, prevent them from being linked. UEFI targets |
| 38 | + // must be freestanding. |
| 39 | + "/nodefaultlib".to_string(), |
| 40 | + |
| 41 | + // Non-standard subsystems have no default entry-point in PE+ files. We have to define |
| 42 | + // one. "efi_main" seems to be a common choice amongst other implementations and the |
| 43 | + // spec. |
| 44 | + "/entry:efi_main".to_string(), |
| 45 | + |
| 46 | + // COFF images have a "Subsystem" field in their header, which defines what kind of |
| 47 | + // program it is. UEFI has 3 fields reserved, which are EFI_APPLICATION, |
| 48 | + // EFI_BOOT_SERVICE_DRIVER, and EFI_RUNTIME_DRIVER. We default to EFI_APPLICATION, |
| 49 | + // which is very likely the most common option. Individual projects can override this |
| 50 | + // with custom linker flags. |
| 51 | + // The subsystem-type only has minor effects on the application. It defines the memory |
| 52 | + // regions the application is loaded into (runtime-drivers need to be put into |
| 53 | + // reserved areas), as well as whether a return from the entry-point is treated as |
| 54 | + // exit (default for applications). |
| 55 | + "/subsystem:efi_application".to_string(), |
| 56 | + ]); |
| 57 | + |
| 58 | + TargetOptions { |
| 59 | + dynamic_linking: false, |
| 60 | + executables: true, |
| 61 | + disable_redzone: true, |
| 62 | + exe_suffix: ".efi".to_string(), |
| 63 | + allows_weak_linkage: false, |
| 64 | + panic_strategy: PanicStrategy::Abort, |
| 65 | + singlethread: true, |
| 66 | + emit_debug_gdb_scripts: false, |
| 67 | + |
| 68 | + linker: Some("lld-link".to_string()), |
| 69 | + lld_flavor: LldFlavor::Link, |
| 70 | + pre_link_args, |
| 71 | + |
| 72 | + .. Default::default() |
| 73 | + } |
| 74 | +} |
0 commit comments