Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile issue of zephyr #306

Merged
merged 61 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b389628
Merge pull request #82 from bytecodealliance/master
wenyongh Mar 16, 2020
62a1992
Merge pull request #83 from bytecodealliance/master
wenyongh Mar 16, 2020
00c5daf
Merge pull request #84 from bytecodealliance/master
wenyongh Mar 17, 2020
7a46018
Merge pull request #85 from bytecodealliance/master
wenyongh Mar 18, 2020
6ed452c
Sync with internal feature
wenyongh Mar 18, 2020
632d63a
Merge pull request #86 from bytecodealliance/master
wenyongh Mar 20, 2020
ee37497
Merge pull request #87 from bytecodealliance/master
wenyongh Mar 23, 2020
44d041d
Merge pull request #88 from bytecodealliance/master
wenyongh Mar 24, 2020
b382a7f
Enable aarch64 support, add component test framework and test suite, …
wenyongh Mar 24, 2020
0a6cef7
Merge pull request #89 from bytecodealliance/master
wenyongh Mar 24, 2020
6df54ce
Merge pull request #90 from bytecodealliance/master
wenyongh Mar 27, 2020
5009206
Merge pull request #91 from bytecodealliance/master
wenyongh Mar 30, 2020
0ab53e6
Implement register/call native API with raw arguments
wenyongh Apr 1, 2020
f890529
Merge pull request #92 from bytecodealliance/master
wenyongh Apr 1, 2020
9d5bfda
Merge pull request #93 from bytecodealliance/master
wenyongh Apr 1, 2020
3b36fb8
Merge pull request #94 from bytecodealliance/master
wenyongh Apr 2, 2020
908c5f7
Merge pull request #95 from bytecodealliance/master
wenyongh Apr 9, 2020
5336e35
Merge pull request #96 from bytecodealliance/master
wenyongh Apr 12, 2020
21275d3
Merge pull request #97 from bytecodealliance/master
wenyongh Apr 13, 2020
4c56eb9
Make heap and linear memory contiguous to refine compilation time and…
wenyongh Apr 13, 2020
f984e20
Modify aot version
wenyongh Apr 13, 2020
5076b77
Merge pull request #98 from bytecodealliance/master
wenyongh Apr 13, 2020
1cf823d
Merge pull request #99 from bytecodealliance/master
wenyongh Apr 22, 2020
33a9f85
Refine aot memory boundary check, add more llvm passes
wenyongh Apr 22, 2020
be5d033
Merge pull request #100 from bytecodealliance/master
wenyongh Apr 22, 2020
aa69a45
Merge pull request #101 from bytecodealliance/master
wenyongh Apr 25, 2020
59f4d15
Sync with internal/feature
wenyongh Apr 30, 2020
af0e324
Merge pull request #102 from bytecodealliance/master
wenyongh Apr 30, 2020
4fa4bad
Sync with internal feature
wenyongh May 8, 2020
9ea9457
Merge pull request #103 from bytecodealliance/master
wenyongh May 8, 2020
54863ed
Fix issues of condition settings of app boundary check
wenyongh May 8, 2020
03ec08f
Merge pull request #104 from bytecodealliance/master
wenyongh May 8, 2020
87151ea
Replace llvm void ptr type with int8 ptr type to avoid assert failed
wenyongh May 8, 2020
ff5e90b
Merge pull request #105 from bytecodealliance/master
wenyongh May 8, 2020
23af40d
Merge pull request #106 from bytecodealliance/master
wenyongh May 15, 2020
f544940
Update API comments, refine footprint of wasm loader
wenyongh May 15, 2020
5568b52
Merge pull request #107 from bytecodealliance/master
wenyongh May 15, 2020
475669d
Merge pull request #108 from bytecodealliance/master
wenyongh May 28, 2020
0cc8c99
Merge pull request #109 from bytecodealliance/master
wenyongh Jun 1, 2020
75533fa
Sync with internal feature
wenyongh Jun 2, 2020
916a86f
update gitignore and clang-format
wenyongh Jun 2, 2020
55eee4c
Merge pull request #110 from bytecodealliance/master
wenyongh Jun 2, 2020
26515b0
Merge pull request #111 from bytecodealliance/master
wenyongh Jun 8, 2020
3c8251f
Sync with internal feature
wenyongh Jun 8, 2020
3de35d5
Merge pull request #112 from bytecodealliance/master
wenyongh Jun 8, 2020
71096fd
Sync with internal feature
wenyongh Jun 11, 2020
f5909d5
Merge pull request #113 from bytecodealliance/master
wenyongh Jun 11, 2020
4c4f8da
Merge pull request #114 from bytecodealliance/master
wenyongh Jun 12, 2020
c5d6754
Merge pull request #115 from bytecodealliance/master
wenyongh Jun 15, 2020
d371e9c
Merge pull request #116 from bytecodealliance/main
wenyongh Jun 27, 2020
c062708
Sync with internal/feature
wenyongh Jun 28, 2020
21d8754
Merge pull request #117 from bytecodealliance/main
wenyongh Jun 28, 2020
16df501
Refine opcode get/set_global for interpreter
wenyongh Jun 29, 2020
f4eb8b2
Merge pull request #118 from bytecodealliance/main
wenyongh Jun 29, 2020
5f56872
Fix issue of aot
wenyongh Jul 1, 2020
499fc94
Merge pull request #119 from bytecodealliance/main
wenyongh Jul 1, 2020
cb3dd0c
Merge pull request #120 from bytecodealliance/main
wenyongh Jul 1, 2020
47d08d0
Merge pull request #121 from bytecodealliance/main
wenyongh Jul 1, 2020
4fcf740
Enhance the native stack overflow check
wenyongh Jul 7, 2020
9d7a493
Merge pull request #122 from bytecodealliance/main
wenyongh Jul 7, 2020
e4b7c89
Fix compile issue of zephyr
wenyongh Jul 9, 2020
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
Prev Previous commit
Next Next commit
Make heap and linear memory contiguous to refine compilation time and…
… footprint
  • Loading branch information
wenyongh committed Apr 13, 2020
commit 4c56eb98f4549799eed1ad1c85349b5a36dfd604
306 changes: 159 additions & 147 deletions core/iwasm/aot/aot_runtime.c

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions core/iwasm/aot/aot_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
extern "C" {
#endif

#define AOT_MAGIC_NUMBER 0x746f6100
#define AOT_CURRENT_VERSION 1

typedef enum AOTExceptionID {
EXCE_UNREACHABLE = 0,
EXCE_OUT_OF_MEMORY,
Expand Down Expand Up @@ -200,19 +197,27 @@ typedef struct AOTModuleInstance {
/* WASI context */
AOTPointer wasi_ctx;

/* total memory size: heap and linear memory */
uint32 total_mem_size;

/* boundary check constants for aot code */
uint32 mem_bound_check_1byte;
uint32 mem_bound_check_2bytes;
uint32 mem_bound_check_4bytes;
uint32 mem_bound_check_8bytes;

/* others */
int32 temp_ret;
uint32 llvm_stack;
int32 DYNAMICTOP_PTR_offset;
uint32 default_wasm_stack_size;

/* reserved */
uint32 reserved[16];
uint32 reserved[12];

union {
uint64 _make_it_8_byte_aligned_;
uint8 bytes[1];
} global_table_heap_data;
} global_table_data;
} AOTModuleInstance;

typedef AOTExportFunc AOTFunctionInstance;
Expand Down Expand Up @@ -441,13 +446,13 @@ aot_is_wasm_type_equal(AOTModuleInstance *module_inst,
*/
bool
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
uint32 *frame_lp, uint32 argc, uint32 *argv_ret);
uint32 argc, uint32 *argv);

bool
aot_call_indirect(WASMExecEnv *exec_env,
bool check_func_type, uint32 func_type_idx,
uint32 table_elem_idx,
uint32 *frame_lp, uint32 argc, uint32 *argv_ret);
uint32 argc, uint32 *argv);

uint32
aot_get_plt_table_size();
Expand Down
2 changes: 2 additions & 0 deletions core/iwasm/common/wasm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ wasm_native_resolve_symbol(const char *module_name, const char *field_name,
if (signature && signature[0] != '\0') {
/* signature is not empty, check its format */
if (!check_symbol_signature(func_type, signature)) {
#if WASM_ENABLE_WAMR_COMPILER == 0 /* Output warning except running aot compiler */
LOG_WARNING("failed to check signature '%s' and resolve "
"pointer params for import function (%s %s)\n",
signature, module_name, field_name);
#endif
return NULL;
}
else
Expand Down
39 changes: 28 additions & 11 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
goto fail;
}

wasi_ctx->curfds = curfds;
wasi_ctx->prestats = prestats;
wasi_ctx->argv_environ = argv_environ;
wasi_ctx->curfds_offset = offset_curfds;
wasi_ctx->prestats_offset = offset_prestats;
wasi_ctx->argv_environ_offset = offset_argv_environ;

fd_table_init(curfds);
fd_prestats_init(prestats);
Expand Down Expand Up @@ -950,14 +950,32 @@ void
wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst)
{
WASIContext *wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst);
struct argv_environ_values *argv_environ;
struct fd_table *curfds;
struct fd_prestats *prestats;

if (wasi_ctx) {
if (wasi_ctx->argv_environ)
argv_environ_destroy(wasi_ctx->argv_environ);
if (wasi_ctx->curfds)
fd_table_destroy(wasi_ctx->curfds);
if (wasi_ctx->prestats)
fd_prestats_destroy(wasi_ctx->prestats);
if (wasi_ctx->argv_environ_offset) {
argv_environ = (struct argv_environ_values *)
wasm_runtime_addr_app_to_native(module_inst,
wasi_ctx->argv_environ_offset);
argv_environ_destroy(argv_environ);
wasm_runtime_module_free(module_inst, wasi_ctx->argv_environ_offset);
}
if (wasi_ctx->curfds_offset) {
curfds = (struct fd_table *)
wasm_runtime_addr_app_to_native(module_inst,
wasi_ctx->curfds_offset);
fd_table_destroy(curfds);
wasm_runtime_module_free(module_inst, wasi_ctx->curfds_offset);
}
if (wasi_ctx->prestats_offset) {
prestats = (struct fd_prestats *)
wasm_runtime_addr_app_to_native(module_inst,
wasi_ctx->prestats_offset);
fd_prestats_destroy(prestats);
wasm_runtime_module_free(module_inst, wasi_ctx->prestats_offset);
}
wasm_runtime_free(wasi_ctx);
}
}
Expand Down Expand Up @@ -2141,8 +2159,7 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env,
#if WASM_ENABLE_AOT != 0
if (exec_env->module_inst->module_type == Wasm_Module_AoT)
return aot_call_indirect(exec_env, false, 0,
element_indices,
argv, argc, argv);
element_indices, argc, argv);
#endif
return false;
}
Expand Down
10 changes: 7 additions & 3 deletions core/iwasm/common/wasm_runtime_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ typedef struct WASMModuleInstanceCommon {

#if WASM_ENABLE_LIBC_WASI != 0
typedef struct WASIContext {
struct fd_table *curfds;
struct fd_prestats *prestats;
struct argv_environ_values *argv_environ;
/* Use offset but not native address, since these fields are
allocated from app's heap, and the heap space may be re-allocated
after memory.grow opcode is executed, the original native address
cannot be accessed again. */
int32 curfds_offset;
int32 prestats_offset;
int32 argv_environ_offset;
} WASIContext;
#endif

Expand Down
3 changes: 2 additions & 1 deletion core/iwasm/compilation/aot_emit_aot_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,14 @@ aot_emit_file_header(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
AOTCompData *comp_data, AOTObjectData *obj_data)
{
uint32 offset = *p_offset;
uint32 aot_curr_version = AOT_CURRENT_VERSION;

EMIT_U8('\0');
EMIT_U8('a');
EMIT_U8('o');
EMIT_U8('t');

EMIT_U32(1);
EMIT_U32(aot_curr_version);

*p_offset = offset;
return true;
Expand Down
125 changes: 53 additions & 72 deletions core/iwasm/compilation/aot_emit_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,19 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMTypeRef ret_type, uint8 wasm_ret_type,
LLVMValueRef *p_value_ret, LLVMValueRef *p_res)
{
LLVMTypeRef func_type, func_ptr_type, func_param_types[5];
LLVMTypeRef func_type, func_ptr_type, func_param_types[4];
LLVMTypeRef ret_ptr_type, elem_ptr_type;
LLVMValueRef func, elem_idx, elem_ptr;
LLVMValueRef func_param_values[5], value_ret = NULL, value_ret_ptr, res;
LLVMValueRef func_param_values[4], value_ret = NULL, res;
char buf[32], *func_name = "aot_invoke_native";
uint32 i, cell_num = 0;

/* prepare function type of aot_invoke_native */
func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
func_param_types[1] = I32_TYPE; /* func_idx */
func_param_types[2] = INT32_PTR_TYPE; /* frame_lp */
func_param_types[3] = I32_TYPE; /* argc */
func_param_types[4] = INT32_PTR_TYPE; /* argv_ret */
if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 5, false))) {
func_param_types[2] = I32_TYPE; /* argc */
func_param_types[3] = INT32_PTR_TYPE; /* argv */
if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 4, false))) {
aot_set_last_error("llvm add function type failed.");
return false;
}
Expand Down Expand Up @@ -216,6 +215,24 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
cell_num += wasm_value_type_cell_num(aot_func_type->types[i]);
}

func_param_values[0] = func_ctx->exec_env;
func_param_values[1] = func_idx;
func_param_values[2] = I32_CONST(param_cell_num);
func_param_values[3] = func_ctx->argv_buf;

if (!func_param_values[2]) {
aot_set_last_error("llvm create const failed.");
return false;
}

/* call aot_invoke_native() function */
if (!(res = LLVMBuildCall(comp_ctx->builder, func,
func_param_values, 4, "res"))) {
aot_set_last_error("llvm build call failed.");
return false;
}

/* get function return value */
if (wasm_ret_type != VALUE_TYPE_VOID) {
if (!(ret_ptr_type = LLVMPointerType(ret_type, 0))) {
aot_set_last_error("llvm add pointer type failed.");
Expand All @@ -227,39 +244,12 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
aot_set_last_error("llvm build bit cast failed.");
return false;
}

/* convert to int32 pointer */
if (!(value_ret_ptr = LLVMBuildBitCast(comp_ctx->builder, value_ret,
INT32_PTR_TYPE, "argv_ret_ptr"))) {
aot_set_last_error("llvm build store failed.");
if (!(*p_value_ret = LLVMBuildLoad(comp_ctx->builder, value_ret,
"value_ret"))) {
aot_set_last_error("llvm build load failed.");
return false;
}
}
else {
value_ret_ptr = LLVMConstNull(INT32_PTR_TYPE);
}

func_param_values[0] = func_ctx->exec_env;
func_param_values[1] = func_idx;
func_param_values[2] = func_ctx->argv_buf;
func_param_values[3] = I32_CONST(param_cell_num);
func_param_values[4] = value_ret_ptr;

if (!func_param_values[3]) {
aot_set_last_error("llvm create const failed.");
return false;
}

/* call aot_invoke_native() function */
if (!(res = LLVMBuildCall(comp_ctx->builder, func,
func_param_values, 5, "res"))) {
aot_set_last_error("llvm build call failed.");
return false;
}

if (wasm_ret_type != VALUE_TYPE_VOID)
/* get function return value */
*p_value_ret = LLVMBuildLoad(comp_ctx->builder, value_ret, "value_ret");

*p_res = res;
return true;
Expand Down Expand Up @@ -395,10 +385,10 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMTypeRef ret_type, uint8 wasm_ret_type,
LLVMValueRef *p_value_ret, LLVMValueRef *p_res)
{
LLVMTypeRef func_type, func_ptr_type, func_param_types[7];
LLVMTypeRef func_type, func_ptr_type, func_param_types[6];
LLVMTypeRef ret_ptr_type, elem_ptr_type;
LLVMValueRef func, elem_idx, elem_ptr;
LLVMValueRef func_param_values[7], value_ret = NULL, value_ret_ptr, res = NULL;
LLVMValueRef func_param_values[6], value_ret = NULL, res = NULL;
char buf[32], *func_name = "aot_call_indirect";
uint32 i, cell_num = 0;

Expand All @@ -407,10 +397,9 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
func_param_types[1] = INT8_TYPE; /* check_func_type */
func_param_types[2] = I32_TYPE; /* func_type_idx */
func_param_types[3] = I32_TYPE; /* table_elem_idx */
func_param_types[4] = INT32_PTR_TYPE; /* frame_lp */
func_param_types[5] = I32_TYPE; /* argc */
func_param_types[6] = INT32_PTR_TYPE; /* argv_ret */
if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 7, false))) {
func_param_types[4] = I32_TYPE; /* argc */
func_param_types[5] = INT32_PTR_TYPE; /* argv */
if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 6, false))) {
aot_set_last_error("llvm add function type failed.");
return false;
}
Expand Down Expand Up @@ -470,36 +459,12 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
cell_num += wasm_value_type_cell_num(aot_func_type->types[i]);
}

