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))
.PHONY: .FORCE
#
# Compel get used by CRIU, build it earlier
compel/%: .FORCE
$(Q) $(MAKE) $(build)=compel $@
test/compel/%: .FORCE
$(Q) $(MAKE) $(build)=compel $@
include Makefile.compel
#
# Next the socket CR library
......@@ -269,6 +266,7 @@ mrproper: subclean
$(Q) $(RM) $(CONFIG_HEADER)
$(Q) $(RM) $(SOCCR_CONFIG)
$(Q) $(RM) $(VERSION_HEADER)
$(Q) $(RM) $(COMPEL_VERSION_HEADER)
$(Q) $(RM) include/common/asm
$(Q) $(RM) cscope.*
$(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
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))
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)))
.PHONY: .FORCE
compel-objs += handle-elf-32.o
export HOSTCFLAGS_handle-elf-32.o += -DCONFIG_X86_32
endif # ARCH == x86
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))
COMPEL_SO_VERSION_CODE := $(shell expr $(COMPEL_SO_VERSION_MAJOR) \* 65536 \+ $(COMPEL_SO_VERSION_MINOR) \* 256 \+ $(COMPEL_SO_VERSION_SUBLEVEL))
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
test/compel/%: .FORCE
$(Q) $(MAKE) $(build)=test/compel $@
obj-y += src/main.o
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 "piegen.h"
#include "uapi/piegen-err.h"
#include "uapi/compel.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)
{
......@@ -17,5 +30,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_aarch64(mem, size);
pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF;
return -EINVAL;
}
#ifndef __COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__
#ifndef 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 arch_is_machine_supported(e_machine) (e_machine == EM_AARCH64)
extern int handle_elf_aarch64(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */
#endif /* COMPEL_HANDLE_ELF_H__ */
#include <string.h>
#include "piegen.h"
#include "uapi/piegen-err.h"
#include "uapi/compel.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)
{
......@@ -10,5 +17,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_arm(mem, size);
pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF;
return -EINVAL;
}
#ifndef __COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__
#ifndef 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 arch_is_machine_supported(e_machine) (e_machine == EM_ARM)
extern int handle_elf_arm(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */
#endif /* COMPEL_HANDLE_ELF_H__ */
#include <string.h>
#include "piegen.h"
#include "uapi/piegen-err.h"
#include "uapi/compel.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)
{
......@@ -17,5 +30,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_ppc64(mem, size);
pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF;
return -EINVAL;
}
#ifndef __COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__
#ifndef COMPEL_HANDLE_ELF_H__
#define COMPEL_HANDLE_ELF_H__
#include "uapi/elf64-types.h"
#include "elf64-types.h"
#define ELF_PPC64
#define __handle_elf handle_elf_ppc64
#define arch_is_machine_supported(e_machine) (e_machine == EM_PPC64)
extern int handle_elf_ppc64(void *mem, size_t size);
#endif /* __COMPEL_HANDLE_ELF_H__ */
#endif /* COMPEL_HANDLE_ELF_H__ */
#include <string.h>
#include "piegen.h"
#include "uapi/piegen-err.h"
#include "uapi/compel.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)
{
......@@ -12,5 +25,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_x86_64(mem, size);
pr_err("Unsupported Elf format detected\n");
return -E_NOT_ELF;
return -EINVAL;
}
#ifndef __COMPEL_HANDLE_ELF_H__
#define __COMPEL_HANDLE_ELF_H__
#ifndef COMPEL_HANDLE_ELF_H__
#define COMPEL_HANDLE_ELF_H__
#ifdef CONFIG_X86_32
#include "uapi/elf32-types.h"
#include "elf32-types.h"
#define ELF_X86_32
#define __handle_elf handle_elf_x86_32
#define arch_is_machine_supported(e_machine) (e_machine == EM_386)
#else /* CONFIG_X86_64 */
#include "uapi/elf64-types.h"
#include "elf64-types.h"
#define ELF_X86_64
#define __handle_elf handle_elf_x86_64
#define arch_is_machine_supported(e_machine) (e_machine == EM_X86_64)
......@@ -20,4 +24,4 @@
extern int handle_elf_x86_32(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__
#define __ELFTIL_H__
#ifndef COMPEL_PIEGEN_H__
#define COMPEL_PIEGEN_H__
#include <stdio.h>
#include <unistd.h>
......@@ -51,20 +51,4 @@ do { \
extern int handle_binary(void *mem, size_t size);
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,
};
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__ */
#endif /* COMPEL_PIEGEN_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__ */
......@@ -11,16 +11,15 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include "uapi/compel.h"
#include "asm-generic/int.h"
#include "uapi/piegen-err.h"
#include "piegen.h"
#include "handle-elf.h"
#include "piegen.h"
/* TODO: merge with util-vdso.c part in criu header */
/* Check if pointer is out-of-bound */
static bool
__ptr_oob(const uintptr_t ptr, const uintptr_t start, const size_t size)
static bool __ptr_oob(const uintptr_t ptr, const uintptr_t start, const size_t size)
{
uintptr_t end = start + size;
......@@ -73,7 +72,8 @@ static int do_relative_toc(long value, uint16_t *location,
}
if ((~mask & 0xffff) & value) {
pr_err("bad TOC16 relocation (%ld) (0x%lx)\n", value, (~mask & 0xffff) & value);
pr_err("bad TOC16 relocation (%ld) (0x%lx)\n",
value, (~mask & 0xffff) & value);
return -1;
}
......@@ -82,7 +82,7 @@ static int do_relative_toc(long value, uint16_t *location,
}
#endif
static bool is_header_supported(Ehdr_t *hdr)
static bool is_header_supported(Elf_Ehdr *hdr)
{
if (!arch_is_machine_supported(hdr->e_machine))
return false;
......@@ -91,11 +91,11 @@ static bool is_header_supported(Ehdr_t *hdr)
return true;
}
static const char *get_strings_section(Ehdr_t *hdr, uintptr_t mem, size_t size)
static const char *get_strings_section(Elf_Ehdr *hdr, uintptr_t mem, size_t size)
{
size_t sec_table_size = ((size_t) hdr->e_shentsize) * hdr->e_shnum;
uintptr_t sec_table = mem + hdr->e_shoff;
Shdr_t *secstrings_hdr;
Elf_Shdr *secstrings_hdr;
uintptr_t addr;
if (__ptr_struct_oob(sec_table, sec_table_size, mem, size)) {
......@@ -109,7 +109,7 @@ static const char *get_strings_section(Ehdr_t *hdr, uintptr_t mem, size_t size)
* (size of section header * index of string section header)
*/
addr = sec_table + ((size_t) hdr->e_shentsize) * hdr->e_shstrndx;
if (__ptr_struct_oob(addr, sizeof(Shdr_t),
if (__ptr_struct_oob(addr, sizeof(Elf_Shdr),
sec_table, sec_table + sec_table_size)) {
pr_err("String section header @%#zx is out of [%#zx, %#zx)\n",
addr, sec_table, sec_table + sec_table_size);
......@@ -128,51 +128,55 @@ static const char *get_strings_section(Ehdr_t *hdr, uintptr_t mem, size_t size)
return (void*)addr;
}
/*
* This name @__handle_elf get renamed into
* @handle_elf_ppc64 or say @handle_elf_x86_64
* depending on the architecture it's compiled
* under.
*/
int __handle_elf(void *mem, size_t size)
{
const char *symstrings = NULL;
Shdr_t *symtab_hdr = NULL;
Sym_t *symbols = NULL;
Ehdr_t *hdr = mem;
Elf_Shdr *symtab_hdr = NULL;
Elf_Sym *symbols = NULL;
Elf_Ehdr *hdr = mem;
Shdr_t *strtab_hdr = NULL;
Shdr_t **sec_hdrs = NULL;
Elf_Shdr *strtab_hdr = NULL;
Elf_Shdr **sec_hdrs = NULL;
const char *secstrings;
size_t i, k, nr_gotpcrel = 0;
#ifdef ELF_PPC64
s64 toc_offset = 0;
#endif
int ret = -E_UNKNOWN;
int ret = -EINVAL;
pr_debug("Header\n");
pr_debug("------------\n");
pr_debug("\ttype 0x%x machine 0x%x version 0x%x\n",
(unsigned)hdr->e_type, (unsigned)hdr->e_machine, (unsigned)hdr->e_version);
(unsigned)hdr->e_type, (unsigned)hdr->e_machine,
(unsigned)hdr->e_version);
if (!is_header_supported(hdr)) {
pr_err("Unsupported header detected\n");
ret = -E_NOT_ELF;
goto err;
}
sec_hdrs = malloc(sizeof(*sec_hdrs) * hdr->e_shnum);
if (!sec_hdrs) {
pr_err("No memory for section headers\n");
ret = -E_NOMEM;
ret = -ENOMEM;
goto err;
}
secstrings = get_strings_section(hdr, (uintptr_t)mem, size);
if (!secstrings) {
ret = -E_NO_STR_SEC;
if (!secstrings)
goto err;
}
pr_debug("Sections\n");
pr_debug("------------\n");
for (i = 0; i < hdr->e_shnum; i++) {
Shdr_t *sh = mem + hdr->e_shoff + hdr->e_shentsize * i;
Elf_Shdr *sh = mem + hdr->e_shoff + hdr->e_shentsize * i;
ptr_func_exit(sh);
if (sh->sh_type == SHT_SYMTAB)
......@@ -221,9 +225,9 @@ int __handle_elf(void *mem, size_t size)
pr_out("#include \"%s/types.h\"\n", opts.uapi_dir);
for (i = 0; i < symtab_hdr->sh_size / symtab_hdr->sh_entsize; i++) {
Sym_t *sym = &symbols[i];
Elf_Sym *sym = &symbols[i];
const char *name;
Shdr_t *sh_src;
Elf_Shdr *sh_src;
ptr_func_exit(sym);
name = &symstrings[sym->st_name];
......@@ -245,7 +249,8 @@ int __handle_elf(void *mem, size_t size)
#endif
if (strncmp(name, "__export", 8))
continue;
if ((sym->st_shndx && sym->st_shndx < hdr->e_shnum) || sym->st_shndx == SHN_ABS) {
if ((sym->st_shndx && sym->st_shndx < hdr->e_shnum) ||
sym->st_shndx == SHN_ABS) {
if (sym->st_shndx == SHN_ABS) {
sh_src = NULL;
} else {
......@@ -254,7 +259,8 @@ int __handle_elf(void *mem, size_t size)
}
pr_out("#define %s%s 0x%lx\n",
opts.prefix_name, name,
(unsigned long)(sym->st_value + (sh_src ? sh_src->sh_addr : 0)));
(unsigned long)(sym->st_value +
(sh_src ? sh_src->sh_addr : 0)));
}
}
}
......@@ -264,8 +270,8 @@ int __handle_elf(void *mem, size_t size)
pr_debug("Relocations\n");
pr_debug("------------\n");
for (i = 0; i < hdr->e_shnum; i++) {
Shdr_t *sh = sec_hdrs[i];
Shdr_t *sh_rel;
Elf_Shdr *sh = sec_hdrs[i];
Elf_Shdr *sh_rel;
if (sh->sh_type != SHT_REL && sh->sh_type != SHT_RELA)
continue;
......@@ -283,11 +289,11 @@ int __handle_elf(void *mem, size_t size)
unsigned long place;
const char *name;
void *where;
Sym_t *sym;
Elf_Sym *sym;
union {
Rel_t rel;
Rela_t rela;
Elf_Rel rel;
Elf_Rela rela;
} *r = mem + sh->sh_offset + sh->sh_entsize * k;
ptr_func_exit(r);
......@@ -341,7 +347,7 @@ int __handle_elf(void *mem, size_t size)
value32 = (s32)sym->st_value;
value64 = (s64)sym->st_value;
} else {
Shdr_t *sh_src;
Elf_Shdr *sh_src;
if ((unsigned)sym->st_shndx > (unsigned)hdr->e_shnum) {
pr_err("Unexpected symbol section index %u/%u\n",
......@@ -356,7 +362,9 @@ int __handle_elf(void *mem, size_t size)
}
#ifdef ELF_PPC64
/* Snippet from the OpenPOWER ABI for Linux Supplement:
/*
* Snippet from the OpenPOWER ABI for Linux Supplement:
*
* The OpenPOWER ABI uses the three most-significant bits in the symbol
* st_other field specifies the number of instructions between a function's
* global entry point and local entry point. The global entry point is used
......@@ -364,6 +372,7 @@ int __handle_elf(void *mem, size_t size)
* local entry point is used when r2 is known to already be valid for the
* function. A value of zero in these bits asserts that the function does
* not use r2.
*
* The st_other values have the following meanings:
* 0 and 1, the local and global entry points are the same.
* 2, the local entry point is at 1 instruction past the global entry point.
......@@ -408,7 +417,7 @@ int __handle_elf(void *mem, size_t size)
case R_PPC64_ADDR32:
pr_debug("\t\t\tR_PPC64_ADDR32 at 0x%-4lx val 0x%x\n",
place, (unsigned int)(value32 + addend32));
pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_INT, "
pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, "
" .addend = %-8d, .value = 0x%-16x, "
"}, /* R_PPC64_ADDR32 */\n",
(unsigned int) place, addend32, value32);
......@@ -418,7 +427,7 @@ int __handle_elf(void *mem, size_t size)
case R_PPC64_REL64:
pr_debug("\t\t\tR_PPC64_ADDR64 at 0x%-4lx val 0x%lx\n",
place, value64 + addend64);
pr_out("\t{ .offset = 0x%-8x, .type = PIEGEN_TYPE_LONG,"
pr_out("\t{ .offset = 0x%-8x, .type = COMPEL_TYPE_LONG,"
" .addend = %-8ld, .value = 0x%-16lx, "
"}, /* R_PPC64_ADDR64 */\n",
(unsigned int) place, (long)addend64, (long)value64);
......@@ -478,13 +487,13 @@ int __handle_elf(void *mem, size_t size)
case R_X86_64_32: /* Symbol + Addend (4 bytes) */
case R_X86_64_32S: /* Symbol + Addend (4 bytes) */
pr_debug("\t\t\t\tR_X86_64_32 at 0x%-4lx val 0x%x\n", place, value32);
pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_INT, "
pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, "
".addend = %-8d, .value = 0x%-16x, }, /* R_X86_64_32 */\n",
(unsigned int)place, addend32, value32);
break;
case R_X86_64_64: /* Symbol + Addend (8 bytes) */
pr_debug("\t\t\t\tR_X86_64_64 at 0x%-4lx val 0x%lx\n", place, (long)value64);
pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_LONG, "
pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_LONG, "
".addend = %-8ld, .value = 0x%-16lx, }, /* R_X86_64_64 */\n",
(unsigned int)place, (long)addend64, (long)value64);
break;
......@@ -504,7 +513,7 @@ int __handle_elf(void *mem, size_t size)
break;
case R_X86_64_GOTPCREL: /* SymbolOffsetInGot + GOT + Addend - Place (4 bytes) */
pr_debug("\t\t\t\tR_X86_64_GOTPCREL at 0x%-4lx val 0x%x\n", place, value32);
pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_LONG | PIEGEN_TYPE_GOTPCREL, "
pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_LONG | COMPEL_TYPE_GOTPCREL, "
".addend = %-8d, .value = 0x%-16x, }, /* R_X86_64_GOTPCREL */\n",
(unsigned int)place, addend32, value32);
nr_gotpcrel++;
......@@ -514,7 +523,7 @@ int __handle_elf(void *mem, size_t size)
#ifdef ELF_X86_32
case R_386_32: /* Symbol + Addend */
pr_debug("\t\t\t\tR_386_32 at 0x%-4lx val 0x%x\n", place, value32 + addend32);
pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_INT, "
pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, "
".addend = %-4d, .value = 0x%x, },\n",
(unsigned int)place, addend32, value32);
break;
......@@ -539,8 +548,8 @@ int __handle_elf(void *mem, size_t size)
pr_out("static __maybe_unused const char %s[] = {\n\t", opts.stream_name);
for (i=0, k=0; i < hdr->e_shnum; i++) {
Shdr_t *sh = sec_hdrs[i];
for (i = 0, k = 0; i < hdr->e_shnum; i++) {
Elf_Shdr *sh = sec_hdrs[i];
unsigned char *shdata;
size_t j;
......@@ -548,19 +557,19 @@ int __handle_elf(void *mem, size_t size)
continue;
shdata = mem + sh->sh_offset;
pr_debug("Copying section '%s'\n" \
pr_debug("Copying section '%s'\n"
"\tstart:0x%lx (gap:0x%lx) size:0x%lx\n",
&secstrings[sh->sh_name], (unsigned long) sh->sh_addr,
(unsigned long)(sh->sh_addr - k), (unsigned long) sh->sh_size);
/* write 0 in the gap between the 2 sections */
for (;k < sh->sh_addr; k++) {
for (; k < sh->sh_addr; k++) {
if (k && (k % 8) == 0)
pr_out("\n\t");
pr_out("0x00,");
}
for (j=0; j < sh->sh_size; j++, k++) {
for (j = 0; j < sh->sh_size; j++, k++) {
if (k && (k % 8) == 0)
pr_out("\n\t");
pr_out("%#02x,", shdata[j]);
......
......@@ -12,6 +12,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include "version.h"
#include "piegen.h"
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