Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Using clang as the system compiler
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
goatcheese
n00b
n00b


Joined: 03 Nov 2005
Posts: 23
Location: Seoul, South Korea

PostPosted: Wed Mar 21, 2018 5:11 am    Post subject: Using clang as the system compiler Reply with quote

I've seen attempts many times over the years to use clang globally & with the recent release of llvm 6 I figured I'd give it. To be precise on what 'using clang' means - swapping out gcc, g++, ar, as, nm, and libunwind with their llvm/clang equivalents. No compiler-rt, no libc++, no lld. Also not using LTO, though thinlto looks rather interesting. Perhaps at a later date.

TL;DR most everything build fine

I found the following links useful as starters.
https://wiki.gentoo.org/wiki/Clang
https://blogs.gentoo.org/gsoc2016-native-clang/2016/08/14/use-clang-as-a-native-compiler-in-gentoo
I also quickly realized that a lot of information available is outdated & not completely accurate given how quickly this stack has developed.

This is a multilib unstable install using profile 17.1. The primary modifications to make.conf were
Code:

CC="clang"
CXX="clang++"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"


I also leveraged the environment feature of portage to add a gcc fallback and various ldconfig flags

After testing a couple individual packages I went ahead & proceeded with
Code:

emerge -e @system


out of 450 or packages about 12 failed. A couple rebuild fine with just a rebuild. The following are my notes on failures. So far only glibc is the only confirmed package that won't build with clang. Apparently is has in the past but seems there's little motivation. Unresolved I'm still working through, Resolved contains all the workarounds.

Unresolved
app-emulation/qemu
* `qxl.c:(.text+0x200): undefined reference to __atomic_fetch_or_4`

dev-lang/spidermonkey
* not sure

media-libs/mesa
* `disk_cache.c:(.text+0xf67): undefined reference to __atomic_fetch_add_8`

Resolved
dev-libs/libgcrypt
* `/var/tmp/portage/dev-libs/libgcrypt-1.8.2-r2/work/libgcrypt-1.8.2/random/jitterentropy-base.c:53:13: warning: unknown pragma ignored [-Wunknown-pragmas]`
* `#pragma GCC optimize ("O0")`
* FIXED: USE="o-flag-munging"

dev-libs/nss
* g++: error: unrecognized command line option ‘-Qunused-arguments’; did you mean ‘-Wunused-parameter’?
* FIXED: https://bugs.gentoo.org/651044

sys-cluster/ceph
* /usr/lib/llvm/6/bin/llvm-ar: Unknown command: open.
* FIXED: use gnu ar

sys-devel/gcc
* `/var/tmp/portage/sys-devel/gcc-7.3.0/work/gcc-7.3.0/gcc/hash-table.h:834:1: internal compiler error: Illegal instruction`
* hash_table<Descriptor, Allocator>
* FIXED: use compiler-rt

sys-devel/m4
* https://bugs.llvm.org/show_bug.cgi?id=16404
* FIXED: use compiler-rt

x11-libs/pixman
* `/var/tmp/portage/x11-libs/pixman-0.34.0/work/pixman-0.34.0/test/utils-prng.c:207:27: error: use of unknown builtin '__builtin_shuffle' [-Wimplicit-function-declaration]`
* FIXED: issue w/ patch https://bugs.freedesktop.org/show_bug.cgi?id=104886

Not Possible
glibc
* `checking if clang -m32 -Wl,-O1 -Wl,--as-needed is sufficient to build libc... no`
* /var/tmp/portage/sys-libs/glibc-2.27-r1/work/build-x86-x86_64-pc-linux-gnu-nptl/config.log
* BROKEN: https://sourceware.org/glibc/wiki/GlibcMeetsClang

And the kernel?
Code:

dmesg | head -1
[    0.000000] Linux version 4.15.9-gentoo (root@monkey) (clang version 6.0.0 (tags/RELEASE_600/final)) #3 SMP PREEMPT Mon Mar 19 21:39:33 KST 2018

Yep. also using zfs and nvidia kernel modules without issue. So that was kinda neat and unexpected.

Hope this is useful to anyone who wants to give this a go. Should also note build times are similar and everything runs about as fast as it used though I've not really done any testing. I use this machine daily & haven't noticed any crashes.
Back to top
View user's profile Send private message
Juippisi
Developer
Developer


Joined: 30 Sep 2005
Posts: 724
Location: /home

PostPosted: Wed Mar 21, 2018 7:45 am    Post subject: Reply with quote

