public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel: Add support for cross-build kernels
@ 2019-06-27 11:15 Andrew Murray
  2019-06-27 14:42 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Murray @ 2019-06-27 11:15 UTC (permalink / raw)
  To: smatch

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

Signed-off-by: Andrew Murray <andrew.murray@arm.com>
---
 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(-)

diff --git a/Documentation/smatch.txt b/Documentation/smatch.txt
index ae9a454dd023..b62e4507ee1d 100644
--- a/Documentation/smatch.txt
+++ b/Documentation/smatch.txt
@@ -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:
 
diff --git a/smatch_scripts/build_generic_data.sh b/smatch_scripts/build_generic_data.sh
index 27ad013bf55b..c8f98d9bdb62 100755
--- a/smatch_scripts/build_generic_data.sh
+++ b/smatch_scripts/build_generic_data.sh
@@ -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
 
diff --git a/smatch_scripts/kchecker b/smatch_scripts/kchecker
index 9754b21f93d0..2ca9b0f00f49 100755
--- a/smatch_scripts/kchecker
+++ b/smatch_scripts/kchecker
@@ -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
diff --git a/smatch_scripts/test_generic.sh b/smatch_scripts/test_generic.sh
index 4655ba74930a..5707d7c6ae70 100755
--- a/smatch_scripts/test_generic.sh
+++ b/smatch_scripts/test_generic.sh
@@ -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
 
diff --git a/smatch_scripts/test_kernel.sh b/smatch_scripts/test_kernel.sh
index b31c61047cfe..d254c56a638c 100755
--- a/smatch_scripts/test_kernel.sh
+++ b/smatch_scripts/test_kernel.sh
@@ -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
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kernel: Add support for cross-build kernels
  2019-06-27 11:15 [PATCH] kernel: Add support for cross-build kernels Andrew Murray
@ 2019-06-27 14:42 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2019-06-27 14:42 UTC (permalink / raw)
  To: Andrew Murray; +Cc: smatch

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-27 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-27 11:15 [PATCH] kernel: Add support for cross-build kernels Andrew Murray
2019-06-27 14:42 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox