-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add target thumbv7a-pc-windows-msvc #53621
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@@ -0,0 +1,57 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2016 or 2018?
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this hard-coded path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping someone might have some suggestions on how to solve this.
The problem is that you must build rust (x.py build
) in a Visual Studio 2017 developer command prompt for the host environment so that it can build code for the host machine. When it tries to build code for the target, it uses the CC_${target}
and CFLAGS_${target}
environment variables, which are used to specify a cross compiler and flags for the cross compiler.
However, when it comes time to link, it invokes link.exe
which ends up invoking the linker for the host machine. I couldn't find anything like LD_${target}
or LDFLAGS_${target}
to let me specify the cross linker via environment variables, so the quickest fix was to use pre_link_args
in the target spec.
Possible solutions include
- Adding
LD_${target}
andLDFLAGS_${target}
environment variables - Writing code to detect the linker paths based on target architecture
- Somehow leveraging vcvars.bat
Open to suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that you must build rust (x.py build) in a Visual Studio 2017 developer command prompt for the host environment so that it can build code for the host machine.
Just don't run in a VS developer command prompt. Most things should be able to find VS themselves, so if something fails to do that we can just fix that and then cross compiling should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip. The following changes allowed me to remove the hardcoded paths:
linker_flavor: LinkerFlavor::Msvc, | ||
|
||
options: TargetOptions { | ||
features: "+v7,+thumb-mode,+vfp3,+d16,+thumb2,+neon".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+thumb-mode
is superfluous when used with +thumb2
, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the thumb
part in 'llvm_target' that makes it superfluous, thumb2
doesn't actually specify the state, it just says what's available when using the Thumb state (but it's implied by +v7
anyway, which is implied by v7
in the llvm_target also).
+d16
should be removed becuase +neon
requires 32 registers.
☔ The latest upstream changes (presumably #53884) made this pull request unmergeable. Please resolve the merge conflicts. |
Hi @jordanrh1, this looks good.
This is actually the correct behaviour I believe, |
The behavior I was seeing was that a BL instruction in the executable was being rewritten to a BLX instruction by the Windows loader, because the relocation tables told it to. A thumb2 BLX instruction to relative offset necessarily changes the CPU to ARM state. When you're branching from thumb code to thumb code, this is not what you want. The effect at runtime is an immediate crash. It executes the branch and changes to ARM mode, then interprets a thumb instruction as ARM which clearly leads to bad things. More precisely, an instruction with the T1 encoding was being written to an instruction with the T2 encoding. The branch target is thumb code. As you can see, the T2 encoding changes the CPU to ARM mode, which is incorrect because the target is thumb code. |
Ah right yes, relative offset, relocations aren't really my speciality. Still, I believe the relocation is correct, the |
I can see why you might think
The real issue is that the documentation is misleading. This discussion really belongs on the LLVM bug report. |
Yes, so it seems you are correct then. Perhaps you should submit your patch to https://reviews.llvm.org/ then someone can review and commit it for you. |
@alexcrichton Please let me know if you think this PR is ready for merge. With the above mentioned fixes to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me, thanks for this!
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push( | ||
"/OPT:NOLBR".to_string()); | ||
|
||
base.panic_strategy = PanicStrategy::Abort; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could a FIXME be left here to eventually remove this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@bors: r+ |
📌 Commit fd41c39 has been approved by |
⌛ Testing commit fd41c39 with merge 2c827146c5f433b3fc75c0bdb08d16d053199663... |
💔 Test failed - status-travis |
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors: retry |
⌛ Testing commit fd41c39 with merge 89ca3c6ef6ff8e6b5f541a7b8ab7c6c2972d558f... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors retry 50 minutes timeout |
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
☀️ Test successful - status-appveyor, status-travis |
This is an early draft of support for Windows/ARM. To test it,
It will build the stage 2 compiler, but fail building stage 2 test. To build an executable targeting windows/arm,
build\x86_64-pc-windows-msvc\stage0\bin\cargo.exe
tobuild\x86_64-pc-windows-msvc\stage2\bin
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:
test
crate:error: cannot link together two panic runtimes: panic_abort and panic_unwind
warning: cl : Command line warning D9002 : ignoring unknown option '-fvisibility=hidden'
. It looks like the build system is passing GCC-style flags to MSVC.This pull request depends on
This PR updates #52659