[CRIU] [PATCH 1/3] compel: shuffle skeleton a bit

Dmitry Safonov dsafonov at virtuozzo.com
Fri Apr 29 12:47:53 PDT 2016


I propose to change compel directory structure:
- if we want support more arch's than x86/ppc66, it seems
  worth to add arch/ folder
- move all sources from src/ folder up
- to have headers and build additional object with CFLAGS for
  a symlink seems for me less hacky way than mess around
  with .c files cross-linking
- I made handle-elf.h header for arch helpers code. I may named
  that just "elf.h", but that may confuse, as there are <elf.h>
  system header
- I would like to drop those ELF_PPC64/ELF_X86_32/ELF_X86_64
  defines and use CONFIG_X86_64 and whatnot

After this patch compel directory become:
compel/
├── arch
│   ├── ppc64
│   │   └── include
│   │       └── handle-elf.h
│   └── x86
│       └── include
│           └── handle-elf.h
├── handle-elf-32.c -> handle-elf.c
├── handle-elf.c
├── include
│   ├── piegen.h
│   └── uapi
│       ├── elf32-types.h
│       ├── elf64-types.h
│       └── types.h
├── main.c
└── Makefile

Note: temporary I make value32 and addend32 for compilation on arm/aarch64

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 compel/Makefile                                    | 22 +++++++++++++++-------
 compel/arch/ppc64/include/handle-elf.h             |  9 +++++++++
 compel/arch/x86/include/handle-elf.h               | 18 ++++++++++++++++++
 compel/handle-elf-32.c                             |  1 +
 compel/{src/elf.c => handle-elf.c}                 |  3 ++-
 .../elf-x86-32.c => include/uapi/elf32-types.h}    |  6 +++---
 .../elf-ppc64.c => include/uapi/elf64-types.h}     |  6 +++---
 compel/{src => }/main.c                            |  0
 compel/src/elf-x86-64.c                            | 16 ----------------
 9 files changed, 51 insertions(+), 30 deletions(-)
 create mode 100644 compel/arch/ppc64/include/handle-elf.h
 create mode 100644 compel/arch/x86/include/handle-elf.h
 create mode 120000 compel/handle-elf-32.c
 rename compel/{src/elf.c => handle-elf.c} (99%)
 rename compel/{src/elf-x86-32.c => include/uapi/elf32-types.h} (71%)
 rename compel/{src/elf-ppc64.c => include/uapi/elf64-types.h} (71%)
 rename compel/{src => }/main.c (100%)
 delete mode 100644 compel/src/elf-x86-64.c

diff --git a/compel/Makefile b/compel/Makefile
index 96709c6c74f2..acba4c3bcb3f 100644
--- a/compel/Makefile
+++ b/compel/Makefile
@@ -2,6 +2,7 @@ include $(SRC_DIR)/Makefile.versions
 
 ccflags-y	+= -iquote criu/include
 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	+= $(ccflags-y)
@@ -9,12 +10,19 @@ HOSTCFLAGS	+= $(WARNINGS) $(DEFINES)
 HOSTLDFLAGS	+= $(LDFLAGS)
 
 hostprogs-y	+= compel
-compel-objs	+= src/main.o
+compel-objs	+= main.o
+compel-objs	+= handle-elf.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
+# Add $(DEFINES) to CFLAGS of compel-objs.
+# We can't do ccflags-y += $(DEFINES)
+# as we need to build handle-elf-32.o
+# with -DCONFIG_X86_32
+define ccflags-defines
+        HOSTCFLAGS_$(1) += $(DEFINES)
+endef
+$(eval $(call map,ccflags-defines,$(compel-objs)))
+
+ifeq ($(ARCH),x86)
+        compel-objs += handle-elf-32.o
+        HOSTCFLAGS_handle-elf-32.o += -DCONFIG_X86_32
 endif
