I decided to give Clang a spin to compile the kernel, and given that I’m not exactly an early adopter in attempting this, it was pretty smooth and straightforward overall. All it took was:
$ make CC=clang HOSTCC=clang -j12
I also did a quick comparison of the output of the two compilers with a standard ‘defconfig’ with CONFIG_DEBUG_INFO=y enabled on x86_64:
With GCC 9.2.1:
- Build #1: real 3m38.073s, user 31m22.669s, sys 3m17.740s
- Build #2: real 3m46.561s, user 31m58.313s, sys 3m22.958s
- Build #3: real 3m38.174s, user 31m33.390s, sys 3m19.014s
With Clang 9.0.0:
- Build #1: real 5m21.978s, user 50m45.085s, sys 3m55.455s
- Build #2: real 5m22.094s, user 50m44.977s, sys 3m53.522s
- Build #3: real 5m17.531s, user 50m29.478s, sys 3m52.730s
It appears that the compile time was up by nearly 50% with Clang.
Next, a comparison of the vmlinux file generated by the two compilers. CONFIG_DEBUG_INFO is enabled:
- GCC 9.2.1: 739M
- Clang 9.0.0: 544M
This was a little interesting at first since the GCC generated kernel is 35% bigger than the Clang generated one. I decided to do another test with CONFIG_DEBUG_INFO disabled for comparison.
- GCC 9.2.1: vmlinux 57M (31M stripped), bzImage 8.7M
- Clang 9.0.0: vmlinux 57M (31M stripped), bzImage 8.9M
With debug information stripped, it comes around to the same size, so both are even on this. The compile-time performance was similarly noticeable in this case as well. While faster than with debugging symbols enabled, Clang took longer to build compared to GCC.
- GCC 9.2.1 : real 2m40.687s, user 26m0.946s, sys 2m36.858s
- Clang 9.0.0 : real 4m41.045s, user 46m9.836s, sys 3m18.187s
Next, I took a very crude look at kernel + systemd start time to login prompt on a qemu emulator, to see if there was any difference to execution speeds and here’s what I saw during three iterations:
- GCC 9.2.1 : 3.85s, 3.98s, 3.74s
- Clang : 3.70s, 3.62s, 3.70s
While it’s a somewhat crude metric, I think the perceived variance is not significant or perceptible at least for the casual user, and would also claim things to be more or less even on this front.
Overall, I think it’s good to have options for open source compilers and I’m glad that Clang has come into the picture as a serious contender for the domination that GCC endured over many decades.
I decided to give Clang a spin to compile the kernel, and given that I’m not exactly an early adopter in attempting this, it was pretty smooth and straightforward overall. All it took was:
I also did a quick comparison of the output of the two compilers with a standard ‘defconfig’ with CONFIG_DEBUG_INFO=y enabled on x86_64:
With GCC 9.2.1:
With Clang 9.0.0:
It appears that the compile time was up by nearly 50% with Clang.
Next, a comparison of the vmlinux file generated by the two compilers. CONFIG_DEBUG_INFO is enabled:
This was a little interesting at first since the GCC generated kernel is 35% bigger than the Clang generated one. I decided to do another test with CONFIG_DEBUG_INFO disabled for comparison.
With debug information stripped, it comes around to the same size, so both are even on this. The compile-time performance was similarly noticeable in this case as well. While faster than with debugging symbols enabled, Clang took longer to build compared to GCC.
Next, I took a very crude look at kernel + systemd start time to login prompt on a qemu emulator, to see if there was any difference to execution speeds and here’s what I saw during three iterations:
While it’s a somewhat crude metric, I think the perceived variance is not significant or perceptible at least for the casual user, and would also claim things to be more or less even on this front.
Overall, I think it’s good to have options for open source compilers and I’m glad that Clang has come into the picture as a serious contender for the domination that GCC endured over many decades.
Read Next
Windows of Opportunity: Microsoft's Open Source Renaissance
Twenty years ago, it was easy to dislike Microsoft. It was the quintessential evil MegaCorp that was quick to squash competition, often ruthlessly, but in some cases slowly through a more insidious process of embracing, extending, and exterminating anything that got in the way. This was the signature personality of
US-11604662-B2
I’m happy to announce, that after a long wait, patent US-11604662-B2 has been issued.
Parallelizing and running distributed builds with distcc
Parallelizing the compilation of a large codebase is a breeze with distcc, which allows you to spread the load across multiple nodes and…
Getting started with Linkerd
If you’ve done anything in the Kubernetes space in recent years, you’ve most likely come across the words “Service Mesh”. It’s backed by a…