linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: linux-kbuild@vger.kernel.org,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Filipe Brandenburger <filbranden@google.com>,
	Greg Thelen <gthelen@google.com>,
	Michael Davidson <md@google.com>,
	Eugene Surovegin <surovegin@google.com>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org (open list:DOCUMENTATION)
Subject: [PATCH] modpost: allow modpost to fail on warnings
Date: Fri, 18 Sep 2020 16:50:10 -0500	[thread overview]
Message-ID: <20200918215010.250580-1-pierre-louis.bossart@linux.intel.com> (raw)

From: Filipe Brandenburger <filbranden@google.com>

Set KBUILD_MODPOST_FAIL_ON_WARNINGS to a non-empty value to make the
kbuild fail when modpost generates any warnings. This will avoid
misses such as [1] where the SOF CI did not catch a missing module
license.

This was initially contributed in 2016 [2], rebase/clean-ups and tests
by Pierre Bossart.

Test example:
$ KBUILD_MODPOST_FAIL_ON_WARNINGS=1 make
  GEN     Makefile
  DESCEND  objtool
  CALL    sof-dev/scripts/atomic/check-atomics.sh
  CALL    sof-dev/scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  MODPOST Module.symvers
Kernel: arch/x86/boot/bzImage is ready  (#13)
WARNING: modpost: missing MODULE_LICENSE() in sound/soc/intel/boards/snd-soc-sof-sdw.o
make[2]: *** [sof-dev/scripts/Makefile.modpost:114: Module.symvers] Error 2

[1] https://lkml.org/lkml/2020/9/17/2343
[2] https://patchwork.kernel.org/patch/8343431/

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Michael Davidson <md@google.com>
Cc: Eugene Surovegin <surovegin@google.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Co-developed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 Documentation/kbuild/kbuild.rst |  5 +++++
 scripts/Makefile.modpost        |  5 ++++-
 scripts/mod/modpost.c           | 12 +++++++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index 2d1fc03d346e..cc102aad8619 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -229,6 +229,11 @@ KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined
 symbols in the final module linking stage. It changes such errors
 into warnings.
 
+KBUILD_MODPOST_FAIL_ON_WARNINGS
+-------------------------------
+KBUILD_MODPOST_FAIL_ON_WARNINGS can be set to turn all warnings into
+errors in the final module linking stage.
+
 KBUILD_MODPOST_NOFINAL
 ----------------------
 KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index f54b6ac37ac2..69297cd6f8ce 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -34,6 +34,8 @@
 
 # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined
 # symbols in the final module linking stage
+# KBUILD_MODPOST_FAIL_ON_WARNINGS can be set to fail whenever modpost
+# generates warnings
 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
 # This is solely useful to speed up test compiles
 
@@ -47,7 +49,8 @@ MODPOST = scripts/mod/modpost								\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
 	$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
-	$(if $(KBUILD_MODPOST_WARN),-w) \
+	$(if $(KBUILD_MODPOST_WARN),-w)							\
+	$(if $(KBUILD_MODPOST_FAIL_ON_WARNINGS),-F)					\
 	-o $@
 
 ifdef MODPOST_VMLINUX
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 69341b36f271..422f1cfca289 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -39,6 +39,9 @@ static int sec_mismatch_fatal = 0;
 static int ignore_missing_files;
 /* If set to 1, only warn (instead of error) about missing ns imports */
 static int allow_missing_ns_imports;
+/* Turn warnings into errors */
+static int fail_on_warnings;
+static int warnings_count;
 
 enum export {
 	export_plain,      export_unused,     export_gpl,
@@ -59,6 +62,7 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...)
 	switch (loglevel) {
 	case LOG_WARN:
 		fprintf(stderr, "WARNING: ");
+		warnings_count++;
 		break;
 	case LOG_ERROR:
 		fprintf(stderr, "ERROR: ");
@@ -2559,7 +2563,7 @@ int main(int argc, char **argv)
 	struct dump_list *dump_read_start = NULL;
 	struct dump_list **dump_read_iter = &dump_read_start;
 
-	while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:")) != -1) {
+	while ((opt = getopt(argc, argv, "ei:mnT:o:awEFNd:")) != -1) {
 		switch (opt) {
 		case 'e':
 			external_module = 1;
@@ -2588,6 +2592,9 @@ int main(int argc, char **argv)
 		case 'w':
 			warn_unresolved = 1;
 			break;
+		case 'F':
+			fail_on_warnings = 1;
+			break;
 		case 'E':
 			sec_mismatch_fatal = 1;
 			break;
@@ -2671,5 +2678,8 @@ int main(int argc, char **argv)
 
 	free(buf.p);
 
+	if (fail_on_warnings && warnings_count)
+		err |= 2;
+
 	return err;
 }
-- 
2.25.1


             reply	other threads:[~2020-09-18 21:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-18 21:50 Pierre-Louis Bossart [this message]
2020-09-19  6:21 ` [PATCH] modpost: allow modpost to fail on warnings Masahiro Yamada
2020-09-21 14:50   ` Pierre-Louis Bossart
2020-09-24 17:22     ` Masahiro Yamada
2020-09-24 18:13       ` Pierre-Louis Bossart
  -- strict thread matches above, loose matches on Subject: below --
2016-02-17 22:25 Filipe Brandenburger
2016-02-18 10:36 ` Michal Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200918215010.250580-1-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=filbranden@google.com \
    --cc=gthelen@google.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=md@google.com \
    --cc=michal.lkml@markovi.net \
    --cc=sfr@canb.auug.org.au \
    --cc=surovegin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).