Clang
clang
and LLVM
are defacto standard tool-chains of the whole modern world. Apple uses clang
and it is developing its Swift with it, Google uses clang
in NDK (and deprecated gcc
), FreeBSD uses clang
as a default compiler, and the standard builds of the Chrome browser are done with clang++
. LLVM's odegeration back-end is used in GHC Haskell compiler, Rust compiler, Ocaml, Julia and so on.
clang++
comes with libc++ - a clean, rewritten from scratch C++11 standard library and STL implementation. It also supports native atomics, OpenMP 4.x via libomp.so
and all the nice things, like native atomics, etc. with its libcompiler_rt
.
Here is how to recompile a project with clang++
and libc++
without using or linking with libstdc++
. Notice the -stdlib=libc++
flags. Usually the resulting binaries are ~20% faster (when you have re-built libc++
itself with the same optimizations -mtune=native
).
This configuration has been tested with whole LLVM toolchain itself and with shit like NodeJS.
export CC=clang export CXX=clang++ export LD=ld.lld export FC=gfortran export FFLAGS="-m64 -march=native -mtune=native -O3 -fPIC -fopenmp" export CFLAGS="-Wformat -Wformat-security -Werror=format-security \ -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \ -fstack-protector-strong --param ssp-buffer-size=4 \ -Wstrict-aliasing=2 -fno-strict-aliasing \ -D_FILE_OFFSET_BITS=64 -D_REENTRANT \ -ffunction-sections -fdata-sections \ -m64 -march=native -mtune=native -O3 \ -fPIC \ -pthread \ -fopenmp=libomp \ -I/usr/local/include" export LDFLAGS="-L/usr/local/lib \ -rtlib=compiler-rt \ -fPIC \ -pthread \ -lm \ -fopenmp=libomp \ -Wl,--gc-sections -Wl,--as-needed \ -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack" export CXXFLAGS="-Wformat -Wformat-security -Werror=format-security -Wstrict-aliasing=2 \ -fno-strict-aliasing \ -fstack-protector-strong --param ssp-buffer-size=4 \ -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \ -D_FILE_OFFSET_BITS=64 -D_REENTRANT \ -ffunction-sections -fdata-sections \ -m64 -march=native -mtune=native -O3 \ -fPIC \ -pthread \ -lm \ -fopenmp=libomp \ -std=c++1z -stdlib=libc++ \ -fno-rtti -fno-exceptions \ -I/usr/local/include" export CXXLDFLAGS="-L/usr/local/lib \ -rtlib=compiler-rt -stdlib=libc++ \ -fPIC \ -pthread \ -fopenmp=libomp \ -Wl,--gc-sections -Wl,--as-needed \ -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"
clang
supports LTO. Notice that LTO has problems with object files produced outside a compiler, like assembly objects. You cannot build ffmpeg
with LTO.
clang
and GNU binutils supports -fPIE
but this is incompatible with static libraries and you cannot compile Emacs with it.