Skip to content

Commit b73edc8

Browse files
authored
Refine code when aux stack global isn't found (#862)
When auxiliary stack global isn't found in wasm app, it must be unused in the wasm app, we set it to __heap_base global and set its size to 0, so as to shrink the linear memory to reduce the memory consumption.
1 parent 212810b commit b73edc8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,18 @@ load_from_sections(WASMModule *module, WASMSection *sections,
30403040
break;
30413041
}
30423042
}
3043+
if (!aux_stack_top_global) {
3044+
/* Auxiliary stack global isn't found, it must be unused
3045+
in the wasm app, as if it is used, the global must be
3046+
defined. Here we set it to __heap_base global and set
3047+
its size to 0. */
3048+
aux_stack_top_global = aux_heap_base_global;
3049+
aux_stack_top = aux_heap_base;
3050+
module->aux_stack_top_global_index =
3051+
module->aux_heap_base_global_index;
3052+
module->aux_stack_bottom = aux_stack_top;
3053+
module->aux_stack_size = 0;
3054+
}
30433055
break;
30443056
}
30453057
}
@@ -3084,7 +3096,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
30843096
export->name, export->index);
30853097

30863098
/* resolve retain function.
3087-
If not find, reset malloc function index */
3099+
If not found, reset malloc function index */
30883100
export_tmp = module->exports;
30893101
for (j = 0; j < module->export_count; j++, export_tmp++) {
30903102
if ((export_tmp->kind == EXPORT_KIND_FUNC)

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,18 @@ load_from_sections(WASMModule *module, WASMSection *sections,
19591959
break;
19601960
}
19611961
}
1962+
if (!aux_stack_top_global) {
1963+
/* Auxiliary stack global isn't found, it must be unused
1964+
in the wasm app, as if it is used, the global must be
1965+
defined. Here we set it to __heap_base global and set
1966+
its size to 0. */
1967+
aux_stack_top_global = aux_heap_base_global;
1968+
aux_stack_top = aux_heap_base;
1969+
module->aux_stack_top_global_index =
1970+
module->aux_heap_base_global_index;
1971+
module->aux_stack_bottom = aux_stack_top;
1972+
module->aux_stack_size = 0;
1973+
}
19621974
break;
19631975
}
19641976
}
@@ -2002,7 +2014,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
20022014
export->name, export->index);
20032015

20042016
/* resolve retain function.
2005-
If not find, reset malloc function index */
2017+
If not found, reset malloc function index */
20062018
export_tmp = module->exports;
20072019
for (j = 0; j < module->export_count; j++, export_tmp++) {
20082020
if ((export_tmp->kind == EXPORT_KIND_FUNC)

0 commit comments

Comments
 (0)