Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Linux kernel

Docs

Building Linux with Clang/LLVM

Get brached code

Stab branch kernel

git clone --no-checkout --depth 1 -b master \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

cd linux

git fetch --shallow-exclude=v6.13 origin

# Checkout any remote branches
git remote set-branches origin linux-6.13.y
# git fetch --depth 1 origin linux-6.13.y
git fetch --shallow-exclude=v6.13 origin

Build

开启DEBUG INFO

./scripts/config --file .config -d DEBUG_INFO_NONE -e DEBUG_KERNEL \
  -e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e KALLSYMS -e KALLSYMS_ALL
make olddefconfig

关闭DEBUG INFO

./scripts/config --file .config -d DEBUG_INFO \
  -d DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -d DEBUG_INFO_DWARF4 \
  -d DEBUG_INFO_DWARF5 -e CONFIG_DEBUG_INFO_NONE
make olddefconfig

Deps

bc flex pahole elfutils bison

My build steps

mkdir build

make LLVM=1 O=build/ defconfig

./scripts/config --file build/.config -d DEBUG_INFO_NONE -e DEBUG_KERNEL \
  -e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e KALLSYMS -e KALLSYMS_ALL -e CONFIG_RUST

make LLVM=1 -C build -j 12

./scripts/clang-tools/gen_compile_commands.py -d build

Build with clang

make CC=clang defconfig
make CC=clang

make LLVM=1 defconfig
make LLVM=1

配置 Rust on Linux

./scripts/config --file build/.config -e CONFIG_RUST

生成 compdb

完成编译后 ./scripts/clang-tools/gen_compile_commands.py

常用 Make 变量

O=build/

CC=clang

LLVM=1 LLVM=/path/to/llvm

ARCH=arm64

CORSS_COMPILE=aarch64-linux-gnu