Apply clang-format for more src files and update spec test script (#775)
Apply clang-format for core/iwasm/include, core/iwasm/common and core/iwasm/aot files. Update spec cases test script: - Checkout latest commit of https://github.com/WebAssembly/spec - Checkout main branch but not master of https://github.com/WebAssembly/threads - Update wabt to latest version And update source debugging document. Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
@ -11,43 +11,30 @@ typedef struct {
|
||||
uint64 flag;
|
||||
} aot_intrinsic;
|
||||
|
||||
/* clang-format off */
|
||||
static const aot_intrinsic g_intrinsic_mapping[] = {
|
||||
{ "llvm.experimental.constrained.fadd.f32", "aot_intrinsic_fadd_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FADD },
|
||||
{ "llvm.experimental.constrained.fadd.f64", "aot_intrinsic_fadd_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FADD },
|
||||
{ "llvm.experimental.constrained.fsub.f32", "aot_intrinsic_fsub_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FSUB },
|
||||
{ "llvm.experimental.constrained.fsub.f64", "aot_intrinsic_fsub_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FSUB },
|
||||
{ "llvm.experimental.constrained.fmul.f32", "aot_intrinsic_fmul_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FMUL },
|
||||
{ "llvm.experimental.constrained.fmul.f64", "aot_intrinsic_fmul_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FMUL },
|
||||
{ "llvm.experimental.constrained.fdiv.f32", "aot_intrinsic_fdiv_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FDIV },
|
||||
{ "llvm.experimental.constrained.fdiv.f64", "aot_intrinsic_fdiv_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FDIV },
|
||||
{ "llvm.experimental.constrained.fadd.f32", "aot_intrinsic_fadd_f32", AOT_INTRINSIC_FLAG_F32_FADD },
|
||||
{ "llvm.experimental.constrained.fadd.f64", "aot_intrinsic_fadd_f64", AOT_INTRINSIC_FLAG_F64_FADD },
|
||||
{ "llvm.experimental.constrained.fsub.f32", "aot_intrinsic_fsub_f32", AOT_INTRINSIC_FLAG_F32_FSUB },
|
||||
{ "llvm.experimental.constrained.fsub.f64", "aot_intrinsic_fsub_f64", AOT_INTRINSIC_FLAG_F64_FSUB },
|
||||
{ "llvm.experimental.constrained.fmul.f32", "aot_intrinsic_fmul_f32", AOT_INTRINSIC_FLAG_F32_FMUL },
|
||||
{ "llvm.experimental.constrained.fmul.f64", "aot_intrinsic_fmul_f64", AOT_INTRINSIC_FLAG_F64_FMUL },
|
||||
{ "llvm.experimental.constrained.fdiv.f32", "aot_intrinsic_fdiv_f32", AOT_INTRINSIC_FLAG_F32_FDIV },
|
||||
{ "llvm.experimental.constrained.fdiv.f64", "aot_intrinsic_fdiv_f64", AOT_INTRINSIC_FLAG_F64_FDIV },
|
||||
{ "llvm.fabs.f32", "aot_intrinsic_fabs_f32", AOT_INTRINSIC_FLAG_F32_FABS },
|
||||
{ "llvm.fabs.f64", "aot_intrinsic_fabs_f64", AOT_INTRINSIC_FLAG_F64_FABS },
|
||||
{ "llvm.ceil.f32", "aot_intrinsic_ceil_f32", AOT_INTRINSIC_FLAG_F32_CEIL },
|
||||
{ "llvm.ceil.f64", "aot_intrinsic_ceil_f64", AOT_INTRINSIC_FLAG_F64_CEIL },
|
||||
{ "llvm.floor.f32", "aot_intrinsic_floor_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FLOOR },
|
||||
{ "llvm.floor.f64", "aot_intrinsic_floor_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FLOOR },
|
||||
{ "llvm.trunc.f32", "aot_intrinsic_trunc_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_TRUNC },
|
||||
{ "llvm.trunc.f64", "aot_intrinsic_trunc_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_TRUNC },
|
||||
{ "llvm.floor.f32", "aot_intrinsic_floor_f32", AOT_INTRINSIC_FLAG_F32_FLOOR },
|
||||
{ "llvm.floor.f64", "aot_intrinsic_floor_f64", AOT_INTRINSIC_FLAG_F64_FLOOR },
|
||||
{ "llvm.trunc.f32", "aot_intrinsic_trunc_f32", AOT_INTRINSIC_FLAG_F32_TRUNC },
|
||||
{ "llvm.trunc.f64", "aot_intrinsic_trunc_f64", AOT_INTRINSIC_FLAG_F64_TRUNC },
|
||||
{ "llvm.rint.f32", "aot_intrinsic_rint_f32", AOT_INTRINSIC_FLAG_F32_RINT },
|
||||
{ "llvm.rint.f64", "aot_intrinsic_rint_f64", AOT_INTRINSIC_FLAG_F64_RINT },
|
||||
{ "llvm.sqrt.f32", "aot_intrinsic_sqrt_f32", AOT_INTRINSIC_FLAG_F32_SQRT },
|
||||
{ "llvm.sqrt.f64", "aot_intrinsic_sqrt_f64", AOT_INTRINSIC_FLAG_F64_SQRT },
|
||||
{ "llvm.copysign.f32", "aot_intrinsic_copysign_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_COPYSIGN },
|
||||
{ "llvm.copysign.f64", "aot_intrinsic_copysign_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_COPYSIGN },
|
||||
{ "llvm.copysign.f32", "aot_intrinsic_copysign_f32", AOT_INTRINSIC_FLAG_F32_COPYSIGN },
|
||||
{ "llvm.copysign.f64", "aot_intrinsic_copysign_f64", AOT_INTRINSIC_FLAG_F64_COPYSIGN },
|
||||
{ "llvm.minnum.f32", "aot_intrinsic_fmin_f32", AOT_INTRINSIC_FLAG_F32_MIN },
|
||||
{ "llvm.minnum.f64", "aot_intrinsic_fmin_f64", AOT_INTRINSIC_FLAG_F64_MIN },
|
||||
{ "llvm.maxnum.f32", "aot_intrinsic_fmax_f32", AOT_INTRINSIC_FLAG_F32_MAX },
|
||||
@ -58,23 +45,24 @@ static const aot_intrinsic g_intrinsic_mapping[] = {
|
||||
{ "llvm.cttz.i64", "aot_intrinsic_ctz_i64", AOT_INTRINSIC_FLAG_I64_CTZ },
|
||||
{ "llvm.ctpop.i32", "aot_intrinsic_popcnt_i32", AOT_INTRINSIC_FLAG_I32_POPCNT },
|
||||
{ "llvm.ctpop.i64", "aot_intrinsic_popcnt_i64", AOT_INTRINSIC_FLAG_I64_POPCNT },
|
||||
{ "f64_convert_i32_s", "aot_intrinsic_i32_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64},
|
||||
{ "f64_convert_i32_u", "aot_intrinsic_u32_to_f64", AOT_INTRINSIC_FLAG_U32_TO_F64},
|
||||
{ "f32_convert_i32_s", "aot_intrinsic_i32_to_f32", AOT_INTRINSIC_FLAG_I32_TO_F32},
|
||||
{ "f32_convert_i32_u", "aot_intrinsic_u32_to_f32", AOT_INTRINSIC_FLAG_U32_TO_F32},
|
||||
{ "f64_convert_i64_s", "aot_intrinsic_i64_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64},
|
||||
{ "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},
|
||||
{ "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},
|
||||
{ "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP},
|
||||
{ "f64_convert_i32_s", "aot_intrinsic_i32_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64 },
|
||||
{ "f64_convert_i32_u", "aot_intrinsic_u32_to_f64", AOT_INTRINSIC_FLAG_U32_TO_F64 },
|
||||
{ "f32_convert_i32_s", "aot_intrinsic_i32_to_f32", AOT_INTRINSIC_FLAG_I32_TO_F32 },
|
||||
{ "f32_convert_i32_u", "aot_intrinsic_u32_to_f32", AOT_INTRINSIC_FLAG_U32_TO_F32 },
|
||||
{ "f64_convert_i64_s", "aot_intrinsic_i64_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64 },
|
||||
{ "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 },
|
||||
{ "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 },
|
||||
{ "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP },
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const uint32 g_intrinsic_count =
|
||||
sizeof(g_intrinsic_mapping) / sizeof(aot_intrinsic);
|
||||
sizeof(g_intrinsic_mapping) / sizeof(aot_intrinsic);
|
||||
|
||||
float32
|
||||
aot_intrinsic_fadd_f32(float32 a, float32 b)
|
||||
@ -223,7 +211,7 @@ float64
|
||||
aot_intrinsic_fmin_f64(float64 a, float64 b)
|
||||
{
|
||||
float64 c = fmin(a, b);
|
||||
if (c==0 && a==b)
|
||||
if (c == 0 && a == b)
|
||||
return signbit(a) ? a : b;
|
||||
return c;
|
||||
}
|
||||
@ -243,7 +231,7 @@ float64
|
||||
aot_intrinsic_fmax_f64(float64 a, float64 b)
|
||||
{
|
||||
float64 c = fmax(a, b);
|
||||
if (c==0 && a==b)
|
||||
if (c == 0 && a == b)
|
||||
return signbit(a) ? b : a;
|
||||
return c;
|
||||
}
|
||||
@ -600,7 +588,8 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
|
||||
return;
|
||||
|
||||
if (!strncmp(comp_ctx->target_arch, "thumb", 5)) {
|
||||
if (!strcmp(comp_ctx->target_cpu, "cortex-m7")) {}
|
||||
if (!strcmp(comp_ctx->target_cpu, "cortex-m7")) {
|
||||
}
|
||||
else if (!strcmp(comp_ctx->target_cpu, "cortex-m4")) {
|
||||
add_f64_common_intrinsics(comp_ctx);
|
||||
}
|
||||
@ -611,7 +600,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
|
||||
}
|
||||
}
|
||||
else if (!strncmp(comp_ctx->target_arch, "riscv", 5)) {
|
||||
/*
|
||||
/*
|
||||
* Note: Use builtin intrinsics since hardware float operation
|
||||
* will cause rodata relocation
|
||||
*/
|
||||
|
||||
@ -22,14 +22,15 @@ extern "C" {
|
||||
* - The lower 48 bits are the intrinsic capability mask
|
||||
*/
|
||||
|
||||
#define AOT_INTRINSIC_FLAG(group, number) \
|
||||
#define AOT_INTRINSIC_FLAG(group, number) \
|
||||
((((uint64)(group & 0xffffLL)) << 48) | ((uint64)1 << number))
|
||||
|
||||
#define AOT_INTRINSIC_FLAG_MASK (0x0000ffffffffffffLL)
|
||||
|
||||
#define AOT_INTRINSIC_GET_GROUP_FROM_FLAG(flag) \
|
||||
#define AOT_INTRINSIC_GET_GROUP_FROM_FLAG(flag) \
|
||||
((((uint64)flag) >> 48) & 0xffffLL)
|
||||
|
||||
/* clang-format off */
|
||||
#define AOT_INTRINSIC_FLAG_F32_FADD AOT_INTRINSIC_FLAG(0, 0)
|
||||
#define AOT_INTRINSIC_FLAG_F32_FSUB AOT_INTRINSIC_FLAG(0, 1)
|
||||
#define AOT_INTRINSIC_FLAG_F32_FMUL AOT_INTRINSIC_FLAG(0, 2)
|
||||
@ -83,6 +84,7 @@ extern "C" {
|
||||
#define AOT_INTRINSIC_FLAG_F64_TO_U64 AOT_INTRINSIC_FLAG(1, 23)
|
||||
#define AOT_INTRINSIC_FLAG_F64_TO_F32 AOT_INTRINSIC_FLAG(1, 24)
|
||||
#define AOT_INTRINSIC_FLAG_F64_CMP AOT_INTRINSIC_FLAG(1, 25)
|
||||
/* clang-format on */
|
||||
|
||||
float32
|
||||
aot_intrinsic_fadd_f32(float32 a, float32 b);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -3,15 +3,23 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _AOT_RELOC_H_
|
||||
#define _AOT_RELOC_H_
|
||||
|
||||
#include "aot_runtime.h"
|
||||
#include "aot_intrinsic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const char *symbol_name;
|
||||
void *symbol_addr;
|
||||
} SymbolMap;
|
||||
|
||||
#define REG_SYM(symbol) { #symbol, (void*)symbol }
|
||||
/* clang-format off */
|
||||
#define REG_SYM(symbol) { #symbol, (void *)symbol }
|
||||
|
||||
#if WASM_ENABLE_BULK_MEMORY != 0
|
||||
#define REG_BULK_MEMORY_SYM() \
|
||||
@ -122,10 +130,11 @@ typedef struct {
|
||||
REG_AOT_TRACE_SYM() \
|
||||
REG_INTRINSIC_SYM() \
|
||||
|
||||
#define CHECK_RELOC_OFFSET(data_size) do { \
|
||||
if (!check_reloc_offset(target_section_size, reloc_offset, data_size, \
|
||||
error_buf, error_buf_size)) \
|
||||
return false; \
|
||||
#define CHECK_RELOC_OFFSET(data_size) do { \
|
||||
if (!check_reloc_offset(target_section_size, \
|
||||
reloc_offset, data_size, \
|
||||
error_buf, error_buf_size)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
SymbolMap *
|
||||
@ -146,4 +155,10 @@ apply_relocation(AOTModule *module,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _AOT_RELOC_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -95,6 +95,7 @@ typedef struct AOTFunctionInstance {
|
||||
} AOTFunctionInstance;
|
||||
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
||||
/* clang-format off */
|
||||
typedef struct AOTUnwindInfo {
|
||||
uint8 Version : 3;
|
||||
uint8 Flags : 5;
|
||||
@ -111,6 +112,7 @@ typedef struct AOTUnwindInfo {
|
||||
uint16 FrameOffset;
|
||||
} UnwindCode[1];
|
||||
} AOTUnwindInfo;
|
||||
/* clang-format on */
|
||||
|
||||
/* size of mov instruction and jmp instruction */
|
||||
#define PLT_ITEM_SIZE 12
|
||||
@ -328,7 +330,7 @@ typedef struct AOTModuleInstance {
|
||||
* TODO: for now we treate imported table like a local table
|
||||
*/
|
||||
uint32 table_count;
|
||||
/* points to global_data */
|
||||
/* points to global_data */
|
||||
AOTPointer global_data;
|
||||
/* points to AOTTableInstance[] */
|
||||
AOTPointer tables;
|
||||
@ -373,15 +375,15 @@ typedef struct AOTModuleInstance {
|
||||
/* reserved */
|
||||
uint32 reserved[6];
|
||||
|
||||
/*
|
||||
* +------------------------------+ <-- memories.ptr
|
||||
* | #0 AOTMemoryInstance
|
||||
* +------------------------------+ <-- global_data.ptr
|
||||
* | global data
|
||||
* +------------------------------+ <-- tables.ptr
|
||||
* | AOTTableInstance[table_count]
|
||||
* +------------------------------+
|
||||
*/
|
||||
/*
|
||||
* +------------------------------+ <-- memories.ptr
|
||||
* | #0 AOTMemoryInstance
|
||||
* +------------------------------+ <-- global_data.ptr
|
||||
* | global data
|
||||
* +------------------------------+ <-- tables.ptr
|
||||
* | AOTTableInstance[table_count]
|
||||
* +------------------------------+
|
||||
*/
|
||||
union {
|
||||
uint64 _make_it_8_byte_aligned_;
|
||||
AOTMemoryInstance memory_instances[1];
|
||||
@ -409,8 +411,7 @@ typedef struct AOTTargetInfo {
|
||||
char arch[16];
|
||||
} AOTTargetInfo;
|
||||
|
||||
typedef struct AOTFuncPerfProfInfo
|
||||
{
|
||||
typedef struct AOTFuncPerfProfInfo {
|
||||
/* total execution time */
|
||||
uint64 total_exec_time;
|
||||
/* total execution count */
|
||||
@ -436,9 +437,9 @@ typedef struct AOTFrame {
|
||||
*
|
||||
* @return return AOT module loaded, NULL if failed
|
||||
*/
|
||||
AOTModule*
|
||||
aot_load_from_aot_file(const uint8 *buf, uint32 size,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
AOTModule *
|
||||
aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
/**
|
||||
* Load a AOT module from a specified AOT section list.
|
||||
@ -449,9 +450,9 @@ aot_load_from_aot_file(const uint8 *buf, uint32 size,
|
||||
*
|
||||
* @return return AOT module loaded, NULL if failed
|
||||
*/
|
||||
AOTModule*
|
||||
aot_load_from_sections(AOTSection *section_list,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
AOTModule *
|
||||
aot_load_from_sections(AOTSection *section_list, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
#if WASM_ENABLE_JIT != 0
|
||||
/**
|
||||
@ -463,9 +464,9 @@ aot_load_from_sections(AOTSection *section_list,
|
||||
*
|
||||
* @return return AOT module loaded, NULL if failed
|
||||
*/
|
||||
AOTModule*
|
||||
aot_convert_wasm_module(WASMModule *wasm_module,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
AOTModule *
|
||||
aot_convert_wasm_module(WASMModule *wasm_module, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -490,10 +491,9 @@ aot_unload(AOTModule *module);
|
||||
*
|
||||
* @return return the instantiated AOT module instance, NULL if failed
|
||||
*/
|
||||
AOTModuleInstance*
|
||||
aot_instantiate(AOTModule *module, bool is_sub_inst,
|
||||
uint32 stack_size, uint32 heap_size,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
AOTModuleInstance *
|
||||
aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
|
||||
uint32 heap_size, char *error_buf, uint32 error_buf_size);
|
||||
|
||||
/**
|
||||
* Deinstantiate a AOT module instance, destroy the resources.
|
||||
@ -514,9 +514,9 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst);
|
||||
*
|
||||
* @return the function instance found
|
||||
*/
|
||||
AOTFunctionInstance*
|
||||
aot_lookup_function(const AOTModuleInstance *module_inst,
|
||||
const char *name, const char *signature);
|
||||
AOTFunctionInstance *
|
||||
aot_lookup_function(const AOTModuleInstance *module_inst, const char *name,
|
||||
const char *signature);
|
||||
/**
|
||||
* Call the given AOT function of a AOT module instance with
|
||||
* arguments.
|
||||
@ -533,8 +533,7 @@ aot_lookup_function(const AOTModuleInstance *module_inst,
|
||||
* the caller can call aot_get_exception to get exception info.
|
||||
*/
|
||||
bool
|
||||
aot_call_function(WASMExecEnv *exec_env,
|
||||
AOTFunctionInstance *function,
|
||||
aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
|
||||
unsigned argc, uint32 argv[]);
|
||||
|
||||
bool
|
||||
@ -553,12 +552,10 @@ aot_create_exec_env_singleton(AOTModuleInstance *module_inst);
|
||||
* @param exception current exception string
|
||||
*/
|
||||
void
|
||||
aot_set_exception(AOTModuleInstance *module_inst,
|
||||
const char *exception);
|
||||
aot_set_exception(AOTModuleInstance *module_inst, const char *exception);
|
||||
|
||||
void
|
||||
aot_set_exception_with_id(AOTModuleInstance *module_inst,
|
||||
uint32 id);
|
||||
aot_set_exception_with_id(AOTModuleInstance *module_inst, uint32 id);
|
||||
|
||||
/**
|
||||
* Get exception info of the AOT module instance.
|
||||
@ -567,7 +564,7 @@ aot_set_exception_with_id(AOTModuleInstance *module_inst,
|
||||
*
|
||||
* @return the exception string
|
||||
*/
|
||||
const char*
|
||||
const char *
|
||||
aot_get_exception(AOTModuleInstance *module_inst);
|
||||
|
||||
/**
|
||||
@ -583,24 +580,23 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
uint32
|
||||
aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr,
|
||||
uint32 size, void **p_native_addr);
|
||||
aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
void
|
||||
aot_module_free(AOTModuleInstance *module_inst, uint32 ptr);
|
||||
|
||||
uint32
|
||||
aot_module_dup_data(AOTModuleInstance *module_inst,
|
||||
const char *src, uint32 size);
|
||||
aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
|
||||
uint32 size);
|
||||
|
||||
bool
|
||||
aot_validate_app_addr(AOTModuleInstance *module_inst,
|
||||
uint32 app_offset, uint32 size);
|
||||
|
||||
aot_validate_app_addr(AOTModuleInstance *module_inst, uint32 app_offset,
|
||||
uint32 size);
|
||||
|
||||
bool
|
||||
aot_validate_native_addr(AOTModuleInstance *module_inst,
|
||||
void *native_ptr, uint32 size);
|
||||
aot_validate_native_addr(AOTModuleInstance *module_inst, void *native_ptr,
|
||||
uint32 size);
|
||||
|
||||
void *
|
||||
aot_addr_app_to_native(AOTModuleInstance *module_inst, uint32 app_offset);
|
||||
@ -609,14 +605,11 @@ uint32
|
||||
aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr);
|
||||
|
||||
bool
|
||||
aot_get_app_addr_range(AOTModuleInstance *module_inst,
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
aot_get_app_addr_range(AOTModuleInstance *module_inst, uint32 app_offset,
|
||||
uint32 *p_app_start_offset, uint32 *p_app_end_offset);
|
||||
|
||||
bool
|
||||
aot_get_native_addr_range(AOTModuleInstance *module_inst,
|
||||
uint8 *native_ptr,
|
||||
aot_get_native_addr_range(AOTModuleInstance *module_inst, uint8 *native_ptr,
|
||||
uint8 **p_native_start_addr,
|
||||
uint8 **p_native_end_addr);
|
||||
|
||||
@ -633,19 +626,18 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count);
|
||||
* @return true if equal, false otherwise
|
||||
*/
|
||||
bool
|
||||
aot_is_wasm_type_equal(AOTModuleInstance *module_inst,
|
||||
uint32 type1_idx, uint32 type2_idx);
|
||||
aot_is_wasm_type_equal(AOTModuleInstance *module_inst, uint32 type1_idx,
|
||||
uint32 type2_idx);
|
||||
|
||||
/**
|
||||
* Invoke native function from aot code
|
||||
*/
|
||||
bool
|
||||
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
|
||||
uint32 argc, uint32 *argv);
|
||||
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||
uint32 *argv);
|
||||
|
||||
bool
|
||||
aot_call_indirect(WASMExecEnv *exec_env,
|
||||
uint32 tbl_idx, uint32 table_elem_idx,
|
||||
aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
|
||||
uint32 argc, uint32 *argv);
|
||||
|
||||
uint32
|
||||
@ -659,8 +651,8 @@ aot_memset(void *s, int c, size_t n);
|
||||
|
||||
#if WASM_ENABLE_BULK_MEMORY != 0
|
||||
bool
|
||||
aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index,
|
||||
uint32 offset, uint32 len, uint32 dst);
|
||||
aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
|
||||
uint32 len, uint32 dst);
|
||||
|
||||
bool
|
||||
aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
|
||||
@ -668,12 +660,10 @@ aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
bool
|
||||
aot_set_aux_stack(WASMExecEnv *exec_env,
|
||||
uint32 start_offset, uint32 size);
|
||||
aot_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
|
||||
|
||||
bool
|
||||
aot_get_aux_stack(WASMExecEnv *exec_env,
|
||||
uint32 *start_offset, uint32 *size);
|
||||
aot_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
|
||||
#endif
|
||||
|
||||
#ifdef OS_ENABLE_HW_BOUND_CHECK
|
||||
@ -697,18 +687,18 @@ void
|
||||
aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx);
|
||||
|
||||
void
|
||||
aot_table_init(AOTModuleInstance *module_inst,
|
||||
uint32 tbl_idx, uint32 tbl_seg_idx,
|
||||
uint32 length, uint32 src_offset, uint32 dst_offset);
|
||||
aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
|
||||
uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
|
||||
uint32 dst_offset);
|
||||
|
||||
void
|
||||
aot_table_copy(AOTModuleInstance *module_inst,
|
||||
uint32 src_tbl_idx, uint32 dst_tbl_idx,
|
||||
uint32 length, uint32 src_offset, uint32 dst_offset);
|
||||
aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
|
||||
uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
|
||||
uint32 dst_offset);
|
||||
|
||||
void
|
||||
aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx,
|
||||
uint32 length, uint32 val, uint32 data_offset);
|
||||
aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
|
||||
uint32 val, uint32 data_offset);
|
||||
|
||||
uint32
|
||||
aot_table_grow(AOTModuleInstance *module_inst, uint32 tbl_idx,
|
||||
@ -735,4 +725,3 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
|
||||
#endif
|
||||
|
||||
#endif /* end of _AOT_RUNTIME_H_ */
|
||||
|
||||
|
||||
@ -5,37 +5,39 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_AARCH64_MOVW_UABS_G0 263
|
||||
#define R_AARCH64_MOVW_UABS_G0_NC 264
|
||||
#define R_AARCH64_MOVW_UABS_G1 265
|
||||
#define R_AARCH64_MOVW_UABS_G1_NC 266
|
||||
#define R_AARCH64_MOVW_UABS_G2 267
|
||||
#define R_AARCH64_MOVW_UABS_G2_NC 268
|
||||
#define R_AARCH64_MOVW_UABS_G3 269
|
||||
#define R_AARCH64_MOVW_UABS_G0 263
|
||||
#define R_AARCH64_MOVW_UABS_G0_NC 264
|
||||
#define R_AARCH64_MOVW_UABS_G1 265
|
||||
#define R_AARCH64_MOVW_UABS_G1_NC 266
|
||||
#define R_AARCH64_MOVW_UABS_G2 267
|
||||
#define R_AARCH64_MOVW_UABS_G2_NC 268
|
||||
#define R_AARCH64_MOVW_UABS_G3 269
|
||||
|
||||
#define R_AARCH64_MOVW_SABS_G0 270
|
||||
#define R_AARCH64_MOVW_SABS_G1 271
|
||||
#define R_AARCH64_MOVW_SABS_G2 272
|
||||
#define R_AARCH64_MOVW_SABS_G0 270
|
||||
#define R_AARCH64_MOVW_SABS_G1 271
|
||||
#define R_AARCH64_MOVW_SABS_G2 272
|
||||
|
||||
#define R_AARCH64_ADR_PREL_LO19 273
|
||||
#define R_AARCH64_ADR_PREL_LO21 274
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21 275
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21_NC 276
|
||||
#define R_AARCH64_ADR_PREL_LO19 273
|
||||
#define R_AARCH64_ADR_PREL_LO21 274
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21 275
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21_NC 276
|
||||
|
||||
#define R_AARCH64_ADD_ABS_LO12_NC 277
|
||||
#define R_AARCH64_ADD_ABS_LO12_NC 277
|
||||
|
||||
#define R_AARCH64_LDST8_ABS_LO12_NC 278
|
||||
#define R_AARCH64_LDST16_ABS_LO12_NC 284
|
||||
#define R_AARCH64_LDST32_ABS_LO12_NC 285
|
||||
#define R_AARCH64_LDST64_ABS_LO12_NC 286
|
||||
#define R_AARCH64_LDST128_ABS_LO12_NC 299
|
||||
#define R_AARCH64_LDST8_ABS_LO12_NC 278
|
||||
#define R_AARCH64_LDST16_ABS_LO12_NC 284
|
||||
#define R_AARCH64_LDST32_ABS_LO12_NC 285
|
||||
#define R_AARCH64_LDST64_ABS_LO12_NC 286
|
||||
#define R_AARCH64_LDST128_ABS_LO12_NC 299
|
||||
|
||||
#define R_AARCH64_JUMP26 282
|
||||
#define R_AARCH64_CALL26 283
|
||||
#define R_AARCH64_JUMP26 282
|
||||
#define R_AARCH64_CALL26 283
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -55,7 +57,7 @@ get_target_symbol_map(uint32 *sym_num)
|
||||
void
|
||||
get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
{
|
||||
const char * s = BUILD_TARGET;
|
||||
const char *s = BUILD_TARGET;
|
||||
size_t s_size = sizeof(BUILD_TARGET);
|
||||
char *d = target_buf;
|
||||
|
||||
@ -64,14 +66,14 @@ get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
s = BUILD_TARGET_AARCH64_DEFAULT;
|
||||
s_size = sizeof(BUILD_TARGET_AARCH64_DEFAULT);
|
||||
}
|
||||
if(target_buf_size < s_size){
|
||||
if (target_buf_size < s_size) {
|
||||
s_size = target_buf_size;
|
||||
}
|
||||
while (--s_size) {
|
||||
if (*s >= 'A' && *s <= 'Z')
|
||||
*d++ = *s++ + 'a' - 'A';
|
||||
else
|
||||
*d++ = *s++ ;
|
||||
*d++ = *s++;
|
||||
}
|
||||
/* Ensure the string is null byte ('\0') terminated */
|
||||
*d = '\0';
|
||||
@ -90,15 +92,16 @@ init_plt_table(uint8 *plt)
|
||||
{
|
||||
uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap);
|
||||
for (i = 0; i < num; i++) {
|
||||
uint32 *p = (uint32*)plt;
|
||||
uint32 *p = (uint32 *)plt;
|
||||
*p++ = 0xf81f0ffe; /* str x30, [sp, #-16]! */
|
||||
*p++ = 0x100000be; /* adr x30, #20 ;symbol addr is PC + 5 instructions below */
|
||||
*p++ = 0x100000be; /* adr x30, #20; symbol addr is PC + 5 instructions
|
||||
below */
|
||||
*p++ = 0xf94003de; /* ldr x30, [x30] */
|
||||
*p++ = 0xd63f03c0; /* blr x30 */
|
||||
*p++ = 0xf84107fe; /* ldr x30, [sp], #16 */
|
||||
*p++ = 0xd61f03c0; /* br x30 */
|
||||
/* symbol addr */
|
||||
*(uint64*)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
*(uint64 *)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
p += 2;
|
||||
plt += get_plt_item_size();
|
||||
}
|
||||
@ -110,17 +113,18 @@ get_plt_table_size()
|
||||
return get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
}
|
||||
|
||||
#define SIGN_EXTEND_TO_INT64(val, bits, val_ext) do { \
|
||||
int64 m = (int64)((uint64)1 << (bits - 1)); \
|
||||
val_ext = ((int64)val ^ m) - m; \
|
||||
} while (0)
|
||||
#define SIGN_EXTEND_TO_INT64(val, bits, val_ext) \
|
||||
do { \
|
||||
int64 m = (int64)((uint64)1 << (bits - 1)); \
|
||||
val_ext = ((int64)val ^ m) - m; \
|
||||
} while (0)
|
||||
|
||||
#define Page(expr) ((expr) & ~0xFFF)
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -132,22 +136,21 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_CALL26:
|
||||
{
|
||||
void *S, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S, *P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm26;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm26 = insn & 0x3FFFFFF;
|
||||
SIGN_EXTEND_TO_INT64(imm26 << 2, 28, initial_addend);
|
||||
A = initial_addend;
|
||||
@ -164,17 +167,18 @@ apply_relocation(AOTModule *module,
|
||||
else {
|
||||
uint8 *plt;
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
}
|
||||
/* Symbol address is not an AOT function,
|
||||
* but a function of runtime or native. Its address is
|
||||
* beyond of the +-128MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
S = plt = (uint8*)module->code + module->code_size
|
||||
S = plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
}
|
||||
@ -191,7 +195,7 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
|
||||
/* write the imm26 back to instruction */
|
||||
*(int32*)P = (insn & 0xFC000000) | ((int32)((X >> 2) & 0x3FFFFFF));
|
||||
*(int32 *)P = (insn & 0xFC000000) | ((int32)((X >> 2) & 0x3FFFFFF));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -203,13 +207,14 @@ apply_relocation(AOTModule *module,
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm16;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm16 = (insn >> 5) & 0xFFFF;
|
||||
|
||||
SIGN_EXTEND_TO_INT64(imm16, 16, initial_addend);
|
||||
@ -241,18 +246,22 @@ apply_relocation(AOTModule *module,
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_MOVW_UABS_G0:
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)((X & 0xFFFF) << 5));
|
||||
*(int32 *)P =
|
||||
(insn & 0xFFE0001F) | ((int32)((X & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G1:
|
||||
case R_AARCH64_MOVW_UABS_G1_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 16) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 16) & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G2:
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 32) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 32) & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 48) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 48) & 0xFFFF) << 5));
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
@ -264,13 +273,14 @@ apply_relocation(AOTModule *module,
|
||||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
case R_AARCH64_ADR_PREL_PG_HI21_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, immhi19, immlo2, imm21;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
immhi19 = (insn >> 5) & 0x7FFFF;
|
||||
immlo2 = (insn >> 29) & 0x3;
|
||||
imm21 = (immhi19 << 2) | immlo2;
|
||||
@ -290,20 +300,21 @@ apply_relocation(AOTModule *module,
|
||||
/* write the imm21 back to instruction */
|
||||
immhi19 = (int32)(((X >> 12) >> 2) & 0x7FFFF);
|
||||
immlo2 = (int32)((X >> 12) & 0x3);
|
||||
*(int32*)P = (insn & 0x9F00001F) | (immlo2 << 29) | (immhi19 << 5);
|
||||
*(int32 *)P = (insn & 0x9F00001F) | (immlo2 << 29) | (immhi19 << 5);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm12;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm12 = (insn >> 10) & 0xFFF;
|
||||
|
||||
SIGN_EXTEND_TO_INT64(imm12, 12, initial_addend);
|
||||
@ -316,7 +327,7 @@ apply_relocation(AOTModule *module,
|
||||
/* No need to check overflow for this reloction type */
|
||||
|
||||
/* write the imm12 back to instruction */
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -326,13 +337,14 @@ apply_relocation(AOTModule *module,
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm12;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm12 = (insn >> 10) & 0xFFF;
|
||||
|
||||
SIGN_EXTEND_TO_INT64(imm12, 12, initial_addend);
|
||||
@ -347,19 +359,24 @@ apply_relocation(AOTModule *module,
|
||||
/* write the imm12 back to instruction */
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_LDST8_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
*(int32 *)P =
|
||||
(insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST16_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 1) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 1) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST32_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 2) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 2) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 3) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 3) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 4) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 4) << 10));
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
|
||||
@ -5,13 +5,14 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_ARC_S21H_PCREL 14
|
||||
#define R_ARC_S21W_PCREL 15
|
||||
#define R_ARC_S25H_PCREL 16
|
||||
#define R_ARC_S25W_PCREL 17
|
||||
#define R_ARC_32 4
|
||||
#define R_ARC_32_ME 27
|
||||
#define R_ARC_S21H_PCREL 14
|
||||
#define R_ARC_S21W_PCREL 15
|
||||
#define R_ARC_S25H_PCREL 16
|
||||
#define R_ARC_S25W_PCREL 17
|
||||
#define R_ARC_32 4
|
||||
#define R_ARC_32_ME 27
|
||||
|
||||
/* clang-format off */
|
||||
void __st_r13_to_r15();
|
||||
void __st_r13_to_r16();
|
||||
void __st_r13_to_r17();
|
||||
@ -56,10 +57,13 @@ void __subdf3();
|
||||
void __subsf3();
|
||||
void __truncdfsf2();
|
||||
void __unorddf2();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
REG_SYM(__st_r13_to_r15),
|
||||
/* clang-format on */
|
||||
REG_SYM(__st_r13_to_r16),
|
||||
REG_SYM(__st_r13_to_r17),
|
||||
REG_SYM(__st_r13_to_r18),
|
||||
@ -81,29 +85,28 @@ static SymbolMap target_sym_map[] = {
|
||||
REG_SYM(__ld_r13_to_r23),
|
||||
REG_SYM(__ld_r13_to_r24),
|
||||
REG_SYM(__ld_r13_to_r25),
|
||||
REG_SYM (__adddf3),
|
||||
REG_SYM (__addsf3),
|
||||
REG_SYM (__divdf3),
|
||||
REG_SYM (__divdi3),
|
||||
REG_SYM (__divsf3),
|
||||
REG_SYM (__divsi3),
|
||||
REG_SYM (__eqsf2),
|
||||
REG_SYM (__extendsfdf2),
|
||||
REG_SYM (__fixdfsi),
|
||||
REG_SYM (__floatsidf),
|
||||
REG_SYM (__floatsisf),
|
||||
REG_SYM (__gedf2),
|
||||
REG_SYM (__gtdf2),
|
||||
REG_SYM (__ledf2),
|
||||
REG_SYM (__lesf2),
|
||||
REG_SYM (__ltdf2),
|
||||
REG_SYM (__muldf3),
|
||||
REG_SYM (__mulsf3),
|
||||
REG_SYM (__subdf3),
|
||||
REG_SYM (__subsf3),
|
||||
REG_SYM (__truncdfsf2),
|
||||
REG_SYM (__unorddf2),
|
||||
|
||||
REG_SYM(__adddf3),
|
||||
REG_SYM(__addsf3),
|
||||
REG_SYM(__divdf3),
|
||||
REG_SYM(__divdi3),
|
||||
REG_SYM(__divsf3),
|
||||
REG_SYM(__divsi3),
|
||||
REG_SYM(__eqsf2),
|
||||
REG_SYM(__extendsfdf2),
|
||||
REG_SYM(__fixdfsi),
|
||||
REG_SYM(__floatsidf),
|
||||
REG_SYM(__floatsisf),
|
||||
REG_SYM(__gedf2),
|
||||
REG_SYM(__gtdf2),
|
||||
REG_SYM(__ledf2),
|
||||
REG_SYM(__lesf2),
|
||||
REG_SYM(__ltdf2),
|
||||
REG_SYM(__muldf3),
|
||||
REG_SYM(__mulsf3),
|
||||
REG_SYM(__subdf3),
|
||||
REG_SYM(__subsf3),
|
||||
REG_SYM(__truncdfsf2),
|
||||
REG_SYM(__unorddf2),
|
||||
};
|
||||
|
||||
static void
|
||||
@ -139,9 +142,9 @@ init_plt_table(uint8 *plt)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -159,11 +162,10 @@ 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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 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:
|
||||
@ -172,7 +174,7 @@ apply_relocation(AOTModule *module,
|
||||
int32 addend, value;
|
||||
uintptr_t S, A, P;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
|
||||
/* Convert from middle endian */
|
||||
insn = middle_endian_convert(insn);
|
||||
@ -187,7 +189,7 @@ apply_relocation(AOTModule *module,
|
||||
addend = addend << 2;
|
||||
|
||||
/* (S + A) - P */
|
||||
S = (uintptr_t)(uint8*)symbol_addr;
|
||||
S = (uintptr_t)(uint8 *)symbol_addr;
|
||||
A = (uintptr_t)reloc_addend;
|
||||
P = (uintptr_t)(target_section_addr + reloc_offset);
|
||||
P &= (uintptr_t)~3;
|
||||
@ -209,11 +211,10 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
uint32 insn;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
|
||||
/* (S + A) */
|
||||
insn = (uint32)(uintptr_t)
|
||||
((uint8*)symbol_addr + reloc_addend);
|
||||
insn = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
if (reloc_type == R_ARC_32_ME)
|
||||
/* Convert to middle endian */
|
||||
@ -234,4 +235,3 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,10 +5,11 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */
|
||||
#define R_ARM_JMP24 29 /* PC relative 24 bit (B/BL<cond>). */
|
||||
#define R_ARM_ABS32 2 /* Direct 32 bit */
|
||||
#define R_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */
|
||||
#define R_ARM_JMP24 29 /* PC relative 24 bit (B/BL<cond>). */
|
||||
#define R_ARM_ABS32 2 /* Direct 32 bit */
|
||||
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __udivdi3();
|
||||
void __moddi3();
|
||||
@ -54,11 +55,14 @@ void __aeabi_fcmple();
|
||||
void __aeabi_fcmpge();
|
||||
void __aeabi_f2iz();
|
||||
void __aeabi_f2d();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
REG_SYM(__divdi3),
|
||||
/* clang-format on */
|
||||
REG_SYM(__udivdi3),
|
||||
REG_SYM(__umoddi3),
|
||||
REG_SYM(__divsi3),
|
||||
@ -122,7 +126,7 @@ get_target_symbol_map(uint32 *sym_num)
|
||||
void
|
||||
get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
{
|
||||
const char * s = BUILD_TARGET;
|
||||
const char *s = BUILD_TARGET;
|
||||
size_t s_size = sizeof(BUILD_TARGET);
|
||||
char *d = target_buf;
|
||||
|
||||
@ -131,14 +135,14 @@ get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
s = BUILD_TARGET_ARM_DEFAULT;
|
||||
s_size = sizeof(BUILD_TARGET_ARM_DEFAULT);
|
||||
}
|
||||
if(target_buf_size < s_size){
|
||||
if (target_buf_size < s_size) {
|
||||
s_size = target_buf_size;
|
||||
}
|
||||
while (--s_size) {
|
||||
if (*s >= 'A' && *s <= 'Z')
|
||||
*d++ = *s++ + 'a' - 'A';
|
||||
else
|
||||
*d++ = *s++ ;
|
||||
*d++ = *s++;
|
||||
}
|
||||
/* Ensure the string is null byte ('\0') terminated */
|
||||
*d = '\0';
|
||||
@ -163,7 +167,7 @@ init_plt_table(uint8 *plt)
|
||||
{
|
||||
uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap);
|
||||
for (i = 0; i < num; i++) {
|
||||
uint32 *p = (uint32*)plt;
|
||||
uint32 *p = (uint32 *)plt;
|
||||
/* ldr pc, [pc] */
|
||||
*p++ = 0xe59ff000;
|
||||
/* nop */
|
||||
@ -175,9 +179,9 @@ init_plt_table(uint8 *plt)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -189,11 +193,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_CALL:
|
||||
@ -201,10 +204,10 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
intptr_t result;
|
||||
int32 RESULT_MASK = 0x03FFFFFE;
|
||||
int32 insn = *(int32*)(target_section_addr + reloc_offset);
|
||||
int32 insn = *(int32 *)(target_section_addr + reloc_offset);
|
||||
/* Initial addend: sign_extend(insn[23:0] << 2) */
|
||||
int32 initial_addend = ((insn & 0xFFFFFF) << 2)
|
||||
| ((insn & 0x800000) ? 0xFC000000 : 0);
|
||||
int32 initial_addend =
|
||||
((insn & 0xFFFFFF) << 2) | ((insn & 0x800000) ? 0xFC000000 : 0);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
@ -214,17 +217,18 @@ apply_relocation(AOTModule *module,
|
||||
* Suppose the symbol address is in +-32MB relative
|
||||
* to the relocation address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T is 0 */
|
||||
result = (intptr_t)
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T
|
||||
* is 0 */
|
||||
result = (intptr_t)((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Symbol address is not an AOT function,
|
||||
@ -232,12 +236,13 @@ apply_relocation(AOTModule *module,
|
||||
* beyond of the +-32MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is 0 */
|
||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is
|
||||
* 0 */
|
||||
uint8 *plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
result = (intptr_t)
|
||||
(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
result = (intptr_t)(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
result += initial_addend;
|
||||
@ -250,20 +255,20 @@ apply_relocation(AOTModule *module,
|
||||
return false;
|
||||
}
|
||||
|
||||
*(int32*)(target_section_addr + reloc_offset) =
|
||||
(int32)
|
||||
((insn & 0xff000000)
|
||||
| (((int32)result & RESULT_MASK) >> 2));
|
||||
*(int32 *)(target_section_addr + reloc_offset) =
|
||||
(int32)((insn & 0xff000000)
|
||||
| (((int32)result & RESULT_MASK) >> 2));
|
||||
break;
|
||||
}
|
||||
case R_ARM_ABS32:
|
||||
{
|
||||
intptr_t initial_addend;
|
||||
/* (S + A) | T where T is 0 */
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
initial_addend = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + initial_addend + reloc_addend;
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
initial_addend =
|
||||
*(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + initial_addend + reloc_addend;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -278,4 +283,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_MIPS_32 2 /* Direct 32 bit */
|
||||
#define R_MIPS_26 4 /* Direct 26 bit shifted */
|
||||
#define R_MIPS_32 2 /* Direct 32 bit */
|
||||
#define R_MIPS_26 4 /* Direct 26 bit shifted */
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
SymbolMap *
|
||||
get_target_symbol_map(uint32 *sym_num)
|
||||
@ -44,11 +46,10 @@ get_plt_table_size()
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
/* TODO: implement relocation for mips */
|
||||
@ -66,4 +67,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,25 +5,29 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_RISCV_32 1
|
||||
#define R_RISCV_64 2
|
||||
#define R_RISCV_CALL 18
|
||||
#define R_RISCV_32 1
|
||||
#define R_RISCV_64 2
|
||||
#define R_RISCV_CALL 18
|
||||
#define R_RISCV_CALL_PLT 19
|
||||
#define R_RISCV_HI20 26
|
||||
#define R_RISCV_LO12_I 27
|
||||
#define R_RISCV_LO12_S 28
|
||||
#define R_RISCV_HI20 26
|
||||
#define R_RISCV_LO12_I 27
|
||||
#define R_RISCV_LO12_S 28
|
||||
|
||||
#define RV_OPCODE_SW 0x23
|
||||
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __moddi3();
|
||||
void __muldi3();
|
||||
void __udivdi3();
|
||||
void __umoddi3();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
REG_SYM(__divdi3),
|
||||
/* clang-format on */
|
||||
REG_SYM(__moddi3),
|
||||
REG_SYM(__muldi3),
|
||||
REG_SYM(__udivdi3),
|
||||
@ -132,20 +136,20 @@ init_plt_table(uint8 *plt)
|
||||
for (i = 0; i < num; i++) {
|
||||
p = plt;
|
||||
/* auipc t1, 0 */
|
||||
*(uint16*)p = 0x0317;
|
||||
*(uint16 *)p = 0x0317;
|
||||
p += 2;
|
||||
*(uint16*)p = 0x0000;
|
||||
*(uint16 *)p = 0x0000;
|
||||
p += 2;
|
||||
/* ld t1, 8(t1) */
|
||||
*(uint16*)p = 0x3303;
|
||||
*(uint16 *)p = 0x3303;
|
||||
p += 2;
|
||||
*(uint16*)p = 0x00C3;
|
||||
*(uint16 *)p = 0x00C3;
|
||||
p += 2;
|
||||
/* jr t1 */
|
||||
*(uint16*)p = 0x8302;
|
||||
*(uint16 *)p = 0x8302;
|
||||
p += 2;
|
||||
/* nop */
|
||||
*(uint16*)p = 0x0001;
|
||||
*(uint16 *)p = 0x0001;
|
||||
p += 2;
|
||||
bh_memcpy_s(p, 8, &target_sym_map[i].symbol_addr, 8);
|
||||
p += 8;
|
||||
@ -159,15 +163,15 @@ typedef struct RelocTypeStrMap {
|
||||
char *reloc_str;
|
||||
} RelocTypeStrMap;
|
||||
|
||||
#define RELOC_TYPE_MAP(reloc_type) { reloc_type, #reloc_type }
|
||||
#define RELOC_TYPE_MAP(reloc_type) \
|
||||
{ \
|
||||
reloc_type, #reloc_type \
|
||||
}
|
||||
|
||||
static RelocTypeStrMap reloc_type_str_maps[] = {
|
||||
RELOC_TYPE_MAP(R_RISCV_32),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL_PLT),
|
||||
RELOC_TYPE_MAP(R_RISCV_HI20),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_I),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_S),
|
||||
RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_CALL),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL_PLT), RELOC_TYPE_MAP(R_RISCV_HI20),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S),
|
||||
};
|
||||
|
||||
static const char *
|
||||
@ -175,7 +179,8 @@ reloc_type_to_str(uint32 reloc_type)
|
||||
{
|
||||
uint32 i;
|
||||
|
||||
for (i = 0; i < sizeof(reloc_type_str_maps) / sizeof(RelocTypeStrMap); i++) {
|
||||
for (i = 0; i < sizeof(reloc_type_str_maps) / sizeof(RelocTypeStrMap);
|
||||
i++) {
|
||||
if (reloc_type_str_maps[i].reloc_type == reloc_type)
|
||||
return reloc_type_str_maps[i].reloc_str;
|
||||
}
|
||||
@ -184,9 +189,9 @@ reloc_type_to_str(uint32 reloc_type)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -198,11 +203,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
int32 val, imm_hi, imm_lo, insn;
|
||||
uint8 *addr = target_section_addr + reloc_offset;
|
||||
@ -211,7 +215,8 @@ apply_relocation(AOTModule *module,
|
||||
switch (reloc_type) {
|
||||
case R_RISCV_32:
|
||||
{
|
||||
uint32 val_32 = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
uint32 val_32 =
|
||||
(uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(uint32));
|
||||
if (val_32 != (uintptr_t)((uint8 *)symbol_addr + reloc_addend)) {
|
||||
@ -223,7 +228,8 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
case R_RISCV_64:
|
||||
{
|
||||
uint64 val_64 = (uint64)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
uint64 val_64 =
|
||||
(uint64)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
CHECK_RELOC_OFFSET(sizeof(uint64));
|
||||
bh_memcpy_s(addr, 8, &val_64, 8);
|
||||
break;
|
||||
@ -237,10 +243,10 @@ apply_relocation(AOTModule *module,
|
||||
if (val != (intptr_t)((uint8 *)symbol_addr - addr)) {
|
||||
if (symbol_index >= 0) {
|
||||
/* Call runtime function by plt code */
|
||||
symbol_addr = (uint8*)module->code + module->code_size
|
||||
symbol_addr = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
val = (int32)(intptr_t)((uint8*)symbol_addr - addr);
|
||||
val = (int32)(intptr_t)((uint8 *)symbol_addr - addr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,8 +259,8 @@ apply_relocation(AOTModule *module,
|
||||
rv_add_val((uint16 *)addr, (imm_hi << 12));
|
||||
if ((rv_get_val((uint16 *)(addr + 4)) & 0x7f) == RV_OPCODE_SW) {
|
||||
/* Adjust imm for SW : S-type */
|
||||
val =
|
||||
(((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
val = (((int32)imm_lo >> 5) << 25)
|
||||
+ (((int32)imm_lo & 0x1f) << 7);
|
||||
|
||||
rv_add_val((uint16 *)(addr + 4), val);
|
||||
}
|
||||
@ -310,8 +316,7 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
addr = target_section_addr + reloc_offset;
|
||||
rv_calc_imm(val, &imm_hi, &imm_lo);
|
||||
val =
|
||||
(((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
val = (((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
rv_add_val((uint16 *)addr, val);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -5,9 +5,10 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_ARM_THM_CALL 10 /* PC relative (Thumb BL and ARMv5 Thumb BLX). */
|
||||
#define R_ARM_THM_JMP24 30 /* B.W */
|
||||
#define R_ARM_THM_CALL 10 /* PC relative (Thumb BL and ARMv5 Thumb BLX). */
|
||||
#define R_ARM_THM_JMP24 30 /* B.W */
|
||||
|
||||
/* clang-format off */
|
||||
void __ltdf2();
|
||||
void __adddf3();
|
||||
void __eqdf2();
|
||||
@ -69,11 +70,14 @@ void __aeabi_fcmple();
|
||||
void __aeabi_fcmpge();
|
||||
void __aeabi_f2iz();
|
||||
void __aeabi_f2d();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
REG_SYM(__ltdf2),
|
||||
/* clang-format on */
|
||||
REG_SYM(__adddf3),
|
||||
REG_SYM(__eqdf2),
|
||||
REG_SYM(__unorddf2),
|
||||
@ -162,14 +166,14 @@ get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
s = BUILD_TARGET_THUMB_V4T;
|
||||
s_size = sizeof(BUILD_TARGET_THUMB_V4T);
|
||||
}
|
||||
if(target_buf_size < s_size){
|
||||
if (target_buf_size < s_size) {
|
||||
s_size = target_buf_size;
|
||||
}
|
||||
while (--s_size) {
|
||||
if (*s >= 'A' && *s <= 'Z')
|
||||
*d++ = *s++ + 'a' - 'A';
|
||||
else
|
||||
*d++ = *s++ ;
|
||||
*d++ = *s++;
|
||||
}
|
||||
/* Ensure the string is null byte ('\0') terminated */
|
||||
*d = '\0';
|
||||
@ -194,7 +198,7 @@ init_plt_table(uint8 *plt)
|
||||
{
|
||||
uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap);
|
||||
for (i = 0; i < num; i++) {
|
||||
uint16 *p = (uint16*)plt;
|
||||
uint16 *p = (uint16 *)plt;
|
||||
/* nop */
|
||||
*p++ = 0xbf00;
|
||||
/* push {r4} */
|
||||
@ -212,15 +216,15 @@ init_plt_table(uint8 *plt)
|
||||
/* nop */
|
||||
*p++ = 0xbf00;
|
||||
/* symbol addr */
|
||||
*(uint32*)p = (uint32)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
*(uint32 *)p = (uint32)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
plt += get_plt_item_size();
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -232,11 +236,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_THM_CALL:
|
||||
@ -250,7 +253,7 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
reloc_addr = (int16*)(target_section_addr + reloc_offset);
|
||||
reloc_addr = (int16 *)(target_section_addr + reloc_offset);
|
||||
initial_addend_0 = (*reloc_addr) & 0x7FF;
|
||||
initial_addend_1 = (*(reloc_addr + 1)) & 0x7FF;
|
||||
sign = (initial_addend_0 & 0x400) ? true : false;
|
||||
@ -263,16 +266,20 @@ apply_relocation(AOTModule *module,
|
||||
* Suppose the symbol address is in +-4MB relative
|
||||
* to the relocation address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T is 1 */
|
||||
result = (int32)(((intptr_t)((uint8*)symbol_addr + reloc_addend) | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
/* operation: ((S + A) | T) - P where S is symbol address
|
||||
and T is 1 */
|
||||
result =
|
||||
(int32)(((intptr_t)((uint8 *)symbol_addr + reloc_addend)
|
||||
| 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Symbol address is not an AOT function,
|
||||
@ -280,11 +287,14 @@ apply_relocation(AOTModule *module,
|
||||
* beyond of the +-4MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is 1 */
|
||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
/* operation: ((S + A) | T) - P where S is PLT address
|
||||
and T is 1 */
|
||||
uint8 *plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index + 1;
|
||||
result = (int32)(((intptr_t)plt | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
result =
|
||||
(int32)(((intptr_t)plt | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
result += initial_addend;
|
||||
@ -316,4 +326,3 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,17 +5,19 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_386_32 1 /* Direct 32 bit */
|
||||
#define R_386_PC32 2 /* PC relative 32 bit */
|
||||
#define R_386_32 1 /* Direct 32 bit */
|
||||
#define R_386_PC32 2 /* PC relative 32 bit */
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN32_)
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __udivdi3();
|
||||
void __moddi3();
|
||||
void __umoddi3();
|
||||
/* clang-format on */
|
||||
#else
|
||||
#pragma function (floor)
|
||||
#pragma function (ceil)
|
||||
#pragma function(floor)
|
||||
#pragma function(ceil)
|
||||
|
||||
static int64
|
||||
__divdi3(int64 a, int64 b)
|
||||
@ -42,6 +44,7 @@ __umoddi3(uint64 a, uint64 b)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
@ -50,6 +53,7 @@ static SymbolMap target_sym_map[] = {
|
||||
REG_SYM(__moddi3),
|
||||
REG_SYM(__umoddi3)
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -84,9 +88,9 @@ init_plt_table(uint8 *plt)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -98,21 +102,20 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_386_32:
|
||||
{
|
||||
intptr_t value;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
value = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + reloc_addend + value; /* S + A */
|
||||
break;
|
||||
}
|
||||
|
||||
@ -120,12 +123,12 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
int32 value;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
value = *(int32*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint32*)(target_section_addr + (uint32)reloc_offset) = (uint32)
|
||||
((uint8*)symbol_addr + (uint32)reloc_addend
|
||||
- (uint8*)(target_section_addr + (uint32)reloc_offset)
|
||||
+ value); /* S + A - P */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(int32 *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint32 *)(target_section_addr + (uint32)reloc_offset) =
|
||||
(uint32)((uint8 *)symbol_addr + (uint32)reloc_addend
|
||||
- (uint8 *)(target_section_addr + (uint32)reloc_offset)
|
||||
+ value); /* S + A - P */
|
||||
break;
|
||||
}
|
||||
|
||||
@ -139,4 +142,3 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -6,30 +6,34 @@
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#if !defined(BH_PLATFORM_WINDOWS)
|
||||
#define R_X86_64_64 1 /* Direct 64 bit */
|
||||
#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
|
||||
#define R_X86_64_PLT32 4 /* 32 bit PLT address */
|
||||
#define R_X86_64_32 10 /* Direct 32 bit zero extended */
|
||||
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
|
||||
#define R_X86_64_64 1 /* Direct 64 bit */
|
||||
#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
|
||||
#define R_X86_64_PLT32 4 /* 32 bit PLT address */
|
||||
#define R_X86_64_32 10 /* Direct 32 bit zero extended */
|
||||
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
|
||||
#else
|
||||
#ifndef IMAGE_REL_AMD64_ADDR64
|
||||
#define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */
|
||||
#define IMAGE_REL_AMD64_ADDR32 2 /* The 32-bit VA of the relocation target */
|
||||
/* clang-format off */
|
||||
#define IMAGE_REL_AMD64_REL32 4 /* The 32-bit relative address from
|
||||
the byte following the relocation*/
|
||||
/* clang-format on */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
#pragma function (floor)
|
||||
#pragma function (ceil)
|
||||
#pragma function (floorf)
|
||||
#pragma function (ceilf)
|
||||
#pragma function(floor)
|
||||
#pragma function(ceil)
|
||||
#pragma function(floorf)
|
||||
#pragma function(ceilf)
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -61,8 +65,8 @@ get_plt_item_size()
|
||||
uint32
|
||||
get_plt_table_size()
|
||||
{
|
||||
uint32 size = get_plt_item_size()
|
||||
* (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
uint32 size =
|
||||
get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
||||
size += get_plt_item_size() + sizeof(AOTUnwindInfo);
|
||||
#endif
|
||||
@ -80,7 +84,7 @@ init_plt_table(uint8 *plt)
|
||||
/* mov symbol_addr, rax */
|
||||
*p++ = 0x48;
|
||||
*p++ = 0xB8;
|
||||
*(uint64*)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
*(uint64 *)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
p += sizeof(uint64);
|
||||
/* jmp rax */
|
||||
*p++ = 0xFF;
|
||||
@ -92,19 +96,19 @@ init_plt_table(uint8 *plt)
|
||||
p = plt;
|
||||
/* mov exception_handler, rax */
|
||||
*p++ = 0x48;
|
||||
*p++ = 0xB8;
|
||||
*(uint64*)p = 0;/*(uint64)(uintptr_t)aot_exception_handler;*/
|
||||
*p++ = 0xB8;
|
||||
*(uint64 *)p = 0; /*(uint64)(uintptr_t)aot_exception_handler;*/
|
||||
p += sizeof(uint64);
|
||||
/* jmp rax */
|
||||
*p++ = 0xFF;
|
||||
*p++ = 0xE0;
|
||||
*p++ = 0xFF;
|
||||
*p++ = 0xE0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -116,11 +120,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
#if !defined(BH_PLATFORM_WINDOWS)
|
||||
@ -131,10 +134,10 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
intptr_t value;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
value = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + reloc_addend + value; /* S + A */
|
||||
break;
|
||||
}
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
@ -144,14 +147,14 @@ apply_relocation(AOTModule *module,
|
||||
uintptr_t target_addr;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(int32*)(target_section_addr + (uint32)reloc_offset);
|
||||
value = *(int32 *)(target_section_addr + (uint32)reloc_offset);
|
||||
target_addr = (uintptr_t)symbol_addr + reloc_addend + value;
|
||||
if ((int32)target_addr != target_addr) {
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit "
|
||||
"IMAGE_REL_AMD64_ADDR32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -162,20 +165,21 @@ apply_relocation(AOTModule *module,
|
||||
#if !defined(BH_PLATFORM_WINDOWS)
|
||||
case R_X86_64_PC32:
|
||||
{
|
||||
intptr_t target_addr = (intptr_t) /* S + A - P */
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
intptr_t target_addr = (intptr_t) /* S + A - P */
|
||||
((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
if ((int32)target_addr != target_addr) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit R_X86_64_PC32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit R_X86_64_PC32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
return false;
|
||||
}
|
||||
|
||||
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
break;
|
||||
}
|
||||
case R_X86_64_32:
|
||||
@ -183,7 +187,7 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
char buf[128];
|
||||
uintptr_t target_addr = (uintptr_t) /* S + A */
|
||||
((uint8*)symbol_addr + reloc_addend);
|
||||
((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
@ -192,16 +196,16 @@ apply_relocation(AOTModule *module,
|
||||
|| (reloc_type == R_X86_64_32S
|
||||
&& (int32)target_addr != (int64)target_addr)) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit %s failed. "
|
||||
"Try using wamrc with --size-level=1 option.",
|
||||
reloc_type == R_X86_64_32
|
||||
? "R_X86_64_32" : "R_X86_64_32S");
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit %s failed. "
|
||||
"Try using wamrc with --size-level=1 option.",
|
||||
reloc_type == R_X86_64_32 ? "R_X86_64_32"
|
||||
: "R_X86_64_32S");
|
||||
set_error_buf(error_buf, error_buf_size, buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@ -217,16 +221,16 @@ apply_relocation(AOTModule *module,
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
if (symbol_index >= 0) {
|
||||
plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
(plt + reloc_addend - (target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
@ -244,7 +248,7 @@ apply_relocation(AOTModule *module,
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
return false;
|
||||
}
|
||||
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -259,4 +263,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,10 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_XTENSA_32 1 /* Direct 32 bit */
|
||||
#define R_XTENSA_SLOT0_OP 20 /* PC relative */
|
||||
#define R_XTENSA_32 1 /* Direct 32 bit */
|
||||
#define R_XTENSA_SLOT0_OP 20 /* PC relative */
|
||||
|
||||
/* clang-format off */
|
||||
/* for soft-float */
|
||||
void __floatsidf();
|
||||
void __divdf3();
|
||||
@ -38,9 +39,9 @@ static SymbolMap target_sym_map[] = {
|
||||
REG_SYM(__muldi3),
|
||||
|
||||
REG_SYM(__modsi3),
|
||||
|
||||
REG_SYM(__divdi3),
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -81,9 +82,9 @@ get_plt_table_size()
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -106,18 +107,18 @@ put_imm16_to_addr(int16 imm16, int16 *addr)
|
||||
int8 bytes[8];
|
||||
int32 *addr_aligned1, *addr_aligned2;
|
||||
|
||||
addr_aligned1 = (int32*)((intptr_t)addr & ~3);
|
||||
addr_aligned1 = (int32 *)((intptr_t)addr & ~3);
|
||||
|
||||
if ((intptr_t)addr % 4 != 3) {
|
||||
*(int32*)bytes = *addr_aligned1;
|
||||
*(int16*)(bytes + ((intptr_t)addr % 4)) = imm16;
|
||||
*(int32 *)bytes = *addr_aligned1;
|
||||
*(int16 *)(bytes + ((intptr_t)addr % 4)) = imm16;
|
||||
memcpy(addr_aligned1, bytes, 4);
|
||||
}
|
||||
else {
|
||||
addr_aligned2 = (int32*)(((intptr_t)addr + 3) & ~3);
|
||||
*(int32*)bytes = *addr_aligned1;
|
||||
*(int32*)(bytes + 4) = *addr_aligned2;
|
||||
*(int16*)(bytes + 3) = imm16;
|
||||
addr_aligned2 = (int32 *)(((intptr_t)addr + 3) & ~3);
|
||||
*(int32 *)bytes = *addr_aligned1;
|
||||
*(int32 *)(bytes + 4) = *addr_aligned2;
|
||||
*(int16 *)(bytes + 3) = imm16;
|
||||
memcpy(addr_aligned1, bytes, 8);
|
||||
}
|
||||
}
|
||||
@ -142,11 +143,10 @@ typedef union {
|
||||
} l32r_insn_t;
|
||||
|
||||
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, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_XTENSA_32:
|
||||
@ -161,19 +161,20 @@ apply_relocation(AOTModule *module,
|
||||
return false;
|
||||
}
|
||||
CHECK_RELOC_OFFSET(4);
|
||||
initial_addend = *(int32*)insn_addr;
|
||||
*(uint8**)insn_addr
|
||||
= (uint8*)symbol_addr + initial_addend + reloc_addend;
|
||||
initial_addend = *(int32 *)insn_addr;
|
||||
*(uint8 **)insn_addr =
|
||||
(uint8 *)symbol_addr + initial_addend + reloc_addend;
|
||||
break;
|
||||
}
|
||||
|
||||
case R_XTENSA_SLOT0_OP:
|
||||
{
|
||||
uint8 *insn_addr = target_section_addr + reloc_offset;
|
||||
/* Currently only l32r instruction generates R_XTENSA_SLOT0_OP relocation */
|
||||
/* Currently only l32r instruction generates R_XTENSA_SLOT0_OP
|
||||
* relocation */
|
||||
l32r_insn_t *l32r_insn = (l32r_insn_t *)insn_addr;
|
||||
uint8 *reloc_addr;
|
||||
int32 relative_offset/*, initial_addend */;
|
||||
int32 relative_offset /*, initial_addend */;
|
||||
int16 imm16;
|
||||
|
||||
CHECK_RELOC_OFFSET(3); /* size of l32r instruction */
|
||||
@ -184,7 +185,7 @@ apply_relocation(AOTModule *module,
|
||||
initial_addend = (int32)imm16 << 2;
|
||||
*/
|
||||
|
||||
reloc_addr = (uint8*)symbol_addr + reloc_addend;
|
||||
reloc_addr = (uint8 *)symbol_addr + reloc_addend;
|
||||
|
||||
if ((intptr_t)reloc_addr & 3) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
@ -193,9 +194,9 @@ apply_relocation(AOTModule *module,
|
||||
return false;
|
||||
}
|
||||
|
||||
relative_offset = (int32)
|
||||
((intptr_t)reloc_addr -
|
||||
(((intptr_t)insn_addr + 3) & ~(intptr_t)3));
|
||||
relative_offset =
|
||||
(int32)((intptr_t)reloc_addr
|
||||
- (((intptr_t)insn_addr + 3) & ~(intptr_t)3));
|
||||
/* relative_offset += initial_addend; */
|
||||
|
||||
/* check relative offset boundary */
|
||||
@ -228,4 +229,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -114,12 +114,13 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
|
||||
if (sh_table) {
|
||||
read_section_header_table64(eh, sh_table);
|
||||
sh_str = get_section64(eh, sh_table[eh->e_shstrndx]);
|
||||
for (i= 0; i < eh->e_shnum; i++) {
|
||||
for (i = 0; i < eh->e_shnum; i++) {
|
||||
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
|
||||
*offset = sh_table[i]->sh_offset;
|
||||
*size = sh_table[i]->sh_size;
|
||||
sh_table[i]->sh_addr = (Elf64_Addr)(uintptr_t)
|
||||
((char *)buf + sh_table[i]->sh_offset);
|
||||
sh_table[i]->sh_addr =
|
||||
(Elf64_Addr)(uintptr_t)((char *)buf
|
||||
+ sh_table[i]->sh_offset);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
@ -134,12 +135,13 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
|
||||
if (sh_table) {
|
||||
read_section_header_table(eh, sh_table);
|
||||
sh_str = get_section(eh, sh_table[eh->e_shstrndx]);
|
||||
for (i= 0; i < eh->e_shnum; i++) {
|
||||
for (i = 0; i < eh->e_shnum; i++) {
|
||||
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
|
||||
*offset = sh_table[i]->sh_offset;
|
||||
*size = sh_table[i]->sh_size;
|
||||
sh_table[i]->sh_addr = (Elf32_Addr)(uintptr_t)
|
||||
((char *)buf + sh_table[i]->sh_offset);
|
||||
sh_table[i]->sh_addr =
|
||||
(Elf32_Addr)(uintptr_t)((char *)buf
|
||||
+ sh_table[i]->sh_offset);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -12,14 +12,14 @@
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2021 Ant Group. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "bh_log.h"
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_runtime.h"
|
||||
#include "../../interpreter/wasm_runtime.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
@ -35,11 +35,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
/* clang-format off */
|
||||
typedef enum JITAction {
|
||||
JIT_NOACTION = 0,
|
||||
JIT_REGISTER_FN,
|
||||
JIT_UNREGISTER_FN
|
||||
} JITAction;
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct JITCodeEntry {
|
||||
struct JITCodeEntry *next_;
|
||||
@ -78,7 +80,8 @@ void __attribute__((noinline)) __jit_debug_register_code()
|
||||
|
||||
JITDescriptor __jit_debug_descriptor = { 1, JIT_NOACTION, NULL, NULL };
|
||||
#else
|
||||
extern void __jit_debug_register_code();
|
||||
extern void
|
||||
__jit_debug_register_code();
|
||||
extern JITDescriptor __jit_debug_descriptor;
|
||||
#endif
|
||||
|
||||
@ -168,8 +171,7 @@ jit_debug_engine_init()
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(jit_debug_engine =
|
||||
wasm_runtime_malloc(sizeof(WASMJITDebugEngine)))) {
|
||||
if (!(jit_debug_engine = wasm_runtime_malloc(sizeof(WASMJITDebugEngine)))) {
|
||||
LOG_ERROR("WASM JIT Debug Engine error: failed to allocate memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user