===== Introduction ===== Link-Time Optimization (LTO) is a compiler toolchain feature that enables additional program optimizations by deferring optimization passes to link time. ===== Kernel ===== [[https://docs.freebsd.org/en/books/handbook/kernelconfig/#kernelconfig-building|Build and link a kernel]] with: * WITHOUT_CTF=yes * WITHOUT_DTRACE=yes * sys/conf/kern.mk -flto=thin (for all clang invocations) ===== Ports ===== LTO is enabled on LLVM 3.7, but it needs the Gold binutils ld(1) plugin. To build with LTO, change your make.conf this way: CC=/usr/local/bin/clang37 CXX=/usr/local/bin/clang++37 CPP=/usr/local/bin/clang-cpp37 CFLAGS.clang+=-flto NM=/usr/local/bin/nm NMFLAGS+=--plugin /usr/local/llvm37/lib/LLVMgold.so LD=/usr/local/bin/ld.gold LDFLAGS+=-fuse-ld=gold -Wl,--plugin /usr/local/llvm37/lib/LLVMgold.so ---- {{tag>Stale Performance}}