Skip to content

llvm

  • Do not set BUILD_SHARED_LIBS as it disables static libraries for llvm and only works with -DLLVM_BUILD_LLVM_DYLIB=ON but not with -DLLVM_LINK_LLVM_DYLIB=ON
  • Do not depend on PyYAML; required for llvm-libc
  • LLVM_ENABLE_ASSERTIONS is OFF by default with Release builds
  • Do we need LLVM_PARALLEL_COMPILE_JOBS?
  • Do we need LLVM_PARALLEL_TABLEGEN_JOBS?
  • Do we need LLVM_INSTALL_UTILS for FileCheck and not? or should we set -DLLVM_INSTALL_UTILS=OFF?
  • Do not set LLVM_EXTERNAL_LIT to allow the bundled lit to run; needed for standalone builds of subprojects
  • Do we need LLVM_ROOT?
  • Rely on the host’s compiler instead of crafting our own for the toolchain stage
  • For list of supported targets by LLVM_TARGETS_TO_BUILD, check llvm/lib/Target/
  • Enable LLVM_OPTIMIZED_TABLEGEN to reduce build time
  • Disable CLANG_ENABLE_STATIC_ANALYZER for toolchain and cross
  • To disable LIBCXX_ENABLE_RTTI disable LIBCXX_ENABLE_EXCEPTIONS first
  • What is the default value for LIBCXX_CXX_ABI?
  • Enable LIBCXX_USE_COMPILER_RT and LIBCXXABI_USE_COMPILER_RT to use compiler-rt over libgcc_s
  • Enable LIBCXXABI_USE_LLVM_UNWINDER to use libunwind over libgcc_s
  • Should we set CMAKE_CXX_STANDARD to 20 instead of 17
  • LLVM_BUILD_BENCHMARKS, LLVM_BUILD_DOCS, LLVM_BUILD_EXAMPLES and LLVM_BUILD_TESTS are OFF by default
  • LLVM_BUILD_LLVM_DYLIB is used to build llvm as a single shared library; it can’t be used with BUILD_SHARED_LIBS
  • LLVM_DEFAULT_TARGET_TRIPLE defaults to host (the machine where llvm is being built according to the docs) if no target is explicitly specified; for cross-compilers use $TGT instead
  • LLVM_ENABLE_ASSERTIONS defaults to OFF if CMAKE_BUILD_TYPE is Release
  • Explicitly disable LLVM_BUILD_TELEMETRY and LLVM_ENABLE_BINDINGS; they are ON by default
  • LLVM_ENABLE_PEDANTIC defaults to ON
  • It is better to pass compiler-rt to LLVM_ENABLE_RUNTIMES rather than LLVM_ENABLE_PROJECTS
  • Try setting LLVM_ENABLE_UNWIND_TABLES to OFF instead of passing -fno-unwind-tables in CFLAGS?
  • Consider LLVM_ENABLE_Z3_SOLVER=ON in the future
  • LLVM_INTEGRATED_CRT_ALLOC is only relevant on Windows
  • Consider LLVM_ENABLE_RPMALLOC?; can’t be used with LLVM_USE_SANITIZER=ON
  • LLVM_LINK_LLVM_DYLIB=ON implies LLVM_BUILD_LLVM_DYLIB=ON
  • If LLVM_TABLEGEN is explicitly set to llvm-tblgen, then no native TableGen will be compiled, and the one provided by the host will be used; this is useful when cross-compiling to reduce build time by not having to compile a native tool that could be provided by the host itself
  • It is better to not have LLVM_TARGET_ARCH set as a triplet, as it’ll resolve via regex to X86 almost always
  • LLVM_USE_LINKER prefixes the value (e.g. mold) with ld. (so it becomes ld.mold)
  • Set LLVM_USE_PERF to ON for pgo to work; also consider LLVM_ENABLE_LIBPFM (should be ON by default)
  • Do we need LLVM_USE_SANITIZER=OFF? It defaults to an empty string "" so no?
  • Do we need this early on LLVM_ENABLE_LIBXML2?
  • Not all LLVM projects require LLVM; compiler-rt can be built without llvm
  • LLVM_ENABLE_LTO=Thin (or even Full) does not work if you are using gcc to build llvm obviously
  • CLANG_VENDOR_UTI is a macOS only option
  • CLANG_LINK_CLANG_DYLIB is set to LLVM_LINK_LLVM_DYLIB value
  • Do we need CLANG_BUILD_TOOLS=ON? Are the tools really needed for just building software?
  • CLANG_INCLUDE_DOCS and CLANG_INCLUDE_TESTS are set to LLVM_INCLUDE_DOCS and LLVM_INCLUDE_TESTS values respectively
  • Prefer CMAKE_C_COMPILER and CMAKE_CXX_COMPILER over C_COMPILER and CXX_COMPILER; the latter are llvm only and they set the former internally
  • Do we need to set CMAKE_ASM_COMPILER=clang?
  • LLVM_LIBDIR_SUFFIX is set to "" by default; also CLANG_LIBDIR_SUFFIX is set to its value
  • Do we need COMPILER_RT_DEFAULT_TARGET_ARCH?
  • Do we need LIBUNWIND_ENABLE_CROSS_UNWINDING?
  • Do we need COMPILER_RT_USE_ATOMIC_LIBRARY; does it use compiler-rt or libatomic?
  • LIBCXX_HARDENING_MODE=fast is recommended due to minimal overhead
  • Do we need LIBCXX_ENABLE_TIME_ZONE_DATABASE=OFF?
  • Do not set LIBCXX_ENABLE_PEDANTIC=ON and LIBCXXABI_ENABLE_PEDANTIC=ON as #include_next is used everywhere
  • Do not mix libstdc++ and libc++ as they export the same symbols…
  • -stdlib=libc++ is not required on systems where libc++ is the default library (e.g. openbsd, freebsd and macos); it is better to specify it otherwise
  • Arch does not provide clang-tblgen
  • -Wno-dev suppresses developer warnings
  • To build mesa you only need libllvm and maybe clang (and libclc?)
  • It’s better to use lld because it can tap into private LLVM APIs instead of going back and forth through the generic linker plugin API; verify this?
  • Do we need to build an llvm distribution?
  • llvm-lipo is macos specific for fat binaries
  • Do we need the following symlinks:
