[CRIU] [PATCH 16/20] compel hgen: use for ARM, kill gen-offsets.sh

Kir Kolyshkin kir at openvz.org
Thu Dec 8 01:44:29 PST 2016


I am not quite sure how that happened, but compel hgen was not used for
ARM/ARM64, instead there's a simple version of it, called
gen-offsets.sh. The main difference is, shell script doesn't handle ELF
relocations, which apparently is not (currently?) needed for ARM.

It's bad to maintain two tools for the same functionality, so this
patch kills gen-offsets.sh and related stuff, making compel hgen
working on ARM. ELF relocations are still not handled, this code
is #ifdef-ed out for now and can be fixed to work on ARM later.

This patch also kills some macros and defines that seem obsoleted
now. For example, compel_relocs_apply() is now called unconditionally,
as it handles the trivial case of 0 relocs just fine.

Now, I checked that the blob headers generated by compel hgen and
gen-offsets.h are similar (i.e. generated blob code and values defined
are the same), but haven't done much above that.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 Makefile                    | 10 ----------
 Makefile.config             |  4 ----
 compel/Makefile             |  6 ++++++
 compel/src/lib/handle-elf.c |  3 ++-
 criu/cr-restore.c           |  4 +++-
 criu/pie/Makefile           | 37 -------------------------------------
 criu/pie/pie-relocs.h       | 12 ------------
 scripts/gen-offsets.sh      | 43 -------------------------------------------
 8 files changed, 11 insertions(+), 108 deletions(-)
 delete mode 100644 scripts/gen-offsets.sh

diff --git a/Makefile b/Makefile
index 6a7cbc2..bfa328d 100644
--- a/Makefile
+++ b/Makefile
@@ -177,16 +177,6 @@ include/common/asm: include/common/arch/$(ARCH)/asm
 $(VERSION_HEADER): include/common/asm
 
 #
-# piegen tool might be disabled by hands. Don't use it until
-# you know what you're doing.
-ifneq ($(filter ia32 x86 ppc64,$(ARCH)),)
-        ifneq ($(PIEGEN),no)
-                piegen-y := y
-                export piegen-y
-        endif
-endif
-
-#
 # Configure variables.
 export CONFIG_HEADER := criu/include/config.h
 ifeq ($(filter clean mrproper,$(MAKECMDGOALS)),)
diff --git a/Makefile.config b/Makefile.config
index 6ff42fe..ad99533 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -55,10 +55,6 @@ ifeq ($$(VDSO),y)
 	$(Q) @echo '#define CONFIG_VDSO'				>> $$@
 	$(Q) @echo ''							>> $$@
 endif
-ifeq ($$(piegen-y),y)
-	$(Q) @echo '#define CONFIG_PIEGEN'				>> $$@
-	$(Q) @echo ''							>> $$@
-endif
 	$(Q) @echo '#endif /* __CR_CONFIG_H__ */'			>> $$@
 endef
 
diff --git a/compel/Makefile b/compel/Makefile
index 8c580fd..65426d8 100644
--- a/compel/Makefile
+++ b/compel/Makefile
@@ -26,6 +26,12 @@ lib-y			+= src/lib/infect-util.o
 lib-y			+= src/lib/infect.o
 lib-y			+= src/lib/ptrace.o
 
+# handle_elf() has no support of ELF relocations on ARM (yet?)
+ifneq ($(filter arm aarch64,$(ARCH)),)
+CFLAGS			+= -DNO_RELOCS
+HOSTCFLAGS		+= -DNO_RELOCS
+endif
+
 ifeq ($(ARCH),x86)
 obj-y			+= src/lib/handle-elf-32.o
 endif
diff --git a/compel/src/lib/handle-elf.c b/compel/src/lib/handle-elf.c
index 5948717..14b066b 100644
--- a/compel/src/lib/handle-elf.c
+++ b/compel/src/lib/handle-elf.c
@@ -267,7 +267,7 @@ int __handle_elf(void *mem, size_t size)
 	}
 
 	pr_out("static __maybe_unused compel_reloc_t %s_relocs[] = {\n", opts.prefix);
-
+#ifndef NO_RELOCS
 	pr_debug("Relocations\n");
 	pr_debug("------------\n");
 	for (i = 0; i < hdr->e_shnum; i++) {
@@ -545,6 +545,7 @@ int __handle_elf(void *mem, size_t size)
 			}
 		}
 	}
+#endif /* !NO_RELOCS */
 	pr_out("};\n");
 	pr_out("static __maybe_unused size_t %s_nr_gotpcrel = %zd;\n", opts.prefix, nr_gotpcrel);
 
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c91de71..c73b7c7 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2453,7 +2453,9 @@ static int remap_restorer_blob(void *addr)
 		return -1;
 	}
 
-	ELF_RELOCS_APPLY(restorer, addr, addr);
+	compel_relocs_apply(addr, addr, sizeof(restorer_blob),
+			restorer_relocs, ARRAY_SIZE(restorer_relocs));
+
 	return 0;
 }
 
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index cfc1378..9ee1f75 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -85,8 +85,6 @@ endif
 
 asflags-y		+= -D__ASSEMBLY__
 
