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
aot: avoid possible relocations around "stack_sizes" for indirect mode #2322
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,32 @@ 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 = get_inst_extra_offset(comp_ctx); | ||
offset_u32 += offsetof(AOTModuleInstanceExtra, stack_sizes); | ||
LLVMValueRef offset = I32_CONST(offset_u32); | ||
if (!offset) { | ||
goto fail; | ||
} | ||
LLVMValueRef stack_sizes_p = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had better declare the variables at the beginning of code piece There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i generally feel less lines are easier to read. but ok. i will follow your style. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better use
DefPointer(const uint32 *, stack_sizes)
? Suppose the aot code may access more fields here in the future, we can ensure the offsets of these fields are fixed, and are the same in compilation time and execution time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done