ln -fs llvm-as as
ln -fs llvm-rtdyld rtdyld
ln -fs ld.lld ld
ln -fs clang c89
ln -fs clang c99
ln -fs clang cc
ln -fs clang cpp
ln -fs clang++ c++
for i in llvm-*; do ln -fs "$i" "${i#llvm-}"; done
for i in llvm-*; do ln -fs "$i" "$TGT-${i#llvm-}"; done
  • Do we need the following environment variables (not used in the previous gcc toolchain):
export ADDR2LINE=llvm-addr2line
export AS=clang # compared to using `llvm-mc` or even `clang -c`
export CC="clang -flto" # `-flto` here as well as in CFLAGS?
export CLANG=clang
export CLANGXX=clang++
export CROSS_COMPILE=llvm-
export CXX="clang++ -flto" # `-flto` here as well as in CXXFLAGS?
export CXXFILT=llvm-cxxfilt
export HOSTAR=llvm-ar
export HOSTCC=clang
export HOSTCXX=clang++
export HOSTLD=ld.lld
export LDFLAGS="-fuse-ld=lld"
export STRINGS=llvm-strings
  • Check:
    • LLVM_UBSAN_FLAGS
    • -DC_COMPILER vs -DCMAKE_C_COMPILER=clang
    • -DCXX_COMPILER vs -DCMAKE_CXX_COMPILER=clang++
    • -DLLVM_USE_LINKER=lld
  • -DLLVM_RUNTIME_TARGETS breaks the build with weird runtimes-x86_64-pc-linux-musl paths
  • clang by design is a full fledged cross compiler
  • clang always ignores -pipe
  • clang uses LLVM’s integrated assembler (llvm-as) by default on all targets where it is supported
  • clang -cc1 --help shows all supported options by the C compiler driver
  • clang defaults to gnu99 mode while GCC defaults to gnu89 mode; try passing -std=gnu89 to clang for weird link-time errors
  • clang has a better loop optimizer than gcc
  • clang is all of these with the exception of a linker:
    • Preprocessor: clang -E
    • Parser: clang -precompile (default if input is header file)
    • Bitcode IR Generator: clang -emit-llvm
    • Textual IR Generator: clang -emit-llvm -S
    • Compiler Backend: clang -S
    • Assembler: clang -c
    • Bitcode Generator: clang -flto
  • clang-tools-extra is not needed for earlier builds of clang