Skip to content

Commit f7fa67c

Browse files
committed
Add target thumbv7a-pc-windows-msvc
1 parent 1c2e17f commit f7fa67c

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

src/libpanic_unwind/seh.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ mod imp {
119119
}
120120
}
121121

122-
#[cfg(target_arch = "x86_64")]
122+
// TODO: this needs to be validated when WinEH for ARM is implemented in LLVM
123+
// It looks like ARM and ARM64 use the same _TypeInfo semantics as x64
124+
#[cfg(any(target_arch = "x86_64", target_arch = "arm"))]
123125
#[macro_use]
124126
mod imp {
125127
pub type ptr_t = u32;

src/librustc_target/spec/mod.rs

Lines changed: 1 addition & 0 deletions
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),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2016 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+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
17+
"/LIBPATH:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.11.25503\\lib\\arm".to_string());
18+
19+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
20+
"/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\ucrt\\arm".to_string());
21+
22+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
23+
"/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\um\\arm".to_string());
24+
25+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
26+
"/MACHINE:ARM".to_string());
27+
28+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
29+
"/INCREMENTAL:NO".to_string());
30+
31+
// Prevent error LNK2013: BRANCH24(T) fixup overflow
32+
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push(
33+
"/OPT:NOLBR".to_string());
34+
35+
base.panic_strategy = PanicStrategy::Abort;
36+
37+
Ok(Target {
38+
llvm_target: "thumbv7a-pc-windows-msvc".to_string(),
39+
target_endian: "little".to_string(),
40+
target_pointer_width: "32".to_string(),
41+
target_c_int_width: "32".to_string(),
42+
data_layout: "e-m:w-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
43+
arch: "arm".to_string(),
44+
target_os: "windows".to_string(),
45+
target_env: "msvc".to_string(),
46+
target_vendor: "pc".to_string(),
47+
linker_flavor: LinkerFlavor::Msvc,
48+
49+
options: TargetOptions {
50+
features: "+v7,+thumb-mode,+vfp3,+d16,+thumb2,+neon".to_string(),
51+
cpu: "generic".to_string(),
52+
max_atomic_width: Some(64),
53+
abi_blacklist: super::arm_base::abi_blacklist(),
54+
.. base
55+
}
56+
})
57+
}

src/libstd/sys/windows/backtrace/mod.rs

Lines changed: 22 additions & 0 deletions
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;

src/libstd/sys/windows/c.rs

Lines changed: 40 additions & 1 deletion
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,43 @@ 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", target_arch = "aarch64", target_arch = "arm"))))]
798837
pub enum CONTEXT {}
799838

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

0 commit comments

Comments
 (0)