Skip to content

Commit db1e492

Browse files
Use small code model for UEFI targets
* Since the code model only applies to the code and not the data and the code model only applies to functions you call through using `call`, `jmp` and data with `lea`, etc… If you are calling functions using the function pointers from the UEFI structures the code model does not apply in that case. It’s just related to the address space size of your own binary. Since UEFI (uefi is all relocatable) uses relocatable PEs (relocatable code does not care about the code model) so, we use the small code model here. * Since applications don't usually take gigabytes of memory, setting the target to use the small code model should result in better codegen (comparable with majority of other targets). Large code models are also known for generating horrible code, for example 16 bytes of code to load a single 8-byte value. * Use the LLVM default code model for the architecture for the x86_64-unknown-uefi targets. For reference small is the default code model on x86 in LLVM: <https://github.com/llvm/llvm-project/blob/7de2173c2a4c45711831cfee3ccf53690c76ff07/llvm/lib/Target/X86/X86TargetMachine.cpp#L204> * Remove the comments too as they are not UEFI-specific and applies to pretty much any target. I added them before as I was explicitily setting the code model to small. Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent a08f25a commit db1e492

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// The win64 ABI is used. It differs from the sysv64 ABI, so we must use a windows target with
66
// LLVM. "x86_64-unknown-windows" is used to get the minimal subset of windows-specific features.
77

8-
use crate::spec::{CodeModel, Target};
8+
use crate::spec::Target;
99

1010
pub fn target() -> Target {
1111
let mut base = super::uefi_msvc_base::opts();
@@ -19,15 +19,11 @@ pub fn target() -> Target {
1919
// to leave these uninitialized, thus triggering exceptions if we make use of them. Which is
2020
// why we avoid them and instead use soft-floats. This is also what GRUB and friends did so
2121
// far.
22+
//
2223
// If you initialize FP units yourself, you can override these flags with custom linker
2324
// arguments, thus giving you access to full MMX/SSE acceleration.
2425
base.features = "-mmx,-sse,+soft-float".to_string();
2526

26-
// UEFI systems run without a host OS, hence we cannot assume any code locality. We must tell
27-
// LLVM to expect code to reference any address in the address-space. The "large" code-model
28-
// places no locality-restrictions, so it fits well here.
29-
base.code_model = Some(CodeModel::Large);
30-
3127
Target {
3228
llvm_target: "x86_64-unknown-windows".to_string(),
3329
pointer_width: 64,

0 commit comments

Comments
 (0)