kernel: Add support for cross-build kernels
PATCH 1/1 kernel: Add support for cross-build kernels
The smatch scripts such as kchecker invoke the Linux kernel build system, however it doesn't pass commonly used environment variables which allow for cross-compilation.
Let's pass the ARCH and CROSS_COMPILE environment variables to the kernel build system to support cross-built kernels. E.g.
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
~/smatch/smatch_scripts/build_kernel_data.sh
--- Documentation/smatch.txt | 4 ++++ smatch_scripts/build_generic_data.sh | 9 ++++++++- smatch_scripts/kchecker | 10 +++++++++- smatch_scripts/test_generic.sh | 11 +++++++++-- smatch_scripts/test_kernel.sh | 11 +++++++++-- 5 files changed, 39 insertions(+), 6 deletions(-)
Documentation/smatch.txt +4 -0
@@ -55,6 +55,10 @@ You can also build a directory like this: The kchecker script prints its warnings to stdout. +The above scripts will ensure that any ARCH or CROSS_COMPILE environment +variables are passed to kernel build system - thus allowing for the use of +Smatch with kernels that are normally built with cross-compilers. + If you are building something else (which is not the Linux kernel) then use something like:
smatch_scripts/build_generic_data.sh +8 -1
@@ -52,7 +52,14 @@ if [ ! -e smatch_db.sqlite ] ; then fi fi -make -j${NR_CPU} CHECK="$BIN_DIR/smatch --call-tree --info --param-mapper --spammy --file-output" $TARGET +if [[ ! -z $ARCH ]]; then + KERNEL_ARCH="ARCH=$ARCH" +fi +if [[ ! -z $CROSS_COMPILE ]] ; then + KERNEL_CROSS_COMPILE="CROSS_COMPILE=$CROSS_COMPILE" +fi + +make $KERNEL_ARCH $KERNEL_CROSS_COMPILE -j${NR_CPU} CHECK="$BIN_DIR/smatch --call-tree --info --param-mapper --spammy --file-output" $TARGET find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > smatch_warns.txt
smatch_scripts/kchecker +9 -1
@@ -70,4 +70,12 @@ if echo $oname | grep -q .o$ ; then rm -f $oname fi -make C=2 $ENDIAN CHECK="$PRE $CMD $POST" $oname +if [[ ! -z $ARCH ]]; then + echo "yes" + KERNEL_ARCH="ARCH=$ARCH" +fi +if [[ ! -z $CROSS_COMPILE ]] ; then + KERNEL_CROSS_COMPILE="CROSS_COMPILE=$CROSS_COMPILE" +fi + +make $KERNEL_CROSS_COMPILE $KERNEL_ARCH C=2 $ENDIAN CHECK="$PRE $CMD $POST" $oname
smatch_scripts/test_generic.sh +9 -2
@@ -52,9 +52,16 @@ else exit 1 fi -make clean +if [[ ! -z $ARCH ]]; then + KERNEL_ARCH="ARCH=$ARCH" +fi +if [[ ! -z $CROSS_COMPILE ]] ; then + KERNEL_CROSS_COMPILE="CROSS_COMPILE=$CROSS_COMPILE" +fi + +make $KERNEL_ARCH $KERNEL_CROSS_COMPILE clean find -name \*.c.smatch -exec rm \{\} \; -make -j${NR_CPU} $ENDIAN -k CHECK="$CMD --file-output $*" \ +make $KERNEL_ARCH $KERNEL_CROSS_COMPILE -j${NR_CPU} $ENDIAN -k CHECK="$CMD --file-output $*" \ C=1 $TARGET 2>&1 | tee $LOG find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > $WLOG
smatch_scripts/test_kernel.sh +9 -2
@@ -56,9 +56,16 @@ else exit 1 fi -make clean +if [[ ! -z $ARCH ]]; then + KERNEL_ARCH="ARCH=$ARCH" +fi +if [[ ! -z $CROSS_COMPILE ]] ; then + KERNEL_CROSS_COMPILE="CROSS_COMPILE=$CROSS_COMPILE" +fi + +make $KERNEL_ARCH $KERNEL_CROSS_COMPILE clean find -name \*.c.smatch -exec rm \{\} \; -make -j${NR_CPU} $ENDIAN -k CHECK="$CMD -p=kernel --file-output --succeed $*" \ +make $KERNEL_ARCH $KERNEL_CROSS_COMPILE -j${NR_CPU} $ENDIAN -k CHECK="$CMD -p=kernel --file-output --succeed $*" \ C=1 $BUILD_PARAM $TARGET 2>&1 | tee $LOG BUILD_STATUS=${PIPESTATUS[0]} find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > $WLOG
Signature · 1 line
2.21.0
Thanks! Applied. I also changed the data source thing to "$0" instead of "p 0" and added an m for modified like "$0 [m]". I want to add a a [c] or something annotation for capped but i'm not totally sure what it would look like.
I guess I'm not really eager to handle the "$0->foo + $1->bar" case...
regards,
dan carpenter