Commit 3b0c8dbd authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

compel: Reshuffle the directories structure

Here we rather suffle source code into directories
preparing ground for future work.

Basically all this files movements should end up in the
following compel/ tree structure

compel/
├── arch
│   ├── aarch64
│   │   ├── plugins
│   │   │   └── std
│   │   └── src
│   │       └── lib
│   ├── arm
	...
│   ├── ppc64
	...
│   └── x86
	...

	This is architectural part, where each arch consists of
	plugins/, and src/. src/ stands for code needed by compel
	cli + lib

├── include
│   ├── compiler.h -> ../../criu/include/compiler.h
│   ├── elf32-types.h
│   ├── elf64-types.h
│   ├── int.h -> ../../criu/include/asm-generic/int.h
│   ├── piegen.h
│   ├── shmem.h
│   └── uapi
│       ├── compel.h
│       └── plugins.h

	Common includes + uapi

├── plugins
│   ├── fds
│   ├── shmem
│   └── std

	Plugins source code

└── src
    ├── lib
    │   ├── handle-elf-32.c -> handle-elf.c
    │   ├── handle-elf-32-host.c -> handle-elf-32.c
    │   ├── handle-elf.c
    │   └── handle-elf-host.c -> handle-elf.c

	compel library

    ├── main.c
    ├── main-host.c -> main.c

	compel cli

    └── shared
        └── fds.c

	shared code between plugins and compel cli

