wiki:Freelancing/Clang

LLVM and Clang

This is, at least for now, the C++ compiler, C++ standard-library and STL implementation.

Just use it. Google and Apple do.

Bootstrapping

you need to have cmake and ninja installed

sudo apt-get install cmake ninja-build

You also need that Z3 theorem prover from MS

Lets tune up the Compiler Flags ($CFLAGS) a bit. This is basically, what hardened Gentoo does.

export CFLAGS="-Wformat -Wformat-security -Werror=format-security \
    -Wstack-protector -fstack-protector-all --param ssp-buffer-size=1 \
    -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
    -fPIE -pie \
    -fno-omit-frame-pointer \
    -Wstrict-aliasing=2 -fno-strict-aliasing \
    -fasynchronous-unwind-tables \
    -m64 -D_FILE_OFFSET_BITS=64 \
    -pthread -D_REENTRANT \
    -march=native -mtune=native -O3 \
    -fopenmp=libomp \
    -ffunction-sections -fdata-sections \
    -I/usr/local/include"

export LDFLAGS="-L/usr/local/lib \
    -pthread \
    -rtlib=compiler-rt \
    -fopenmp=libomp \
    -lm \
    -fPIE -pie \
    -Wl,--gc-sections -Wl,--as-needed \
    -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"

export CXXFLAGS="-Wformat -Wformat-security -Werror=format-security \
    -Wstack-protector -fstack-protector-all --param ssp-buffer-size=1 \
    -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
    -fPIE -pie \
    -fno-omit-frame-pointer -fno-strict-aliasing \
    -fasynchronous-unwind-tables \
    -m64 -D_FILE_OFFSET_BITS=64 \
    -pthread -D_REENTRANT \
    -fopenmp=libomp \
    -std=c++17 -stdlib=libc++ \
    -fno-rtti -fno-exceptions \
    -march=native -mtune=native -O3 \
    -fopenmp=libomp \
    -ffunction-sections -fdata-sections \
    -I/usr/local/include"

export CXXLDFLAGS="-L/usr/local/lib \
    -pthread \
    -rtlib=compiler-rt -stdlib=libc++ \
    -fopenmp=libomp \
    -lm \
    -fPIE -pie \
    -Wl,--gc-sections -Wl,--as-needed \
    -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"

Get the sources

git clone --recurse-submodules --shallow-submodules --depth=1 \
    git://github.com/llvm/llvm-project
cd llvm-project

There is some magic shit

cmake -G Ninja \
      -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
      -DLLVM_ENABLE_PROJECTS='compiler-rt;polly;pstl;clang;clang-tools-extra;libunwind;libcxx;libcxxabi;parallel-libs;openmp;lld;lldb' \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_CXX_COMPILER_ARG1="-stdlib=libc++" \
      -DCMAKE_INSTALL_PREFIX="/usr/local" \
      -DCLANG_DEFAULT_RTLIB="compiler-rt" \
      -DCLANG_DEFAULT_CXX_STDLIB="libc++" \
      -DCLANG_DEFAULT_OPENMP_RUNTIME="libomp" \
      -DCLANG_DEFAULT_UNWINDLIB="libunwind" \
      -DCLANG_DEFAULT_LINKER="lld" \
      -DCLANG_PLUGIN_SUPPORT=ON \
      -DLLVM_BUILD_EXTERNAL_COMPILER_RT=OFF \
      -DLIBCLANG_BUILD_STATIC=ON \
      -DLIBCXX_ENABLE_SHARED=YES \
      -DLIBCXX_ENABLE_STATIC=YES \
      -DLIBCXX_ENABLE_FILESYSTEM=ON \
      -DLIBCXX_USE_COMPILER_RT=ON \
      -DLIBCXXABI_USE_COMPILER_RT=ON \
      -DLIBUNWIND_USE_COMPILER_RT=ON \
      -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
      -DLIBCXX_ENABLE_THREADS=ON \
      -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=ON \
      -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
      -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=OFF \
      -DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY=OFF \
      -DLLVM_ENABLE_Z3_SOLVER=ON \
      -DLLVM_INSTALL_UTILS=ON \
      -DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
      -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON \
      -DLLVM_ENABLE_RTTI=OFF \
      -DLLVM_ENABLE_EH=OFF \
      -DLLVM_TARGETS_TO_BUILD="host" \
      -DLLVM_ENABLE_LTO=OFF \
      -DLLVM_ENABLE_PIC=ON \
      -DLLVM_ENABLE_FFI=ON \
      -DLLVM_ENABLE_LIBCXX=ON \
      -DLLVM_ENABLE_LLD=ON \
      -DLLVM_BINUTILS_INCDIR=/usr/include \
      -DLLVM_ENABLE_OCAMLDOC=OFF \
      -DLLVM_TOOL_LIBCLC_BUILD=ON \
      -DLLVM_TOOL_OPENMP_BUILD=ON\
      -DLLVM_TOOL_PARALLEL_LIBS_BUILD=ON \
      -DLLVM_OPTIMIZED_TABLEGEN=ON \
      -DLIBOMP_ENABLE_SHARED=ON \
      -DOPENMP_ENABLE_LIBOMPTARGET=ON \
      -DLLDB_RELOCATABLE_PYTHON=ON \
      ../llvm
ninja -j4 
sudo ninja install

see also Freelancing

Last modified 15 months ago Last modified on Aug 29, 2019, 6:15:05 AM
Note: See TracWiki for help on using the wiki.