The arrow of time

Ivan Voras' blog

FreeBSD/CLANG ready for testing!

CLANG is a new C compiler built to work with LLVM. Getting away from gcc on the BSD side is kind of important (including, but not only because of GPLv3) so getting FreeBSD to compile and work with CLANG is a high profile project.

FreeBSD on CLANG is ready for testing right now!

Roman Divacky writes:

ClangBSD is a branch of FreeBSD that aims at integrating clang (clang.llvm.org)
into FreeBSD, replacing GCC as a system compiler.

Recently, we've achieved the state when clang can compile all of FreeBSD world
on i386/amd64 platforms (including all the C++ apps we have and itself)
and a bootable kernel. Thus we feel that the time has come to ask the FreeBSD
community for wider testing on i386/amd64 (you sure can help with other
platforms too :)).

How to setup ClangBSD:

The default configuration of ClangBSD requires clang installed so you can
either install fresh llvm-devel port (portinstall devel/llvm-devel) or change
CC to "gcc" and CXX to "g++" in share/mk/sys.mk. I recommend the former.

svn co http://svn.freebsd.org/base/projects/clangbsd/ clangbsd

cd clangbsd && make buildworld

echo NO_WERROR= >> /etc/make.conf
echo WERROR= >> /etc/make.conf

make DESTDIR=/clangbsd-chroot/ installworld

now you have ClangBSD world installed and you can chroot into it. I don't
recommend installing ClangBSD into real root as it is not tested enough.

You can also start using clang compiled kernel - either build the kernel in
the ClangBSD chroot (set NO_WERROR=yo and WERROR=yo in /etc/src.conf) or set
CC to clang and build kernel the normal way.

This information (and more) is also provided on:

http://wiki.freebsd.org/BuildingFreeBSDWithClang

We kindly ask you to setup ClangBSD chroot and/or use clang compiled kernel and
use it as you would normally use FreeBSD. Please report back

Thank you,

Roman Divacky on behalf of the ClangBSD team

(note: the instructions in the quoted message have a typo: the modifications of /etc/make.conf should go before buildworld!)

I'm currently trying it on amd64. I'll write about how well it goes for me here :)

Random impressions:

  • Well, the llvm-devel port builds in parallel (all my CPU cores are being used) - which is nice :)
  • The svn checkout part takes a long-ish time to complete - it really does checkout the whole FreeBSD system. The checked out tree is nearly 1.4 GB in size (includes .svn directories)
  • Apparently, building world in parallel (make -j# buildworld) still works! Keeping fingers crossed. Clang warnings look shiny and colorful when parallel builds are not used (stdout redirection causes color to be surpressed)
  • I have CFLAGS+=-mtune=generic in my system make.conf by habit, and clang/clang++ picked it up without complaints
  • Because this is a snapshot of HEAD, the system identifier is "amd64-undermydesk-freebsd9.0". My current kernel is 8-STABLE. We'll se how this goes for runtime (shouldn't be any major problems)
  • If I'm reading the make output correctly, clang is also building the base system's gcc :)
  • clang should be a bit faster than gcc in compile times, but judging from subjective buildworld time it doesn't seem like a spectacular difference, though there really is some.

One of rht first things I want to try is performance benchmarks of generated code. Here is "openssl speed" on clang:

