Global Clang/LLVM Compiler Suite

Posted on Fri 24 January 2020 in linux

Since clang/llvm:9 has been marked stable on Gentoo, it's time to switch the system compiler.

Migration guides

Up to date

  • https://forums.gentoo.org/viewtopic-t-1102590-start-0.html
  • https://wiki.gentoo.org/wiki/Clang

A bit outdated

  • https://forums.gentoo.org/viewtopic-t-1078694.html
  • https://blogs.gentoo.org/gsoc2016-native-clang/2016/08/14/use-clang-as-a-native-compiler-in-gentoo/

Notable

  • https://github.com/BilyakA/gentoo-clang
  • https://bugs.llvm.org/show_bug.cgi?id=43411

My steps

  • Add clang to global USE, emerge clang llvm (CC=gcc)
  • Add compiler-rt default-compiler-rt default-libcxx libcxx libcxxabi libunwind to global USE, then:
# CC=gcc
emerge llvm-common libomp llvm-libunwind llvm llvmgold \
libcxxabi libcxx lld \
clang clang-common clang-runtime \
compiler-rt compiler-rt-sanitizers
  • Set the following variables in make.conf:
CC="clang"
CXX="clang++"
COMMON_FLAGS="${COMMON_FLAGS} -flto=thin"
CXXFLAGS="-stdlib=libc++ ${COMMON_FLAGS}"
LDFLAGS="${LDFLAGS} -fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"
  • Reemerge the 13 packages. (No need to use the fallback env trick here.)
  • (clean up the contaminated world, emerge -e world)

gw