-GEN-OFFSETS		:= $(obj)/../../scripts/gen-offsets.sh
-
 BLOBS			+= $(obj)/restorer-blob.h
 
 define gen-pields-blobs-var
@@ -99,7 +97,6 @@ $(eval $(call map,gen-pields-blobs-var,$(parasite_target)))
 # for C files, we need "parasite-native" to be "parasite_native"
 target-name = $(patsubst criu/pie/%_blob.h,%,$(subst -,_,$(1)))
 
-ifeq ($(piegen-y),y)
 ifeq ($(strip $(V)),)
         piegen_stdout := >/dev/null
 endif
@@ -127,40 +124,6 @@ $(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(SRC_DIR)/compel/compel-host
 		-p $(call target-name,$@)				\
 		-o $@ $(piegen_stdout)
 
-else # !piegen-y
-
-# ld on arm doesn't like -pie and -r options together
-ifeq ($(filter arm aarch64,$(ARCH)),)
-        LD_R := -r
-endif
-
-define gen-rule-built-in.bin.o
-$(obj)/$(1).built-in.o: $(compel_std-$(1))
-$(obj)/parasite-$(1).built-in.bin.o: $(obj)/$(1).built-in.o		\
-				$(compel_pack_lds-$(1)) $(obj)/native.lib.a
-	$$(call msg-gen, $$@)
-	$(Q) $(LD) $(LD_R) -T $(compel_pack_lds-$(1)) -o $$@ $$< $(obj)/native.lib.a
-endef
-
-$(eval $(call map,gen-rule-built-in.bin.o,$(parasite_target)))
-
-$(obj)/restorer.built-in.o: $(compel_std-native)
-$(obj)/restorer.built-in.bin.o: $(obj)/restorer.built-in.o		\
-				$(compel_pack_lds-native) $(obj)/native.lib.a
-	$(call msg-gen, $@)
-	$(Q) $(LD) $(LD_R) -T $(compel_pack_lds-native) -o $@ $< $(obj)/native.lib.a
-
-$(obj)/%.built-in.bin: $(obj)/%.built-in.bin.o
-	$(call msg-gen, $@)
-	$(Q) $(OBJCOPY) -O binary $^ $@
-
-$(obj)/%-blob.h: $(obj)/%.built-in.bin $(GEN-OFFSETS)
-	$(call msg-gen, $@)
-	$(Q) $(SH) $(GEN-OFFSETS) $(@:-blob.h=) $(call target-name,$@) $(CROSS_COMPILE) > $@
-
-
-endif # !piegen-y
-
 all-y += $(BLOBS)
 # blobs and pields are in cleanup, rather than in mrproper because
 # we want them to be re-generated after `make clean && make`
diff --git a/criu/pie/pie-relocs.h b/criu/pie/pie-relocs.h
index 442e70d..5a18d8c 100644
--- a/criu/pie/pie-relocs.h
+++ b/criu/pie/pie-relocs.h
@@ -6,19 +6,7 @@
 #include "common/compiler.h"
 #include "config.h"
 
-#ifdef CONFIG_PIEGEN
-
 #define pie_size(__pie_name)	(round_up(sizeof(__pie_name##_blob) + \
 			__pie_name ## _nr_gotpcrel * sizeof(long), page_size()))
-#define ELF_RELOCS_APPLY(__pie_name, __mem, __vbase)			\
-	compel_relocs_apply(__mem, __vbase, sizeof(__pie_name##_blob),	\
-			 __pie_name##_relocs, ARRAY_SIZE(__pie_name##_relocs))
-
-#else
-
-#define pie_size(__pie_name)	(round_up(sizeof(__pie_name##_blob), page_size()))
-#define ELF_RELOCS_APPLY(__pie_name, __mem, __vbase)
-
-#endif
 
 #endif /* __PIE_RELOCS_H__ */
diff --git a/scripts/gen-offsets.sh b/scripts/gen-offsets.sh
deleted file mode 100644
index 16a0394..0000000
--- a/scripts/gen-offsets.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-
-set -e
-set -u
-
-FILE=$1
-NAME=$2
-
-if test $# -ge 3; then
-CROSS_COMPILE=$3
-else
-CROSS_COMPILE=
-fi
-
-INC_GUARD=__${NAME}_h__
-SYM=${NAME}_sym
-BLOB=${NAME}_blob
-OBJNAME=${FILE}.built-in.bin.o
-BINARY=${FILE}.built-in.bin
-
-AWK_CMD='$2 ~ /^[tTA]$/ { print "#define '$SYM'" $3 " 0x" $1; }'
-
-cat << EOF
-/* Autogenerated by $0, do not edit */
-#ifndef $INC_GUARD
-#define $INC_GUARD
-
-EOF
-
-${CROSS_COMPILE}nm $OBJNAME | grep "__export_" | tr . _ | awk "$AWK_CMD"
-
-cat << EOF
-
-static char $BLOB[] = {
-EOF
-
-hexdump -v -e '"\t" 8/1 "0x%02x, " "\n"' $BINARY
-
-cat << EOF
-};
-
-#endif /* $INC_GUARD */
-EOF
-- 
2.7.4



More information about the CRIU mailing list