Add new E_TYPE_XIP to indicate XIP mode (#874)

Emit e_type = E_TYPE_XIP in target info section to indicate that it is
an XIP file, and replace related checks in aot loader.
This commit is contained in:
Huang Qi
2021-12-08 18:43:08 +08:00
committed by GitHub
parent 5fbf03fa6e
commit 208cafc776
7 changed files with 80 additions and 34 deletions

View File

@ -1909,6 +1909,9 @@ struct coff_hdr {
U16 u16Characs;
};
#define E_TYPE_REL 1
#define E_TYPE_XIP 4
#define IMAGE_FILE_MACHINE_AMD64 0x8664
#define IMAGE_FILE_MACHINE_I386 0x014c
#define IMAGE_FILE_MACHINE_IA64 0x0200
@ -2025,7 +2028,13 @@ aot_resolve_target_info(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
return false;
}
coff_header = (struct coff_hdr *)elf_buf;
obj_data->target_info.e_type = 1;
/* Emit eXecute In Place file type while in indirect mode */
if (comp_ctx->is_indirect_mode)
obj_data->target_info.e_type = E_TYPE_XIP;
else
obj_data->target_info.e_type = E_TYPE_REL;
obj_data->target_info.e_machine = coff_header->u16Machine;
obj_data->target_info.e_version = 1;
obj_data->target_info.e_flags = 0;
@ -2047,6 +2056,11 @@ aot_resolve_target_info(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
}
elf_header = (struct elf32_ehdr *)elf_buf;
/* Emit eXecute In Place file type while in indirect mode */
if (comp_ctx->is_indirect_mode)
elf_header->e_type = E_TYPE_XIP;
SET_TARGET_INFO(e_type, e_type, uint16, is_little_bin);
SET_TARGET_INFO(e_machine, e_machine, uint16, is_little_bin);
SET_TARGET_INFO(e_version, e_version, uint32, is_little_bin);
@ -2063,6 +2077,11 @@ aot_resolve_target_info(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
}
elf_header = (struct elf64_ehdr *)elf_buf;
/* Emit eXecute In Place file type while in indirect mode */
if (comp_ctx->is_indirect_mode)
elf_header->e_type = E_TYPE_XIP;
SET_TARGET_INFO(e_type, e_type, uint16, is_little_bin);
SET_TARGET_INFO(e_machine, e_machine, uint16, is_little_bin);
SET_TARGET_INFO(e_version, e_version, uint32, is_little_bin);