LKML Archive on
help / color / mirror / Atom feed
From: Masahiro Yamada <>
Cc: Sam Ravnborg <>,
	Cao jin <>,,
	Masahiro Yamada <>,
	Michal Marek <>
Subject: [PATCH v2 2/5] kbuild: define KBUILD_MODNAME even if multiple modules share objects
Date: Mon, 19 Mar 2018 18:01:24 +0900	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Currently, KBUILD_MODNAME is defined only when $(modname) contains
just one word.  If an object is shared among multiple modules,
undefined KBUILD_MODNAME could cause a build error.  For example,
if CONFIG_DYNAMIC_DEBUG is enabled, any call of printk() populates
.modname, then fails to build due to undefined KBUILD_MODNAME.

Take the following code as an example:

  obj-m += foo.o
  obj-m += bar.o
  foo-objs := foo-bar-common.o foo-main.o
  bar-objs := foo-bar-common.o bar-main.o

In this case, there is room for argument what to define for
KBUILD_MODNAME when foo-bar-common.o is being compiled.
"foo", "bar", or what else?

One idea is to define colon-separated modules that share the object,
in this case, "bar:foo" (modules are sorted alphabetically by
$(sort ...).

Signed-off-by: Masahiro Yamada <>
Reviewed-by: Cao jin <>

Changes in v2:
  - Remove comments that will be no longer true

 scripts/Makefile.lib | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4eedd6e..7feb960 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -87,13 +87,9 @@ subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
 # These flags are needed for modversions and compiling, so we define them here
 # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
 # end up in (or would, if it gets compiled in)
-# Note: Files that end up in two or more modules are compiled without the
-#       KBUILD_MODNAME definition. The reason is that any made-up name would
-#       differ in different configs.
 name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
 basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
-modname_flags  = $(if $(filter 1,$(words $(modname))),\
-                 -DKBUILD_MODNAME=$(call name-fix,$(modname)))
+modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname))
 orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
                  $(ccflags-y) $(CFLAGS_$(basetarget).o)
@@ -174,8 +170,10 @@ dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
 		 -undef -D__DTS__
 # Finds the multi-part object the current object will be linked into
-modname-multi = $(sort $(foreach m,$(multi-used),\
-		$(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
+# If the object belongs to two or more multi-part objects, all of them are
+# concatenated with a colon separator.
+modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
+		$(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))))
 # Useful for describing the dependency of composite objects
 # Usage:

  reply	other threads:[~2018-03-19  9:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-19  9:01 [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi Masahiro Yamada
2018-03-19  9:01 ` Masahiro Yamada [this message]
2018-03-19  9:01 ` [PATCH v2 3/5] kbuild: fix modname for composite modules Masahiro Yamada
2018-03-19  9:01 ` [PATCH v2 4/5] kbuild: simplify modname calculation Masahiro Yamada
2018-03-19  9:01 ` [PATCH v2 5/5] kbuild: move modname and modname-multi close to modname_flags Masahiro Yamada
2018-03-20 15:33 ` [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \
    --subject='Re: [PATCH v2 2/5] kbuild: define KBUILD_MODNAME even if multiple modules share objects' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).