[CRIU] [PATCH 09/24] compel cli: show includes

Kir Kolyshkin kir at openvz.org
Sat Dec 17 03:22:02 PST 2016


1. Add "compel includes" command, to be used for parasite *loading*
   code compilation.

2. Add includes to output of "compel cflags", which is used for parasite
   code compilation.

Now, this patch looks big and complex, this is mostly because we want
compel cli to work for both uninstalled (right from the source tree)
and installed cases. The paths to be printed are quite different for
these two cases, so I had to introduce a wrapper for a non-installed
case. The wrapper sets an environment variable, which compel binary
uses as a path to non-installed file. If this env var is not set,
it means compel is installed so no tricks are needed.

Note the wrapper is only provided for the compel-host binary, as compel
(which differs from compel-host in case of cross-compiling) is not
executed from within the source tree.

Because of the wrapper, the original binary had to be renamed, thus the
changes to Makefiles and .gitignore.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 .gitignore                  |  2 +-
 Makefile                    |  4 ++--
 compel/Makefile             |  7 ++++---
 compel/compel-host          |  8 ++++++++
 compel/src/main.c           | 35 ++++++++++++++++++++++++++++++++++-
 compel/test/infect/Makefile |  5 ++---
 compel/test/rsys/Makefile   |  4 ++--
 criu/pie/Makefile           |  2 +-
 8 files changed, 54 insertions(+), 13 deletions(-)
 create mode 100755 compel/compel-host

diff --git a/.gitignore b/.gitignore
index 1879db4..1b60cab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,7 +17,7 @@ tags
 TAGS
 Makefile.local
 compel/compel
