From patchwork Mon Nov 7 11:27:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 9414787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6D1D60512 for ; Mon, 7 Nov 2016 11:27:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7D2A28CA6 for ; Mon, 7 Nov 2016 11:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC7B528CB4; Mon, 7 Nov 2016 11:27:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4517628CA6 for ; Mon, 7 Nov 2016 11:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752707AbcKGL1x (ORCPT ); Mon, 7 Nov 2016 06:27:53 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:32044 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751970AbcKGL1s (ORCPT ); Mon, 7 Nov 2016 06:27:48 -0500 Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id 0E9BF71A1240F; Mon, 7 Nov 2016 11:27:28 +0000 (GMT) Received: from localhost (10.100.200.221) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 7 Nov 2016 11:27:29 +0000 From: Paul Burton To: CC: Paul Burton , Michal Marek Subject: [PATCH] kbuild: Always build modules when CONFIG_TRIM_UNUSED_KSYMS=y Date: Mon, 7 Nov 2016 11:27:10 +0000 Message-ID: <20161107112711.14135-1-paul.burton@imgtec.com> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 X-Originating-IP: [10.100.200.221] Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If CONFIG_TRIM_UNUSED_KSYMS is enabled and we build the kernel with a specific target, eg. "make vmlinux" rather than simply "make", we need to build module source in order to generate the .mod files in $MODVERDIR (.tmp_versions/). Without doing so we: 1) Trigger an error from sed due to the missing files during the build of vmlinux: CHK include/generated/autoksyms.h sed: can't read .tmp_versions/*.mod: No such file or directory 2) Discard all symbol exports since we kept no record of which ones may be used: $ nm vmlinux | grep ksymtab 8069c9b8 R __start___ksymtab 8069c9b8 R __start___ksymtab_gpl 8069c9b8 R __start___ksymtab_gpl_future 8069c9b8 R __start___ksymtab_unused 8069c9b8 R __start___ksymtab_unused_gpl 8069c9b8 R __stop___ksymtab 8069c9b8 R __stop___ksymtab_gpl 8069c9b8 R __stop___ksymtab_gpl_future 8069c9b8 R __stop___ksymtab_unused 8069c9b8 R __stop___ksymtab_unused_gpl 3) Fail to build modules if we then run "make modules", since the modules reference symbols which we have discarded: ERROR: "pnfs_unregister_layoutdriver" [fs/nfs/flexfilelayout/nfs_layout_flexfiles.ko] undefined! ERROR: "nfs4_schedule_session_recovery" [fs/nfs/flexfilelayout/nfs_layout_flexfiles.ko] undefined! ... Fix this by ensuring that we build modules as part of the main kernel build by setting KBUILD_MODULES to 1 when CONFIG_TRIM_UNUSED_KSYMS is enabled, regardless of what was specified as the make target. Doing this involves exporting KBUILD_MODULES from the main Makefile after having read the configuration, later than it was previously exported. Signed-off-by: Paul Burton Cc: Michal Marek Cc: linux-kbuild@vger.kernel.org --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f97f786..ce1b44a 100644 --- a/Makefile +++ b/Makefile @@ -336,7 +336,7 @@ ifeq ($(MAKECMDGOALS),) KBUILD_MODULES := 1 endif -export KBUILD_MODULES KBUILD_BUILTIN +export KBUILD_BUILTIN export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD # We need some generic definitions (do not try to remake the file). @@ -606,6 +606,16 @@ else include/config/auto.conf: ; endif # $(dot-config) +# If we're using CONFIG_TRIM_UNUSED_KSYMS then we need to compile +# modules in order to generate the .mod files in $MODVERDIR so that +# we know which symbols to export. + +ifdef CONFIG_TRIM_UNUSED_KSYMS + KBUILD_MODULES := 1 +endif + +export KBUILD_MODULES + # The all: target is the default when no target is given on the # command line. # This allow a user to issue only 'make' to build a kernel including modules