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"