All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] kbuild: do not create built-in.a that is never linked to vmlinux
@ 2019-09-12 16:22 Masahiro Yamada
  2019-09-12 16:22 ` [PATCH v2 2/4] kbuild: warn orphan built-in objects Masahiro Yamada
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Masahiro Yamada @ 2019-09-12 16:22 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Masahiro Yamada, Michal Marek, linux-kernel

Both 'obj-y += foo/' and 'obj-m += foo/' requrest Kbuild to visit the
sub-directory foo/, but the difference is that only the former combines
foo/built-in.a into the built-in.a of the current directory because
everything in sub-directories visited by obj-m is supposed to be modular.

So, it makes sense to create built-in.a only if that sub-directory is
reachable by the chain of obj-y. Otherwise, useless orphan built-in.a
files are generated.

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

Changes in v2: None

 scripts/Makefile.build | 2 +-
 scripts/Makefile.lib   | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index f72aba64d611..6c3e6cb0c0af 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -66,7 +66,7 @@ lib-target := $(obj)/lib.a
 real-obj-y += $(obj)/lib-ksyms.o
 endif
 
-ifneq ($(strip $(real-obj-y) $(need-builtin)),)
+ifdef need-builtin
 builtin-target := $(obj)/built-in.a
 endif
 
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4a0cdd6f5909..26ac638525cb 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -35,7 +35,11 @@ __subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
 subdir-y	+= $(__subdir-y)
 __subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
 subdir-m	+= $(__subdir-m)
+ifdef need-builtin
 obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
+else
+obj-y		:= $(filter-out %/, $(obj-y))
+endif
 obj-m		:= $(filter-out %/, $(obj-m))
 
 # Subdirectories we need to descend into
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/4] kbuild: warn orphan built-in objects
  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
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2019-09-12 16:22 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Masahiro Yamada, Michal Marek, linux-kernel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/4] kbuild: clear KBUILD_MODULES in top Makefile if CONFIG_MODULES=n
  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 ` [PATCH v2 2/4] kbuild: warn orphan built-in objects Masahiro Yamada
@ 2019-09-12 16:22 ` Masahiro Yamada
  2019-09-12 16:22 ` [PATCH v2 4/4] kbuild: change need-modorder implementation slightly Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2019-09-12 16:22 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Masahiro Yamada, Michal Marek, linux-kernel

Do not try to build any module-related artifacts when CONFIG_MODULES
is disabled.

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

Changes in v2:
  - New patch

 Makefile               | 4 ++++
 scripts/Makefile.build | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index adc0cabe2382..0ecc62dbe234 100644
--- a/Makefile
+++ b/Makefile
@@ -1797,6 +1797,10 @@ single-build = $(if $(filter-out $@/, $(single-no-ko)),1)
 
 endif
 
+ifndef CONFIG_MODULES
+KBUILD_MODULES :=
+endif
+
 # FIXME Should go into a make.lib or something
 # ===========================================================================
 
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index fb29c898604a..aab9a14fa78d 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -76,7 +76,7 @@ else ifneq ($(real-obj-y),)
 builtin-target := __warn-orphan-obj-y
 endif
 
-ifeq ($(CONFIG_MODULES)$(need-modorder),y1)
+ifdef need-modorder
 modorder-target := $(obj)/modules.order
 endif
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 4/4] kbuild: change need-modorder implementation slightly
  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 ` [PATCH v2 2/4] kbuild: warn orphan built-in objects Masahiro Yamada
  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 ` Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2019-09-12 16:22 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Masahiro Yamada, Michal Marek, linux-kernel

Align with the need-builtin implementation.

I also added need-modorder=1 to scripts/link-vmlinux.sh to make it more
future-proof; currently, we have no module in the init/ directory, but
if we had a one, scripts/Makefile.build would show a false positive
warning.

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

Changes in v2:
  - do not show orphan obj-m warning unless you are building modules

 scripts/Makefile.build  | 16 ++++++++--------
 scripts/Makefile.lib    |  2 ++
 scripts/link-vmlinux.sh |  2 +-
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index aab9a14fa78d..3b04ff23deb1 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -56,12 +56,10 @@ 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.)
-$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
-endif
-endif
+PHONY += __warn-orphan-obj-m
+__warn-orphan-obj-m:
+	@echo "warning: $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified." >&2
+	@echo "warning: You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead." >&2
 
 # ===========================================================================
 
@@ -78,6 +76,8 @@ endif
 
 ifdef need-modorder
 modorder-target := $(obj)/modules.order
+else ifneq ($(obj-m),)
+modorder-target := __warn-orphan-obj-m
 endif
 
 mod-targets := $(patsubst %.o, %.mod, $(obj-m))
@@ -406,7 +406,7 @@ targets += $(obj)/built-in.a
 #
 # Create commands to either record .ko file or cat modules.order from
 # a subdirectory
-$(modorder-target): $(subdir-ym) FORCE
+$(obj)/modules.order: $(subdir-ym) FORCE
 	$(Q){ $(foreach m, $(modorder), \
 	$(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
 	| $(AWK) '!x[$$0]++' - > $@
@@ -513,7 +513,7 @@ $(subdir-ym):
 	$(Q)$(MAKE) $(build)=$@ \
 	$(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
 	need-builtin=$(if $(filter $@/built-in.a, $(subdir-obj-y)),1) \
-	need-modorder=$(if $(need-modorder),$(if $(filter $@/modules.order, $(modorder)),1))
+	need-modorder=$(if $(filter $@/modules.order, $(modorder)),1)
 
 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 26ac638525cb..23e524027740 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -23,7 +23,9 @@ lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
 # Determine modorder.
 # Unfortunately, we don't have information about ordering between -y
 # and -m subdirs.  Just put -y's first.
+ifdef need-modorder
 modorder	:= $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
+endif
 
 # Handle objects in subdirs
 # ---------------------------------------------------------------------------
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 8961d999b86b..d9edfba54d84 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 need-builtin=1
+${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1 need-modorder=1
 
 #link vmlinux.o
 info LD vmlinux.o
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-12 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2 2/4] kbuild: warn orphan built-in objects Masahiro Yamada
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.