aot: Avoid possible relocations around "stack_sizes" for XIP mode (#2322)
Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/2316 Lightly tested on riscv64 qemu.
This commit is contained in:
@ -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"
|
||||
|
||||
@ -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.
|
||||
*
|
||||
@ -327,9 +339,36 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
|
||||
/*
|
||||
* load the value for this wrapped function from the stack_sizes array
|
||||
*/
|
||||
LLVMValueRef stack_sizes;
|
||||
if (comp_ctx->is_indirect_mode) {
|
||||
uint32 offset_u32;
|
||||
LLVMValueRef offset;
|
||||
LLVMValueRef stack_sizes_p;
|
||||
|
||||
offset_u32 = get_inst_extra_offset(comp_ctx);
|
||||
offset_u32 += offsetof(AOTModuleInstanceExtra, stack_sizes);
|
||||
offset = I32_CONST(offset_u32);
|
||||
if (!offset) {
|
||||
goto fail;
|
||||
}
|
||||
stack_sizes_p =
|
||||
LLVMBuildInBoundsGEP2(b, INT8_TYPE, func_ctx->aot_inst, &offset, 1,
|
||||
"aot_inst_stack_sizes_p");
|
||||
if (!stack_sizes_p) {
|
||||
goto fail;
|
||||
}
|
||||
stack_sizes =
|
||||
LLVMBuildLoad2(b, INT32_PTR_TYPE, stack_sizes_p, "stack_sizes");
|
||||
if (!stack_sizes) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else {
|
||||
stack_sizes = comp_ctx->stack_sizes;
|
||||
}
|
||||
LLVMValueRef func_index_const = I32_CONST(func_index);
|
||||
LLVMValueRef sizes =
|
||||
LLVMBuildBitCast(b, comp_ctx->stack_sizes, INT32_PTR_TYPE, "sizes");
|
||||
LLVMBuildBitCast(b, stack_sizes, INT32_PTR_TYPE, "sizes");
|
||||
if (!sizes) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user