Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Using clang as the system compiler

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
goatcheese
n00b
n00b
User avatar
Posts: 23
Joined: Thu Nov 03, 2005 7:44 am
Location: Seoul, South Korea

Using clang as the system compiler

  • Quote

Post by goatcheese » Wed Mar 21, 2018 5:11 am

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-nativ ... -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: Select all

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: Select all

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: Select all

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.
Top
Juippisi
Developer
Developer
User avatar
Posts: 784
Joined: Fri Sep 30, 2005 3:51 pm
Location: /home

  • Quote

Post by Juippisi » Wed Mar 21, 2018 7:45 am

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.
Top
lyallp
Veteran
Veteran
User avatar
Posts: 1655
Joined: Thu Jul 15, 2004 12:07 am
Location: Adelaide/Australia
Contact:
Contact lyallp
Website

  • Quote

Post by lyallp » Wed Mar 21, 2018 9:08 am

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: Select all

=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
Top
42n4
n00b
n00b
User avatar
Posts: 25
Joined: Tue Feb 10, 2015 1:06 pm

  • Quote

Post by 42n4 » Tue Jun 26, 2018 10:10 am

I understand why people go to gcc 8.1.0 lto graphite
I used your list and

Code: Select all

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:
viewtopic-p-8241956.html#8241956

Thus, clang compiling seems to be more difficult now.
OS: Gentoo gcc14
Kernel: Linux 6.14.6-zen1
KDE Plasma 6.2.0
WM: NVIDIA 4060 Wayland
http://bit.ly/gen2ls
Top
Post Reply

4 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic