Skip to content

Commit 57870ea

Browse files
committed
rustc_target: Introduce msvc_base
and inherit both `windows_msvc_base` and `uefi_msvc_base` from it.
1 parent 88c4802 commit 57870ea

File tree

6 files changed

+59
-48
lines changed

6 files changed

+59
-48
lines changed

src/librustc_target/spec/i686_unknown_uefi.rs

-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ pub fn target() -> TargetResult {
2323
// arguments, thus giving you access to full MMX/SSE acceleration.
2424
base.features = "-mmx,-sse,+soft-float".to_string();
2525

26-
// UEFI mirrors the calling-conventions used on windows. In case of i686 this means small
27-
// structs will be returned as int. This shouldn't matter much, since the restrictions placed
28-
// by the UEFI specifications forbid any ABI to return structures.
29-
base.abi_return_struct_as_int = true;
30-
3126
// Use -GNU here, because of the reason below:
3227
// Background and Problem:
3328
// If we use i686-unknown-windows, the LLVM IA32 MSVC generates compiler intrinsic

src/librustc_target/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ mod l4re_base;
5959
mod linux_base;
6060
mod linux_kernel_base;
6161
mod linux_musl_base;
62+
mod msvc_base;
6263
mod netbsd_base;
6364
mod openbsd_base;
6465
mod redox_base;

src/librustc_target/spec/msvc_base.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
2+
3+
pub fn opts() -> TargetOptions {
4+
let pre_link_args_msvc = vec![
5+
// Suppress the verbose logo and authorship debugging output, which would needlessly
6+
// clog any log files.
7+
"/NOLOGO".to_string(),
8+
// Tell the compiler that non-code sections can be marked as non-executable,
9+
// including stack pages.
10+
// UEFI is fully compatible to non-executable data pages.
11+
// In fact, firmware might enforce this, so we better let the linker know about this,
12+
// so it will fail if the compiler ever tries placing code on the stack
13+
// (e.g., trampoline constructs and alike).
14+
"/NXCOMPAT".to_string(),
15+
];
16+
let mut pre_link_args = LinkArgs::new();
17+
pre_link_args.insert(LinkerFlavor::Msvc, pre_link_args_msvc.clone());
18+
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Link), pre_link_args_msvc);
19+
20+
TargetOptions {
21+
executables: true,
22+
is_like_windows: true,
23+
is_like_msvc: true,
24+
// set VSLANG to 1033 can prevent link.exe from using
25+
// language packs, and avoid generating Non-UTF-8 error
26+
// messages if a link error occurred.
27+
link_env: vec![("VSLANG".to_string(), "1033".to_string())],
28+
lld_flavor: LldFlavor::Link,
29+
pre_link_args,
30+
// UEFI mirrors the calling-conventions used on windows. In case of x86-64 and i686 this
31+
// means small structs will be returned as int. This shouldn't matter much, since the
32+
// restrictions placed by the UEFI specifications forbid any ABI to return structures.
33+
abi_return_struct_as_int: true,
34+
emit_debug_gdb_scripts: false,
35+
36+
..Default::default()
37+
}
38+
}

src/librustc_target/spec/uefi_msvc_base.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,12 @@
99
// the timer-interrupt. Device-drivers are required to use polling-based models. Furthermore, all
1010
// code runs in the same environment, no process separation is supported.
1111

12-
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions};
12+
use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions};
1313

1414
pub fn opts() -> TargetOptions {
15+
let mut base = super::msvc_base::opts();
16+
1517
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(),
2518
// Non-standard subsystems have no default entry-point in PE+ files. We have to define
2619
// one. "efi_main" seems to be a common choice amongst other implementations and the
2720
// spec.
@@ -37,25 +30,29 @@ pub fn opts() -> TargetOptions {
3730
// exit (default for applications).
3831
"/subsystem:efi_application".to_string(),
3932
];
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);
33+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().extend(pre_link_args_msvc.clone());
34+
base.pre_link_args
35+
.get_mut(&LinkerFlavor::Lld(LldFlavor::Link))
36+
.unwrap()
37+
.extend(pre_link_args_msvc);
4338

4439
TargetOptions {
45-
dynamic_linking: false,
46-
executables: true,
4740
disable_redzone: true,
4841
exe_suffix: ".efi".to_string(),
4942
allows_weak_linkage: false,
5043
panic_strategy: PanicStrategy::Abort,
5144
stack_probes: true,
5245
singlethread: true,
53-
emit_debug_gdb_scripts: false,
54-
5546
linker: Some("rust-lld".to_string()),
56-
lld_flavor: LldFlavor::Link,
57-
pre_link_args,
47+
// FIXME: This should likely be `true` inherited from `msvc_base`
48+
// because UEFI follows Windows ABI and uses PE/COFF.
49+
// The `false` is probably causing ABI bugs right now.
50+
is_like_windows: false,
51+
// FIXME: This should likely be `true` inherited from `msvc_base`
52+
// because UEFI follows Windows ABI and uses PE/COFF.
53+
// The `false` is probably causing ABI bugs right now.
54+
is_like_msvc: false,
5855

59-
..Default::default()
56+
..base
6057
}
6158
}
+3-18
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
1+
use crate::spec::TargetOptions;
22

33
pub fn opts() -> TargetOptions {
4-
let pre_link_args_msvc = vec!["/NOLOGO".to_string(), "/NXCOMPAT".to_string()];
5-
let mut pre_link_args = LinkArgs::new();
6-
pre_link_args.insert(LinkerFlavor::Msvc, pre_link_args_msvc.clone());
7-
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Link), pre_link_args_msvc);
4+
let base = super::msvc_base::opts();
85

96
TargetOptions {
10-
function_sections: true,
117
dynamic_linking: true,
12-
executables: true,
138
dll_prefix: String::new(),
149
dll_suffix: ".dll".to_string(),
1510
exe_suffix: ".exe".to_string(),
1611
staticlib_prefix: String::new(),
1712
staticlib_suffix: ".lib".to_string(),
1813
target_family: Some("windows".to_string()),
19-
is_like_windows: true,
20-
is_like_msvc: true,
21-
// set VSLANG to 1033 can prevent link.exe from using
22-
// language packs, and avoid generating Non-UTF-8 error
23-
// messages if a link error occurred.
24-
link_env: vec![("VSLANG".to_string(), "1033".to_string())],
25-
lld_flavor: LldFlavor::Link,
26-
pre_link_args,
2714
crt_static_allows_dylibs: true,
2815
crt_static_respected: true,
29-
abi_return_struct_as_int: true,
30-
emit_debug_gdb_scripts: false,
3116
requires_uwtable: true,
3217
// Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
3318
// as there's been trouble in the past of linking the C++ standard
@@ -40,6 +25,6 @@ pub fn opts() -> TargetOptions {
4025
// not ever be possible for us to pass this flag.
4126
no_default_libraries: false,
4227

43-
..Default::default()
28+
..base
4429
}
4530
}

src/librustc_target/spec/x86_64_unknown_uefi.rs

-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ pub fn target() -> TargetResult {
2828
// places no locality-restrictions, so it fits well here.
2929
base.code_model = Some("large".to_string());
3030

31-
// UEFI mirrors the calling-conventions used on windows. In case of x86-64 this means small
32-
// structs will be returned as int. This shouldn't matter much, since the restrictions placed
33-
// by the UEFI specifications forbid any ABI to return structures.
34-
base.abi_return_struct_as_int = true;
35-
3631
Ok(Target {
3732
llvm_target: "x86_64-unknown-windows".to_string(),
3833
target_endian: "little".to_string(),

0 commit comments

Comments
 (0)