I used to have clang as my main compiler .... some time ago (when chromium was still faster to compile with clang)

I remember having a lot more packages that failed, nice to see its made some progress!

I still keep an eye of gcc vs. clang comparisons in phoronix.com web site, and they do seem rather similar. Nowadays Im using gcc with O3, graphite and LTO so I believe thats a "faster" setup because graphite optimizations are not available in clang. I used to follow this guy, https://github.com/fsvm88/gentoo-portage_etc/ when he used clang as his main compiled. He's moved to gcc now and only uses clang with specific packages.

But looks like with GCC-8 just behind the corner and clang-6 just released, GCC will take a huge step forward and pass clang in where clang used to shine.
Back to top
View user's profile Send private message
lyallp
Veteran
Veteran


Joined: 15 Jul 2004
Posts: 1557
Location: Adelaide/Australia

PostPosted: Wed Mar 21, 2018 9:08 am    Post subject: Reply with quote

I have had a VirtualBox VM on my Gentoo system, running Gentoo built with Clang.
Whenever I came across a package that didn't build, I stuffed it in my package.env file.
Below is the current contents of my package.env file (specific packages that appeared to require gcc, rather than clang to compile.
Not that many, but then the VM is a basic Gentoo system using fluxbox window manager, not gnome or kde.

Edit: And, just for giggles, I occasionally do an "emerge --emptytree @world"

Code:
=dev-lang/spidermonkey-1.8.5-r4              gcc
=dev-lang/spidermonkey-1.8.5-r6              gcc
=dev-libs/elfutils-0.166                gcc
=dev-libs/elfutils-0.169-r1                gcc
=dev-libs/elfutils-0.170                gcc
=dev-libs/elfutils-0.170-r1                gcc
=dev-libs/klibc-1.5.25                   gcc
=dev-libs/klibc-2.0.4-r2                gcc
=media-libs/gstreamer-0.10.36-r2             gcc
=net-libs/gnutls-3.3.26                   gcc
=sys-boot/efibootmgr-14::gentoo                gcc
=sys-boot/efibootmgr-15::gentoo                gcc
=sys-boot/grub-2.02_beta3-r1                gcc
=sys-devel/autogen-5.18.4                gcc
=sys-libs/efivar-30::gentoo                gcc
=sys-libs/glibc-2.23-r3                   gcc
=sys-libs/glibc-2.23-r4                   gcc
=sys-libs/glibc-2.25-r9                   gcc
=sys-libs/glibc-2.25-r10                gcc
=x11-misc/lightdm-gtk-greeter-2.0.1-r1             gcc

app-emulation/virtualbox-guest-additions          gcc
x11-drivers/xf86-video-fbdev                gcc
x11-drivers/xf86-video-vesa                gcc
x11-drivers/xf86-video-virtualbox             gcc
                         
=sys-apps/v86d-0.1.10                   gcc
=sys-auth/consolekit-1.1.0-r1                  gcc
=x11-wm/fluxbox-1.3.7-r3                gcc
=dev-qt/qtwebkit-4.8.6-r1                gcc
=dev-qt/qtwebkit-4.8.7                   gcc
=dev-qt/qtcore-5.7.1-r3                   gcc
=media-video/vlc-2.2.4-r1                gcc
=x11-misc/slim-1.3.6-r5                   gcc

=app-editors/emacs-25.2               gcc
=app-editors/emacs-25.3               gcc
=app-editors/emacs-25.3-r1               gcc
=dev-libs/double-conversion-2.0.1         gcc
=sys-fs/udev-233               gcc
=dev-libs/libgcrypt-1.8.1            gcc

=x11-libs/pixman-0.34.0               gcc

_________________
...Lyall
Back to top
View user's profile Send private message
42n4
n00b
n00b


Joined: 10 Feb 2015
Posts: 9

PostPosted: Tue Jun 26, 2018 10:10 am    Post subject: Reply with quote

I understand why people go to gcc 8.1.0 lto graphite
I used your list and
Code:
layman -a gentoo-clang

and so far I compiled all system, not a world :)
But it was not very easy for clang 6.0.1 and several packages did not compile.

For gcc LTO just use ltoize from the site https://github.com/InBetweenNames/gentooLTO
described here:
https://forums.gentoo.org/viewtopic-p-8241956.html#8241956

Thus, clang compiling seems to be more difficult now.
_________________
gentoo gcc 8.3.0 lto graphite, arm rpi3 7.4.0,
http://bit.ly/gen2ls
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum