kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andre Przywara <andre.przywara@arm.com>,
	Dimitri Ledkov <dimitri.j.ledkov@intel.com>,
	Ingo Molnar <mingo@kernel.org>, Pekka Enberg <penberg@kernel.org>,
	Will Deacon <will.deacon@arm.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 2/3] kvmtool/build: introduce GUEST_PRE_INIT target
Date: Mon, 19 Oct 2015 12:59:45 +0200	[thread overview]
Message-ID: <20151019105945.GA12428@redhat.com> (raw)
In-Reply-To: <20151019105930.GA12411@redhat.com>

This comes as a separate patch because I do not really understand
/usr/bin/make, probably it should be updated.

Change the main Makefile so that if an arch defines ARCH_PRE_INIT
then we

    - build $GUEST_INIT without "-static"

    - add -DCONFIG_GUEST_PRE_INIT to $CFLAGS

    - build $ARCH_PRE_INIT as guest/guest_pre_init.o and embed it
      into lkvm the same as we do with guest/guest_init.o

This also means that ARCH_PRE_INIT case doesn't depend on glibc-static,
we can relax the SOURCE_STATIC check later.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 .gitignore |  1 +
 Makefile   | 25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index f10d3c5..697a63f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ include/common-cmds.h
 tests/boot/boot_test.iso
 tests/boot/rootfs/
 guest/init
+guest/pre_init
 guest/init_stage2
 KVMTOOLS-VERSION-FILE
 /x86/bios/bios.bin
diff --git a/Makefile b/Makefile
index f1701aa..0f8e003 100644
--- a/Makefile
+++ b/Makefile
@@ -281,6 +281,14 @@ ifeq ($(call try-build,$(SOURCE_STATIC),,-static),y)
 	CFLAGS		+= -DCONFIG_GUEST_INIT
 	GUEST_INIT	:= guest/init
 	GUEST_OBJS	= guest/guest_init.o
+	ifeq ($(ARCH_PRE_INIT),)
+		GUEST_INIT_FLAGS	+= -static
+	else
+		CFLAGS			+= -DCONFIG_GUEST_PRE_INIT
+		GUEST_INIT_FLAGS	+= -DCONFIG_GUEST_PRE_INIT
+		GUEST_PRE_INIT		:= guest/pre_init
+		GUEST_OBJS		+= guest/guest_pre_init.o
+	endif
 else
 	$(warning No static libc found. Skipping guest init)
 	NOTFOUND        += static-libc
@@ -346,7 +354,7 @@ ifneq ($(WERROR),0)
 	CFLAGS += -Werror
 endif
 
-all: $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT)
+all: $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT) $(GUEST_PRE_INIT)
 
 # CFLAGS used when building objects
 # This is intentionally not assigned using :=
@@ -360,11 +368,11 @@ c_flags	= -Wp,-MD,$(depfile) $(CFLAGS)
 #
 STATIC_OBJS = $(patsubst %.o,%.static.o,$(OBJS) $(OBJS_STATOPT))
 
-$(PROGRAM)-static:  $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT)
+$(PROGRAM)-static:  $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT) $(GUEST_PRE_INIT)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) -static $(CFLAGS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_STATOPT) -o $@
 
-$(PROGRAM): $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT)
+$(PROGRAM): $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT) $(GUEST_PRE_INIT)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) $(CFLAGS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_DYNOPT) -o $@
 
@@ -372,9 +380,16 @@ $(PROGRAM_ALIAS): $(PROGRAM)
 	$(E) "  LN      " $@
 	$(Q) ln -f $(PROGRAM) $@
 
+ifneq ($(ARCH_PRE_INIT),)
+$(GUEST_PRE_INIT): $(ARCH_PRE_INIT)
+	$(E) "  LINK    " $@
+	$(Q) $(CC) -s -nostdlib $(ARCH_PRE_INIT) -o $@
+	$(Q) $(LD) $(LDFLAGS) -r -b binary -o guest/guest_pre_init.o $(GUEST_PRE_INIT)
+endif
+
 $(GUEST_INIT): guest/init.c
 	$(E) "  LINK    " $@
-	$(Q) $(CC) -static guest/init.c -o $@
+	$(Q) $(CC) $(GUEST_INIT_FLAGS) guest/init.c -o $@
 	$(Q) $(LD) $(LDFLAGS) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
 
 %.s: %.c
@@ -473,7 +488,7 @@ clean:
 	$(Q) rm -f x86/bios/bios-rom.h
 	$(Q) rm -f tests/boot/boot_test.iso
 	$(Q) rm -rf tests/boot/rootfs/
-	$(Q) rm -f $(DEPS) $(OBJS) $(OTHEROBJS) $(OBJS_DYNOPT) $(STATIC_OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(PROGRAM)-static $(GUEST_INIT) $(GUEST_OBJS)
+	$(Q) rm -f $(DEPS) $(OBJS) $(OTHEROBJS) $(OBJS_DYNOPT) $(STATIC_OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(PROGRAM)-static $(GUEST_INIT) $(GUEST_PRE_INIT) $(GUEST_OBJS)
 	$(Q) rm -f cscope.*
 	$(Q) rm -f tags
 	$(Q) rm -f TAGS
-- 
2.4.3


  parent reply	other threads:[~2015-10-19 11:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-19 10:59 [PATCH 0/3] kvmtool: tiny init fox x86_64 Oleg Nesterov
2015-10-19 10:59 ` [PATCH 1/3] kvmtool/setup: Introduce extract_file() helper Oleg Nesterov
2015-10-19 10:59 ` Oleg Nesterov [this message]
2015-10-19 10:59 ` [PATCH 3/3] kvmtool/x86: implement guest_pre_init Oleg Nesterov
2015-10-22  7:59 ` [PATCH 0/3] kvmtool: tiny init fox x86_64 Pekka Enberg
2015-10-22 15:58   ` Oleg Nesterov

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=20151019105945.GA12428@redhat.com \
    --to=oleg@redhat.com \
    --cc=andre.przywara@arm.com \
    --cc=dimitri.j.ledkov@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=penberg@kernel.org \
    --cc=will.deacon@arm.com \
    /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;
as well as URLs for NNTP newsgroup(s).