[llvmlinux] [GSoC: Static analysis] Report 1 + PATCH
Eduard Bachmakov
e.bachmakov at gmail.com
Mon Jun 24 18:57:00 UTC 2013
Hey everyone,
After what felt like a million do-overs I think I found a workable
location for the integration of clang-analyzer. See patch below.
The GOOD: x64 works. How?
cd targets/x86_64; make kernel-scan-build; scan-view <watch end of
output, last line before time statistics>
The BAD: Should work for other targets, however, it seems some flags
aren't passed down in cases of cross-compilation, I'm ironing that
out. Feel free to try though!
The UGLY: takes forever. However, JSM might donate a stripped down
.config soon. That would speed things up a bit.
This code will also be pushed to my branch once I get access.
Comments, concerns? Also, despite using git imap-send, I'm afraid
gmail might screw things up. In that case please respond, I'll send
out an attachment.
---
Build a clang-analyzer target into the build-system.
Run "make kernel-build-scan"
USE ENABLE_CHECKERS/DISABLE_CHECKERS in <target>/Makefile to customize.
Tested on x64. Fails on ARM (flags not passed correctly?).
Signed-off-by: Eduard Bachmakov <e.bachmakov at gmail.com>
---
arch/all/all.mk | 18 +++++++++++++++++-
arch/arm/bin/make-kernel.sh | 5 ++++-
arch/x86_64/bin/make-kernel.sh | 4 +++-
targets/x86_64/Makefile | 3 +++
4 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/arch/all/all.mk b/arch/all/all.mk
index 8104e61..076a748 100644
--- a/arch/all/all.mk
+++ b/arch/all/all.mk
@@ -138,6 +138,16 @@ VERSION_TARGETS += ${KERNEL_TARGETS_VERSION}
.PHONY: ${KERNEL_TARGETS_CLANG} ${KERNEL_TARGETS_GCC}
${KERNEL_TARGETS_APPLIED} ${KERNEL_TARGETS_CLEAN}
${KERNEL_TARGETS_VERSION}
#############################################################################
+SCAN_BUILD := scan-build
+SCAN_BUILD_FLAGS := --use-cc=clang
+ifdef ENABLE_CHECKERS
+ SCAN_BUILD_FLAGS += -enable-checker ${ENABLE_CHECKERS}
+endif
+ifdef DISABLE_CHECKERS
+ SCAN_BUILD_FLAGS += -disable-checker ${DISABLE_CHECKERS}
+endif
+
+#############################################################################
kernel-help:
@echo
@echo "These are the kernel make targets:"
@@ -303,7 +313,7 @@ state/kernel-build: ${TMPDIR}
${LLVMSTATE}/clang-build ${STATE_TOOLCHAIN} state/
@[ -d ${KERNEL_BUILD} ] || ($(call
leavestate,${STATEDIR},kernel-configure) && ${MAKE} kernel-configure)
@$(MAKE) kernel-quilt-link-patches
@$(call banner,Building kernel with clang...)
- (cd ${KERNELDIR} && ${KERNEL_VAR} time ${MAKE_KERNEL})
+ (cd ${KERNELDIR} && ${KERNEL_VAR} time ${CHECKER} ${MAKE_KERNEL})
@$(call banner,Successfully Built kernel with clang!)
@mkdir -p ${TOPLOGDIR}
@( ${CLANG} --version | head -1 ; \
@@ -328,6 +338,12 @@ state/kernel-gcc-build: ${TMPDIR} ${CROSS_GCC}
${STATE_TOOLCHAIN} state/kernel-g
$(call state,$@,done)
#############################################################################
+kernel-scan-build: ${TMPDIR} ${LLVMSTATE}/clang-build
${STATE_TOOLCHAIN} state/kernel-configure
+ @$(eval CHECKER := ${SCAN_BUILD} ${SCAN_BUILD_FLAGS})
+ @$(call banner,Enabling clang static analyzer: ${CHECKER})
+ ${MAKE} CHECKER="${CHECKER}" kernel-build
+
+#############################################################################
kernel-build-force kernel-gcc-build-force: %-force:
@rm -f state/$*
${MAKE} $*
diff --git a/arch/arm/bin/make-kernel.sh b/arch/arm/bin/make-kernel.sh
index fa11a2e..5d0e51b 100755
--- a/arch/arm/bin/make-kernel.sh
+++ b/arch/arm/bin/make-kernel.sh
@@ -29,7 +29,10 @@ EXTRAFLAGS=$*
# Use clang by default
if [ -z "$USEGCC" ]; then
- CC="clang -gcc-toolchain $COMPILER_PATH" # $CLANGFLAGS"
+ if [ -z "$CC" ]; then
+ CC="clang"
+ fi
+ CFLAGS="-gcc-toolchain $COMPILER_PATH" # $CLANGFLAGS"
else
CC=${CROSS_COMPILE}gcc
fi
diff --git a/arch/x86_64/bin/make-kernel.sh b/arch/x86_64/bin/make-kernel.sh
index 8eb4074..e76bc31 100755
--- a/arch/x86_64/bin/make-kernel.sh
+++ b/arch/x86_64/bin/make-kernel.sh
@@ -29,7 +29,9 @@ EXTRAFLAGS=$*
# Use clang by default
if [ -z "$USEGCC" ]; then
- CC="clang"
+ if [ -z "$CC" ]; then
+ CC="clang"
+ fi
fi
JOBS=${JOBS:-`getconf _NPROCESSORS_ONLN`}
diff --git a/targets/x86_64/Makefile b/targets/x86_64/Makefile
index c3a66b6..db218e8 100644
--- a/targets/x86_64/Makefile
+++ b/targets/x86_64/Makefile
@@ -32,6 +32,9 @@ KERNEL_CFG = ${TARGETDIR}/config_x86_64
#GDB_OPTS = -gdb tcp::1234 -s -S
GDB_OPTS =
+ENABLE_CHECKERS =
+DISABLE_CHECKERS =
+
all: prep kernel-build
include ${TOPDIR}/common.mk
--
1.8.3.1
More information about the LLVMLinux
mailing list