Hi,
attached patch adds scan-build support to coreboot-v4.
It's configurable using Kconfig and defaults to off.
If set, it expects scan-build to be around and runs it.
The target directory for the scan-build report is configurable. If not
set, the default (/tmp/scan-build-$date-$number) is used.
Also, abuild is adapted to make use of the feature when running with the
-sb flag.
While adding it, I discovered an issue in the build system that I worked
around in this patch, and will fix in a future patch:
$(obj)/$path/$file.c -> $(obj)/$path/$file.o rules rely on implicit
default rules in make. For some reasons, these are missing when make is
invoked by make.
There should also be some path normalization for object file paths
(using $(abspath)), so the option_table.c rule hack can go.
Maybe it's a good idea to avoid reading in all Makefile.incs in the
outer make in a scan-build based build, but it's probably not worth the
trouble (it's harder to keep make clean and the likes working with such
an optimization)
Signed-off-by: Patrick Georgi <[email protected]>
Index: src/Kconfig
===================================================================
--- src/Kconfig (Revision 5206)
+++ src/Kconfig (Arbeitskopie)
@@ -46,6 +46,20 @@
Select the prefix to all files put into the image. It's "fallback"
by default, "normal" is a common alternative.
+config SCANBUILD_ENABLE
+ bool "build with scan-build for static analysis"
+ default n
+ help
+ Changes the build process to scan-build is used.
+ Requires scan-build in path.
+
+config SCANBUILD_REPORT_LOCATION
+ string "directory to put scan-build report in"
+ default ""
+ depends on SCANBUILD_ENABLE
+ help
+ Where the scan-build report should be stored
+
endmenu
source src/mainboard/Kconfig
Index: src/cpu/x86/smm/Makefile.inc
===================================================================
--- src/cpu/x86/smm/Makefile.inc (Revision 5206)
+++ src/cpu/x86/smm/Makefile.inc (Arbeitskopie)
@@ -38,5 +38,9 @@
$(obj)/cpu/x86/smm/smm_bin.c: $(obj)/cpu/x86/smm/smm
(echo 'unsigned char smm[] = {'; od -vtx1 $(obj)/cpu/x86/smm/smm | sed
-e 's,^[0-9]* *,,' -e 's:[0-9a-f][0-9a-f] :0x&,:g' -e
's:[0-9a-f][0-9a-f]$$:0x&,:'; echo '}; unsigned int smm_len = '; wc -c
$(obj)/cpu/x86/smm/smm |awk '{print $$1;}' ; echo ';') > $@
+$(obj)/cpu/x86/smm/smm_bin.o: $(obj)/cpu/x86/smm/smm_bin.c
+ @printf " CC $(subst $(obj)/,,$(@))\n"
+ $(CC) $(CFLAGS) -c -o $@ $<
+
endif
Index: src/arch/i386/Makefile.inc
===================================================================
--- src/arch/i386/Makefile.inc (Revision 5206)
+++ src/arch/i386/Makefile.inc (Arbeitskopie)
@@ -60,7 +60,7 @@
$(obj)/coreboot_ram.o: $(obj)/arch/i386/lib/c_start.o $(drivers)
$(obj)/coreboot.a $(LIBGCC_FILE_NAME)
@printf " CC $(subst $(obj)/,,$(@))\n"
- $(CC) -nostdlib -r -o $@ $(obj)/arch/i386/lib/c_start.o $(drivers)
-Wl,-\( $(obj)/coreboot.a $(LIBGCC_FILE_NAME) -Wl,-\)
+ $(CC) -nostdlib -r -o $@ $(obj)/arch/i386/lib/c_start.o $(drivers)
-Wl,--start-group $(obj)/coreboot.a $(LIBGCC_FILE_NAME) -Wl,--end-group
$(obj)/coreboot.a: $(objs)
@printf " AR $(subst $(obj)/,,$(@))\n"
Index: util/abuild/abuild
===================================================================
--- util/abuild/abuild (Revision 5206)
+++ util/abuild/abuild (Arbeitskopie)
@@ -173,6 +173,12 @@
echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y" >>
.config
echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >>
.config
fi
+
+ if [ "$scanbuild" = "true" ]; then
+ printf "(scan-build enabled) "
+ echo "CONFIG_SCANBUILD_ENABLE=y" >> .config
+ echo
"CONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\"" >> .config
+ fi
fi
yes "" | $MAKE oldconfig obj=${build_dir} > ${build_dir}/config.log
@@ -364,21 +370,6 @@
CC="$CC -fno-stack-protector"
fi
- if [ "$scanbuild" = "true" ]; then
- ccwrap=`mktemp`
- mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
- mkdir -p $TARGET/scan-build-results-tmp
- mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
- ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
- echo '#!/bin/sh' > $ccwrap
- echo $CC' "$@"' >> $ccwrap
- chmod +x $ccwrap
- origMAKE=$MAKE
- MAKE="scan-build --use-cc=$ccwrap -o
$TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
- CC="\$(CC)"
- HOSTCC="CCC_CC=$HOSTCC \$(CC)"
- fi
-
built_successfully $VENDOR $MAINBOARD && \
{
printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
Index: Makefile
===================================================================
--- Makefile (Revision 5206)
+++ Makefile (Arbeitskopie)
@@ -19,8 +19,16 @@
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
+ifeq ($(INNER_SCANBUILD),y)
+CC_real:=$(CC)
+endif
$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile >
.xcompile)))
include .xcompile
+ifeq ($(INNER_SCANBUILD),y)
+CC:=$(CC_real)
+HOSTCC:=$(CC_real) --hostcc
+HOSTCXX:=$(CC_real) --hostcxx
+endif
export top := $(PWD)
export src := $(top)/src
@@ -90,7 +98,25 @@
# The primary target needs to be here before we include the
# other files
+ifeq ($(INNER_SCANBUILD),y)
+CONFIG_SCANBUILD_ENABLE:=
+endif
+
+ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
+ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
+CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
+endif
+all:
+ echo '#!/bin/sh' > .ccwrap
+ echo 'CC="$(CC)"' >> .ccwrap
+ echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >>
.ccwrap
+ echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >>
.ccwrap
+ echo 'eval $$CC $$*' >> .ccwrap
+ chmod +x .ccwrap
+ scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers
--use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
+else
all: coreboot
+endif
#######################################################################
@@ -110,8 +136,13 @@
(cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig
export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top)
$(obj)/mainboard/$(MAINBOARDDIR))
$(obj)/mainboard/$(MAINBOARDDIR)/static.o:
$(obj)/mainboard/$(MAINBOARDDIR)/static.c
-#
+ @printf " CC $(subst $(obj)/,,$(@))\n"
+ $(CC) $(CFLAGS) -c -o $@ $<
+$(obj)/arch/i386/../../option_table.o: $(obj)/arch/i386/../../option_table.c
+ @printf " CC $(subst $(obj)/,,$(@))\n"
+ $(CC) $(CFLAGS) -c -o $@ $<
+
objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
initobjs:=
drivers:=
@@ -325,7 +356,7 @@
$(MAKE) -C util/sconfig clean
clean: clean-for-update
- rm -f $(obj)/coreboot*
+ rm -f $(obj)/coreboot* .ccwrap
distclean: clean
rm -rf $(obj)
--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot