makepkg clang + LTO + -O3 + mold linker

make your unix programs perform better

Install packages

doas pacman -S llvm clang mold

Add the following to /etc/makepkg.conf

Don’t forget to set MAKEFLAGS to the number of threads your ЭВМ has.

#-- Compiler and Linker Flags
export CC="clang"
export CXX="clang++"
export LD="ld.mold"
export AR="llvm-ar"
export NM="llvm-nm"
export RANLIB="llvm-ranlib"
export STRIP="llvm-strip"
export OBJCOPY="llvm-objcopy"
export OBJDUMP="llvm-objdump"

CFLAGS="-O3 -march=native -pipe -flto=thin \
    -fno-semantic-interposition -ffp-contract=fast"
CXXFLAGS="$CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"
LDFLAGS="-fuse-ld=mold -flto -rtlib=compiler-rt -unwindlib=libunwind -Wl,-O3 \
    -Wl,--lto-O3 -Wl,--as-needed -Wl,--gc-sections -Wl,--icf=all \
    -Wl,--strip-all -Wl,-z,norelro -lgcc_s"
# Fallback LDFLAGS
# LDFLAGS="-fuse-ld=mold -Wl,-O3  -Wl,--lto-O3 -Wl,--as-needed"
MAKEFLAGS="-j32"
#-- Debugging flags
DEBUG_CFLAGS="-g"
DEBUG_CXXFLAGS="$DEBUG_CFLAGS"

Change RUSTFLAGS in /etc/makepkg.conf.d/rust.conf

RUSTFLAGS="-C debuginfo=0 -C target-cpu=native -C opt-level=3 \
    -C codegen-units=1 -C strip=symbols \
    -Clinker-plugin-lto -Clinker=clang \
    -Clink-arg=-fuse-ld=mold -Clink-arg=-flto"

Optional (signing packages)

If you want to sign your packages, add your information to /etc/makepkg.conf by setting the PACKAGER variable:

PACKAGER="cat <cat@meow.tld>"