Skip to content

Commit

Permalink
restore aot abi compatibility
Browse files Browse the repository at this point in the history
by moving aot_stack_sizes from aot inst to inst extra
  • Loading branch information
yamt committed Jun 28, 2023
1 parent e0f44a9 commit f7ec28b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions core/iwasm/aot/aot_runtime.c
Expand Up @@ -39,10 +39,10 @@ bh_static_assert(offsetof(AOTModuleInstance, func_type_indexes)
== 6 * sizeof(uint64));
bh_static_assert(offsetof(AOTModuleInstance, cur_exception)
== 13 * sizeof(uint64));
bh_static_assert(offsetof(AOTModuleInstance, aot_stack_sizes)
== 13 * sizeof(uint64) + 128 + 11 * sizeof(uint64));
bh_static_assert(offsetof(AOTModuleInstance, global_table_data)
== 13 * sizeof(uint64) + 128 + 12 * sizeof(uint64));
== 13 * sizeof(uint64) + 128 + 11 * sizeof(uint64));

bh_static_assert(offsetof(AOTModuleInstanceExtra, stack_sizes) == 0);

static void
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
Expand Down Expand Up @@ -1212,7 +1212,7 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
#endif
module_inst->default_wasm_stack_size = stack_size;

module_inst->aot_stack_sizes =
((AOTModuleInstanceExtra *)module_inst->e)->stack_sizes =
aot_get_data_section_addr(module, AOT_STACK_SIZES_SECTION_NAME, NULL);

#if WASM_ENABLE_PERF_PROFILING != 0
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/aot/aot_runtime.h
Expand Up @@ -88,6 +88,7 @@ typedef struct AOTFunctionInstance {
} AOTFunctionInstance;

typedef struct AOTModuleInstanceExtra {
const uint32 *stack_sizes;
CApiFuncImport *c_api_func_imports;
} AOTModuleInstanceExtra;

Expand Down
17 changes: 15 additions & 2 deletions core/iwasm/compilation/aot_llvm.c
Expand Up @@ -7,6 +7,7 @@
#include "aot_llvm_extra2.h"
#include "aot_compiler.h"
#include "aot_emit_exception.h"
#include "aot_emit_table.h"
#include "../aot/aot_runtime.h"
#include "../aot/aot_intrinsic.h"

Expand Down Expand Up @@ -230,6 +231,17 @@ aot_estimate_stack_usage_for_function_call(const AOTCompContext *comp_ctx,
return size;
}

static uint32
get_inst_extra_offset(AOTCompContext *comp_ctx)
{
const AOTCompData *comp_data = comp_ctx->comp_data;
uint32 table_count = comp_data->import_table_count + comp_data->table_count;
uint64 offset = get_tbl_inst_offset(comp_ctx, NULL, table_count);
bh_assert(offset <= UINT_MAX);
offset = align_uint(offset, 8);
return offset;
}

/*
* a "precheck" function performs a few things before calling wrapped_func.
*
Expand Down Expand Up @@ -329,8 +341,9 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
*/
LLVMValueRef stack_sizes;
if (comp_ctx->is_indirect_mode) {
LLVMValueRef offset =
I32_CONST(offsetof(AOTModuleInstance, aot_stack_sizes));
uint32 offset_u32 = get_inst_extra_offset(comp_ctx);
offset_u32 += offsetof(AOTModuleInstanceExtra, stack_sizes);
LLVMValueRef offset = I32_CONST(offset_u32);
if (!offset) {
goto fail;
}
Expand Down
3 changes: 0 additions & 3 deletions core/iwasm/interpreter/wasm_runtime.h
Expand Up @@ -318,9 +318,6 @@ struct WASMModuleInstance {
uint32 default_wasm_stack_size;
uint32 reserved[3];

/* AOT */
DefPointer(const uint32 *, aot_stack_sizes);

/*
* +------------------------------+ <-- memories
* | WASMMemoryInstance[mem_count], mem_count is always 1 for LLVM JIT/AOT
Expand Down

0 comments on commit f7ec28b

Please sign in to comment.