Bringing Clang to Windows
blogs.msdn.com
blogs.msdn.com
This blog post is announcing:
1. Using clang as a frontend.
2. Using C2 (MS compiler) as a backend.
What the LLVM community (IE not MS so far, but participation is of course, welcome)) has been building:
1. Using clang as a frontend
2. Using llvm as a backend
and even more specifically
1. Using MS Headers + MS Libraries
2. Using clang as a frontend
3. Using llvm as a backend.
(see blog.llvm.org/2014/07/clangllvm-on-windows-update.html for a 9 month old view)
Some of the mingw32 folks have been working on replacing #1 with non-ms stuff, but let's put that aside for the sake of this description )
Using clang as a frontend is where almost all of the ABI compatibility happens anyway (and where various developers have been focusing), so you end up with VC++ ABI compatible binaries whether you use C2 or not, if you/they use the pre-existing clang stuff.
Whether they are doing that (and then lowering llvm ir to c2 ir) , or if they've built an alternative IR generation with clang (IE generating c2 ir directly from clang), that they haven't released, is not clear.
If they've built something that generates C2 IR from clang, they would have had to write their own ABI compat, which would mean it may be different than the binaries clang would build.
(exception handling is also codegen'd by llvm, so exception handling could end up different, though of course, compatibility is the goal)
The problem was that clang is quite intertwined with LLVM IR. ABI is spread all over the place, both FE and BE. It was proving hard to get something the house optimizers/code generators would be happy with. So a more radical path was chosen — wiring clang's parser + ASTs to another C++ front-end's AST and then using the old IR generator to get all of the idiosyncrasies right for the target. It was wacky, but seemed to be half-way working when I left, such that major open source code was compiling.
The whole idea of taking just parts of clang/llvm reeks of a half-measure anyway. It's probably better to either keep the existing compiler stack, or cut it right out and put the secret sauce into LLVM as add-in modules.
You can definitely build obj and lib files and link them with files built by MSVC. That works well.
We also support putting DWARF debug info (the standard format) into the binaries, and the LLVM linker LLD will link them and you can debug the resulting program with the LLVM debugger LLDB (or GDB for that matter).
I mean, the reason everyone does interop strictly in C is that there are zero standards for how a compiler implements the C++ features exactly down-low.
Here is their implementation of name mangling: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Micros...
Here is their implementation of record layout: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Record...
Here is their implementation of vtable generation: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTable...
Here is their implementation of RTTI: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mi...
Here is their implementation of C++ throw metadata: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mi...
AFAIK, Microsoft hasn't contributed to any of these ends. I, for one, hope that they do.
We're already using Clang with msbuild on Windows for native C11 support (come on, Microsoft!), courtesy of pre-built Clang for Windows binaries [1] - using the Microsoft C/C++ headers and linking against the Microsoft C/C++ runtimes.
There's already a plugin for MSVC that makes the Clang toolset available. VS 2013 (or maybe it was 2012?) decoupled the MSVC build chain/toolset from the IDE, making it possible to swap out which toolchain you're using from the project properties. Actually, it may have even been VS 2010, because I was using it to compile with ICC, but then again, I remember having a hell of a hard time so perhaps it was VS2012/2013.
IE this is literally not different from what was already being done, without MS :)
Not quite true. Different compilers can decide to do different alignment/padding. It should be fairly simple to make clang and MSVC avoid that scenario, though.
Also, they must have taken care to use the same ABI and C++ name mangling rules in both compilers. I would guess Microsoft's version of clang follows MSVC here, so that one can link clang code to existing third party libraries.
MS strategy is much more straight forward. Simply offer reasons and make it easier for customers to use their products. Mainly the cloud and mobile services. They're just smart enough to understand where Google and Facebook make their money with - not by selling OS.
The support for Objective-C, Clang, etc is, in my opinion, merely about bringing iOS and Android software to Windows (especially for phones and tablets). Microsoft knows they need current high quality apps on their platform to get users. Users which will buy their devices and operating systems. They don't really want developers to run iOS software unmodified on Windows but they do want to make it really easy for them to attempt a port.
Sure, you might have VDI and access a Windows VM remotely from your iPad or whatever, but Windows is not going away for a long time.
(And don't get me wrong, I would love replacing every single Windows desktop at our company with Debian or CentOS or even OSX, but unless a lot of companies decide to port their applications to one of these systems, it is not going to happen.)
In other words, the set of vc++ features.
'clang' is probably approaching the point that its good enough so the question for Microsoft is do they still see any value in continuing the develop their own compiler or should they just switch to 'clang' ?
I think this is the big shift we are seeing in MS this year. Instead trying to owning everything, they seem to be shifting their focus to owning the parts that have value and commoditizing the rest. The strategy was successful for Apple so its unsurprising that Microsoft is looking to a similar strategy as part of their salvation.
I know, I know, that's foolish, but it would be so great if that could be true ^^
If you mean C and C++ features, Microsoft standard conformance has slowly improved over the years from not giving a fuck to reasonable, but the only bleeding edge tools they've ever created are experimental research projects. They are completely out of clang and GCC's race to implement C and C++ standards and future standard changes.
If you mean some new API, they are libraries and all compilers have equal access to them.
They wish. Microsoft still hates GNU.
EDIT:
In reply to davidgerard's comment below:
> I will not believe this falsifiable claim without numbers. FreeBSD has almost no users compared to Linux.
Non-Windows does not mean Linux.
And what falsifiable claim? They didn't say Clang is the most popular - they said it's becoming. But if that's really the game you want to play, then it's Linux that has almost no users compared to the number of iPhones/iPads/iWatches/MacBooks out there - Clang/LLVM-powered, each and every one of them.
http://unix.stackexchange.com/questions/49906/why-is-freebsd...
Another contributing factor may be momentum. Clang is easier to work with than GCC, and doesn't have the baggage of GCC, so more and more people and companies are starting to use it, fund it, and commit code to it. It's been improving in leaps and bounds, and still rapidly improving. It's only a matter of time before it's all around better than GCC.
This is based on fairly limited experience, but I believe it's simply a better toolset. LLDB was easier to work with for me. The error messages make things quicker to diagnose. I prefer the added verbosity for things like flags.
~30% of North American traffic is from Netflix, whose servers are FreeBSD.
Everyone is a FreeBSD user and they don't need to know it to for it to count. Nobody actually gives a shit about numbers of users sitting on FreeBSD desktops.
A couple examples. Core Image needs an optimizing JIT compiler that can take a chain of image filters and turn it into a single efficient filter for execution on the GPU or CPU (whichever will be faster on the particular system for the particular effects). XCode needs to parse C/C++/Objective-C code in the editor and in the debugger.
What Apple needed for these things was a modular compiler system, designed to work as a compiler toolkit from which you can pick and choose the parts that you need for your particular needs. A compiler toolkit that is designed to be easy to interface with outside tools.
Gcc was explicitly designed to not be that. It was only competition from LLVM/Clang that forced some liberalization onto gcc.
If that's changed it's not showing in their careful use of the (very fine) Apache license rather than the GPL.
I know that they identified the USB/DVD tool and re-released it under GPL.
http://www.zdnet.com/article/microsoft-admits-its-gpl-violat...