if (wasm_ret_type != VALUE_TYPE_VOID) {
if (!(ret_ptr_type = LLVMPointerType(ret_type, 0))) {
aot_set_last_error("llvm add pointer type failed.");
return false;
}

if (!(value_ret = LLVMBuildBitCast(comp_ctx->builder, func_ctx->argv_buf,
ret_ptr_type, "argv_ret"))) {
aot_set_last_error("llvm build bit cast failed.");
return false;
}

/* convert to int32 pointer */
if (!(value_ret_ptr = LLVMBuildBitCast(comp_ctx->builder, value_ret,
INT32_PTR_TYPE, "argv_ret_ptr"))) {
aot_set_last_error("llvm build store failed.");
return false;
}
}
else {
value_ret_ptr = LLVMConstNull(INT32_PTR_TYPE);
}

func_param_values[0] = func_ctx->exec_env;
func_param_values[1] = I8_CONST(true);
func_param_values[2] = func_type_idx;
func_param_values[3] = table_elem_idx;
func_param_values[4] = func_ctx->argv_buf;
func_param_values[5] = I32_CONST(param_cell_num);
func_param_values[6] = value_ret_ptr;
func_param_values[4] = I32_CONST(param_cell_num);
func_param_values[5] = func_ctx->argv_buf;

if (!func_param_values[1] || !func_param_values[4]) {
aot_set_last_error("llvm create const failed.");
Expand All @@ -508,14 +473,30 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,

/* call aot_call_indirect() function */
if (!(res = LLVMBuildCall(comp_ctx->builder, func,
func_param_values, 7, "res"))) {
func_param_values, 6, "res"))) {
aot_set_last_error("llvm build call failed.");
return false;
}

if (wasm_ret_type != VALUE_TYPE_VOID)
/* get function return value */
*p_value_ret = LLVMBuildLoad(comp_ctx->builder, value_ret, "value_ret");
/* get function return value */
if (wasm_ret_type != VALUE_TYPE_VOID) {
if (!(ret_ptr_type = LLVMPointerType(ret_type, 0))) {
aot_set_last_error("llvm add pointer type failed.");
return false;
}

if (!(value_ret = LLVMBuildBitCast(comp_ctx->builder, func_ctx->argv_buf,
ret_ptr_type, "argv_ret"))) {
aot_set_last_error("llvm build bit cast failed.");
return false;
}

if (!(*p_value_ret = LLVMBuildLoad(comp_ctx->builder, value_ret,
"value_ret"))) {
aot_set_last_error("llvm build load failed.");
return false;
}
}

*p_res = res;
return true;
Expand Down
Loading