Skip to content

Commit fe5e7a9

Browse files
authored
Implement Memory64 support for AOT (#3362)
Refer to: #3266 #3091
1 parent c85bada commit fe5e7a9

26 files changed

+521
-294
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,7 @@ jobs:
566566
test_option: $GC_TEST_OPTIONS
567567
- running_mode: "multi-tier-jit"
568568
test_option: $GC_TEST_OPTIONS
569-
# aot, fast-interp, fast-jit, llvm-jit, multi-tier-jit don't support Memory64
570-
- running_mode: "aot"
571-
test_option: $MEMORY64_TEST_OPTIONS
569+
# fast-interp, fast-jit, llvm-jit, multi-tier-jit don't support Memory64
572570
- running_mode: "fast-interp"
573571
test_option: $MEMORY64_TEST_OPTIONS
574572
- running_mode: "fast-jit"
@@ -616,6 +614,7 @@ jobs:
616614
if: >
617615
((matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS'
618616
|| matrix.test_option == '$WASI_TEST_OPTIONS' || matrix.test_option == '$GC_TEST_OPTIONS')
617+
&& matrix.test_option != '$MEMORY64_TEST_OPTIONS'
619618
&& matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit')
620619
run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV
621620

core/iwasm/aot/aot_loader.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "aot_reloc.h"
1010
#include "../common/wasm_runtime_common.h"
1111
#include "../common/wasm_native.h"
12+
#include "../common/wasm_loader_common.h"
1213
#include "../compilation/aot.h"
1314

1415
#if WASM_ENABLE_DEBUG_AOT != 0
@@ -1043,6 +1044,12 @@ load_memory_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
10431044

10441045
for (i = 0; i < module->memory_count; i++) {
10451046
read_uint32(buf, buf_end, module->memories[i].memory_flags);
1047+
1048+
if (!wasm_memory_check_flags(module->memories[i].memory_flags,
1049+
error_buf, error_buf_size, true)) {
1050+
return false;
1051+
}
1052+
10461053
read_uint32(buf, buf_end, module->memories[i].num_bytes_per_page);
10471054
read_uint32(buf, buf_end, module->memories[i].mem_init_page_count);
10481055
read_uint32(buf, buf_end, module->memories[i].mem_max_page_count);
@@ -3634,6 +3641,21 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
36343641
return ret;
36353642
}
36363643

3644+
#if WASM_ENABLE_MEMORY64 != 0
3645+
static bool
3646+
has_module_memory64(AOTModule *module)
3647+
{
3648+
/* TODO: multi-memories for now assuming the memory idx type is consistent
3649+
* across multi-memories */
3650+
if (module->import_memory_count > 0)
3651+
return !!(module->import_memories[0].memory_flags & MEMORY64_FLAG);
3652+
else if (module->memory_count > 0)
3653+
return !!(module->memories[0].memory_flags & MEMORY64_FLAG);
3654+
3655+
return false;
3656+
}
3657+
#endif
3658+
36373659
static bool
36383660
load_from_sections(AOTModule *module, AOTSection *sections,
36393661
bool is_load_from_file_buf, char *error_buf,
@@ -3645,6 +3667,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
36453667
uint32 i, func_index, func_type_index;
36463668
AOTFuncType *func_type;
36473669
AOTExport *exports;
3670+
uint8 malloc_free_io_type = VALUE_TYPE_I32;
36483671

36493672
while (section) {
36503673
buf = section->section_body;
@@ -3719,7 +3742,10 @@ load_from_sections(AOTModule *module, AOTSection *sections,
37193742
module->malloc_func_index = (uint32)-1;
37203743
module->free_func_index = (uint32)-1;
37213744
module->retain_func_index = (uint32)-1;
3722-
3745+
#if WASM_ENABLE_MEMORY64 != 0
3746+
if (has_module_memory64(module))
3747+
malloc_free_io_type = VALUE_TYPE_I64;
3748+
#endif
37233749
exports = module->exports;
37243750
for (i = 0; i < module->export_count; i++) {
37253751
if (exports[i].kind == EXPORT_KIND_FUNC
@@ -3729,8 +3755,8 @@ load_from_sections(AOTModule *module, AOTSection *sections,
37293755
func_type_index = module->func_type_indexes[func_index];
37303756
func_type = (AOTFuncType *)module->types[func_type_index];
37313757
if (func_type->param_count == 1 && func_type->result_count == 1
3732-
&& func_type->types[0] == VALUE_TYPE_I32
3733-
&& func_type->types[1] == VALUE_TYPE_I32) {
3758+
&& func_type->types[0] == malloc_free_io_type
3759+
&& func_type->types[1] == malloc_free_io_type) {
37343760
bh_assert(module->malloc_func_index == (uint32)-1);
37353761
module->malloc_func_index = func_index;
37363762
LOG_VERBOSE("Found malloc function, name: %s, index: %u",
@@ -3742,9 +3768,9 @@ load_from_sections(AOTModule *module, AOTSection *sections,
37423768
func_type_index = module->func_type_indexes[func_index];
37433769
func_type = (AOTFuncType *)module->types[func_type_index];
37443770
if (func_type->param_count == 2 && func_type->result_count == 1
3745-
&& func_type->types[0] == VALUE_TYPE_I32
3771+
&& func_type->types[0] == malloc_free_io_type
37463772
&& func_type->types[1] == VALUE_TYPE_I32
3747-
&& func_type->types[2] == VALUE_TYPE_I32) {
3773+
&& func_type->types[2] == malloc_free_io_type) {
37483774
uint32 j;
37493775
WASMExport *export_tmp;
37503776

@@ -3768,8 +3794,8 @@ load_from_sections(AOTModule *module, AOTSection *sections,
37683794
(AOTFuncType *)module->types[func_type_index];
37693795
if (func_type->param_count == 1
37703796
&& func_type->result_count == 1
3771-
&& func_type->types[0] == VALUE_TYPE_I32
3772-
&& func_type->types[1] == VALUE_TYPE_I32) {
3797+
&& func_type->types[0] == malloc_free_io_type
3798+
&& func_type->types[1] == malloc_free_io_type) {
37733799
bh_assert(module->retain_func_index
37743800
== (uint32)-1);
37753801
module->retain_func_index = export_tmp->index;
@@ -3795,7 +3821,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
37953821
func_type_index = module->func_type_indexes[func_index];
37963822
func_type = (AOTFuncType *)module->types[func_type_index];
37973823
if (func_type->param_count == 1 && func_type->result_count == 0
3798-
&& func_type->types[0] == VALUE_TYPE_I32) {
3824+
&& func_type->types[0] == malloc_free_io_type) {
37993825
bh_assert(module->free_func_index == (uint32)-1);
38003826
module->free_func_index = func_index;
38013827
LOG_VERBOSE("Found free function, name: %s, index: %u",

0 commit comments

Comments
 (0)