linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Michal Marek <michal.lkml@markovi.net>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/4] kbuild: warn orphan built-in objects
Date: Fri, 13 Sep 2019 01:22:52 +0900	[thread overview]
Message-ID: <20190912162254.9603-2-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <20190912162254.9603-1-yamada.masahiro@socionext.com>

obj-y specifies objects linked into vmlinux, but they are actually
linked if and only if that sub-directory is visited by the chain of
obj-y. If you have an orphan obj-y object, it is a bug, but may not
be easy to notice. This commit provides build-time warning.

I tested x86 allmodconfig based on v5.3-rc4, and I saw one warning:

warning: 'sound/soc/sprd/sprd-mcdt.o' will not be linked to vmlinux even though obj-y is specified.

This is a proper warning. sound/soc/sprd/sprd-mcdt.o is compiled as
built-in since CONFIG_SND_SOC_SPRD_MCDT is boolean. However, CONFIG_SND
and CONFIG_SND_SOC are tristate, and set to m by allmodconfig.
So, Kbuild descends into sound/soc/, then sound/soc/sprd/ by obj-m.
Thus, sound/soc/sprd/sprd-mcdt.o is not linked to vmlinux.

More warnings for arm allmodconfig, all of which are valid:

warning: 'drivers/video/fbdev/mmp/hw/mmp_ctrl.o' 'drivers/video/fbdev/mmp/hw/mmp_spi.o' will not be linked to vmlinux even though obj-y is specified.
warning: 'drivers/video/fbdev/mmp/panel/tpo_tj032md01bw.o' will not be linked to vmlinux even though obj-y is specified.
warning: 'sound/soc/pxa/mmp-pcm.o' will not be linked to vmlinux even though obj-y is specified.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
 - fix false-positive warning for arm64

 scripts/Makefile.build  | 12 ++++++++----
 scripts/link-vmlinux.sh |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 6c3e6cb0c0af..fb29c898604a 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -52,6 +52,10 @@ ifndef obj
 $(warning kbuild: Makefile.build is included improperly)
 endif
 
+PHONY += __warn-orphan-obj-y
+__warn-orphan-obj-y:
+	@echo "warning: $(patsubst %,'%',$(real-obj-y)) will not be linked to vmlinux even though obj-y is specified." >&2
+
 ifeq ($(need-modorder),)
 ifneq ($(obj-m),)
 $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
@@ -68,6 +72,8 @@ endif
 
 ifdef need-builtin
 builtin-target := $(obj)/built-in.a
+else ifneq ($(real-obj-y),)
+builtin-target := __warn-orphan-obj-y
 endif
 
 ifeq ($(CONFIG_MODULES)$(need-modorder),y1)
@@ -386,16 +392,14 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
 #
 # Rule to compile a set of .o files into one .a file (without symbol table)
 #
-ifdef builtin-target
 
 quiet_cmd_ar_builtin = AR      $@
       cmd_ar_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
 
-$(builtin-target): $(real-obj-y) FORCE
+$(obj)/built-in.a: $(real-obj-y) FORCE
 	$(call if_changed,ar_builtin)
 
-targets += $(builtin-target)
-endif # builtin-target
+targets += $(obj)/built-in.a
 
 #
 # Rule to create modules.order file
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 2438a9faf3f1..8961d999b86b 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -216,7 +216,7 @@ else
 fi;
 
 # final build of init/
-${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
+${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
 
 #link vmlinux.o
 info LD vmlinux.o
-- 
2.17.1


  reply	other threads:[~2019-09-12 16:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 16:22 [PATCH v2 1/4] kbuild: do not create built-in.a that is never linked to vmlinux Masahiro Yamada
2019-09-12 16:22 ` Masahiro Yamada [this message]
2019-09-12 16:22 ` [PATCH v2 3/4] kbuild: clear KBUILD_MODULES in top Makefile if CONFIG_MODULES=n Masahiro Yamada
2019-09-12 16:22 ` [PATCH v2 4/4] kbuild: change need-modorder implementation slightly Masahiro Yamada

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=20190912162254.9603-2-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    /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).