mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: live-patching@vger.kernel.org, Josh Poimboeuf <jpoimboe@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] livepatch: fixup klp-convert tool integration
Date: Sat, 17 Dec 2016 16:08:28 +0300	[thread overview]
Message-ID: <148198010850.17522.18300831416724024821.stgit@buzz> (raw)
In-Reply-To: <732c52b5ab40da9c1547e835d929e3ca6e9c33c9.1477578530.git.jpoimboe@redhat.com>

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@yandex-team.ru>
---
 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

  reply	other threads:[~2016-12-17 13:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27 14:35 [PATCH RFC 0/2] livepatch: patch creation tooling proposal Josh Poimboeuf
2016-10-27 14:35 ` [PATCH RFC 1/2] livepatch: add klp-convert tool and integrate with module build Josh Poimboeuf
2016-12-17 13:08   ` Konstantin Khlebnikov [this message]
2016-12-19 14:29     ` [PATCH] livepatch: fixup klp-convert tool integration Miroslav Benes
2016-10-27 14:35 ` [PATCH RFC 2/2] livepatch: update sample module to use klp relocations Josh Poimboeuf
2016-11-10 15:36 ` [PATCH RFC 0/2] livepatch: patch creation tooling proposal Josh Poimboeuf
2016-11-10 15:48   ` Miroslav Benes
2016-11-10 15:54     ` Miroslav Benes
2016-11-10 16:10     ` Josh Poimboeuf
2017-03-01 10:53 ` Miroslav Benes

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=148198010850.17522.18300831416724024821.stgit@buzz \
    --to=khlebnikov@yandex-team.ru \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®