From patchwork Wed Feb 17 22:25:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Brandenburger X-Patchwork-Id: 8343431 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 047A09F2F0 for ; Wed, 17 Feb 2016 22:26:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 50C4D2026C for ; Wed, 17 Feb 2016 22:26:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95711201DD for ; Wed, 17 Feb 2016 22:26:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161234AbcBQW0E (ORCPT ); Wed, 17 Feb 2016 17:26:04 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:35849 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965454AbcBQW0C (ORCPT ); Wed, 17 Feb 2016 17:26:02 -0500 Received: by mail-pa0-f45.google.com with SMTP id yy13so18419551pab.3 for ; Wed, 17 Feb 2016 14:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=G28s2iiBEy/rdFaCKb1NAqCwRt6RzXS9OujxhXEpzTw=; b=Wx9yzpsvqzdzPoMoHdOpdKo0XP/ocHxLCMdfO2GwbySD2SlKa+8DXSFm7KVufPM9ff uqTIboWtQjbQ1Cj8rajcQwB7kCp8UfAQ6lBCNttR2+8LvWj43SB8cPCkwEeeYK3iEGZ1 8ptnKY3CJ/lz5qpp0C3v2Wftb9kjKq44mnE7IR0hfZIn6II5tzt6LP3KStxgXHfTQamk GydzWn3KfzPxBtw8FMsjkVi/z4889wqdPvamGTPwiK5qE4rEBROhrB4AGIlRz2cmbjw+ NhDuXDuxc4+nQ9HuEsyAgTyM6vZrhjqFSM+WdseprFfvesiOYZYdWpggVvakbYAYgt9K U1Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=G28s2iiBEy/rdFaCKb1NAqCwRt6RzXS9OujxhXEpzTw=; b=bPSUYST8bB51opR3T1CapEHprLIpn8IgkUnhu5KmVELzV4rM482xGCuI6Aswin3XAq hscIMxwpzuUU3eRgKcW/S3hzIefP9sDgwAnQzt/wRrV3rnuQiSdbGpZZ41CaNJzP/w+g i/4Hut+apy0IioV2zUSWWbuYzOQwgeU1mI6UpOOEZj6AmC6jrT6qIaIvQ5OW4dXqB/Hz QnBOtq4YIbNZXBqSTtIRiFsDb0H8DGLMFHkpzbhUmy6wWdY4lnrJc/Q23YI+xB20dGWm jkArI/AZT3QA9NwVsR0jMIcjF3sEx03vRBwYeTIGc13br/huC8uGoyKoW+Gyc1Y06Nbt Stng== X-Gm-Message-State: AG10YORHvr5yBuCw8hwFKU9tL73UjGJ/TC99HtofCJya5m9Ur+bqKHzEs1Wjn8K69M+RC87i X-Received: by 10.66.242.17 with SMTP id wm17mr5511400pac.155.1455747961087; Wed, 17 Feb 2016 14:26:01 -0800 (PST) Received: from montreal.mtv.corp.google.com ([172.22.64.215]) by smtp.gmail.com with ESMTPSA id lq10sm4899404pab.36.2016.02.17.14.26.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 14:26:00 -0800 (PST) From: Filipe Brandenburger To: Michal Marek , linux-kbuild@vger.kernel.org Cc: Filipe Brandenburger , Greg Thelen , Michael Davidson , Eugene Surovegin Subject: [PATCH] modpost: allow modpost to fail on warnings Date: Wed, 17 Feb 2016 14:25:39 -0800 Message-Id: <1455747939-34515-1-git-send-email-filbranden@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Set KBUILD_MODPOST_FAIL_ON_WARNINGS to a non-empty value to make the kbuild fail when modpost generates any warnings. Tested: Replaced ntp_clear() with ntp_init() in kernel/time/timekeeping.c, which produces a modpost warning since the latter is marked __init. Confirmed that the build failed with a hard error. $ make bzImage modules KBUILD_MODPOST_FAIL_ON_WARNINGS=1 CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h CHK include/generated/bounds.h CHK include/generated/timeconst.h CHK include/generated/asm-offsets.h CALL scripts/checksyscalls.sh CHK include/generated/compile.h CC kernel/time/timekeeping.o LD kernel/time/built-in.o LD kernel/built-in.o LINK vmlinux LD vmlinux.o MODPOST vmlinux.o WARNING: modpost: Found 1 section mismatch(es). To see full details build your kernel with: 'make CONFIG_DEBUG_SECTION_MISMATCH=y' scripts/Makefile.modpost:100: recipe for target 'vmlinux.o' failed make[1]: *** [vmlinux.o] Error 2 Makefile:936: recipe for target 'vmlinux' failed make: *** [vmlinux] Error 2 Signed-off-by: Filipe Brandenburger Cc: Greg Thelen Cc: Michael Davidson Cc: Eugene Surovegin --- Documentation/kbuild/kbuild.txt | 5 +++++ scripts/Makefile.modpost | 5 ++++- scripts/mod/modpost.c | 13 ++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt index 0ff6a466a05b..03d876d7a03d 100644 --- a/Documentation/kbuild/kbuild.txt +++ b/Documentation/kbuild/kbuild.txt @@ -185,6 +185,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 1366a94b6c39..516cb20494d2 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 PHONY := _modpost @@ -78,7 +80,8 @@ modpost = scripts/mod/modpost \ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ - $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) + $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \ + $(if $(KBUILD_MODPOST_FAIL_ON_WARNINGS),-F) MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS))) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 48958d3cec9e..3ec62df4ee6b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -41,6 +41,9 @@ static int sec_mismatch_verbose = 1; static int sec_mismatch_fatal = 0; /* ignore missing files */ static int ignore_missing_files; +/* Turn warnings into errors */ +static int fail_on_warnings; +static int warnings_count; enum export { export_plain, export_unused, export_gpl, @@ -71,6 +74,8 @@ PRINTF void warn(const char *fmt, ...) va_start(arglist, fmt); vfprintf(stderr, fmt, arglist); va_end(arglist); + + warnings_count++; } PRINTF void merror(const char *fmt, ...) @@ -2389,7 +2394,7 @@ int main(int argc, char **argv) struct ext_sym_list *extsym_iter; struct ext_sym_list *extsym_start = NULL; - while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) { + while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awFM:K:E")) != -1) { switch (opt) { case 'i': kernel_read = optarg; @@ -2430,6 +2435,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; @@ -2497,5 +2505,8 @@ int main(int argc, char **argv) } } + if (fail_on_warnings && warnings_count) + err |= 2; + return err; }