Note: cross-compile won't work for a while.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 596767d5
...@@ -201,12 +201,9 @@ $(eval $(call gen-built-in,images)) ...@@ -201,12 +201,9 @@ $(eval $(call gen-built-in,images))
.PHONY: .FORCE .PHONY: .FORCE
#
# Compel get used by CRIU, build it earlier # Compel get used by CRIU, build it earlier
compel/%: .FORCE include Makefile.compel
$(Q) $(MAKE) $(build)=compel $@
test/compel/%: .FORCE
$(Q) $(MAKE) $(build)=compel $@
# #
# Next the socket CR library # Next the socket CR library
...@@ -269,6 +266,7 @@ mrproper: subclean ...@@ -269,6 +266,7 @@ mrproper: subclean
$(Q) $(RM) $(CONFIG_HEADER) $(Q) $(RM) $(CONFIG_HEADER)
$(Q) $(RM) $(SOCCR_CONFIG) $(Q) $(RM) $(SOCCR_CONFIG)
$(Q) $(RM) $(VERSION_HEADER) $(Q) $(RM) $(VERSION_HEADER)
$(Q) $(RM) $(COMPEL_VERSION_HEADER)
$(Q) $(RM) include/common/asm $(Q) $(RM) include/common/asm
$(Q) $(RM) cscope.* $(Q) $(RM) cscope.*
$(Q) $(RM) tags TAGS $(Q) $(RM) tags TAGS
......
COMPEL_VERSION_HEADER := compel/include/version.h
$(COMPEL_VERSION_HEADER): $(SRC_DIR)/Makefile.versions
$(call msg-gen, $(COMPEL_VERSION_HEADER))
$(E) " GEN " $@
$(Q) echo "/* Autogenerated, do not edit */" > $(COMPEL_VERSION_HEADER)
$(Q) echo "#ifndef COMPEL_SO_VERSION_H__" >> $(COMPEL_VERSION_HEADER)
$(Q) echo "#define COMPEL_SO_VERSION_H__" >> $(COMPEL_VERSION_HEADER)
$(Q) echo "#define COMPEL_SO_VERSION \"$(COMPEL_SO_VERSION)\"" >> $(COMPEL_VERSION_HEADER)
$(Q) echo "#define COMPEL_SO_VERSION_MAJOR " $(COMPEL_SO_VERSION_MAJOR) >> $(COMPEL_VERSION_HEADER)
$(Q) echo "#define COMPEL_SO_VERSION_MINOR " $(COMPEL_SO_VERSION_MINOR) >> $(COMPEL_VERSION_HEADER)
$(Q) echo "#define COMPEL_SO_VERSION_SUBLEVEL " $(COMPEL_SO_VERSION_SUBLEVEL) >> $(COMPEL_VERSION_HEADER)
$(Q) echo "#endif /* COMPEL_SO_VERSION_H__ */" >> $(COMPEL_VERSION_HEADER)
#
# Compel itself.
compel/%: $(COMPEL_VERSION_HEADER) $(CONFIG_HEADER) .FORCE
$(Q) $(MAKE) $(build)=compel $@
#
# Plugins
compel/plugins/%: $(COMPEL_VERSION_HEADER) $(CONFIG_HEADER) .FORCE
$(Q) $(MAKE) $(build)=compel/plugins $@
compel/compel: compel/built-in.o compel/lib.a $(COMPEL_VERSION_HEADER)
$(call msg-link, $@)
$(Q) $(CC) $(CFLAGS) $^ $(WRAPFLAGS) $(LDFLAGS) -rdynamic -o $@
#
# And compel library.
LIBCOMPEL_SO := libcompel.so
LIBCOMPEL_SO_CFLAGS += $(CFLAGS) -rdynamic -Wl,-soname,$(LIBCOMPEL_SO).$(COMPEL_SO_VERSION_MAJOR)
compel/$(LIBCOMPEL_SO): compel/lib.a
$(call msg-link, $@)
$(Q) $(CC) -shared $(LIBCOMPEL_SO_CFLAGS) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(LDFLAGS)
include $(SRC_DIR)/Makefile.versions include $(SRC_DIR)/Makefile.versions
ccflags-y += -iquote criu/include .PHONY: .FORCE
ccflags-y += -iquote compel/include
ccflags-y += -iquote compel/arch/$(ARCH)/include
ccflags-y += -DCOMPEL_VERSION=\"$(COMPEL_SO_VERSION_MAJOR).$(COMPEL_SO_VERSION_MINOR)\"
host-ccflags-y += $(filter-out -pg $(CFLAGS-GCOV),$(ccflags-y))
HOSTCFLAGS += $(filter-out -pg $(CFLAGS-GCOV),$(WARNINGS) $(DEFINES))
HOSTLDFLAGS += $(filter-out -pg $(CFLAGS-GCOV),$(LDFLAGS))
HOSTCFLAGS := $(filter-out -DCONFIG_X86_64,$(HOSTCFLAGS))
export host-ccflags-y HOSTCFLAGS HOSTLDFLAGS
hostprogs-y += compel
compel-objs += main.o
compel-objs += handle-elf.o
compel-objs += arch/$(ARCH)/handle-elf.o
ifeq ($(ARCH),x86)
# Add -DCONFIG_X86_64 or -DCONFIG_X86_32 to HOSTCFLAGS
define ccflags-defines
export HOSTCFLAGS_$(notdir $(1)) += -DCONFIG_X86_64
endef
$(eval $(call map,ccflags-defines,$(compel-objs)))
compel-objs += handle-elf-32.o 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))
export HOSTCFLAGS_handle-elf-32.o += -DCONFIG_X86_32 COMPEL_SO_VERSION_CODE := $(shell expr $(COMPEL_SO_VERSION_MAJOR) \* 65536 \+ $(COMPEL_SO_VERSION_MINOR) \* 256 \+ $(COMPEL_SO_VERSION_SUBLEVEL))
endif # ARCH == x86 ccflags-y += -iquote compel/arch/$(ARCH)/src/lib/include
ccflags-y += -iquote compel/include
ccflags-y += -iquote compel/plugins/include
ccflags-y += -iquote $(SRC_DIR)/criu/include
ccflags-y += -fPIC
.PHONY: .FORCE lib-y += arch/$(ARCH)/src/lib/handle-elf.o
lib-y += src/lib/handle-elf.o
lib-y += src/lib/handle-elf-32.o
export compel-objs obj-y += src/main.o
test/compel/%: .FORCE
$(Q) $(MAKE) $(build)=test/compel $@
test: test/compel/test_handle_binary CFLAGS_handle-elf-32.o += -UCONFIG_X86_64 -DCONFIG_X86_32
CFLAGS_handle-elf-32.d += -UCONFIG_X86_64 -DCONFIG_X86_32
.PHONY: test cleanup-y += compel/compel
cleanup-y += compel/libcompel.so
#include <string.h> #include <string.h>
#include "piegen.h" #include "uapi/compel.h"
#include "uapi/piegen-err.h"
#include "handle-elf.h" #include "handle-elf.h"
#include "piegen.h"
static const unsigned char __maybe_unused
elf_ident_64_le[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char __maybe_unused
elf_ident_64_be[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int handle_binary(void *mem, size_t size) int handle_binary(void *mem, size_t size)
{ {
...@@ -17,5 +30,5 @@ int handle_binary(void *mem, size_t size) ...@@ -17,5 +30,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_aarch64(mem, size); return handle_elf_aarch64(mem, size);
pr_err("Unsupported Elf format detected\n"); pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF; return -EINVAL;
} }
#ifndef __COMPEL_HANDLE_ELF_H__ #ifndef COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__ #define COMPEL_HANDLE_ELF_H__
#include "uapi/elf64-types.h" #include "elf64-types.h"
#define __handle_elf handle_elf_aarch64 #define __handle_elf handle_elf_aarch64
#define arch_is_machine_supported(e_machine) (e_machine == EM_AARCH64) #define arch_is_machine_supported(e_machine) (e_machine == EM_AARCH64)
extern int handle_elf_aarch64(void *mem, size_t size); extern int handle_elf_aarch64(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */ #endif /* COMPEL_HANDLE_ELF_H__ */
#include <string.h> #include <string.h>
#include "piegen.h" #include "uapi/compel.h"
#include "uapi/piegen-err.h"
#include "handle-elf.h" #include "handle-elf.h"
#include "piegen.h"
static const unsigned char __maybe_unused
elf_ident_32[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int handle_binary(void *mem, size_t size) int handle_binary(void *mem, size_t size)
{ {
...@@ -10,5 +17,5 @@ int handle_binary(void *mem, size_t size) ...@@ -10,5 +17,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_arm(mem, size); return handle_elf_arm(mem, size);
pr_err("Unsupported Elf format detected\n"); pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF; return -EINVAL;
} }
#ifndef __COMPEL_HANDLE_ELF_H__ #ifndef COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__ #define COMPEL_HANDLE_ELF_H__
#include "uapi/elf32-types.h" #include "elf32-types.h"
#define __handle_elf handle_elf_arm #define __handle_elf handle_elf_arm
#define arch_is_machine_supported(e_machine) (e_machine == EM_ARM) #define arch_is_machine_supported(e_machine) (e_machine == EM_ARM)
extern int handle_elf_arm(void *mem, size_t size); extern int handle_elf_arm(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */ #endif /* COMPEL_HANDLE_ELF_H__ */
#include <string.h> #include <string.h>
#include "piegen.h" #include "uapi/compel.h"
#include "uapi/piegen-err.h"
#include "handle-elf.h" #include "handle-elf.h"
#include "piegen.h"
static const unsigned char __maybe_unused
elf_ident_64_le[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char __maybe_unused
elf_ident_64_be[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int handle_binary(void *mem, size_t size) int handle_binary(void *mem, size_t size)
{ {
...@@ -17,5 +30,5 @@ int handle_binary(void *mem, size_t size) ...@@ -17,5 +30,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_ppc64(mem, size); return handle_elf_ppc64(mem, size);
pr_err("Unsupported Elf format detected\n"); pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF; return -EINVAL;
} }
#ifndef __COMPEL_HANDLE_ELF_H__ #ifndef COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__ #define COMPEL_HANDLE_ELF_H__
#include "uapi/elf64-types.h" #include "elf64-types.h"
#define ELF_PPC64 #define ELF_PPC64
#define __handle_elf handle_elf_ppc64
#define __handle_elf handle_elf_ppc64
#define arch_is_machine_supported(e_machine) (e_machine == EM_PPC64) #define arch_is_machine_supported(e_machine) (e_machine == EM_PPC64)
extern int handle_elf_ppc64(void *mem, size_t size); extern int handle_elf_ppc64(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */ #endif /* COMPEL_HANDLE_ELF_H__ */
#include <string.h> #include <string.h>
#include "piegen.h" #include "uapi/compel.h"
#include "uapi/piegen-err.h"
#include "handle-elf.h" #include "handle-elf.h"
#include "piegen.h"
static const unsigned char __maybe_unused
elf_ident_64_le[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char __maybe_unused
elf_ident_32[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int handle_binary(void *mem, size_t size) int handle_binary(void *mem, size_t size)
{ {
...@@ -12,5 +25,5 @@ int handle_binary(void *mem, size_t size) ...@@ -12,5 +25,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_x86_64(mem, size); return handle_elf_x86_64(mem, size);
pr_err("Unsupported Elf format detected\n"); pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF; return -EINVAL;
} }
#ifndef __COMPEL_HANDLE_ELF_H__ #ifndef COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__ #define COMPEL_HANDLE_ELF_H__
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
#include "uapi/elf32-types.h" #include "elf32-types.h"
#define ELF_X86_32 #define ELF_X86_32
#define __handle_elf handle_elf_x86_32
#define __handle_elf handle_elf_x86_32
#define arch_is_machine_supported(e_machine) (e_machine == EM_386) #define arch_is_machine_supported(e_machine) (e_machine == EM_386)
#else /* CONFIG_X86_64 */ #else /* CONFIG_X86_64 */
#include "uapi/elf64-types.h" #include "elf64-types.h"
#define ELF_X86_64 #define ELF_X86_64
#define __handle_elf handle_elf_x86_64
#define __handle_elf handle_elf_x86_64
#define arch_is_machine_supported(e_machine) (e_machine == EM_X86_64) #define arch_is_machine_supported(e_machine) (e_machine == EM_X86_64)
#endif #endif
...@@ -20,4 +24,4 @@ ...@@ -20,4 +24,4 @@
extern int handle_elf_x86_32(void *mem, size_t size); extern int handle_elf_x86_32(void *mem, size_t size);
extern int handle_elf_x86_64(void *mem, size_t size); extern int handle_elf_x86_64(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */ #endif /* COMPEL_HANDLE_ELF_H__ */
#ifndef COMPEL_ELF32_TYPES_H__
#define COMPEL_ELF32_TYPES_H__
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Rel Elf32_Rel
#define Elf_Rela Elf32_Rela
#define ELF_ST_TYPE ELF32_ST_TYPE
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_R_SYM ELF32_R_SYM
#define ELF_R_TYPE ELF32_R_TYPE
#endif /* COMPEL_ELF32_TYPES_H__ */
#ifndef COMPEL_ELF64_TYPES_H__
#define COMPEL_ELF64_TYPES_H__
#define Elf_Ehdr Elf64_Ehdr
#define Elf_Shdr Elf64_Shdr
#define Elf_Sym Elf64_Sym
#define Elf_Rel Elf64_Rel
#define Elf_Rela Elf64_Rela
#define ELF_ST_TYPE ELF64_ST_TYPE
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#endif /* COMPEL_ELF64_TYPES_H__ */
#ifndef __ELFTIL_H__ #ifndef COMPEL_PIEGEN_H__
#define __ELFTIL_H__ #define COMPEL_PIEGEN_H__
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
...@@ -51,20 +51,4 @@ do { \ ...@@ -51,20 +51,4 @@ do { \
extern int handle_binary(void *mem, size_t size); extern int handle_binary(void *mem, size_t size);
static const unsigned char __maybe_unused #endif /* COMPEL_PIEGEN_H__ */
elf_ident_32[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char __maybe_unused
elf_ident_64_le[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char __maybe_unused
elf_ident_64_be[EI_NIDENT] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif /* __ELFTIL_H__ */
#ifndef __COMPEL_ELF32_TYPES_H__
#define __COMPEL_ELF32_TYPES_H__
#define Ehdr_t Elf32_Ehdr
#define Shdr_t Elf32_Shdr
#define Sym_t Elf32_Sym
#define Rel_t Elf32_Rel
#define Rela_t Elf32_Rela
#define Off_t Elf32_Off
#define Word_t Elf32_Word
#define Half_t Elf32_Half
#define ELF_ST_TYPE ELF32_ST_TYPE
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_R_SYM ELF32_R_SYM
#define ELF_R_TYPE ELF32_R_TYPE
#endif /* __COMPEL_ELF32_TYPES_H__ */
#ifndef __COMPEL_ELF64_TYPES_H__
#define __COMPEL_ELF64_TYPES_H__
#define Ehdr_t Elf64_Ehdr
#define Shdr_t Elf64_Shdr
#define Sym_t Elf64_Sym
#define Rel_t Elf64_Rel
#define Rela_t Elf64_Rela
#define Off_t Elf64_Off
#define Word_t Elf64_Word
#define Half_t Elf64_Half
#define ELF_ST_TYPE ELF64_ST_TYPE
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#endif /* __COMPEL_ELF64_TYPES_H__ */
#ifndef __PIEGEN_ERR_H__
#define __PIEGEN_ERR_H__
/* Error numbers for piegen. Success is 0, so errors should differ. */
#define E_UNKNOWN 1
#define E_NOMEM 2
#define E_NOT_ELF 3
#define E_NO_STR_SEC 4
#endif /* __PIEGEN_ERR_H__ */
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "version.h"
#include "piegen.h" #include "piegen.h"
static const char compel_cflags_pie[] = "-fpie -Wa,--noexecstack -fno-stack-protector"; static const char compel_cflags_pie[] = "-fpie -Wa,--noexecstack -fno-stack-protector";
......
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