[CRIU] [PATCH 5/5] compel: Initial commit for standalone tool

Cyrill Gorcunov gorcunov at openvz.org
Tue Apr 5 08:41:15 PDT 2016


The compel component is a replacement for several aspects of CRIU
functionality: binary blobs generation for PIE parasite/restore code,
and a library for parasite code injection and execution (to be implemented).

In the commit we rather shuffle compel into own directory and
use it for

1) Fetching cflags when compiling PIE blobs
2) Use its "piegen" functionality to generate blobs themselves.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile                                         | 11 ++++++++---
 Makefile.versions                                |  4 ++++
 compel/Makefile                                  | 20 ++++++++++++++++++++
 {criu/pie/piegen => compel/include}/piegen.h     |  0
 {criu/pie/piegen => compel/include}/uapi/types.h |  0
 {criu/pie/piegen => compel/src}/elf-ppc64.c      |  0
 {criu/pie/piegen => compel/src}/elf-x86-32.c     |  0
 {criu/pie/piegen => compel/src}/elf-x86-64.c     |  0
 {criu/pie/piegen => compel/src}/elf.c            |  0
 {criu/pie/piegen => compel/src}/main.c           |  0
 criu/Makefile                                    | 17 +----------------
 criu/pie/Makefile                                | 13 ++++++-------
 criu/pie/pie-relocs.c                            |  2 +-
 criu/pie/pie-relocs.h                            |  2 +-
 criu/pie/piegen/Makefile                         | 19 -------------------
 15 files changed, 41 insertions(+), 47 deletions(-)
 create mode 100644 compel/Makefile
 rename {criu/pie/piegen => compel/include}/piegen.h (100%)
 rename {criu/pie/piegen => compel/include}/uapi/types.h (100%)
 rename {criu/pie/piegen => compel/src}/elf-ppc64.c (100%)
 rename {criu/pie/piegen => compel/src}/elf-x86-32.c (100%)
 rename {criu/pie/piegen => compel/src}/elf-x86-64.c (100%)
 rename {criu/pie/piegen => compel/src}/elf.c (100%)
 rename {criu/pie/piegen => compel/src}/main.c (100%)
 delete mode 100644 criu/pie/piegen/Makefile

diff --git a/Makefile b/Makefile
index 4e1c1df45b46..ec2eb7399f7c 100644
--- a/Makefile
+++ b/Makefile
@@ -108,6 +108,9 @@ CFLAGS			+= $(WARNINGS) $(DEFINES)
 # on anything else.
 $(eval $(call gen-built-in,images))
 
+# Compel get used by CRIU, build it earlier
+$(eval $(call gen-built-in,compel))
+
 #
 # CRIU building done in own directory
 # with slightly different rules so we
@@ -116,9 +119,9 @@ $(eval $(call gen-built-in,images))
 #
 # But note that we're already included
 # the nmk so we can reuse it there.
-criu/%: images/built-in.o
+criu/%: images/built-in.o compel/compel
 	$(Q) $(MAKE) -C criu $@
-criu: images/built-in.o
+criu: images/built-in.o compel/compel
 	$(Q) $(MAKE) -C criu all
 .PHONY: criu
 
@@ -132,7 +135,7 @@ lib: criu
 	$(Q) $(MAKE) -C lib all
 .PHONY: lib
 
-all: criu lib
+all: compel criu lib
 .PHONY: all
 
 subclean:
@@ -144,12 +147,14 @@ subclean:
 
 clean: subclean
 	$(Q) $(MAKE) $(build)=images $@
+	$(Q) $(MAKE) $(build)=compel $@
 	$(Q) $(MAKE) -C criu $@
 .PHONY: clean
 
 # mrproper depends on clean in nmk
 mrproper: subclean
 	$(Q) $(MAKE) $(build)=images $@
+	$(Q) $(MAKE) $(build)=compel $@
 	$(Q) $(MAKE) -C criu $@
 	$(Q) $(RM) cscope.*
 	$(Q) $(RM) tags TAGS
diff --git a/Makefile.versions b/Makefile.versions
index 1c66439bd805..6980320751c5 100644
--- a/Makefile.versions
+++ b/Makefile.versions
@@ -17,3 +17,7 @@ CRIU_SO_VERSION_MINOR	:= 0
 
 export CRIU_SO_VERSION_MAJOR CRIU_SO_VERSION_MINOR
 
+COMPEL_SO_VERSION_MAJOR	:= 1
+COMPEL_SO_VERSION_MINOR	:= 0
+
+export COMPEL_SO_VERSION_MAJOR COMPEL_SO_VERSION_MINOR
diff --git a/compel/Makefile b/compel/Makefile
new file mode 100644
index 000000000000..96709c6c74f2
--- /dev/null
+++ b/compel/Makefile
@@ -0,0 +1,20 @@
+include $(SRC_DIR)/Makefile.versions
+
+ccflags-y	+= -iquote criu/include
+ccflags-y	+= -iquote compel/include
+ccflags-y	+= -DCOMPEL_VERSION=\"$(COMPEL_SO_VERSION_MAJOR).$(COMPEL_SO_VERSION_MINOR)\"
+
+host-ccflags-y	+= $(ccflags-y)
+HOSTCFLAGS	+= $(WARNINGS) $(DEFINES)
+HOSTLDFLAGS	+= $(LDFLAGS)
+
+hostprogs-y	+= compel
+compel-objs	+= src/main.o
+
+ifneq ($(filter ia32 x86, $(ARCH)),)
+compel-objs	+= src/elf-x86-32.o
+compel-objs	+= src/elf-x86-64.o
+endif
+ifeq ($(SRCARCH),ppc64)
+compel-objs	+= src/elf-ppc64.o
+endif
diff --git a/criu/pie/piegen/piegen.h b/compel/include/piegen.h
similarity index 100%
rename from criu/pie/piegen/piegen.h
rename to compel/include/piegen.h
diff --git a/criu/pie/piegen/uapi/types.h b/compel/include/uapi/types.h
similarity index 100%
rename from criu/pie/piegen/uapi/types.h
rename to compel/include/uapi/types.h
diff --git a/criu/pie/piegen/elf-ppc64.c b/compel/src/elf-ppc64.c
similarity index 100%
rename from criu/pie/piegen/elf-ppc64.c
rename to compel/src/elf-ppc64.c
diff --git a/criu/pie/piegen/elf-x86-32.c b/compel/src/elf-x86-32.c
similarity index 100%
rename from criu/pie/piegen/elf-x86-32.c
rename to compel/src/elf-x86-32.c
diff --git a/criu/pie/piegen/elf-x86-64.c b/compel/src/elf-x86-64.c
similarity index 100%
rename from criu/pie/piegen/elf-x86-64.c
rename to compel/src/elf-x86-64.c
diff --git a/criu/pie/piegen/elf.c b/compel/src/elf.c
similarity index 100%
rename from criu/pie/piegen/elf.c
rename to compel/src/elf.c
diff --git a/criu/pie/piegen/main.c b/compel/src/main.c
similarity index 100%
rename from criu/pie/piegen/main.c
rename to compel/src/main.c
diff --git a/criu/Makefile b/criu/Makefile
index 3486d19d932b..acd44ac12136 100644
--- a/criu/Makefile
+++ b/criu/Makefile
@@ -144,25 +144,13 @@ arch_lib: syscalls_lib
 .PHONY: arch_lib
 
 #
-# piegen tool needed for PIE code.
-ifeq ($(piegen-y),y)
-piegen-bin		:= pie/piegen/piegen
-
-pie/piegen/%: config
-	$(Q) CC=$(HOSTCC) LD=$(HOSTLD) CFLAGS="$(ccflags-y) $(HOSTCFLAGS) $(WARNINGS) $(DEFINES)" $(MAKE) $(build)=pie/piegen $@
-$(piegen-bin): pie/piegen/built-in.o
-	$(call msg-link, $@)
-	$(Q) $(HOSTCC) $(HOSTCFLAGS) $^ $(LDFLAGS) -o $@
-endif
-
-#
 # PIE library code.
 pie/lib.a: arch_lib
 	$(Q) $(MAKE) $(call build-as,Makefile.library,pie) all
 
 #
 # PIE code blobs themseves.
-pie: $(piegen-bin) pie/lib.a
+pie: pie/lib.a
 	$(Q) $(MAKE) $(build)=pie all
 .PHONY: pie
 
