about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-09-13 15:22:05 +0000
committerbors <bors@rust-lang.org>2018-09-13 15:22:05 +0000
commit90d36fb5905bbe5004f5b465ea14b53d10dae260 (patch)
treeafcc620e767d325667feca17c52dd4bbb043ca0d /src/libstd
parent994cdd918589535d705177545bf503cd0c3c5148 (diff)
parentfd41c390534e15c223200031c93a10173046ebfa (diff)
downloadrust-90d36fb5905bbe5004f5b465ea14b53d10dae260.tar.gz
rust-90d36fb5905bbe5004f5b465ea14b53d10dae260.zip
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-nursery/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-nursery/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
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sys/windows/backtrace/mod.rs22
-rw-r--r--src/libstd/sys/windows/c.rs42
2 files changed, 63 insertions, 1 deletions
diff --git a/src/libstd/sys/windows/backtrace/mod.rs b/src/libstd/sys/windows/backtrace/mod.rs
index 70de4a6f2b6..cfa9e7b7c25 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 4c64322a6dc..f4bd9c22bb9 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,44 @@ 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")]