[PATCH] livepatch: fixup klp-convert tool integration
From: Konstantin Khlebnikov
Date: Sat Dec 17 2016 - 08:16:17 EST
I've found some minor problems, this patch fixes:
* save cmd_ld_ko_o into .module.cmd, if_changed_rule doesn't do that
* fix bashisms for debian where /bin/sh is a symlink to /bin/dash
* rename rule_link_module to rule_ld_ko_o, otherwise arg-check inside
if_changed_rule compares cmd_link_module and cmd_ld_ko_o
* use HOSTLOADLIBES_$module instead of HOSTLDFLAGS: -lelf must be at the end
* check modinfo -F livepatch only if CONFIG_LIVEPATCH is true
I think "modinfo -F" could be replaced with explicit mark in makefile,
for example: LIVEPATCH_module.ko := y (like KASAN_SANITIZE_obj.o := n).
Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>
---
scripts/Kbuild.include | 4 +++-
scripts/Makefile.modpost | 24 +++++++++++-------------
scripts/livepatch/Makefile | 2 +-
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 179219845dfc..e299fde3423b 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -247,6 +247,8 @@ endif
# (needed for the shell)
make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
+save-cmd = printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd
+
# Find any prerequisites that is newer than target or that does not exist.
# PHONY targets skipped in both cases.
any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
@@ -256,7 +258,7 @@ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
@set -e; \
$(echo-cmd) $(cmd_$(1)); \
- printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
+ $(save-cmd), @:)
# Execute the command and also postprocess generated .d dependencies file.
if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 916dd347e8f6..5d149d0b05c2 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -123,24 +123,22 @@ quiet_cmd_ld_ko_o = LD [M] $@
$(LD) -r $(LDFLAGS) \
$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
-o $@ $(filter-out FORCE,$^) ; \
- $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) ;
+ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
-ifdef CONFIG_LIVEPATCH
KLP_CONVERT = scripts/livepatch/klp-convert
- cmd_klp_convert = \
- if [[ -n "`modinfo -F livepatch $@`" ]]; then \
- mv $@ $(@:.ko=.klp.o); \
- $(KLP_CONVERT) $(@:.ko=.klp.o) $@; \
- fi ;
-endif
-
-define rule_link_module
- $(call echo-cmd,ld_ko_o) $(cmd_ld_ko_o) \
- $(cmd_klp_convert)
+quiet_cmd_klp_convert = LIVEPATCH $@
+ cmd_klp_convert = mv $@ $(@:.ko=.klp.o); $(KLP_CONVERT) $(@:.ko=.klp.o) $@
+
+define rule_ld_ko_o
+ $(call echo-cmd,ld_ko_o) $(cmd_ld_ko_o) ; \
+ $(call save-cmd,ld_ko_o) ; \
+ $(if $(CONFIG_LIVEPATCH), \
+ if [ -n "`modinfo -F livepatch $@`" ] ; then \
+ $(call echo-cmd,klp_convert) $(cmd_klp_convert) ; fi)
endef
$(modules): %.ko :%.o %.mod.o FORCE
- +$(call if_changed_rule,link_module)
+ +$(call if_changed_rule,ld_ko_o)
targets += $(modules)
diff --git a/scripts/livepatch/Makefile b/scripts/livepatch/Makefile
index 221829bb34c7..bd5c1ae553ab 100644
--- a/scripts/livepatch/Makefile
+++ b/scripts/livepatch/Makefile
@@ -4,4 +4,4 @@ always := $(hostprogs-y)
klp-convert-objs := klp-convert.o elf.o
HOSTCFLAGS := -g -I$(INSTALL_HDR_PATH)/include -Wall
-HOSTLDFLAGS := -lelf
+HOSTLOADLIBES_klp-convert := -lelf