From f7fa67cea13efdacfc82389f6f592bb4bda86a2e Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Tue, 26 Jun 2018 09:44:19 -0700 Subject: [PATCH 1/4] Add target thumbv7a-pc-windows-msvc --- src/libpanic_unwind/seh.rs | 4 +- src/librustc_target/spec/mod.rs | 1 + .../spec/thumbv7a_pc_windows_msvc.rs | 57 +++++++++++++++++++ src/libstd/sys/windows/backtrace/mod.rs | 22 +++++++ src/libstd/sys/windows/c.rs | 41 ++++++++++++- 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs index d6298a38a2601..8333477a8416e 100644 --- a/src/libpanic_unwind/seh.rs +++ b/src/libpanic_unwind/seh.rs @@ -119,7 +119,9 @@ mod imp { } } -#[cfg(target_arch = "x86_64")] +// TODO: this needs to be validated when WinEH for ARM is implemented in LLVM +// It looks like ARM and ARM64 use the same _TypeInfo semantics as x64 +#[cfg(any(target_arch = "x86_64", target_arch = "arm"))] #[macro_use] mod imp { pub type ptr_t = u32; diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 2514909ba75f3..3c68b5a7ab116 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -386,6 +386,7 @@ supported_targets! { ("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc), ("i686-pc-windows-msvc", i686_pc_windows_msvc), ("i586-pc-windows-msvc", i586_pc_windows_msvc), + ("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc), ("asmjs-unknown-emscripten", asmjs_unknown_emscripten), ("wasm32-unknown-emscripten", wasm32_unknown_emscripten), diff --git a/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs b/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs new file mode 100644 index 0000000000000..2da975a21a222 --- /dev/null +++ b/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs @@ -0,0 +1,57 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use spec::{LinkerFlavor, Target, TargetOptions, TargetResult, PanicStrategy}; + +pub fn target() -> TargetResult { + let mut base = super::windows_msvc_base::opts(); + + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( + "/LIBPATH:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.11.25503\\lib\\arm".to_string()); + + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( + "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\ucrt\\arm".to_string()); + + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( + "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\um\\arm".to_string()); + + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( + "/MACHINE:ARM".to_string()); + + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( + "/INCREMENTAL:NO".to_string()); + + // Prevent error LNK2013: BRANCH24(T) fixup overflow + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( + "/OPT:NOLBR".to_string()); + + base.panic_strategy = PanicStrategy::Abort; + + Ok(Target { + llvm_target: "thumbv7a-pc-windows-msvc".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:w-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), + arch: "arm".to_string(), + target_os: "windows".to_string(), + target_env: "msvc".to_string(), + target_vendor: "pc".to_string(), + linker_flavor: LinkerFlavor::Msvc, + + options: TargetOptions { + features: "+v7,+thumb-mode,+vfp3,+d16,+thumb2,+neon".to_string(), + cpu: "generic".to_string(), + max_atomic_width: Some(64), + abi_blacklist: super::arm_base::abi_blacklist(), + .. base + } + }) +} diff --git a/src/libstd/sys/windows/backtrace/mod.rs b/src/libstd/sys/windows/backtrace/mod.rs index 70de4a6f2b617..cfa9e7b7c25b3 100644 --- a/src/libstd/sys/windows/backtrace/mod.rs +++ b/src/libstd/sys/windows/backtrace/mod.rs @@ -248,6 +248,17 @@ impl StackFrame for c::STACKFRAME_EX { c::IMAGE_FILE_MACHINE_AMD64 } + #[cfg(target_arch = "arm")] + fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD { + self.AddrPC.Offset = ctx.Pc as u64; + self.AddrPC.Mode = c::ADDRESS_MODE::AddrModeFlat; + self.AddrStack.Offset = ctx.Sp as u64; + self.AddrStack.Mode = c::ADDRESS_MODE::AddrModeFlat; + self.AddrFrame.Offset = ctx.R11 as u64; + self.AddrFrame.Mode = c::ADDRESS_MODE::AddrModeFlat; + c::IMAGE_FILE_MACHINE_ARMNT + } + #[cfg(target_arch = "aarch64")] fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD { self.AddrPC.Offset = ctx.Pc as u64; @@ -291,6 +302,17 @@ impl StackFrame for c::STACKFRAME64 { c::IMAGE_FILE_MACHINE_AMD64 } + #[cfg(target_arch = "arm")] + fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD { + self.AddrPC.Offset = ctx.Pc as u64; + self.AddrPC.Mode = c::ADDRESS_MODE::AddrModeFlat; + self.AddrStack.Offset = ctx.Sp as u64; + self.AddrStack.Mode = c::ADDRESS_MODE::AddrModeFlat; + self.AddrFrame.Offset = ctx.R11 as u64; + self.AddrFrame.Mode = c::ADDRESS_MODE::AddrModeFlat; + c::IMAGE_FILE_MACHINE_ARMNT + } + #[cfg(target_arch = "aarch64")] fn init(&mut self, ctx: &c::CONTEXT) -> c::DWORD { self.AddrPC.Offset = ctx.Pc as u64; diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 4c64322a6dce3..dc0eb24415538 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -114,6 +114,11 @@ pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000; pub const FIONBIO: c_ulong = 0x8004667e; +#[cfg(target_arch = "arm")] +const ARM_MAX_BREAKPOINTS: usize = 8; +#[cfg(target_arch = "arm")] +const ARM_MAX_WATCHPOINTS: usize = 1; + #[repr(C)] #[derive(Copy)] pub struct WIN32_FIND_DATAW { @@ -283,6 +288,9 @@ pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664; #[cfg(target_arch = "aarch64")] #[cfg(feature = "backtrace")] pub const IMAGE_FILE_MACHINE_ARM64: DWORD = 0xAA64; +#[cfg(target_arch = "arm")] +#[cfg(feature = "backtrace")] +pub const IMAGE_FILE_MACHINE_ARMNT: DWORD = 0x01c4; pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0; pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd; @@ -789,12 +797,43 @@ pub struct FLOATING_SAVE_AREA { _Dummy: [u8; 512] // FIXME: Fill this out } +#[cfg(target_arch = "arm")] +#[repr(C)] +pub struct CONTEXT { + pub ContextFlags: ULONG, + pub R0: ULONG, + pub R1: ULONG, + pub R2: ULONG, + pub R3: ULONG, + pub R4: ULONG, + pub R5: ULONG, + pub R6: ULONG, + pub R7: ULONG, + pub R8: ULONG, + pub R9: ULONG, + pub R10: ULONG, + pub R11: ULONG, + pub R12: ULONG, + pub Sp: ULONG, + pub Lr: ULONG, + pub Pc: ULONG, + pub Cpsr: ULONG, + pub Fpscr: ULONG, + pub Padding: ULONG, + pub D: [u64; 32], + pub Bvr: [ULONG; ARM_MAX_BREAKPOINTS], + pub Bcr: [ULONG; ARM_MAX_BREAKPOINTS], + pub Wvr: [ULONG; ARM_MAX_WATCHPOINTS], + pub Wcr: [ULONG; ARM_MAX_WATCHPOINTS], + pub Padding2: [ULONG; 2] +} + // FIXME(#43348): This structure is used for backtrace only, and a fake // definition is provided here only to allow rustdoc to pass type-check. This // will not appear in the final documentation. This should be also defined for // other architectures supported by Windows such as ARM, and for historical // interest, maybe MIPS and PowerPC as well. -#[cfg(all(rustdoc, not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))))] +#[cfg(all(rustdoc, not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64", target_arch = "arm"))))] pub enum CONTEXT {} #[cfg(target_arch = "aarch64")] From b081a49a0701e6d95bc868a526138bc7a3cf6d46 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Fri, 7 Sep 2018 08:34:24 -0700 Subject: [PATCH 2/4] Removed hardcoded paths and unnecessary LLVM features --- .../spec/thumbv7a_pc_windows_msvc.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs b/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs index 2da975a21a222..a699e15d417b9 100644 --- a/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs +++ b/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs @@ -1,4 +1,4 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,21 +13,6 @@ use spec::{LinkerFlavor, Target, TargetOptions, TargetResult, PanicStrategy}; pub fn target() -> TargetResult { let mut base = super::windows_msvc_base::opts(); - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( - "/LIBPATH:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.11.25503\\lib\\arm".to_string()); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( - "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\ucrt\\arm".to_string()); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( - "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17134.0\\um\\arm".to_string()); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( - "/MACHINE:ARM".to_string()); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( - "/INCREMENTAL:NO".to_string()); - // Prevent error LNK2013: BRANCH24(T) fixup overflow base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( "/OPT:NOLBR".to_string()); @@ -47,7 +32,7 @@ pub fn target() -> TargetResult { linker_flavor: LinkerFlavor::Msvc, options: TargetOptions { - features: "+v7,+thumb-mode,+vfp3,+d16,+thumb2,+neon".to_string(), + features: "+vfp3,+neon".to_string(), cpu: "generic".to_string(), max_atomic_width: Some(64), abi_blacklist: super::arm_base::abi_blacklist(), From 54a16aea6a3b6a765ebf1821d339456c87f6e82c Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Fri, 7 Sep 2018 08:41:16 -0700 Subject: [PATCH 3/4] Fix tidy errors --- src/libpanic_unwind/seh.rs | 2 -- src/libstd/sys/windows/c.rs | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs index 8333477a8416e..832a0aff71be1 100644 --- a/src/libpanic_unwind/seh.rs +++ b/src/libpanic_unwind/seh.rs @@ -119,8 +119,6 @@ mod imp { } } -// TODO: this needs to be validated when WinEH for ARM is implemented in LLVM -// It looks like ARM and ARM64 use the same _TypeInfo semantics as x64 #[cfg(any(target_arch = "x86_64", target_arch = "arm"))] #[macro_use] mod imp { diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index dc0eb24415538..f4bd9c22bb93f 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -833,7 +833,8 @@ pub struct CONTEXT { // will not appear in the final documentation. This should be also defined for // other architectures supported by Windows such as ARM, and for historical // interest, maybe MIPS and PowerPC as well. -#[cfg(all(rustdoc, not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64", target_arch = "arm"))))] +#[cfg(all(rustdoc, not(any(target_arch = "x86_64", target_arch = "x86", + target_arch = "aarch64", target_arch = "arm"))))] pub enum CONTEXT {} #[cfg(target_arch = "aarch64")] From fd41c390534e15c223200031c93a10173046ebfa Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Wed, 12 Sep 2018 11:28:02 -0700 Subject: [PATCH 4/4] Expand comments in thumbv7a-pc-windows-msvc target spec --- src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs b/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs index a699e15d417b9..dab10ca241ebc 100644 --- a/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs +++ b/src/librustc_target/spec/thumbv7a_pc_windows_msvc.rs @@ -14,9 +14,17 @@ pub fn target() -> TargetResult { let mut base = super::windows_msvc_base::opts(); // Prevent error LNK2013: BRANCH24(T) fixup overflow + // The LBR optimization tries to eliminate branch islands, + // but if the displacement is larger than can fit + // in the instruction, this error will occur. The linker + // should be smart enough to insert branch islands only + // where necessary, but this is not the observed behavior. + // Disabling the LBR optimization works around the issue. base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( "/OPT:NOLBR".to_string()); + // FIXME(jordanrh): use PanicStrategy::Unwind when SEH is + // implemented for windows/arm in LLVM base.panic_strategy = PanicStrategy::Abort; Ok(Target {