-compel/compel-host
+compel/compel-host-bin
 images/*.c
 images/*.h
 images/google/protobuf/*.c
diff --git a/Makefile b/Makefile
index 9b7b474..a143870 100644
--- a/Makefile
+++ b/Makefile
@@ -222,9 +222,9 @@ $(SOCCR_A): |soccr/built-in.o
 #
 # But note that we're already included
 # the nmk so we can reuse it there.
-criu/%: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host $(VERSION_HEADER) .FORCE
+criu/%: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host-bin $(VERSION_HEADER) .FORCE
 	$(Q) $(MAKE) $(build)=criu $@
-criu: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host $(SOCCR_A) $(VERSION_HEADER)
+criu: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host-bin $(SOCCR_A) $(VERSION_HEADER)
 	$(Q) $(MAKE) $(build)=criu all
 .PHONY: criu
 
diff --git a/compel/Makefile b/compel/Makefile
index b200038..ef932fe 100644
--- a/compel/Makefile
+++ b/compel/Makefile
@@ -2,6 +2,7 @@ include $(SRC_DIR)/Makefile.versions
 
 COMPEL_SO_VERSION	:= $(COMPEL_SO_VERSION_MAJOR)$(if $(COMPEL_SO_VERSION_MINOR),.$(COMPEL_SO_VERSION_MINOR))$(if $(COMPEL_SO_VERSION_SUBLEVEL),.$(COMPEL_SO_VERSION_SUBLEVEL))
 COMPEL_SO_VERSION_CODE	:= $(shell expr $(COMPEL_SO_VERSION_MAJOR) \* 65536 \+ $(COMPEL_SO_VERSION_MINOR) \* 256 \+ $(COMPEL_SO_VERSION_SUBLEVEL))
+ccflags-y		+= -DINCLUDEDIR=\"$(INCLUDEDIR)\"
 ccflags-y		+= -iquote compel/arch/$(ARCH)/src/lib/include
 ccflags-y		+= -iquote compel/include
 ccflags-y		+= -iquote compel/plugins/include
@@ -45,8 +46,8 @@ endif
 
 host-ccflags-y		+= $(ccflags-y)
 
-hostprogs-y		+= compel-host
-compel-host-objs	:= $(patsubst %.o,%-host.o,$(obj-y) $(host-lib-y))
+hostprogs-y		+= compel-host-bin
+compel-host-bin-objs	:= $(patsubst %.o,%-host.o,$(obj-y) $(host-lib-y))
 
 ifeq ($(ARCH),x86)
 HOSTCFLAGS_handle-elf-32-host.o += -UCONFIG_X86_64 -DCONFIG_X86_32
@@ -54,7 +55,7 @@ HOSTCFLAGS_handle-elf-32-host.d += -UCONFIG_X86_64 -DCONFIG_X86_32
 endif
 
 cleanup-y		+= compel/compel
-cleanup-y		+= compel/compel-host
+cleanup-y		+= compel/compel-host-bin
 cleanup-y		+= compel/libcompel.so
 
 install: compel/compel compel/$(LIBCOMPEL_SO) compel/$(LIBCOMPEL_A)
diff --git a/compel/compel-host b/compel/compel-host
new file mode 100755
index 0000000..bf78862
--- /dev/null
+++ b/compel/compel-host
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# A wrapper to use compel-host right from the source dir
+# (i.e. when it is not yet installed).
+
+COMPEL_UNINSTALLED_ROOTDIR=$(dirname "$0")
+export COMPEL_UNINSTALLED_ROOTDIR
+exec "${COMPEL_UNINSTALLED_ROOTDIR}/compel-host-bin" "$@"
diff --git a/compel/src/main.c b/compel/src/main.c
index c943feb..764c794 100644
--- a/compel/src/main.c
+++ b/compel/src/main.c
@@ -48,6 +48,7 @@ static const flags_t flags = {
 };
 
 piegen_opt_t opts = {};
+const char *uninst_root;
 
 static int piegen(void)
 {
@@ -114,7 +115,7 @@ static int usage(int rc) {
 
 	fprintf(out,
 "Usage:\n"
-"  compel [--compat] cflags | ldflags\n"
+"  compel [--compat] includes | cflags | ldflags\n"
 "  compel -f FILE -o FILE -p NAME [-l N] hgen\n"
 "    -f, --file FILE		input (parasite object) file name\n"
 "    -o, --output FILE		output (header) file name\n"
@@ -128,9 +129,35 @@ static int usage(int rc) {
 	return rc;
 }
 
+static void print_includes(void)
+{
+	int i;
+	// list of standard include dirs (built into C preprocessor)
+	const char *standard_includes[] = {
+		"/usr/include",
+		"/usr/local/include",
+	};
+
+	// I am not installed, called via a wrapper
+	if (uninst_root) {
+		printf("-I %s/include/uapi\n", uninst_root);
+		return;
+	}
+
+	// I am installed
+	// Make sure to not print banalities
+	for (i = 0; i < ARRAY_SIZE(standard_includes); i++)
+		if (strcmp(INCLUDEDIR, standard_includes[i]) == 0)
+			return;
+
+	// Finally, print our non-standard include path
+	printf("%s\n", "-I " INCLUDEDIR);
+}
+
 static void print_cflags(bool compat)
 {
 	printf("%s\n", compat ? flags.cflags_compat : flags.cflags);
+	print_includes();
 }
 
 int main(int argc, char *argv[])
@@ -152,6 +179,8 @@ int main(int argc, char *argv[])
 		{ },
 	};
 
+	uninst_root = getenv("COMPEL_UNINSTALLED_ROOTDIR");
+
 	while (1) {
 		idx = -1;
 		opt = getopt_long(argc, argv, short_opts, long_opts, &idx);
@@ -195,6 +224,10 @@ int main(int argc, char *argv[])
 	}
 	action = argv[optind++];
 
+	if (!strcmp(action, "includes")) {
+		print_includes();
+		return 0;
+	}
 	if (!strcmp(action, "cflags")) {
 		print_cflags(compat);
 		return 0;
diff --git a/compel/test/infect/Makefile b/compel/test/infect/Makefile
index ede9a47..8d35c29 100644
--- a/compel/test/infect/Makefile
+++ b/compel/test/infect/Makefile
@@ -3,7 +3,6 @@ CFLAGS	?= -O2 -g -Wall -Werror
 ARCH	?= x86
 
 COMPEL		:= ../../../compel/compel-host
-COMPEL_IDIR	:= ../../../compel/include/uapi
 COMPEL_PACK_LDS	:= ../../../compel/arch/$(ARCH)/scripts/compel-pack.lds.S
 COMPEL_PLUGINS	:= ../../../compel/plugins
 COMPEL_LIBRARY	:= ../../../compel/libcompel.a
@@ -21,7 +20,7 @@ victim: victim.c
 	$(CC) $(CFLAGS) -o $@ $^
 
 spy: spy.c | parasite.h
-	$(CC) $(CFLAGS) -I$(COMPEL_IDIR) -o $@ $^ $(COMPEL_LIBRARY)
+	$(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $^ $(COMPEL_LIBRARY)
 
 parasite.h: parasite.po
 	$(COMPEL) hgen -f $^ -l 4		\
@@ -32,4 +31,4 @@ parasite.po: parasite.o $(COMPEL_PLUGINS)/std.built-in.o
 	ld -r -T $(COMPEL_PACK_LDS) -o $@ $^
 
 parasite.o: parasite.c
-	$(CC) $(CFLAGS) -c $(shell $(COMPEL) cflags) -I$(COMPEL_IDIR) -o $@ $^
+	$(CC) $(CFLAGS) -c $(shell $(COMPEL) cflags) -o $@ $^
diff --git a/compel/test/rsys/Makefile b/compel/test/rsys/Makefile
index a4fda54..3c5ef5b 100644
--- a/compel/test/rsys/Makefile
+++ b/compel/test/rsys/Makefile
@@ -1,7 +1,7 @@
 CC	:= gcc
 CFLAGS	?= -O2 -g -Wall -Werror
 
-COMPEL_IDIR	:= ../../../compel/include/uapi
+COMPEL		:= ../../../compel/compel-host
 COMPEL_LIBRARY	:= ../../../compel/libcompel.a
 
 all: victim spy
@@ -14,4 +14,4 @@ victim: victim.c
 	$(CC) $(CFLAGS) -o $@ $^
 
 spy: spy.c
-	$(CC) $(CFLAGS) -I$(COMPEL_IDIR) -o $@ $^ $(COMPEL_LIBRARY)
+	$(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $^ $(COMPEL_LIBRARY)
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index a45936c..8906112 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -59,7 +59,7 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/pie.lib.a $(compel_lds)
 	$(call msg-gen, $@)
 	$(Q) $(LD) -r -T $(compel_lds) -o $@ $< $(obj)/pie.lib.a
 
-$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(SRC_DIR)/compel/compel-host
+$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(SRC_DIR)/compel/compel-host-bin
 	$(call msg-gen, $@)
 	$(Q) $(SRC_DIR)/compel/compel-host hgen -f $<			\
 		-l 4							\
-- 
2.7.4



More information about the CRIU mailing list