Commit 9d622863 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Andrei Vagin

compel hgen: use for ARM, kill gen-offsets.sh

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: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 7cd6ad5e
......@@ -176,16 +176,6 @@ include/common/asm: include/common/arch/$(ARCH)/asm
$(Q) ln -s ./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
......
......@@ -54,10 +54,6 @@ $(call map,gen-feature-test,$(FEATURES_LIST))
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
......
......@@ -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
......
......@@ -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);
......
......@@ -2459,7 +2459,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;
}
......
......@@ -87,8 +87,6 @@ endif
asflags-y += -D__ASSEMBLY__
GEN-OFFSETS := $(obj)/../../scripts/gen-offsets.sh
BLOBS += $(obj)/restorer-blob.h
define gen-pields-blobs-var
......@@ -101,7 +99,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
......@@ -129,40 +126,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`
......
......@@ -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__ */
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment