* [PATCH v2 2/5] kbuild: define KBUILD_MODNAME even if multiple modules share objects
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
2018-03-19 9:01 ` [PATCH v2 3/5] kbuild: fix modname for composite modules Masahiro Yamada
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-19 9:01 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Cao jin, linux-kernel, Masahiro Yamada, Michal Marek
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 <yamada.masahiro@socionext.com>
Reviewed-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
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:
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/5] kbuild: fix modname for composite modules
2018-03-19 9:01 [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi Masahiro Yamada
2018-03-19 9:01 ` [PATCH v2 2/5] kbuild: define KBUILD_MODNAME even if multiple modules share objects Masahiro Yamada
@ 2018-03-19 9:01 ` Masahiro Yamada
2018-03-19 9:01 ` [PATCH v2 4/5] kbuild: simplify modname calculation Masahiro Yamada
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-19 9:01 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Cao jin, linux-kernel, Masahiro Yamada, Michal Marek
From: Cao jin <caoj.fnst@cn.fujitsu.com>
Commit cf4f21938e13 ("kbuild: Allow to specify composite modules
with modname-m") added modname-m support, but missed to update the
corresponding multi-objs-m & modname-multi definition.
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
Changes in v2: None
scripts/Makefile.lib | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 7feb960..35c868f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -50,7 +50,7 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
# Build list of the parts of our composite objects, our composite
# objects depend on those (obviously)
multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
-multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
+multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)))
# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
# tell kbuild to descend
@@ -173,7 +173,7 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
# 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=)))))
+ $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))))
# Useful for describing the dependency of composite objects
# Usage:
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 4/5] kbuild: simplify modname calculation
2018-03-19 9:01 [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi Masahiro Yamada
2018-03-19 9:01 ` [PATCH v2 2/5] kbuild: define KBUILD_MODNAME even if multiple modules share objects Masahiro Yamada
2018-03-19 9:01 ` [PATCH v2 3/5] kbuild: fix modname for composite modules Masahiro Yamada
@ 2018-03-19 9:01 ` 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
4 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-19 9:01 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Cao jin, linux-kernel, Masahiro Yamada, Michal Marek
modname can be calculated much more simply. If modname-multi is
empty, it is a single-used object. So, modname = $(basetarget).
Otherwise, modname = $(modname-multi).
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
Changes in v2: None
scripts/Makefile.build | 12 +-----------
scripts/Makefile.lib | 7 -------
2 files changed, 1 insertion(+), 18 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 7cd2f4a..f5858f6 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -131,17 +131,7 @@ $(real-objs-m:.o=.lst): quiet_modtag := [M]
$(obj-m) : quiet_modtag := [M]
-# Default for not multi-part modules
-modname = $(basetarget)
-
-$(multi-objs-m) : modname = $(modname-multi)
-$(multi-objs-m:.o=.i) : modname = $(modname-multi)
-$(multi-objs-m:.o=.s) : modname = $(modname-multi)
-$(multi-objs-m:.o=.lst) : modname = $(modname-multi)
-$(multi-objs-y) : modname = $(modname-multi)
-$(multi-objs-y:.o=.i) : modname = $(modname-multi)
-$(multi-objs-y:.o=.s) : modname = $(modname-multi)
-$(multi-objs-y:.o=.lst) : modname = $(modname-multi)
+modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 35c868f..537629f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -47,11 +47,6 @@ multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m
multi-used := $(multi-used-y) $(multi-used-m)
single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
-# Build list of the parts of our composite objects, our composite
-# objects depend on those (obviously)
-multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
-multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)))
-
# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
# tell kbuild to descend
subdir-obj-y := $(filter %/built-in.a, $(obj-y))
@@ -80,8 +75,6 @@ real-objs-m := $(addprefix $(obj)/,$(real-objs-m))
single-used-m := $(addprefix $(obj)/,$(single-used-m))
multi-used-y := $(addprefix $(obj)/,$(multi-used-y))
multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
-multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y))
-multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
# These flags are needed for modversions and compiling, so we define them here
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 5/5] kbuild: move modname and modname-multi close to modname_flags
2018-03-19 9:01 [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi Masahiro Yamada
` (2 preceding siblings ...)
2018-03-19 9:01 ` [PATCH v2 4/5] kbuild: simplify modname calculation Masahiro Yamada
@ 2018-03-19 9:01 ` Masahiro Yamada
2018-03-20 15:33 ` [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi Masahiro Yamada
4 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-19 9:01 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Cao jin, linux-kernel, Masahiro Yamada, Michal Marek
Just a cosmetic change to put related code close together.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
Changes in v2: None
scripts/Makefile.build | 2 --
scripts/Makefile.lib | 14 ++++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index f5858f6..93d05e3 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -131,8 +131,6 @@ $(real-objs-m:.o=.lst): quiet_modtag := [M]
$(obj-m) : quiet_modtag := [M]
-modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
-
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 537629f..33af8d4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -77,6 +77,14 @@ multi-used-y := $(addprefix $(obj)/,$(multi-used-y))
multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
+# Finds the multi-part object the current object will be linked into.
+# 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=-m))),$(m:.o=)))))
+
+modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
+
# 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)
@@ -162,12 +170,6 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
$(addprefix -I,$(DTC_INCLUDE)) \
-undef -D__DTS__
-# Finds the multi-part object the current object will be linked into
-# 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=-m))),$(m:.o=)))))
-
# Useful for describing the dependency of composite objects
# Usage:
# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi
2018-03-19 9:01 [PATCH v2 1/5] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi Masahiro Yamada
` (3 preceding siblings ...)
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 ` Masahiro Yamada
4 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-20 15:33 UTC (permalink / raw)
To: Linux Kbuild mailing list
Cc: Sam Ravnborg, Cao jin, Linux Kernel Mailing List,
Masahiro Yamada, Michal Marek
2018-03-19 18:01 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> In the context ...
>
> $(obj)/%.s: $(src)/%.c FORCE
> $(call if_changed_dep,cc_s_c)
>
> $(obj)/%.i: $(src)/%.c FORCE
> $(call if_changed_dep,cpp_i_c)
>
> $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
> $(call cmd,force_checksrc)
> $(call if_changed_rule,cc_o_c)
>
> $(obj)/%.lst: $(src)/%.c FORCE
> $(call if_changed_dep,cc_lst_c)
>
> '$*' returns the stem of the target (the part of '%'), so $(obj)/ has
> already been ripped off.
>
> $(subst $(obj)/,,$*.o) is the same as $*.o
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reviewed-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
>
> Changes in v2: None
>
Series, applied to linux-kbuild.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 6+ messages in thread