OpenSSL 0.9.8n 24 Mar 2010
built on: date not available
options:bn(64,64) md2(int) rc4(ptr,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: clang -isystem /usr/obj/mt/clangbsd/tmp/usr/include/clang/1.5 -isystem /usr/obj/mt/clangbsd/tmp/usr/include -B/usr/obj/mt/clangbsd/tmp/usr/lib/ -L/usr/obj/mt/clangbsd/tmp/usr/lib/
available timing options: USE_TOD HZ=128 [sysconf value]
timing function used: getrusage
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 1923.60k 4054.76k 5604.77k 6199.22k 6395.64k
mdc2 6955.38k 8094.89k 8373.09k 8522.53k 8558.77k
md4 19634.24k 71257.75k 212252.60k 421486.56k 590572.54k
md5 15508.08k 53492.84k 147463.50k 260760.51k 338023.21k
hmac(md5) 16161.25k 55682.33k 151719.62k 264361.10k 338637.79k
sha1 16090.02k 50963.36k 121940.70k 187942.13k 224072.84k
rmd160 13852.78k 40637.00k 89005.45k 126376.49k 143973.22k
rc4 257659.58k 271029.59k 274710.22k 272998.38k 276912.10k
des cbc 38819.17k 39641.42k 39209.56k 39268.51k 39238.14k
des ede3 15131.94k 15363.06k 15482.49k 15519.78k 15373.38k
idea cbc 0.00 0.00 0.00 0.00 0.00
seed cbc 0.00 0.00 0.00 0.00 0.00
rc2 cbc 20750.18k 21255.22k 21384.19k 21455.05k 20981.28k
rc5-32/12 cbc 111311.24k 126210.84k 131087.12k 132192.58k 132408.83k
blowfish cbc 65926.22k 71418.06k 72800.28k 73135.06k 71863.93k
cast cbc 55334.77k 59529.80k 59830.94k 58374.23k 57956.81k
aes-128 cbc 75752.93k 78665.26k 79636.54k 79831.71k 79562.22k
aes-192 cbc 65278.62k 67884.89k 68594.60k 68785.83k 68499.39k
aes-256 cbc 57790.80k 59675.87k 60218.06k 60388.35k 60165.11k
camellia-128 cbc 52430.96k 54279.06k 54858.63k 55035.26k 54818.99k
camellia-192 cbc 39225.97k 40585.04k 40819.75k 40899.86k 40850.41k
camellia-256 cbc 38894.04k 40575.89k 40814.76k 40884.12k 40812.32k
sha256 12591.49k 30276.46k 55091.44k 69264.16k 74994.73k
sha512 9431.67k 38128.18k 65271.76k 95578.60k 110922.89k
aes-128 ige 75250.05k 79826.78k 81106.94k 81331.45k 81157.14k
aes-192 ige 65511.77k 68610.53k 69501.24k 69789.37k 69698.55k
aes-256 ige 57620.68k 59789.92k 61024.55k 61169.71k 61113.17k
sign verify sign/s verify/s
rsa 512 bits 0.000324s 0.000025s 3087.8 39377.2
rsa 1024 bits 0.001130s 0.000059s 884.7 17022.5
rsa 2048 bits 0.006364s 0.000170s 157.1 5899.3
rsa 4096 bits 0.039033s 0.000580s 25.6 1724.3
sign verify sign/s verify/s
dsa 512 bits 0.000231s 0.000242s 4327.0 4139.5
dsa 1024 bits 0.000571s 0.000618s 1750.9 1617.7
dsa 2048 bits 0.001617s 0.001933s 618.3 517.4

 And here it is on gcc:

 OpenSSL 0.9.8k 25 Mar 2009
built on: date not available
options:bn(64,64) md2(int) rc4(ptr,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: cc
available timing options: USE_TOD HZ=128 [sysconf value]
timing function used: getrusage
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 1704.33k 3578.63k 4924.66k 5442.72k 5612.26k
mdc2 6419.79k 6987.28k 7145.42k 7176.30k 7194.51k
md4 22522.48k 77461.09k 208989.36k 364347.90k 464505.24k
md5 17248.69k 56853.03k 143614.43k 231283.82k 282376.99k
hmac(md5) 14363.09k 48629.38k 129923.77k 221063.51k 280454.17k
sha1 16107.52k 48161.19k 105928.89k 151613.04k 173434.51k
rmd160 13490.18k 37488.50k 76360.13k 102811.31k 114006.02k
rc4 228379.61k 252224.64k 260613.16k 258267.36k 261427.45k
des cbc 34013.39k 34504.63k 34561.42k 34580.71k 34581.87k
des ede3 13157.03k 13336.35k 13370.27k 13398.30k 13407.19k
idea cbc 0.00 0.00 0.00 0.00 0.00
seed cbc 0.00 0.00 0.00 0.00 0.00
rc2 cbc 20226.51k 20691.20k 20793.27k 20812.46k 20845.25k
rc5-32/12 cbc 115259.73k 125098.43k 128671.43k 129249.14k 129507.72k
blowfish cbc 67123.78k 70605.20k 71551.28k 72205.80k 72139.67k
cast cbc 53824.49k 56455.76k 57132.90k 57312.32k 57352.86k
aes-128 cbc 98099.68k 102909.62k 104340.42k 104864.43k 104141.73k
aes-192 cbc 85928.08k 90476.52k 91608.28k 91987.51k 91608.48k
aes-256 cbc 78053.63k 81166.26k 81911.66k 82104.68k 81828.42k
camellia-128 cbc 63129.07k 65543.74k 66275.00k 66460.65k 66443.87k
camellia-192 cbc 48602.56k 50127.47k 50572.44k 50663.64k 50674.31k
camellia-256 cbc 48620.90k 49973.24k 50673.39k 50818.03k 50801.29k
sha256 14139.93k 34875.63k 64531.47k 81896.63k 88864.65k
sha512 11252.81k 44991.20k 80473.76k 120173.20k 140902.29k
aes-128 ige 96268.56k 106893.74k 109948.41k 110340.68k 110060.75k
aes-192 ige 88121.16k 94096.69k 96046.92k 96441.43k 96184.20k
aes-256 ige 77672.91k 84133.65k 85499.34k 85769.36k 85568.61k
sign verify sign/s verify/s
rsa 512 bits 0.000298s 0.000020s 3360.0 50006.5
rsa 1024 bits 0.001091s 0.000053s 916.8 18883.5
rsa 2048 bits 0.006291s 0.000166s 159.0 6013.1
rsa 4096 bits 0.039328s 0.000575s 25.4 1739.5
sign verify sign/s verify/s
dsa 512 bits 0.000207s 0.000218s 4824.8 4590.6
dsa 1024 bits 0.000520s 0.000630s 1921.7 1588.4
dsa 2048 bits 0.001614s 0.001857s 619.5 538.4

Unfortunately, surprisingly little can be concluded from these results. The algorithms are integer number crunching and it seemed that clever optimizations would be most likely visible on tight loops that dominate this kind of code but the results are very varied. And there is the issue of assembler optimizations that I'm not sure are present in the clang builds. It looks like, though it's of newer design, llvm/clang doesn't offer much generated code performance increases in comparison with gcc. Or maybe it's just this workload.

The size of the binaries is roughly the same as with gcc, maybe a few percent larger.

 

#1 Re: FreeBSD/CLANG ready for testing!

Added on 2010-04-17T02:46 by lydia nalen

// The default configuration of ClangBSD requires clang installed so
you can
// either install fresh llvm-devel port (portinstall devel/llvm-devel) or change
// CC to "gcc" and CXX to "g++" in share/mk/sys.mk. I recommend the former.

Did you mean something else than you wrote...
Setting CC to "gcc" to not use it?

#2 Re: FreeBSD/CLANG ready for testing!

Added on 2010-04-17T02:52 by lydia nalen

sorry, it all dawned on me, guess I should'nt write questions while drunk

#3 Re: FreeBSD/CLANG ready for testing!

Added on 2010-04-17T14:01 by Andrius

"The svn checkout part takes a long-ish time to complete"
You can copy existing svn checkout of current or stable (if you have one) and svn switch it to clangbsd.

"clang is also building the base system's gcc"
I think that's correct, but there were some problems with clang miscompiling gcc, so I'm not sure what's the status now. Generally, we don't care about gcc too much.

"judging from subjective buildworld time it doesn't seem like a spectacular difference"
Maybe that's because now it has to build two compilers?

#4 Re: FreeBSD/CLANG ready for testing!

Added on 2010-04-17T14:17 by Joe Sixpack

Just wanted to say that this is very exciting news :)

Post your comment here!

Your name:
Comment title:
Text:
Type "xxx" here:

Comments are subject to moderation and will be deleted if deemed inappropriate. All content is © Ivan Voras. Comments are owned by their authors... who agree to basically surrender all rights by publishing them here :)