Skip to content

Commit 90d36fb

Browse files
committed
Auto merge of #53621 - jordanrh1:windows-arm, r=alexcrichton
Add target thumbv7a-pc-windows-msvc This is an early draft of support for Windows/ARM. To test it, 1. Install Visual Studio 2017 and Windows SDK version 17134. 1. Obtain alexcrichton/xz2-rs#35, rust-lang/compiler-builtins#256, and the fix for [LLVM Bug 38620](https://bugs.llvm.org/show_bug.cgi?id=38620). 2. Open a command prompt and run ``` set CC_thumbv7a-pc-windows-msvc=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\bin\HostX64\arm\CL.exe set CFLAGS_thumbv7a-pc-windows-msvc=/D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1 /nologo c:\python27\python.exe x.py build --host x86_64-pc-windows-msvc --build x86_64-pc-windows-msvc --target thumbv7a-pc-windows-msvc ``` It will build the stage 2 compiler, but fail building stage 2 test. To build an executable targeting windows/arm, 1. Copy `build\x86_64-pc-windows-msvc\stage0\bin\cargo.exe` to `build\x86_64-pc-windows-msvc\stage2\bin` 2. Open a command prompt and run ``` "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat" set PATH=build\x86_64-pc-windows-msvc\stage2\bin;%PATH% cargo new hello cd hello cargo build --target thumbv7a-pc-windows-msvc –release ``` Copy target\thumbv7a-pc-windows-msvc\release\hello.exe to your platform and run. There are a number of open issues that I'm hoping to get help with: - Error when compiling the `test` crate: `error: cannot link together two panic runtimes: panic_abort and panic_unwind` - Warnings when building the compiler_builtins crate: `warning: cl : Command line warning D9002 : ignoring unknown option '-fvisibility=hidden'`. It looks like the build system is passing GCC-style flags to MSVC. - How to specify the LIBPATH entries for ARM. Right now they are hardcoded as absolute paths in the target spec. This pull request depends on - alexcrichton/xz2-rs#35 - update vcxproj to Visual Studio 2017 - rust-lang/compiler-builtins#256 - fix compile errors when building for windows/arm - [Bug 38620 - ARM: Incorrect COFF relocation type for thumb bl instruction](https://bugs.llvm.org/show_bug.cgi?id=38620) This PR updates #52659
2 parents 994cdd9 + fd41c39 commit 90d36fb

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

Diff for: src/libpanic_unwind/seh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod imp {
119119
}
120120
}
121121

122-
#[cfg(target_arch = "x86_64")]
122+
#[cfg(any(target_arch = "x86_64", target_arch = "arm"))]
123123
#[macro_use]
124124
mod imp {
125125
pub type ptr_t = u32;

Diff for: src/librustc_target/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ supported_targets! {
386386
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
387387
("i686-pc-windows-msvc", i686_pc_windows_msvc),
388388
("i586-pc-windows-msvc", i586_pc_windows_msvc),
389+
("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
389390

390391
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
391392
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),

Diff for: src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
use spec::{LinkerFlavor, Target, TargetOptions, TargetResult, PanicStrategy};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::windows_msvc_base::opts();
15+
16+
// Prevent error LNK2013: BRANCH24(T) fixup overflow
17+
// The LBR optimization tries to eliminate branch islands,
18+
// but if the displacement is larger than can fit
19+
// in the instruction, this error will occur. The linker
20+
// should be smart enough to insert branch islands only
21+
// where necessary, but this is not the observed behavior.
22+
// Disabling the LBR optimization works around the issue.
23+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
24+
"/OPT:NOLBR".to_string());
25+
26+
// FIXME(jordanrh): use PanicStrategy::Unwind when SEH is
27+
// implemented for windows/arm in LLVM
28+
base.panic_strategy = PanicStrategy::Abort;
29+
30+
Ok(Target {
31+
llvm_target: "thumbv7a-pc-windows-msvc".to_string(),
32+
target_endian: "little".to_string(),
33+
target_pointer_width: "32".to_string(),
34+
target_c_int_width: "32".to_string(),
35+
data_layout: "e-m:w-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
36+
arch: "arm".to_string(),
37+
target_os: "windows".to_string(),
38+
target_env: "msvc".to_string(),
39+
target_vendor: "pc".to_string(),
40+
linker_flavor: LinkerFlavor::Msvc,
41+
42+
options: TargetOptions {
43+
features: "+vfp3,+neon".to_string(),
44+
cpu: "generic".to_string(),
45+
max_atomic_width: Some(64),
46+
abi_blacklist: super::arm_base::abi_blacklist(),
47+
.. base
48+
}
49+
})
50+
}

Diff for: src/libstd/sys/windows/backtrace/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ impl StackFrame for c::STACKFRAME_EX {
248248
c::IMAGE_FILE_MACHINE_AMD64
249249
}
250250

