Skip to contentSkip to conversation

kbuild: factor out genksyms command from cmd_gensymtypes_{c,S}

PATCH Superseded Masahiro Yamada 2 participants 7 messages Mar 29, 2022 – Apr 5, 2022 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kbuild: factor out genksyms command from cmd_gensymtypes_{c,S}

The genksyms command part in cmd_gensymtypes_{c,S} is duplicated. Factor it out into the 'genksyms' macro.

For the readability, I slightly refactor the arguments to genksyms.

---

 scripts/Makefile.build | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
scripts/Makefile.build +8 -11
index 9717e6f6fb31..3f2985df4d60 100644
@@ -125,13 +125,14 @@ cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
 $(obj)/%.i: $(src)/%.c FORCE
 	$(call if_changed_dep,cpp_i_c)
 
+genksyms = scripts/genksyms/genksyms		\
+	$(if $(1), -T $(2))			\
+	$(if $(CONFIG_MODULE_REL_CRCS), -R)	\
+	$(if $(KBUILD_PRESERVE), -p)		\
+	-r $(or $(wildcard $(2:.symtypes=.symref), /dev/null))
+
 # These mirror gensymtypes_S and co below, keep them in synch.
-cmd_gensymtypes_c =                                                         \
-    $(CPP) -D__GENKSYMS__ $(c_flags) $< |                                   \
-    scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
-     $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
-     $(if $(KBUILD_PRESERVE),-p)                                            \
-     -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
 
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_c =                                                         \
@@ -344,11 +345,7 @@ cmd_gensymtypes_S =                                                         \
     $(CPP) $(a_flags) $< |                                                  \
      grep "\<___EXPORT_SYMBOL\>" |                                          \
      sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
-    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - |                                \
-    scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
-     $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
-     $(if $(KBUILD_PRESERVE),-p)                                            \
-     -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_S =                                                         \
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/2 kbuild: do not remove empty *.symtypes explicitly

Presumably, 'test -s $@ || rm -f $@' intends to remove the output when the genksyms command fails.

It is unneeded because .DELETE_ON_ERROR automatically removes the output on failure.

---

 scripts/Makefile.build | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
scripts/Makefile.build +2 -6
index 3f2985df4d60..974bb6435826 100644
@@ -135,9 +135,7 @@ genksyms = scripts/genksyms/genksyms		\
 cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
 
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_c =                                                         \
-    $(call cmd_gensymtypes_c,true,$@) >/dev/null;                           \
-    test -s $@ || rm -f $@
+      cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@)
 
 $(obj)/%.symtypes : $(src)/%.c FORCE
 	$(call cmd,cc_symtypes_c)
@@ -348,9 +346,7 @@ cmd_gensymtypes_S =                                                         \
     $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_S =                                                         \
-    $(call cmd_gensymtypes_S,true,$@) >/dev/null;                           \
-    test -s $@ || rm -f $@
+      cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null
 
 $(obj)/%.symtypes : $(src)/%.S FORCE
 	$(call cmd,cc_symtypes_S)
Signature · 1 line
2.32.0
#2 lore raw

Re: [PATCH 2/2] kbuild: do not remove empty *.symtypes explicitly

Quoted 18 lines · Masahiro Yamada

Presumably, 'test -s $@ || rm -f $@' intends to remove the output when the genksyms command fails.

It is unneeded because .DELETE_ON_ERROR automatically removes the output on failure.

---

 scripts/Makefile.build | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
scripts/Makefile.build +0 -0
index 3f2985df4d60..974bb6435826 100644

scripts/Makefile.build genksyms = scripts/genksyms/genksyms \ · line 138

Quoted 7 lines
scripts/Makefile.build +1 -3
@@ -135,9 +135,7 @@ genksyms = scripts/genksyms/genksyms                \
 cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
 
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_c =                                                         \
-    $(call cmd_gensymtypes_c,true,$@) >/dev/null;                           \
-    test -s $@ || rm -f $@
+      cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@)

