Skip to content

Commit 9500937

Browse files
committed
Rebase newest wamr
1 parent e1921b5 commit 9500937

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

core/iwasm/aot/aot_loader.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -2558,9 +2558,19 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
25582558
}
25592559
}
25602560

2561+
#if defined(BUILD_TARGET_XTENSA)
2562+
/*
2563+
* For Xtensa XIP, real func_count is doubled, including aot_func and
2564+
* aot_func_internal, so need to divide func_count by 2 here.
2565+
*/
2566+
if (module->is_indirect_mode)
2567+
size = sizeof(uint32) * (uint64)module->func_count / 2;
2568+
else
2569+
#else
25612570
size = sizeof(uint32) * (uint64)module->func_count;
2571+
#endif
25622572

2563-
if (size > 0) {
2573+
if (size > 0) {
25642574
#if WASM_ENABLE_AOT_STACK_FRAME != 0
25652575
if (!(module->max_local_cell_nums =
25662576
loader_malloc(size, error_buf, error_buf_size))) {

core/iwasm/compilation/aot_emit_aot_file.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ is_little_endian_binary(const AOTObjectData *obj_data)
179179
return obj_data->target_info.bin_type & 1 ? false : true;
180180
}
181181

182+
static bool
183+
need_call_wrapped_indirect(const AOTObjectData *obj_data)
184+
{
185+
const bool need_precheck = obj_data->comp_ctx->enable_stack_bound_check
186+
|| obj_data->comp_ctx->enable_stack_estimation;
187+
188+
return obj_data->comp_ctx->is_indirect_mode && need_precheck
189+
&& !strncmp(obj_data->comp_ctx->target_arch, "xtensa", 6);
190+
}
191+
182192
static bool
183193
str_starts_with(const char *str, const char *prefix)
184194
{
@@ -870,11 +880,8 @@ get_func_section_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
870880
/* function type indexes */
871881
size += (uint32)sizeof(uint32) * comp_data->func_count;
872882

873-
const bool need_precheck = obj_data->comp_ctx->enable_stack_bound_check
874-
|| obj_data->comp_ctx->enable_stack_estimation;
875883
/* aot_func#xxx + aot_func_internal#xxx in XIP mode for xtensa */
876-
if (obj_data->comp_ctx->is_indirect_mode && need_precheck
877-
&& !strncmp(obj_data->comp_ctx->target_arch, "xtensa", 6))
884+
if (need_call_wrapped_indirect(obj_data))
878885
size *= 2;
879886

880887
/* max_local_cell_nums */
@@ -2416,10 +2423,7 @@ aot_emit_init_data_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
24162423
return false;
24172424

24182425
offset = align_uint(offset, 4);
2419-
const bool need_precheck = obj_data->comp_ctx->enable_stack_bound_check
2420-
|| obj_data->comp_ctx->enable_stack_estimation;
2421-
if (obj_data->comp_ctx->is_indirect_mode && need_precheck
2422-
&& !strncmp(obj_data->comp_ctx->target_arch, "xtensa", 6))
2426+
if (need_call_wrapped_indirect(obj_data))
24232427
EMIT_U32(comp_data->func_count * 2);
24242428
else
24252429
EMIT_U32(comp_data->func_count);
@@ -2607,10 +2611,7 @@ aot_emit_func_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
26072611
EMIT_U64(func->text_offset);
26082612
}
26092613

2610-
const bool need_precheck = obj_data->comp_ctx->enable_stack_bound_check
2611-
|| obj_data->comp_ctx->enable_stack_estimation;
2612-
if (obj_data->comp_ctx->is_indirect_mode && need_precheck
2613-
&& !strncmp(obj_data->comp_ctx->target_arch, "xtensa", 6)) {
2614+
if (need_call_wrapped_indirect(obj_data)) {
26142615
/*
26152616
* Explicitly emit aot_func_internal#xxx for Xtensa XIP, therefore,
26162617
* for aot_func#xxx, func_indexes ranged from 0 ~ func_count,
@@ -2628,8 +2629,7 @@ aot_emit_func_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
26282629
for (i = 0; i < comp_data->func_count; i++)
26292630
EMIT_U32(funcs[i]->func_type_index);
26302631

2631-
if (obj_data->comp_ctx->is_indirect_mode && need_precheck
2632-
&& !strncmp(obj_data->comp_ctx->target_arch, "xtensa", 6)) {
2632+
if (need_call_wrapped_indirect(obj_data)) {
26332633
/* func_type_index for aot_func_internal#xxxx */
26342634
for (i = 0; i < comp_data->func_count; i++)
26352635
EMIT_U32(funcs[i]->func_type_index);

0 commit comments

Comments
 (0)