-
Notifications
You must be signed in to change notification settings - Fork 262
Example Projects
Fangrui Song edited this page Jan 16, 2021
·
4 revisions
LLVM=1 enables a full set of LLVM tools: clang, llvm-objcopy, llvm-objdump, llvm-nm, etc.
# Use clang 9 or newer.
make O=/tmp/out/x86_64 ARCH=x86_64 LLVM=1 defconfig
make O=/tmp/out/x86_64 ARCH=x86_64 LLVM=1 -k bzImage modules # generate .<target>.cmd files
scripts/clang-tools/gen_compile_commands.py -d /tmp/out/x86_64
For older kernel (before http://git.kernel.org/linus/a0d1c951ef08ed24f35129267e3595d86f57f5d3), use
make O=/tmp/out/x86_64 CC=/path/to/clang defconfig
make O=/tmp/out/x86_64 CC=/path/to/clang bzImage modules # generate .<target>.cmd files
For other architectures:
make O=/tmp/out/arm ARCH=arm CROSS_COMPILE=arm-linux-gnu- LLVM=1 defconfig
make O=/tmp/out/arm ARCH=arm CROSS_COMPILE=arm-linux-gnu- LLVM=1 -k zImage modules
make O=/tmp/out/arm64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LLVM=1 defconfig
make O=/tmp/out/arm64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LLVM=1 -k Image.gz modules
make O=/tmp/out/powerpc ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- LLVM=1 powernv_defconfig
make O=/tmp/out/powerpc ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- LLVM=1 -k zImage.epapr modules
2019-11-09: ARCH=x86_64 defconfig => 1.4G .ccls-cache
Arch Linux:
mkdir out
wget 'https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux' -O out/.config
yes '' | make O=out config
If CC=gcc, there may be some options that need filtering out:
ccls -index ~/Dev/Linux -init='{"clang":{"excludeArgs":[
"-falign-jumps=1","-falign-loops=1","-fconserve-stack","-fmerge-constants","-fno-code-hoisting","-fno-schedule-insns","-fno-sched-pressure","-fno-var-tracking-assignments","-fsched-pressure",
"-mhard-float","-mindirect-branch-register","-mindirect-branch=thunk-inline","-mpreferred-stack-boundary=2","-mpreferred-stack-boundary=3","-mpreferred-stack-boundary=4","-mrecord-mcount","-mindirect-branch=thunk-extern","-mno-fp-ret-in-387","-mskip-rax-setup",
"--param=allow-store-data-races=0","-Wa,arch/x86/kernel/macros.s","-Wa,-"
], "extraArgs":["--gcc-toolchain=/usr"]}}'
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
cmake -Hllvm -BDebug -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lld' <other options>
ln -s Debug/compile_commands.json
You can filter out some files to speed up indexing. Example initialization options:
{"index":{"initialBlacklist":["/(clang|lld|llvm)/(test|unittests)/", "/llvm/(bindings|examples|utils)/", "/StaticAnalyzer/"]}}
mkdir Debug; cd Debug
../configure --enable-optimize=no --enable-debug --prefix=~/.local/stow/musl
bear make -j
cd ..; ln -s Debug/compile_commands.json
See https://github.com/MaskRay/ccls/issues/753 for an example.
autoreconf
mkdir Debug; cd Debug
../configure --prefix=/tmp/opt
bear make -j main
cd ..; ln -s Debug/compile_commands.json