Was it an accident that you removed the redirection of stdout to /dev/null here, but not also below?
If quiet_modtag silences the output, perhaps the redirection should be dropped below as well?

Quoted 17 lines
scripts/Makefile.build +1 -4
 $(obj)/%.symtypes : $(src)/%.c FORCE
        $(call cmd,cc_symtypes_c)
@@ -348,9 +346,7 @@ cmd_gensymtypes_S =                                                         \
     $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_S =                                                         \
-    $(call cmd_gensymtypes_S,true,$@) >/dev/null;                           \
-    test -s $@ || rm -f $@
+      cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null
 
 $(obj)/%.symtypes : $(src)/%.S FORCE
        $(call cmd,cc_symtypes_S)
--

2.32.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw

Re: [PATCH 2/2] kbuild: do not remove empty *.symtypes explicitly

Quoted 22 lines · Nick Desaulniers
Quoted 20 lines · Masahiro Yamada

Presumably, 'test -s $@ || rm -f $@' intends to remove the output when the genksyms command fails.

It is unneeded because .DELETE_ON_ERROR automatically removes the output on failure.

---

 scripts/Makefile.build | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
scripts/Makefile.build +0 -0
index 3f2985df4d60..974bb6435826 100644
@@ -135,9 +135,7 @@ genksyms = scripts/genksyms/genksyms                \
 cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
 
Quoted 8 lines

scripts/Makefile.build genksyms = scripts/genksyms/genksyms \ · line 138

Quoted 5 lines
scripts/Makefile.build +1 -3
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_c =                                                         \
-    $(call cmd_gensymtypes_c,true,$@) >/dev/null;                           \
-    test -s $@ || rm -f $@
+      cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@)

Was it an accident that you removed the redirection of stdout to /dev/null here, but not also below?

It was an accident. I will fix it. Thanks.

Quoted 25 lines

If quiet_modtag silences the output, perhaps the redirection should be dropped below as well?

Quoted 15 lines
scripts/Makefile.build +1 -4
 $(obj)/%.symtypes : $(src)/%.c FORCE
        $(call cmd,cc_symtypes_c)
@@ -348,9 +346,7 @@ cmd_gensymtypes_S =                                                         \
     $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_S =                                                         \
-    $(call cmd_gensymtypes_S,true,$@) >/dev/null;                           \
-    test -s $@ || rm -f $@
+      cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null
 
 $(obj)/%.symtypes : $(src)/%.S FORCE
        $(call cmd,cc_symtypes_S)
--
Quoted 2 lines

2.32.0

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Best Regards
Masahiro Yamada
Reviewed-by on v1 1/2
#4 lore raw
In reply to Masahiro Yamada
Quoted 5 lines · Masahiro Yamada

The genksyms command part in cmd_gensymtypes_{c,S} is duplicated. Factor it out into the 'genksyms' macro.

For the readability, I slightly refactor the arguments to genksyms.

Looks nicer, thanks for the patch!

Quoted 48 lines

---

 scripts/Makefile.build | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
scripts/Makefile.build +8 -12
index 9717e6f6fb31..3f2985df4d60 100644
@@ -125,13 +125,14 @@ cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
 $(obj)/%.i: $(src)/%.c FORCE
        $(call if_changed_dep,cpp_i_c)
 
+genksyms = scripts/genksyms/genksyms           \
+       $(if $(1), -T $(2))                     \
+       $(if $(CONFIG_MODULE_REL_CRCS), -R)     \
+       $(if $(KBUILD_PRESERVE), -p)            \
+       -r $(or $(wildcard $(2:.symtypes=.symref), /dev/null))
+
 # These mirror gensymtypes_S and co below, keep them in synch.
