Skip to content

Commit 04d41e1

Browse files
committed
rustc_target: Mark UEFI targets as is_like_windows/is_like_msvc
Document what `is_like_windows` and `is_like_msvc` mean in more detail.
1 parent 7f5a42b commit 04d41e1

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,7 @@ unsafe fn embed_bitcode(
925925
|| cgcx.opts.target_triple.triple().starts_with("asmjs")
926926
{
927927
// nothing to do here
928-
} else if cgcx.opts.target_triple.triple().contains("windows")
929-
|| cgcx.opts.target_triple.triple().contains("uefi")
930-
{
928+
} else if cgcx.is_pe_coff {
931929
let asm = "
932930
.section .llvmbc,\"n\"
933931
.section .llvmcmd,\"n\"

compiler/rustc_codegen_ssa/src/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
307307
pub allocator_module_config: Arc<ModuleConfig>,
308308
pub tm_factory: TargetMachineFactory<B>,
309309
pub msvc_imps_needed: bool,
310+
pub is_pe_coff: bool,
310311
pub target_pointer_width: u32,
311312
pub target_arch: String,
312313
pub debuginfo: config::DebugInfo,
@@ -1022,6 +1023,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
10221023
tm_factory: TargetMachineFactory(backend.target_machine_factory(tcx.sess, ol)),
10231024
total_cgus,
10241025
msvc_imps_needed: msvc_imps_needed(tcx),
1026+
is_pe_coff: tcx.sess.target.is_like_windows,
10251027
target_pointer_width: tcx.sess.target.pointer_width,
10261028
target_arch: tcx.sess.target.arch.clone(),
10271029
debuginfo: tcx.sess.opts.debuginfo,

compiler/rustc_target/src/spec/mod.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,23 @@ pub struct TargetOptions {
819819
/// Only useful for compiling against Illumos/Solaris,
820820
/// as they have a different set of linker flags. Defaults to false.
821821
pub is_like_solaris: bool,
822-
/// Whether the target toolchain is like Windows'. Only useful for compiling against Windows,
823-
/// only really used for figuring out how to find libraries, since Windows uses its own
824-
/// library naming convention. Defaults to false.
822+
/// Whether the target is like Windows.
823+
/// This is a combination of several more specific properties represented as a single flag:
824+
/// - The target uses a Windows ABI,
825+
/// - uses PE/COFF as a format for object code,
826+
/// - uses Windows-style dllexport/dllimport for shared libraries,
827+
/// - uses import libraries and .def files for symbol exports,
828+
/// - executables support setting a subsystem.
825829
pub is_like_windows: bool,
830+
/// Whether the target is like MSVC.
831+
/// This is a combination of several more specific properties represented as a single flag:
832+
/// - The target has all the properties from `is_like_windows`
833+
/// (for in-tree targets "is_like_msvc ⇒ is_like_windows" is ensured by a unit test),
834+
/// - has some MSVC-specific Windows ABI properties,
835+
/// - uses a link.exe-like linker,
836+
/// - uses CodeView/PDB for debuginfo and natvis for its visualization,
837+
/// - uses SEH-based unwinding,
838+
/// - supports control flow guard mechanism.
826839
pub is_like_msvc: bool,
827840
/// Whether the target toolchain is like Emscripten's. Only useful for compiling with
828841
/// Emscripten toolchain.

compiler/rustc_target/src/spec/tests/tests_impl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(super) fn test_target(target: Target) {
88

99
impl Target {
1010
fn check_consistency(&self) {
11+
assert!(self.is_like_windows || !self.is_like_msvc);
1112
// Check that LLD with the given flavor is treated identically to the linker it emulates.
1213
// If your target really needs to deviate from the rules below, except it and document the
1314
// reasons.
@@ -16,6 +17,7 @@ impl Target {
1617
|| self.linker_flavor == LinkerFlavor::Lld(LldFlavor::Link),
1718
self.lld_flavor == LldFlavor::Link,
1819
);
20+
assert_eq!(self.is_like_msvc, self.lld_flavor == LldFlavor::Link);
1921
for args in &[
2022
&self.pre_link_args,
2123
&self.late_link_args,

compiler/rustc_target/src/spec/uefi_msvc_base.rs

-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ pub fn opts() -> TargetOptions {
4646
stack_probes: true,
4747
singlethread: true,
4848
linker: Some("rust-lld".to_string()),
49-
// FIXME: This should likely be `true` inherited from `msvc_base`
50-
// because UEFI follows Windows ABI and uses PE/COFF.
51-
// The `false` is probably causing ABI bugs right now.
52-
is_like_windows: false,
53-
// FIXME: This should likely be `true` inherited from `msvc_base`
54-
// because UEFI follows Windows ABI and uses PE/COFF.
55-
// The `false` is probably causing ABI bugs right now.
56-
is_like_msvc: false,
57-
5849
..base
5950
}
6051
}

0 commit comments

Comments
 (0)