Showcase of the Windows/ARM64/MinGW target


At the Build conference recently, Microsoft had a session about Windows on ARM(64), [1]. As case example of a large, nontrivial app rebuilt for this arch, they demonstrated VLC.

The presentation claimed that this was built with MSVC, with zero changes to the source.

This actually isn't true; the app that was demonstrated was actually built with Clang and LLD with mingw-w64 as SDK (and there had been quite a few minor fixes throughout the codebase to make it all build both with clang/libc++ for windows, and for windows on non x86 targets).

Despite the pretty drastic miscommunication, I think it was nice to have at least the output from these tools demonstrated. (The presenter was reminded about how it actually was built after the presentation; apparently this information had been lost somewhere along the chain.)

And as a fun fact, it can be mentioned that a large amout of the windows/arm64 support in LLVM/LLD was developed before I even had access to this OS for testing, or even MSVC for reference - most of it was developed and tested just with wine (bootstrapped from a handful of reference windows/arm64 binaries).

Thanks to everybody who have helped make this happen!

// Martin

[1] Windows 10 on ARM for developers : Build 2018 - YouTube

So are you saying that LLVM can be built as ARM64 on Windows now?
CMake doesn't show me an option for ARM64 when using MSVC on Windows.
I have the latest CMake.

I'm saying that LLVM can produce code for the Windows/ARM64 target.

As for compiling LLVM itself to run on ARM64 on Windows, I don't know how to configure MSVC to do that; MSVC doesn't install the ARM64 compiler by default but you manually need to check a box in the installer (available since 15.4, and more intended for actual public use since the 15.8 preview). No idea how you configure that in CMake.

You can build LLVM+Clang for ARM64 with Clang/mingw-w64/libcxx though, with the same toolchain used to build VLC in that demo.

// Martin

Ok. How much work was it to enable ARM64 codegen? Is it is
significantly more work than for Linux targets? Are there any special
relocations in ARM64 land?

It was surprisingly little work, I'd say. Yes, Windows uses COFF, and there's a separate set of relocations for each architecture. Probably not more work than for Linux targets, but just new things to implement.

The initial commits for ARM64 in COFF were done by Mandeep Singh Grang, and after that, there were a few details to fill in about how the relocations are supposed to behave. The public documentation only names them, but luckily link.exe supported those relocations since long ago, so I was able to use llvm-mc together with link.exe to figure out how e.g. the IMAGE_REL_ARM64_REL21/IMAGE_REL_ARM64_PAGEOFFSET_12A relocation pairs are supposed to handle overflow/carry.

Other than relocations, the main bits were varargs handling, hooking up small flags and bits here and there as you find what's missing, minor windows/coff specific details like linker directives and dllimport handling, and slightly larger things such as stack probing and TLS.

// Martin

Or, you know, just all the things. :slight_smile:

Congrats on the demo!

      Other than relocations, the main bits were varargs
      handling, hooking up
      small flags and bits here and there as you find what's
      missing, minor
      windows/coff specific details like linker directives and
      handling, and slightly larger things such as stack
      probing and TLS.

Or, you know, just all the things. :slight_smile:

Hah, well, at least the non-vararg calling convention is (as far as I know this far) the same as on other platforms - unlike on x86_64, where everything differs.

Or maybe put another way; the ARM64 related bits wasn't all that much work, compared to everything related to MinGW.

Congrats on the demo!


// Martin