-cmd_gensymtypes_c =                                                         \
-    $(CPP) -D__GENKSYMS__ $(c_flags) $< |                                   \
-    scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
-     $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
-     $(if $(KBUILD_PRESERVE),-p)                                            \
-     -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
 
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_c =                                                         \
@@ -344,11 +345,7 @@ cmd_gensymtypes_S =                                                         \
     $(CPP) $(a_flags) $< |                                                  \
      grep "\<___EXPORT_SYMBOL\>" |                                          \
      sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
-    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - |                                \
-    scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
-     $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
-     $(if $(KBUILD_PRESERVE),-p)                                            \
-     -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_S =                                                         \
--

2.32.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw
Quoted 12 lines · Nick Desaulniers
Quoted 5 lines · Masahiro Yamada

The genksyms command part in cmd_gensymtypes_{c,S} is duplicated. Factor it out into the 'genksyms' macro.

For the readability, I slightly refactor the arguments to genksyms.

Looks nicer, thanks for the patch!

Quoted 1 line

Applied to linux-kbuild.

Quoted 52 lines
Quoted 45 lines

---

 scripts/Makefile.build | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
scripts/Makefile.build +8 -12
index 9717e6f6fb31..3f2985df4d60 100644
@@ -125,13 +125,14 @@ cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
 $(obj)/%.i: $(src)/%.c FORCE
        $(call if_changed_dep,cpp_i_c)
 
+genksyms = scripts/genksyms/genksyms           \
+       $(if $(1), -T $(2))                     \
+       $(if $(CONFIG_MODULE_REL_CRCS), -R)     \
+       $(if $(KBUILD_PRESERVE), -p)            \
+       -r $(or $(wildcard $(2:.symtypes=.symref), /dev/null))
+
 # These mirror gensymtypes_S and co below, keep them in synch.
-cmd_gensymtypes_c =                                                         \
-    $(CPP) -D__GENKSYMS__ $(c_flags) $< |                                   \
-    scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
-     $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
-     $(if $(KBUILD_PRESERVE),-p)                                            \
-     -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
 
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_c =                                                         \
@@ -344,11 +345,7 @@ cmd_gensymtypes_S =                                                         \
     $(CPP) $(a_flags) $< |                                                  \
      grep "\<___EXPORT_SYMBOL\>" |                                          \
      sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
-    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - |                                \
-    scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
-     $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
-     $(if $(KBUILD_PRESERVE),-p)                                            \
-     -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_S =                                                         \
--
Quoted 2 lines

2.32.0

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Best Regards
Masahiro Yamada
#6 lore raw
Quoted 9 lines · Masahiro Yamada
Quoted 6 lines · Nick Desaulniers
Quoted 4 lines · Masahiro Yamada

The genksyms command part in cmd_gensymtypes_{c,S} is duplicated. Factor it out into the 'genksyms' macro.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

For the readability, I slightly refactor the arguments to genksyms.

Looks nicer, thanks for the patch!

Quoted 1 line

Applied to linux-kbuild.

No, this patch is wrong.
I will send v2 later.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

---

 scripts/Makefile.build | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
scripts/Makefile.build +0 -0
index 9717e6f6fb31..3f2985df4d60 100644
@@ -125,13 +125,14 @@ cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
 $(obj)/%.i: $(src)/%.c FORCE
        $(call if_changed_dep,cpp_i_c)
 
Quoted 5 lines
Quoted 5 lines

scripts/Makefile.build cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< · line 132

Quoted 5 lines
scripts/Makefile.build +5 -0
+genksyms = scripts/genksyms/genksyms           \
+       $(if $(1), -T $(2))                     \
+       $(if $(CONFIG_MODULE_REL_CRCS), -R)     \
+       $(if $(KBUILD_PRESERVE), -p)            \
+       -r $(or $(wildcard $(2:.symtypes=.symref), /dev/null))

The position of the closing parenthesis was wrong.

    -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null)
Signature · 2 lines
Best Regards
Masahiro Yamada