Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/iwasm/aot/aot_intrinsic.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static const aot_intrinsic g_intrinsic_mapping[] = {
{ "f64_convert_i64_u", "aot_intrinsic_u64_to_f64", AOT_INTRINSIC_FLAG_U64_TO_F64 },
{ "f32_convert_i64_s", "aot_intrinsic_i64_to_f32", AOT_INTRINSIC_FLAG_I64_TO_F32 },
{ "f32_convert_i64_u", "aot_intrinsic_u64_to_f32", AOT_INTRINSIC_FLAG_U64_TO_F32 },
{ "i32_trunc_f64_u", "aot_intrinsic_f64_to_u32", AOT_INTRINSIC_FLAG_I32_TO_F64 },
{ "i32_trunc_f64_u", "aot_intrinsic_f64_to_u32", AOT_INTRINSIC_FLAG_F64_TO_U32 },
{ "i32_trunc_f64_s", "aot_intrinsic_f64_to_i32", AOT_INTRINSIC_FLAG_F64_TO_I32 },
{ "f32_demote_f64", "aot_intrinsic_f64_to_f32", AOT_INTRINSIC_FLAG_F64_TO_F32 },
{ "f64_promote_f32", "aot_intrinsic_f32_to_f64", AOT_INTRINSIC_FLAG_F32_TO_F64 },
{ "f32_cmp", "aot_intrinsic_f32_cmp", AOT_INTRINSIC_FLAG_F32_CMP },
Expand Down
12 changes: 8 additions & 4 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static bool
check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
char *error_buf, uint32 error_buf_size)
{
if (buf + length > buf_end) {
if (buf + length < buf || buf + length > buf_end) {
set_error_buf(error_buf, error_buf_size, "unexpect end");
return false;
}
Expand Down Expand Up @@ -166,6 +166,7 @@ GET_U64_FROM_ADDR(uint32 *addr)
#define BIN_TYPE_ELF32B 1 /* 32-bit big endian */
#define BIN_TYPE_ELF64L 2 /* 64-bit little endian */
#define BIN_TYPE_ELF64B 3 /* 64-bit big endian */
#define BIN_TYPE_COFF32 4 /* 32-bit little endian */
#define BIN_TYPE_COFF64 6 /* 64-bit little endian */

/* Legal values for e_type (object file type). */
Expand All @@ -188,7 +189,8 @@ GET_U64_FROM_ADDR(uint32 *addr)
#define E_MACHINE_ARC_COMPACT2 195 /* Synopsys ARCompact V2 */
#define E_MACHINE_XTENSA 94 /* Tensilica Xtensa Architecture */
#define E_MACHINE_RISCV 243 /* RISC-V 32/64 */
#define E_MACHINE_WIN_X86_64 0x8664 /* Windowx x86-64 architecture */
#define E_MACHINE_WIN_I386 0x14c /* Windows i386 architecture */
#define E_MACHINE_WIN_X86_64 0x8664 /* Windows x86-64 architecture */

/* Legal values for e_version */
#define E_VERSION_CURRENT 1 /* Current version */
Expand Down Expand Up @@ -317,6 +319,7 @@ get_aot_file_target(AOTTargetInfo *target_info, char *target_buf,
machine_type = "x86_64";
break;
case E_MACHINE_386:
case E_MACHINE_WIN_I386:
machine_type = "i386";
break;
case E_MACHINE_ARM:
Expand Down Expand Up @@ -2038,7 +2041,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,

for (j = 0; j < relocation_count; j++) {
AOTRelocation relocation = { 0 };
uint32 symbol_index, offset32, addend32;
uint32 symbol_index, offset32;
int32 addend32;
uint16 symbol_name_len;
uint8 *symbol_name;

Expand All @@ -2050,7 +2054,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
read_uint32(buf, buf_end, offset32);
relocation.relocation_offset = (uint64)offset32;
read_uint32(buf, buf_end, addend32);
relocation.relocation_addend = (uint64)addend32;
relocation.relocation_addend = (int64)addend32;
}
read_uint32(buf, buf_end, relocation.relocation_type);
read_uint32(buf, buf_end, symbol_index);
Expand Down
8 changes: 5 additions & 3 deletions core/iwasm/aot/aot_reloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef struct {
REG_SYM(aot_intrinsic_i64_to_f64), \
REG_SYM(aot_intrinsic_u64_to_f64), \
REG_SYM(aot_intrinsic_f64_to_f32), \
REG_SYM(aot_intrinsic_f64_to_i32), \
REG_SYM(aot_intrinsic_f64_to_u32), \
REG_SYM(aot_intrinsic_f32_to_f64), \
REG_SYM(aot_intrinsic_f32_cmp), \
Expand All @@ -110,8 +111,9 @@ typedef struct {
REG_SYM(aot_call_indirect), \
REG_SYM(aot_enlarge_memory), \
REG_SYM(aot_set_exception), \
{"memset", (void*)aot_memset}, \
{"memmove", (void*)aot_memmove}, \
{ "memset", (void*)aot_memset }, \
{ "memmove", (void*)aot_memmove }, \
{ "memcpy", (void*)aot_memmove }, \
REG_SYM(fmin), \
REG_SYM(fminf), \
REG_SYM(fmax), \
Expand Down Expand Up @@ -152,7 +154,7 @@ get_current_target(char *target_buf, uint32 target_buf_size);
bool
apply_relocation(AOTModule *module,
uint8 *target_section_addr, uint32 target_section_size,
uint64 reloc_offset, uint64 reloc_addend,
uint64 reloc_offset, int64 reloc_addend,
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
char *error_buf, uint32 error_buf_size);
/* clang-format off */
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
}
}

heap_data = heap_data_old + (memory_data - memory_data_old);
heap_data = memory_data + (heap_data_old - memory_data_old);
memory_inst->heap_data.ptr = heap_data;
memory_inst->heap_data_end.ptr = heap_data + heap_size;

Expand Down
5 changes: 2 additions & 3 deletions core/iwasm/aot/aot_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ typedef struct AOTObjectDataSection {
/* Relocation info */
typedef struct AOTRelocation {
uint64 relocation_offset;
uint64 relocation_addend;
int64 relocation_addend;
uint32 relocation_type;
char *symbol_name;
/* index in the symbol offset field */
Expand Down Expand Up @@ -197,8 +197,7 @@ typedef struct AOTModule {
uint8 *literal;
uint32 literal_size;

#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \
&& defined(BH_PLATFORM_WINDOWS)
#if defined(BH_PLATFORM_WINDOWS)
/* extra plt data area for __xmm and __real constants
in Windows platform, NULL for JIT mode */
uint8 *extra_plt_data;
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/aot/arch/aot_reloc_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
bool
apply_relocation(AOTModule *module, uint8 *target_section_addr,
uint32 target_section_size, uint64 reloc_offset,
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
int64 reloc_addend, uint32 reloc_type, void *symbol_addr,
int32 symbol_index, char *error_buf, uint32 error_buf_size)
{
switch (reloc_type) {
Expand Down
9 changes: 5 additions & 4 deletions core/iwasm/aot/arch/aot_reloc_arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,16 @@ middle_endian_convert(uint32 insn)
bool
apply_relocation(AOTModule *module, uint8 *target_section_addr,
uint32 target_section_size, uint64 reloc_offset,
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
int64 reloc_addend, uint32 reloc_type, void *symbol_addr,
int32 symbol_index, char *error_buf, uint32 error_buf_size)
{
switch (reloc_type) {
case R_ARC_S25W_PCREL:
{
uint32 insn = LOAD_I32(target_section_addr + reloc_offset);
int32 addend, value;
uintptr_t S, A, P;
uintptr_t S, P;
intptr_t A;

CHECK_RELOC_OFFSET(sizeof(void *));

Expand All @@ -190,7 +191,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,

/* (S + A) - P */
S = (uintptr_t)(uint8 *)symbol_addr;
A = (uintptr_t)reloc_addend;
A = (intptr_t)reloc_addend;
P = (uintptr_t)(target_section_addr + reloc_offset);
P &= (uintptr_t)~3;
value = (int32)(S + A + addend - P);
Expand All @@ -214,7 +215,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
CHECK_RELOC_OFFSET(sizeof(void *));

/* (S + A) */
insn = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
insn = (uint32)((uintptr_t)symbol_addr + (intptr_t)reloc_addend);

if (reloc_type == R_ARC_32_ME)
/* Convert to middle endian */
Expand Down
Loading