instructions: using clang's static analyzer on arbitrary kernel modules

From: Jason A. Donenfeld
Date: Fri Jan 03 2020 - 09:19:24 EST


Hi,

I figure I should document this somewhere. Here's what I've been using
to run both clang's scan-build and sparse at the same time on the
wireguard kernel module:

rm -rf /tmp/check-wireguard-linux
make CC=clang O=/tmp/check-wireguard-linux defconfig -j$(nproc)
printf 'CONFIG_WIREGUARD=m\nCONFIG_WIREGUARD_DEBUG=y\n' >> /tmp/check-wireguard-linux/.config
make CC=clang O=/tmp/check-wireguard-linux prepare -j$(nproc)
scan-build --use-cc=clang -maxloop 100 --view --keep-going make CC=clang O=/tmp/check-wireguard-linux drivers/net/wireguard/wireguard.ko -j$(nproc) C=2 CF="-D__CHECK_ENDIAN__"

It seems to generally work well at catching super stupid mistakes.

Regards,
Jason