@@ -183,7 +171,6 @@ criu: $(PROGRAM-BUILTINS)
 subclean:
 	$(Q) $(RM) ./*.{gcda,gcno,gcov}
 	$(Q) $(RM) ./pie/*.{gcda,gcno,gcov}
-	$(Q) $(RM) ./pie/piegen/*.{gcda,gcno,gcov}
 	$(Q) $(RM) -r ./gcov
 	$(Q) $(RM) criu
 .PHONY: subclean
@@ -195,7 +182,6 @@ clean: subclean
 	$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) $@
 	$(Q) $(MAKE) $(call build-as,Makefile.library,pie) $@
 	$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) $@
-	$(Q) $(MAKE) $(build)=pie/piegen $@
 	$(Q) $(MAKE) $(build)=pie $@
 .PHONY: clean
 
@@ -206,7 +192,6 @@ mrproper: subclean
 	$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) $@
 	$(Q) $(MAKE) $(call build-as,Makefile.library,pie) $@
 	$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) $@
-	$(Q) $(MAKE) $(build)=pie/piegen $@
 	$(Q) $(MAKE) $(build)=pie $@
 	$(Q) $(RM) $(VERSION_HEADER)
 	$(Q) $(RM) $(CONFIG_HEADER)
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index 504562e5dd1d..e2f9e790f331 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -15,12 +15,11 @@ restorer-obj-e		+= ./$(ARCH_DIR)/syscalls.built-in.o
 # applications, which is not the target of the
 # project.
 #
-CFLAGS			:= $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) -iquote pie/piegen -iquote arch/$(ARCH)/include -iquote $(SRC_DIR) -iquote $(SRC_DIR)/criu/include
+CFLAGS			:= $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) -iquote $(SRC_DIR)/compel/include -iquote arch/$(ARCH)/include -iquote $(SRC_DIR) -iquote $(SRC_DIR)/criu/include
 
-ifneq ($(filter-out ia32,$(ARCH)),)
-        ccflags-y	+= -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector
-else
-        ccflags-y	+= -DCR_NOGLIBC -fno-pic -Wa,--noexecstack -fno-stack-protector
+ccflags-y		+= -DCR_NOGLIBC
+ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),)
+	ccflags-y	+= $(shell $(SRC_DIR)/compel/compel --arch=$(ARCH) cflags)
 endif
 
 ifeq ($(SRCARCH),arm)
@@ -68,9 +67,9 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/lib.a $(obj)/$(PIELDS)
 	$(call msg-gen, $@)
 	$(Q) $(LD) -r -T $(obj)/$(PIELDS) -o $@ $< $(obj)/lib.a
 
-$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) pie/piegen
+$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) $(SRC_DIR)/compel/compel
 	$(call msg-gen, $@)
-	$(Q) pie/piegen/piegen piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -o $@ $(piegen_stdout)
+	$(Q) $(SRC_DIR)/compel/compel piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -u $(SRC_DIR)/compel/include/uapi -o $@ $(piegen_stdout)
 
 else
 
diff --git a/criu/pie/pie-relocs.c b/criu/pie/pie-relocs.c
index 7e825b2320d9..72665e39621f 100644
--- a/criu/pie/pie-relocs.c
+++ b/criu/pie/pie-relocs.c
@@ -15,7 +15,7 @@
 #include "asm-generic/int.h"
 
 #include "compiler.h"
-#include "piegen/uapi/types.h"
+#include "compel/include/uapi/types.h"
 #include "bug.h"
 
 __maybe_unused void elf_relocs_apply(void *mem, void *vbase, size_t size, elf_reloc_t *elf_relocs, size_t nr_relocs)
diff --git a/criu/pie/pie-relocs.h b/criu/pie/pie-relocs.h
index 1449ca630908..bd313f8bfcba 100644
--- a/criu/pie/pie-relocs.h
+++ b/criu/pie/pie-relocs.h
@@ -1,7 +1,7 @@
 #ifndef __PIE_RELOCS_H__
 #define __PIE_RELOCS_H__
 
-#include "piegen/uapi/types.h"
+#include "compel/include/uapi/types.h"
 
 #include "compiler.h"
 #include "config.h"
diff --git a/criu/pie/piegen/Makefile b/criu/pie/piegen/Makefile
deleted file mode 100644
index 0af489070ba0..000000000000
--- a/criu/pie/piegen/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-CFLAGS += -iquote pie/piegen
-
-obj-y += main.o
-ifneq ($(filter ia32 x86, $(ARCH)),)
-obj-y += elf-x86-32.o
-obj-y += elf-x86-64.o
-endif
-ifeq ($(SRCARCH),ppc64)
-obj-y += elf-ppc64.o
-endif
-
-cleanup-y += $(obj)/piegen
-cleanup-y += $(obj)/*.o
-
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(MAKECMDGOALS),mrproper)
-incdeps := y
-endif
-endif
-- 
2.5.5



More information about the CRIU mailing list