251+
#[cfg(target_arch = "arm")]
252+
fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD {
253+
self.AddrPC.Offset = ctx.Pc as u64;
254+
self.AddrPC.Mode = c::ADDRESS_MODE::AddrModeFlat;
255+
self.AddrStack.Offset = ctx.Sp as u64;
256+
self.AddrStack.Mode = c::ADDRESS_MODE::AddrModeFlat;
257+
self.AddrFrame.Offset = ctx.R11 as u64;
258+
self.AddrFrame.Mode = c::ADDRESS_MODE::AddrModeFlat;
259+
c::IMAGE_FILE_MACHINE_ARMNT
260+
}
261+
251262
#[cfg(target_arch = "aarch64")]
252263
fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD {
253264
self.AddrPC.Offset = ctx.Pc as u64;
@@ -291,6 +302,17 @@ impl StackFrame for c::STACKFRAME64 {
291302
c::IMAGE_FILE_MACHINE_AMD64
292303
}
293304

305+
#[cfg(target_arch = "arm")]
306+
fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD {
307+
self.AddrPC.Offset = ctx.Pc as u64;
308+
self.AddrPC.Mode = c::ADDRESS_MODE::AddrModeFlat;
309+
self.AddrStack.Offset = ctx.Sp as u64;
310+
self.AddrStack.Mode = c::ADDRESS_MODE::AddrModeFlat;
311+
self.AddrFrame.Offset = ctx.R11 as u64;
312+
self.AddrFrame.Mode = c::ADDRESS_MODE::AddrModeFlat;
313+
c::IMAGE_FILE_MACHINE_ARMNT
314+
}
315+
294316
#[cfg(target_arch = "aarch64")]
295317
fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD {
296318
self.AddrPC.Offset = ctx.Pc as u64;

Diff for: src/libstd/sys/windows/c.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
114114

115115
pub const FIONBIO: c_ulong = 0x8004667e;
116116

117+
#[cfg(target_arch = "arm")]
118+
const ARM_MAX_BREAKPOINTS: usize = 8;
119+
#[cfg(target_arch = "arm")]
120+
const ARM_MAX_WATCHPOINTS: usize = 1;
121+
117122
#[repr(C)]
118123
#[derive(Copy)]
119124
pub struct WIN32_FIND_DATAW {
@@ -283,6 +288,9 @@ pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
283288
#[cfg(target_arch = "aarch64")]
284289
#[cfg(feature = "backtrace")]
285290
pub const IMAGE_FILE_MACHINE_ARM64: DWORD = 0xAA64;
291+
#[cfg(target_arch = "arm")]
292+
#[cfg(feature = "backtrace")]
293+
pub const IMAGE_FILE_MACHINE_ARMNT: DWORD = 0x01c4;
286294

287295
pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
288296
pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
@@ -789,12 +797,44 @@ pub struct FLOATING_SAVE_AREA {
789797
_Dummy: [u8; 512] // FIXME: Fill this out
790798
}
791799

800+
#[cfg(target_arch = "arm")]
801+
#[repr(C)]
802+
pub struct CONTEXT {
803+
pub ContextFlags: ULONG,
804+
pub R0: ULONG,
805+
pub R1: ULONG,
806+
pub R2: ULONG,
807+
pub R3: ULONG,
808+
pub R4: ULONG,
809+
pub R5: ULONG,
810+
pub R6: ULONG,
811+
pub R7: ULONG,
812+
pub R8: ULONG,
813+
pub R9: ULONG,
814+
pub R10: ULONG,
815+
pub R11: ULONG,
816+
pub R12: ULONG,
817+
pub Sp: ULONG,
818+
pub Lr: ULONG,
819+
pub Pc: ULONG,
820+
pub Cpsr: ULONG,
821+
pub Fpscr: ULONG,
822+
pub Padding: ULONG,
823+
pub D: [u64; 32],
824+
pub Bvr: [ULONG; ARM_MAX_BREAKPOINTS],
825+
pub Bcr: [ULONG; ARM_MAX_BREAKPOINTS],
826+
pub Wvr: [ULONG; ARM_MAX_WATCHPOINTS],
827+
pub Wcr: [ULONG; ARM_MAX_WATCHPOINTS],
828+
pub Padding2: [ULONG; 2]
829+
}
830+
792831
// FIXME(#43348): This structure is used for backtrace only, and a fake
793832
// definition is provided here only to allow rustdoc to pass type-check. This
794833
// will not appear in the final documentation. This should be also defined for
795834
// other architectures supported by Windows such as ARM, and for historical
796835
// interest, maybe MIPS and PowerPC as well.
797-
#[cfg(all(rustdoc, not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))))]
836+
#[cfg(all(rustdoc, not(any(target_arch = "x86_64", target_arch = "x86",
837+
target_arch = "aarch64", target_arch = "arm"))))]
798838
pub enum CONTEXT {}
799839

800840
#[cfg(target_arch = "aarch64")]

0 commit comments

Comments
 (0)