diff --git a/compel/arch/ppc64/include/handle-elf.h b/compel/arch/ppc64/include/handle-elf.h
new file mode 100644
index 000000000000..203e91b651bd
--- /dev/null
+++ b/compel/arch/ppc64/include/handle-elf.h
@@ -0,0 +1,9 @@
+#ifndef __COMPEL_HANDLE_ELF_H__
+#define __COMPEL_HANDLE_ELF_H__
+
+#include "uapi/elf32-types.h"
+
+#define ELF_PPC64
+#define handle_elf	handle_elf_ppc64
+
+#endif /* __COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/x86/include/handle-elf.h b/compel/arch/x86/include/handle-elf.h
new file mode 100644
index 000000000000..75e3c3974771
--- /dev/null
+++ b/compel/arch/x86/include/handle-elf.h
@@ -0,0 +1,18 @@
+#ifndef __COMPEL_HANDLE_ELF_H__
+#define __COMPEL_HANDLE_ELF_H__
+
+#ifdef CONFIG_X86_32
+
+#include "uapi/elf32-types.h"
+#define ELF_X86_32
+#define handle_elf	handle_elf_x86_32
+
+#else /* CONFIG_X86_64 */
+
+#include "uapi/elf64-types.h"
+#define ELF_X86_64
+#define handle_elf	handle_elf_x86_64
+
+#endif
+
+#endif /* __COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/handle-elf-32.c b/compel/handle-elf-32.c
new file mode 120000
index 000000000000..fe4611886df8
--- /dev/null
+++ b/compel/handle-elf-32.c
@@ -0,0 +1 @@
+handle-elf.c
\ No newline at end of file
diff --git a/compel/src/elf.c b/compel/handle-elf.c
similarity index 99%
rename from compel/src/elf.c
rename to compel/handle-elf.c
index bd651770b58d..11f28ab5f18c 100644
--- a/compel/src/elf.c
+++ b/compel/handle-elf.c
@@ -16,6 +16,7 @@
 
 #include "compiler.h"
 #include "piegen.h"
+#include "handle-elf.h"
 
 static bool __ptr_oob(const void *ptr, const void *start, const size_t size)
 {
@@ -219,7 +220,7 @@ int handle_elf(void *mem, size_t size)
 
 		for (k = 0; k < sh->sh_size / sh->sh_entsize; k++) {
 			s64 __maybe_unused addend64, __maybe_unused value64;
-			s32 addend32, value32;
+			s32 __maybe_unused addend32, __maybe_unused value32;
 			unsigned long place;
 			const char *name;
 			void *where;
diff --git a/compel/src/elf-x86-32.c b/compel/include/uapi/elf32-types.h
similarity index 71%
rename from compel/src/elf-x86-32.c
rename to compel/include/uapi/elf32-types.h
index 413113ef396b..0a3b08a328fb 100644
--- a/compel/src/elf-x86-32.c
+++ b/compel/include/uapi/elf32-types.h
@@ -1,5 +1,5 @@
-#define ELF_X86_32
-#define handle_elf	handle_elf_x86_32
+#ifndef __COMPEL_ELF32_TYPES_H__
+#define __COMPEL_ELF32_TYPES_H__
 
 #define Ehdr_t		Elf32_Ehdr
 #define Shdr_t		Elf32_Shdr
@@ -13,4 +13,4 @@
 #define ELF_R_SYM	ELF32_R_SYM
 #define ELF_R_TYPE	ELF32_R_TYPE
 
-#include "elf.c"
+#endif /* __COMPEL_ELF32_TYPES_H__ */
diff --git a/compel/src/elf-ppc64.c b/compel/include/uapi/elf64-types.h
similarity index 71%
rename from compel/src/elf-ppc64.c
rename to compel/include/uapi/elf64-types.h
index 472725f9fe7c..31fcbdb06c71 100644
--- a/compel/src/elf-ppc64.c
+++ b/compel/include/uapi/elf64-types.h
@@ -1,5 +1,5 @@
-#define ELF_PPC64
-#define handle_elf	handle_elf_ppc64
+#ifndef __COMPEL_ELF64_TYPES_H__
+#define __COMPEL_ELF64_TYPES_H__
 
 #define Ehdr_t		Elf64_Ehdr
 #define Shdr_t		Elf64_Shdr
@@ -13,4 +13,4 @@
 #define ELF_R_SYM	ELF64_R_SYM
 #define ELF_R_TYPE	ELF64_R_TYPE
 
-#include "elf.c"
+#endif /* __COMPEL_ELF64_TYPES_H__ */
diff --git a/compel/src/main.c b/compel/main.c
similarity index 100%
rename from compel/src/main.c
rename to compel/main.c
diff --git a/compel/src/elf-x86-64.c b/compel/src/elf-x86-64.c
deleted file mode 100644
index 8ba26672bc82..000000000000
--- a/compel/src/elf-x86-64.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#define ELF_X86_64
-#define handle_elf	handle_elf_x86_64
-
-#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 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
-
-#include "elf.c"
-- 
2.8.0



More information about the CRIU mailing list