LINUX: Run the 'sparse' checker if available 65/13665/3
authorAndrew Deason <adeason@sinenomine.net>
Fri, 28 Jun 2019 19:14:48 +0000 (14:14 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Tue, 2 Jul 2019 17:37:22 +0000 (13:37 -0400)
The Linux kernel module buildsystem supports running an external tool
(by default, the 'sparse' tool) during the build to run additional
static checks on the source code to flag various warnings.

Tell the kernel build to run such a tool, if 'sparse' is installed.
This causes various new warnings in the build, such as:

  CHECK   /.../src/libafs/MODLOAD-4.9.0-8-amd64-MP/afs_tokens.c
/.../src/libafs/MODLOAD-4.9.0-8-amd64-MP/afs_tokens.c:73:1: warning: symbol 'afs_FreeOneToken' was not declared. Should it be static?
/.../src/libafs/MODLOAD-4.9.0-8-amd64-MP/afs_tokens.c:160:1: warning: symbol 'afs_IsTokenExpired' was not declared. Should it be static?
/.../src/libafs/MODLOAD-4.9.0-8-amd64-MP/afs_tokens.c:187:1: warning: symbol 'afs_IsTokenUsable' was not declared. Should it be static?

None cause the build to fail currently, but are just printed for
potential further investigation.

To control detecting 'sparse', add the --with-sparse configure option
and SPARSE configure variable. Default to checking if sparse is
available, and enabling it if so.

Further information on using sparse in the Linux kernel is available
in Documentation/sparse.txt in the Linux tree.

Using 'sparse' during the build was suggested by yadayada@in.ibm.com.

Change-Id: I57944d792ba1c8093196a8b335a12dfa741b119b
Reviewed-on: https://gerrit.openafs.org/13665
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/cf/linux-checks.m4
src/cf/linux-test1.m4
src/libafs/MakefileProto.LINUX.in

index a433aff..d4a6c97 100644 (file)
@@ -24,6 +24,7 @@ AC_SUBST(LINUX_GCC_KOPTS)
 
 dnl Setup the kernel build environment
 LINUX_KBUILD_USES_EXTRA_CFLAGS
+LINUX_KBUILD_SPARSE_CHECKS
 LINUX_KERNEL_COMPILE_WORKS
 ])
 
index 02f3f90..9390b9a 100644 (file)
@@ -27,8 +27,8 @@ $2
 
 MODULE_LICENSE("http://www.openafs.org/dl/license10.html");
 _ACEOF
-    echo make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD &&
-    make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD 2>conftest.err &&
+    echo make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir $SPARSE_MAKEFLAGS modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD &&
+    make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir $SPARSE_MAKEFLAGS modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD 2>conftest.err &&
     ! grep -i "WARNING: .* undefined!$" conftest.err >/dev/null 2>&1
     then [$3]
     else
@@ -85,6 +85,28 @@ AC_DEFUN([LINUX_KBUILD_USES_EXTRA_CFLAGS], [
     CPPFLAGS="$save_CPPFLAGS"
     AC_MSG_RESULT($ac_linux_kbuild_requires_extra_cflags)])
 
+AC_DEFUN([LINUX_KBUILD_SPARSE_CHECKS], [
+  AC_ARG_WITH([sparse],
+              AS_HELP_STRING([--with-sparse@<:@=PATH@:>@],
+                             [Location of the 'sparse' tool]),
+              [SPARSE="$withval"],
+              [SPARSE=check])
+
+  AS_CASE([$SPARSE],
+          [check], [AC_PATH_PROG([SPARSE], [sparse], [])],
+          [yes],   [AC_PATH_PROG([SPARSE], [sparse], [])
+                    AS_IF([test "x$SPARSE" = "x"], [AC_MSG_ERROR([sparse not found])])],
+          [no],    [SPARSE=])
+
+  AS_IF([test x"$SPARSE" != x],
+        [SPARSE_MAKEFLAGS="C=2 CHECK=$SPARSE"])
+
+  AC_SUBST([SPARSE_MAKEFLAGS])
+
+  AC_ARG_VAR([SPARSE], [Path to the 'sparse' tool])
+])
+
+
 dnl AC_CHECK_LINUX_BUILD([msg], [var], [includes], [code], [define], [CFLAGS])
 AC_DEFUN([AC_CHECK_LINUX_BUILD],
  [AS_VAR_PUSHDEF([ac_linux_build], [$2])dnl
index ed687f1..ba2fabb 100644 (file)
@@ -296,6 +296,8 @@ SYSTEM_LIBAFS = /lib/modules/${CLIENT}/extra/${LINUX_LIBAFS_NAME}/${LINUX_LIBAFS
 INST_SYSTEM = ${DESTDIR}${SYSTEM_LIBAFS}
 DEST_SYSTEM = ${DEST}/root.client${SYSTEM_LIBAFS}
 
+SPARSE_MAKEFLAGS = @SPARSE_MAKEFLAGS@
+
 libafs:        $(LIBAFS) 
        echo SP Build Complete
 
@@ -319,7 +321,7 @@ ${LIBAFS} ${LIBAFS_MP} ${LIBAFS_EP} ${LIBAFS_BM}: ${LINUX_LIBAFS_NAME}.ko
 ${LINUX_LIBAFS_NAME}.ko afspag.ko: .FORCE
        env EXTRA_CFLAGS="${EXTRA_CFLAGS}" @TOP_SRCDIR@/libafs/make_kbuild_makefile.pl ${KDIR} $@ @TOP_OBJDIR@/src/config/Makefile.config Makefile.afs Makefile.common
        ( env EXTRA_CFLAGS="${EXTRA_CFLAGS}" \
-               $(MAKE) -C ${LINUX_KERNEL_BUILD} M=@TOP_OBJDIR@/src/libafs/${KDIR} modules 2>&1 \
+               $(MAKE) -C ${LINUX_KERNEL_BUILD} M=@TOP_OBJDIR@/src/libafs/${KDIR} $(SPARSE_MAKEFLAGS) modules 2>&1 \
                || echo "FAILURE: make exit code $$?" ) | tee .makelog
        @if grep -E -q '^(FAILURE|WARNING)' .makelog; then \
                grep -q '^WARNING' .makelog && echo "Error: Undefined symbols in modules" ; \