News for hackers. Stuff that matters.
Re:Chromium Windows builds now use Clang by default by blinkingled on Friday July 28, 2017 @07:16PM (#14878330)
Hmm. I went through the thread and could not find an answer to the question - why? Using platform's default compiler would be the safest thing to do and MS is making good progress with VC as far as adding standards support goes. They have been receptive of bug reports and relatively quick at fixing them too as far as I remember. Switching to clang also takes away the nice VS IDE based debugging experience [turns out it doesn't, I misread the post as saying you can still compile and debug with VS].

So what is Chromium gaining from switching to clang-cl? Perhaps just less amount of compiler specific code/hacks/quirks/workarounds etc?

Edit: This being Google I was expecting interesting data or at least somewhat thorough reasoning. The post just felt like a fyi for switching to clang. Nonetheless some good possible reasons in below replies.

Re:Chromium Windows builds now use Clang by default by dxf on Friday July 28, 2017 @07:42PM (#14878487)
Not having to worry about language feature support across different compilers is a big win. See https://bugs.chromium.org/p/libyuv/issues/detail?id=685 for one specific example of why using Clang can have benefits over MSVC (TL;DR: 64-bit MSVC doesn't support inline assembly). Clang was already being used to compile this little part of Chrome on Win64.

Switching to Clang also allows the use of Clang-based sanitizers and fuzzing, which improves the security of Chrome.

Re:Chromium Windows builds now use Clang by default by blinkingled on Friday July 28, 2017 @09:09PM (#14878922)
> 64-bit MSVC doesn't support inline assembly

Wow. That's a big omission on Microsoft's part! I wonder how they themselves are getting around it for Win64 performance sensitive code.

Re:Chromium Windows builds now use Clang by default by CoolGuySteve on Saturday July 29, 2017 @07:52AM (#14880724)
IIRC, Microsoft wants you to use intrinsics because it plays better with their register coloring and code reordering optimizations.

Unless there's an instruction you need that doesn't have an intrinsic or you're writing something like a spin lock where instruction ordering is critical and a compiler barrier for some reason is not sufficient, there's no reason to ever write assembly.

Your code won't be appreciably faster than if you tuned it in the compiler, and after a few years the compiler will integrate new instructions while your assembly just gets stale.

Re:Chromium Windows builds now use Clang by default by xorblurb on Saturday July 29, 2017 @09:08AM (#14881028)
> Unless there's an instruction you need that doesn't have an intrinsic or you're writing something like a spin lock where instruction ordering is critical and a compiler barrier for some reason is not sufficient, there's no reason to ever write assembly.

So there are reasons to write code in assembly language.

Re:Chromium Windows builds now use Clang by default by CoolGuySteve on Saturday July 29, 2017 @09:38AM (#14881163)
OK, there's no reason for YOU to write code in assembly.
Re:Chromium Windows builds now use Clang by default by xorblurb on Monday August 07, 2017 @02:30PM (#14949940)
For me, personally? I occasionally can write that kind of stuff.
Re:Chromium Windows builds now use Clang by default by dman on Friday July 28, 2017 @09:12PM (#14878931)
You can still write routines in assembly, you cant write it inline.
Re:Chromium Windows builds now use Clang by default by MaulingMonkey on Friday July 28, 2017 @11:01PM (#14879267)
You can also use intrinsics if you don't want to write your entire routine in assembly.
Re:Chromium Windows builds now use Clang by default by yuhong on Friday July 28, 2017 @11:02PM (#14879269)
You are supposed to use special MASM directives to generate function tables for SEH.
Re:Chromium Windows builds now use Clang by default by raverbashing on Saturday July 29, 2017 @06:17AM (#14880477)
There are few reasons to use assembly, and even fewer to use inline assembly

Using CPUID is one, using very specific vector instructions another (but you can do most of this using intrinsics) and it's better if they get their own .s file

Re:Chromium Windows builds now use Clang by default by imron on Saturday July 29, 2017 @11:41AM (#14881707)
inline assembly e.g. intermixed with C/C++ code is not supported. You can still have separate files that are ASM only.

It's more hassle, but still possible to use.

Re:Chromium Windows builds now use Clang by default by zmodem on Friday July 28, 2017 @08:13PM (#14878638)
> So what is Chromium gaining from switching to clang-cl?

There are lots of good reasons, but my favourite point -- besides considering clang to be a superiour c++ compiler in general -- is that using an open-source compiler allows us to fix things.

When a developer runs into a miscompile or compiler crash, finds an inefficiency in the generated code or has an idea for a new warning, we can fix it and push a new compiler out within days. And in addition to the work we put in ourselves, we benefit from the huge amount of work put in by the wider llvm/clang community.

It leads to a better developer experience, and in the end a better product.

Re:Chromium Windows builds now use Clang by default by zetafunction on Friday July 28, 2017 @10:44PM (#14879216)
Two other reasons that haven't been mentioned yet:

- MSVC had trouble with dead code elimination in some cases: fixing https://crbug.com/684105 reduced binary size by almost 900KB on Windows.

- It lets tooling like https://chromium.googlesource.com/chromium/src/+/master/docs... and the custom clang plugin checks run on Windows-specific code.

Re:Chromium Windows builds now use Clang by default by microcolonel on Friday July 28, 2017 @07:28PM (#14878406)
As far as I'm aware, there are no downsides to switching to Clang on Windows. Clang produces VS-compatible debug info, it's integrated perfectly fine into VS. In addition, you don't need a VS license to compile the desired 64-bit Windows binaries. In addition, the code generated is typically faster and smaller. They get to use new C++ features without waiting for a major VC++ release. They can hope to do cross compilation on an operating system with a filesystem that isn't outrageously slow. They can stop having to put in VS-specific warning disables and go with the GCC-Clang standard ones. Clang is also just faster to run in general. They get to use one compiler on every platform, and when they improve the compiler, it helps all of their platforms.

Seems like a win on every level to me.

Re:Chromium Windows builds now use Clang by default by azakai on Friday July 28, 2017 @10:01PM (#14879097)
Not a win on every level: As the link says, clang is slower than Visual Studio's compiler.
Re:Chromium Windows builds now use Clang by default by blinkingled on Friday July 28, 2017 @07:33PM (#14878438)
But on the other hand Microsoft's compiler, linker, headers, debuggers are tested together for the OS releases they support. clang-cl doesn't have that advantage. I guess Google is picking up clang-cl maintenance to make sure it remains compatible with various dependencies MS changes.
Re:Chromium Windows builds now use Clang by default by microcolonel on Friday July 28, 2017 @07:43PM (#14878491)
Microsoft endorses and works on clang-cl, though I wouldn't say they give it as much attention as their own compiler. As for compatibility, I don't think it's a huge issue, if they never changed the compiler again, it would probably still generate working binaries for the next decade, including PDBs.
Re:Chromium Windows builds now use Clang by default by lukegb on Friday July 28, 2017 @07:22PM (#14878364)
According to the first post in the linked thread, the switch to clang is transparent enough that the VS IDE-based debugging experience still works.

My guess (not being a Chromium developer myself) is that this is an exercise in consistency across platforms - I can imagine that using the same compiler on all supported platforms makes the language features supported consistent and removes the risk of one compiler generating much worse output for the same code. But I'm just postulating, I don't actually know for sure.

Re:Chromium Windows builds now use Clang by default by netheril96 on Friday July 28, 2017 @07:40PM (#14878474)
One reason is to use AddressSanitizers, ThreadSanitizers, static analysis and other tools clang and LLVM bring.
Re:Chromium Windows builds now use Clang by default by blinkingled on Friday July 28, 2017 @07:56PM (#14878557)
That's a good point. It's good enough a reason to be able to run AS/TS on Windows code base. Not actually sure it works on Windows though.
Re:Chromium Windows builds now use Clang by default by netheril96 on Friday July 28, 2017 @08:33PM (#14878734)
Google is the original writer or significant contributor of these tools. So presumably they first get clang work properly on Windows, then port these tools to Windows, then profit.
Re:Chromium Windows builds now use Clang by default by kairuku on Friday July 28, 2017 @07:27PM (#14878393)
If you live in an "all compiler warnings are errors" world, having two compilers where a bit of code can cause a warning in one compiler and not cause a warning in another compiler is really annoying.
Re:Chromium Windows builds now use Clang by default by to3m on Friday July 28, 2017 @07:30PM (#14878419)
And this is why the intersection area in the Venn diagram of "people that use -Werror" and "people that use multiple compilers" is labeled "people who are making their own lives difficult, for no obvious reason".
Re:Chromium Windows builds now use Clang by default by AstralStorm on Saturday July 29, 2017 @02:24AM (#14879845)
By different you also mean different versions, right?
Re:Chromium Windows builds now use Clang by default by to3m on Saturday July 29, 2017 @04:47PM (#14882939)
Yes, sure - any time different people will be getting different sets of warnings, -Werror (or equivalent) is just going to make your life harder.

You should always strive for zero warnings on all builds across all compilers. It's a realistic, achievable and worthwhile goal. But while pretty much all warnings are worth looking at, a much smaller set are worth breaking the build over. You're much better off (in my view) promoting those particular warnings to errors, and leaving the rest as-is.

Re:Chromium Windows builds now use Clang by default by myusernameisok on Friday July 28, 2017 @07:29PM (#14878418)
Presumably end users who are compiling from source wouldn't want to enable -Werror though.

If you are an application developer and a compiler X gives warnings that compiler Y doesn't for your application, then ideally you should probably fix the warnings from compiler X. An end user probably doesn't care either way, they just want to compile the program without any issues.

Re:Chromium Windows builds now use Clang by default by dmurray on Friday July 28, 2017 @07:44PM (#14878493)
Realistically, though, an end user doesn't compile anything these days. If you build Chromium from source you're at least half interested in tinkering with it.
Re:Chromium Windows builds now use Clang by default by myusernameisok on Friday July 28, 2017 @07:59PM (#14878572)
Well certain Linux distros (Gentoo comes to mind) are designed to support their users compiling applications from source. Some users just want to be able to compile using -march=native, and aren't interested in fixing compiler warnings that they didn't introduce. I personally would hate it if I wanted to compile an application from source but -Werror stopped complication through no fault of my own.
Re:Chromium Windows builds now use Clang by default by dboreham on Friday July 28, 2017 @07:20PM (#14878354)
Using fewer compilers has obvious benefits to the software development and production process. E.g. no need to fix code when a checkin from developer on Platform X breaks the build on Platform Y.
Re:Chromium Windows builds now use Clang by default by taeric on Friday July 28, 2017 @08:14PM (#14878646)
I'd be curious if it robs it of some benefits, though. The process you describe above sounds like it might actually be beneficial in an "antifragile" kind of way.

That is, there are benefits to be had by knowing you do work on multiple toolchains. Painful at times, but mainly in ways that make a better product.

Re:Chromium Windows builds now use Clang by default by adrianmonk on Friday July 28, 2017 @10:40PM (#14879209)
I don't know how the Chromium project is set up, but another way to achieve that benefit is to require that succeed on all platforms before code can be checked in. Which you should probably do anyway.
Re:Chromium Windows builds now use Clang by default by Jyaif on Saturday July 29, 2017 @01:53AM (#14879758)
They do that, but for the programmers it's still annoying (and a waste of time) to have patches rejected because some compiler on some platform behaves differently.
Re:Chromium Windows builds now use Clang by default by groby_b on Friday July 28, 2017 @07:24PM (#14878375)
Re:Chromium Windows builds now use Clang by default by Ono-Sendai on Saturday July 29, 2017 @10:09AM (#14881290)
Clang is generally a better compiler that produces faster code (with some exceptions).
Re:Chromium Windows builds now use Clang by default by hendzen on Saturday July 29, 2017 @10:19AM (#14881332)
I agree that it is a better compiler, but have heard mixed results on whether it produces faster code. Do you have a citation?
Re:Chromium Windows builds now use Clang by default by Ono-Sendai on Saturday July 29, 2017 @10:30AM (#14881380)
I'm basing this assessment mostly on my own experience and testing. In terms of performance difference, it can be hard to compare since Clang-compiled programs often run on Linux, and MSVC programs run on Windows, so it's difficult to factor out the perf differences due to the OS. However I have measured one of our programs running significantly faster in a Linux VM, compiled in Clang, running with Windows as a host OS, than the program compiled with MSVC running directly on Windows.

In addition, the analyses and optimisations performed by Clang are generally more sophisticated than by MSVC. See for example http://www.forwardscattering.org/post/51.

The only optimisation I know of that MSVC performs that Clang doesn't (in some cases at least) is autovectorisation of some maths functions: https://bugs.llvm.org/show_bug.cgi?id=23645

(Actually MSVC has a pretty effective link-time code gen option, that is often turned off by projects using Clang)

Re:Chromium Windows builds now use Clang by default by adamnemecek on Friday July 28, 2017 @07:21PM (#14878357)
One compiler for all platforms is a major win.
Re:Chromium Windows builds now use Clang by default by to3m on Friday July 28, 2017 @07:26PM (#14878382)
The post says that the debugging experience stays... so perhaps clang outputs PDBs now, and/or you can interface it with Windows gdb somehow.
Re:Chromium Windows builds now use Clang by default by dxf on Friday July 28, 2017 @07:32PM (#14878431)
CodeView debug info is supported in Clang.

See https://www.youtube.com/watch?v=5twzd06NqGU

Re:Chromium Windows builds now use Clang by default by frik on Saturday July 29, 2017 @05:01AM (#14880316)
Will the reliance on recent msvcredist (Visual c++ redistributable) be gone too with the move to Clang?

Their 2015 (and later) tooling and runtime cannot be trusted anymore, they send home data like there is no tomorrow - as observed on Win7. It's the VC++ runtime, the dotNet runtime, the dotNet optimization process, VSCode, dotNetCore, etc all send data home with no opt-in or opt-out option. This doesn't happen on other operating systems.

Re:Chromium Windows builds now use Clang by default by netheril96 on Saturday July 29, 2017 @11:31AM (#14881667)
No. clang on Windows is only a compiler. No SDK or runtime libraries are included.
Re:Chromium Windows builds now use Clang by default by rurban on Sunday July 30, 2017 @01:49AM (#14884598)
Did this come with the switch from msvcrtNNN.dll to ucrt.dll, which is the more POSIX compliant runtime?
Re:Chromium Windows builds now use Clang by default by am1988 on Friday July 28, 2017 @08:26PM (#14878696)
Same compiler on all platforms would be one guess.
Re:Chromium Windows builds now use Clang by default by pjmlp on Saturday July 29, 2017 @03:04AM (#14879957)
> So what is Chromium gaining from switching to clang-cl?

Slower build times.