From 427f68f0a3033d608e44cadb6e21799ce456293c Mon Sep 17 00:00:00 2001 From: Dmitry Safonov Date: Fri, 29 Apr 2016 22:47:00 +0300 Subject: [PATCH] compel: shuffle skeleton a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 Signed-off-by: Dmitry Safonov Acked-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- 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 ++- .../uapi/elf32-types.h} | 6 ++--- .../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 5e4bd7b76..d08e470df 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 += $(filter-out -pg $(CFLAGS-GCOV),$(ccflags-y)) @@ -9,12 +10,19 @@ HOSTCFLAGS += $(filter-out -pg $(CFLAGS-GCOV),$(WARNINGS) $(DEFINES)) HOSTLDFLAGS += $(filter-out -pg $(CFLAGS-GCOV),$(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 000000000..203e91b65 --- /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 000000000..75e3c3974 --- /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 000000000..fe4611886 --- /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 37c8a36ee..089c9284d 100644 --- a/compel/src/elf.c +++ b/compel/handle-elf.c @@ -16,6 +16,7 @@ #include "common/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 413113ef3..0a3b08a32 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 472725f9f..31fcbdb06 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 8ba26672b..000000000 --- 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"