
OpenBSD switches the default compiler on amd64 and i386 to clang - cnst
http://marc.info/?l=openbsd-cvs&m=150109829003860&w=2
======
wuch
Now that OpenBSD has an optimizing compiler maybe they will notice and fix
dataraces in their pthread_mutex_lock implementation. Currently they use
broken double-checked locking pattern when mutex is lazy initialized with
PTHREAD_MUTEX_INITIALIZER.

~~~
fulafel
They used GCC before Clang, so they switched to a less optimizing compiler.

~~~
wuch
I would argue to the contrary, especially that we are comparing modern
Clang/LLVM with a GCC that was released back in 2008. At that point C
programming language didn't even have a memory model.

------
Crontab
The commit sounds like the people using OpenBSD for these processors will have
two compilers installed.

I am not a programmer but I am curious: how does one select GCC as a compiler
if the default is Clang? Just change what CC links to?

~~~
kev009
Make and most other build systems respect the CC and CXX variables.

Switching compilers is a very common thing among systems developers..
bootstrapping OS builds, crosscompiling for a different arch, getting compiler
feedback from another compiler, etc

------
yazr
Where does CLANG vs GCC debate stand in 2017

I know CLANG is used in many research projects (which are often committed to
the branch).

And i assume many, many legacy projects stick with GCC.

~~~
sprash
People choose CLANG mainly because of its license. But GCC still produces
faster binaries.

~~~
floatboth
(what's with the CAPSLOCK, it's lowercase clang)

Such blanket statements are not useful. Actually different compilers win on
different benchmarks.

Look at any test e.g.
[https://www.phoronix.com/scan.php?page=article&item=gcc8-cla...](https://www.phoronix.com/scan.php?page=article&item=gcc8-clang5-znver1&num=2)
— GCC is faster for FFTs, clang is faster for matrix factorization, … they
trade blows basically.

------
dman
Any idea if they are switching to using lld as the system linker as well?

~~~
milcron
Based on this mailing list thread, I would assume so.
[https://marc.info/?l=openbsd-
tech&m=148961125932497&w=2](https://marc.info/?l=openbsd-
tech&m=148961125932497&w=2)

~~~
dman
Excellent! I have a soft spot for openbsd as a workstation os. Will give it a
try again once this hits a release.

------
saghm
What's the easiest way to view the actual commit diff? I'm curious about what
version of clang they're using, as the message indicates that they were using
gcc4 before, which is fairly old.

~~~
voutilad
OpenBSD has had a github mirror for awhile now. The commit is here:
[https://github.com/openbsd/src/commit/bc04e837fd81a3001f68f1...](https://github.com/openbsd/src/commit/bc04e837fd81a3001f68f102c770b45a53840885)

As for clang version, it looks to be 4.0.0 per
[https://github.com/openbsd/src/commit/53d771aafdbe5b919f264f...](https://github.com/openbsd/src/commit/53d771aafdbe5b919f264f53cba3788e2c4cffd2)

~~~
cpach
Side-note: In the changed file, the first line is “$OpenBSD: bsd.own.mk,v
1.186 2017/07/26 19:44:42 robert Exp $”. Does anyone know if this line is
updated by CVS or some other tool?

~~~
gkya
That's a CVS keyword, it's updated when the file is checked out or after it's
committed. 1.186 is the most recent version of that file.

------
efficax
This is awesome. It's going to save so many headaches building/porting C++
based code on OpenBSD. Hurrah.

~~~
fromme2you
Awesome? Maybe... [https://www.bitrig.org/](https://www.bitrig.org/)

------
voutilad
Note, latest amd64 snapshots reflect the switch to clang if folks are curious
and want to experiment:

    
    
      > cc -v
      OpenBSD clang version 4.0.0 (tags/RELEASE_400/final) (based on LLVM 4.0.0)
      Target: amd64-unknown-openbsd6.1
      Thread model: posix
      InstalledDir: /usr/bin

------
anon_d
This is a big deal! Weren't the OpenBSD pretty clang-hostile a few years back?
Maybe I'm mixing up them and the suckless people?

I think I remember that they were even trying to move away from gcc to
something home-grown and simpler, since gcc is such a huge dependency and even
uses c++ now.

~~~
shakna
> I think I remember that they were even trying to move away from gcc to
> something home-grown and simpler

You remember pcc, "Portable C Compiler", which, though currently actively
developed [0], has a not-so-dependable history. 1.0 released in 2011, 1.1 in
2014, and no releases since.

pcc was merged in, but with the spotty history, taken out of base again.

> Weren't the OpenBSD pretty clang-hostile a few years back?

Not quite. LLVM was evaluated for the main compiler back in 2013 [1], but the
main drawbacks was LLVM can't be used for every platform that OpenBSD
supports. They also go on to talk about how every open compiler is painful,
because there are no LTS releases. Compiler bugs were a major problem for
OpenBSD, and I doubt its changed enough for that to not be the case.

[0] Mailing list is still going strong, and patches are still coming in and
merging. ([http://marc.info/?l=pcc-list](http://marc.info/?l=pcc-list))

[1] Long read, but in-depth: [http://marc.info/?l=openbsd-
misc&m=137530560232232](http://marc.info/?l=openbsd-misc&m=137530560232232)

------
fithisux
I thought they were fan of pcc. In any case, if they drop gcc, then please
keep pcc active.

~~~
4ad
Pcc was added to the base system (not used for anything), but then pcc
development stalled so pcc was removed from the base system.

~~~
fithisux
It is unfortunate.

------
justin66
What's the meaning of "default compiler" in this context? Will the kernel be
built with clang or gcc?

~~~
thesmallestcat
cc

~~~
justin66
Which was gcc, until today. Has that changed?

~~~
thesmallestcat
It's a symlink. And yes, there is no other meaning of "switching the default
compiler." The effect is that any tooling that uses `cc` (like the `CC`
implicit variable in Make) will now use `clang` rather than `gcc`. So any
software built on the system uses clang unless you force it to use something
else. No idea if they will still distribute gcc by default.

~~~
justin66
What I'm getting from your comment is that they're switching everything over
to building with clang, including the kernel. That's interesting (it's a bold
move) since there have been a few systems over the years that set aside a
separate compiler just for building the kernel.

~~~
bluGill
It would have been a bold move 4 years ago. Today most software that builds
with gcc also builds with clang. FreeBSD's switch everything to clang project
is dead because there is nothing left to do: nearly every open source project
builds with clang by default, the rare exceptions are complex cases not worth
fixing.

OpenBSD has spent the last few years ensuring their code all builds with
clang, and they support. All the add on software you might want to use also
works well built in clang.

------
Cieplak
What are some cool ways to introduce vulnerabilities into LLVM so that even
"secure" languages like Rust are vulnerable to software-based exploits?

~~~
adrianN
Become a regular contributor to LLVM for some time to build trust and then
sneak in some complex optimization that under some rareish circumstances leads
to exploitable binaries.

