From patchwork Wed Nov 6 11:23:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 178665 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp466364ilf; Wed, 6 Nov 2019 03:25:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzRH6vgXetbUVBzqYdR+1qE0kyz+plt6/9LPOtnPlUxDtDfXJFQjHKKOEB7WYqwY6sVUI4x X-Received: by 2002:a17:906:2a89:: with SMTP id l9mr34239529eje.329.1573039525125; Wed, 06 Nov 2019 03:25:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573039525; cv=none; d=google.com; s=arc-20160816; b=Eu0uf+o8GW3tWmAfFyroUHUm/I16kqDOrmBV3SaEo9YLyR4auUjpeFeVMUhcgvTFLK wOVxtPjdoG0XHpzxhhEyPDIUvVYgxySaMS5wLCj2MZgPC4uxxSTF1Rla7M03b+1g1ibj rRXrKXkHlLUuQxajaK6PWVzRUZHoVEa23ZQMzyr1rkOQpZg2KEXwcwdQ73+aXCO1WNsF Sj5xKN63oeD59Dj71ke3aBU+0p/+ytRksuRvqS4XeiaWl+GLGsLBAk5MHpTkQ3dYGUcb h0N0CUJGuTzs/FIs9XYJGJzrCY52uMvi1bhj5K/M4h/Pk1iXnOYDLUQs2BoBsC/kaqjh HKIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=rLZcOrok9PdZlKG4VRBTQujCqfo2C2HipVKQXAB7ZNc=; b=hnUAievOpoPuDnx34NdsMP4Q/MN2UXWjR//v+eQreJAFQdCjy+hkd05rUNoKwUR9vJ 8MjDZ51tFEie7sEYEllKr+1jylO03bNFAxN6CmmEXe45IVAgCIc3aQiX79lbucnUnXRC Foa2m659s5hYssIr8WDSD+m4S+1AtemkWCmNGYSJ57fHSQn0kPPvOr1PndZijzJHT5dJ NHcsBa3fJBjU/uNTEyi4l4TNHN+XnAyBIc0cJCeDQMuoJlFI3eIiOEsTMRyQqqkHJS0I UR/pQk2FeJCscpIEHh2WesF5DMGEEb5Ijt0BngzeDMzmf8G3XJjGCEj4suJKCSzTUnN1 iwUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pkbFRrG7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19si11360041ejr.411.2019.11.06.03.25.24; Wed, 06 Nov 2019 03:25:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pkbFRrG7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731544AbfKFLZV (ORCPT + 26 others); Wed, 6 Nov 2019 06:25:21 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:47954 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbfKFLZV (ORCPT ); Wed, 6 Nov 2019 06:25:21 -0500 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id xA6BO1Em018531; Wed, 6 Nov 2019 20:24:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com xA6BO1Em018531 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1573039442; bh=rLZcOrok9PdZlKG4VRBTQujCqfo2C2HipVKQXAB7ZNc=; h=From:To:Cc:Subject:Date:From; b=pkbFRrG7vHWYHM1pshA3Ue0PBy3/uE1m+zP1ucyA47F9KzYFOotOL6eexS7TnejYE ZZozWyll4V5rXUTCogyxXfrNOvS6RvCFk3W8bPnF7wXohalB42Wg9uzIUby2FeQinx dWibk0Yx0vGo0ATJBme0jcGKqeKucr0lTIiVjDYhg30ZWHd0BKHifgaFjJSBNf+72l 7GPoN6/nOariFEnqJP/Ftz11zjC1F2A2bOB3qI+iAGRAH89AUU2eEaQzQZgDFCr0M+ Jv8bQvAkzWQQw0iR2irr4/VO2Rd1O+eFrsgptLDQy8yi4xDMhlQS9JyKgH8V6OZI9B 5jZAZupTC33qQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Lucas De Marchi , Sam Ravnborg , Jeff Moyer , Dan Williams , Masahiro Yamada , Dave Jiang , Jonathan Corbet , Michal Marek , Vishal Verma , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] modpost: add an option to suppress 'exported twice' warnings Date: Wed, 6 Nov 2019 20:23:57 +0900 Message-Id: <20191106112357.29053-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit "modpost: do not set ->preloaded for symbols from Module.symvers", the modpost always warns about symbols exported multiple times. Generally, I believe it is a good thing to show a warning when the same symbol name is exported twice. This avoids the accidental symbol conflict. However, in some cases, we build an external module to provide a different version/variant of the in-kernel module, overriding the same set of exported symbols. At least, there is one use-case in the upstream code; tools/testing/nvdimm/libnvdimm.ko replaces drivers/nvdimm/libnvdimm.ko in order to link it against mocked version of core kernel symbols. Now, this emits a lots of 'exported twice' warnings: https://lkml.org/lkml/2019/10/31/627 To suppress those, add a new option KBUILD_DUPLICATED_EXPORTS_NO_WARN. If you intentionally override the existing symbols, you can pass it from the command line: make M=tools/testing/nvdimm KBUILD_DUPLICATED_EXPORTS_NO_WARN=1 Or, more conveniently, you can add it to the module Makefile, so you can still do: make M=tools/testing/nvdimm without sprinkling the warnings. Reported-by: Jeff Moyer Signed-off-by: Masahiro Yamada --- Jeff Moyer, Dan Williams, Please check if this patch solves the nvdimm build issue. Documentation/kbuild/kbuild.rst | 7 +++++++ scripts/Makefile.modpost | 1 + scripts/mod/modpost.c | 9 +++++++-- tools/testing/nvdimm/Kbuild | 4 ++++ 4 files changed, 19 insertions(+), 2 deletions(-) -- 2.17.1 Tested-by: Jeff Moyer diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index f1e5dce86af7..8ff0935f9e7f 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -223,6 +223,13 @@ KBUILD_SIGN_PIN This variable allows a passphrase or PIN to be passed to the sign-file utility when signing kernel modules, if the private key requires such. +KBUILD_DUPLICATED_EXPORTS_NO_WARN +--------------------------------- +This variable can be set to suppress warnings about symbols exported +multiple times. This is useful when you are building an external module +to provide a different version of an in-tree module. + + KBUILD_MODPOST_WARN ------------------- KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 8359f8af5ee6..52e50ac45688 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -53,6 +53,7 @@ MODPOST = scripts/mod/modpost \ $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ + $(if $(KBUILD_DUPLICATED_EXPORTS_NO_WARN),-W) \ $(if $(KBUILD_MODPOST_WARN),-w) ifdef MODPOST_VMLINUX diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index f70b924f379f..858568f4edb4 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -33,6 +33,8 @@ static int external_module = 0; static int vmlinux_section_warnings = 1; /* Only warn about unresolved symbols */ static int warn_unresolved = 0; +/* Warn about symbols exported multiple times */ +static int warn_duplicated_exports = 1; /* How a symbol is exported */ static int sec_mismatch_count = 0; static int sec_mismatch_fatal = 0; @@ -382,7 +384,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, if (!s) { s = new_symbol(name, mod, export); } else { - if (!s->preloaded) { + if (warn_duplicated_exports && !s->preloaded) { warn("%s: '%s' exported twice. Previous export was in %s%s\n", mod->name, name, s->module->name, is_vmlinux(s->module->name) ? "" : ".ko"); @@ -2559,7 +2561,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:e:mnsT:o:awEd:")) != -1) { + while ((opt = getopt(argc, argv, "i:e:mnsT:o:awWEd:")) != -1) { switch (opt) { case 'i': kernel_read = optarg; @@ -2594,6 +2596,9 @@ int main(int argc, char **argv) case 'w': warn_unresolved = 1; break; + case 'W': + warn_duplicated_exports = 0; + break; case 'E': sec_mismatch_fatal = 1; break; diff --git a/tools/testing/nvdimm/Kbuild b/tools/testing/nvdimm/Kbuild index c4a9196d794c..c848374f3b0b 100644 --- a/tools/testing/nvdimm/Kbuild +++ b/tools/testing/nvdimm/Kbuild @@ -93,4 +93,8 @@ libnvdimm-y += dimm_devs.o libnvdimm-y += libnvdimm_test.o libnvdimm-y += config_check.o +# This intentionally overrides the original libnvdimm.ko +# Suppress 'exported twice' warnings from the modpost. +KBUILD_DUPLICATED_EXPORTS_NO_WARN := 1 + obj-m += test/