@@ -2533,6 +2533,7 @@ load_function_import(const uint8 **p_buf, const uint8 *buf_end,
25332533 WASMFunction *linked_func = NULL;
25342534#if WASM_ENABLE_MULTI_MODULE != 0
25352535 WASMModule *sub_module = NULL;
2536+ bool is_built_in_module = false;
25362537#endif
25372538 const char *linked_signature = NULL;
25382539 void *linked_attachment = NULL;
@@ -2568,17 +2569,16 @@ load_function_import(const uint8 **p_buf, const uint8 *buf_end,
25682569 }
25692570#if WASM_ENABLE_MULTI_MODULE != 0
25702571 else {
2571- if (!wasm_runtime_is_built_in_module(sub_module_name)) {
2572+ if (!(is_built_in_module =
2573+ wasm_runtime_is_built_in_module(sub_module_name))) {
25722574 sub_module = (WASMModule *)wasm_runtime_load_depended_module(
25732575 (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
25742576 error_buf_size);
2575- if (!sub_module) {
2576- return false;
2577- }
25782577 }
2579- linked_func = wasm_loader_resolve_function(
2580- sub_module_name, function_name, declare_func_type, error_buf,
2581- error_buf_size);
2578+ if (is_built_in_module || sub_module)
2579+ linked_func = wasm_loader_resolve_function(
2580+ sub_module_name, function_name, declare_func_type, error_buf,
2581+ error_buf_size);
25822582 }
25832583#endif
25842584
@@ -2691,24 +2691,20 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
26912691 sub_module = (WASMModule *)wasm_runtime_load_depended_module(
26922692 (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
26932693 error_buf_size);
2694- if (!sub_module) {
2695- return false;
2696- }
2697-
2698- linked_table = wasm_loader_resolve_table(
2699- sub_module_name, table_name, declare_init_size, declare_max_size,
2700- error_buf, error_buf_size);
2701- if (!linked_table) {
2702- return false;
2694+ if (sub_module) {
2695+ linked_table = wasm_loader_resolve_table(
2696+ sub_module_name, table_name, declare_init_size,
2697+ declare_max_size, error_buf, error_buf_size);
2698+ if (linked_table) {
2699+ /* reset with linked table limit */
2700+ declare_elem_type = linked_table->table_type.elem_type;
2701+ declare_init_size = linked_table->table_type.init_size;
2702+ declare_max_size = linked_table->table_type.max_size;
2703+ declare_max_size_flag = linked_table->table_type.flags;
2704+ table->import_table_linked = linked_table;
2705+ table->import_module = sub_module;
2706+ }
27032707 }
2704-
2705- /* reset with linked table limit */
2706- declare_elem_type = linked_table->table_type.elem_type;
2707- declare_init_size = linked_table->table_type.init_size;
2708- declare_max_size = linked_table->table_type.max_size;
2709- declare_max_size_flag = linked_table->table_type.flags;
2710- table->import_table_linked = linked_table;
2711- table->import_module = sub_module;
27122708 }
27132709#endif /* WASM_ENABLE_MULTI_MODULE != 0 */
27142710
@@ -2870,31 +2866,19 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
28702866 sub_module = (WASMModule *)wasm_runtime_load_depended_module(
28712867 (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
28722868 error_buf_size);
2873- if (!sub_module) {
2874- #if WASM_ENABLE_LIB_WASI_THREADS != 0
2875- /* Avoid memory import failure when wasi-threads is enabled
2876- and the memory is shared */
2877- if (!(mem_flag & SHARED_MEMORY_FLAG))
2878- return false;
2879- #else
2880- return false;
2881- #endif /* WASM_ENABLE_LIB_WASI_THREADS */
2882- }
2883- else {
2869+ if (sub_module) {
28842870 linked_memory = wasm_loader_resolve_memory(
28852871 sub_module_name, memory_name, declare_init_page_count,
28862872 declare_max_page_count, error_buf, error_buf_size);
2887- if (!linked_memory) {
2888- return false;
2873+ if (linked_memory) {
2874+ /**
2875+ * reset with linked memory limit
2876+ */
2877+ memory->import_module = sub_module;
2878+ memory->import_memory_linked = linked_memory;
2879+ declare_init_page_count = linked_memory->init_page_count;
2880+ declare_max_page_count = linked_memory->max_page_count;
28892881 }
2890-
2891- /**
2892- * reset with linked memory limit
2893- */
2894- memory->import_module = sub_module;
2895- memory->import_memory_linked = linked_memory;
2896- declare_init_page_count = linked_memory->init_page_count;
2897- declare_max_page_count = linked_memory->max_page_count;
28982882 }
28992883 }
29002884#endif
@@ -2920,6 +2904,29 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
29202904 declare_init_page_count = spectest_memory_init_page;
29212905 declare_max_page_count = spectest_memory_max_page;
29222906 }
2907+ #if WASM_ENABLE_WASI_TEST != 0
2908+ /* a case in wasi-testsuite which imports ("foo" "bar") */
2909+ else if (!strcmp("foo", sub_module_name)) {
2910+ uint32 spectest_memory_init_page = 1;
2911+ uint32 spectest_memory_max_page = 1;
2912+
2913+ if (strcmp("bar", memory_name)) {
2914+ set_error_buf(error_buf, error_buf_size,
2915+ "incompatible import type or unknown import");
2916+ return false;
2917+ }
2918+
2919+ if (declare_init_page_count > spectest_memory_init_page
2920+ || declare_max_page_count < spectest_memory_max_page) {
2921+ set_error_buf(error_buf, error_buf_size,
2922+ "incompatible import type");
2923+ return false;
2924+ }
2925+
2926+ declare_init_page_count = spectest_memory_init_page;
2927+ declare_max_page_count = spectest_memory_max_page;
2928+ }
2929+ #endif
29232930
29242931 /* now we believe all declaration are ok */
29252932 memory->mem_type.flags = mem_flag;
@@ -2983,20 +2990,19 @@ load_tag_import(const uint8 **p_buf, const uint8 *buf_end,
29832990 sub_module = (WASMModule *)wasm_runtime_load_depended_module(
29842991 (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
29852992 error_buf_size);
2986- if (!sub_module) {
2987- return false;
2988- }
2989- /* wasm_loader_resolve_tag checks, that the imported tag
2990- * and the declared tag have the same type
2991- */
2992- uint32 linked_tag_index = 0;
2993- WASMTag *linked_tag = wasm_loader_resolve_tag(
2994- sub_module_name, tag_name, declare_tag_type,
2995- &linked_tag_index /* out */, error_buf, error_buf_size);
2996- if (linked_tag) {
2997- tag->import_module = sub_module;
2998- tag->import_tag_linked = linked_tag;
2999- tag->import_tag_index_linked = linked_tag_index;
2993+ if (sub_module) {
2994+ /* wasm_loader_resolve_tag checks, that the imported tag
2995+ * and the declared tag have the same type
2996+ */
2997+ uint32 linked_tag_index = 0;
2998+ WASMTag *linked_tag = wasm_loader_resolve_tag(
2999+ sub_module_name, tag_name, declare_tag_type,
3000+ &linked_tag_index /* out */, error_buf, error_buf_size);
3001+ if (linked_tag) {
3002+ tag->import_module = sub_module;
3003+ tag->import_tag_linked = linked_tag;
3004+ tag->import_tag_index_linked = linked_tag_index;
3005+ }
30003006 }
30013007 }
30023008#endif
@@ -3095,18 +3101,16 @@ load_global_import(const uint8 **p_buf, const uint8 *buf_end,
30953101 sub_module = (WASMModule *)wasm_runtime_load_depended_module(
30963102 (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
30973103 error_buf_size);
3098- if (!sub_module) {
3099- return false;
3100- }
3101-
3102- /* check sub modules */
3103- linked_global = wasm_loader_resolve_global(
3104- sub_module_name, global_name, declare_type, declare_mutable,
3105- error_buf, error_buf_size);
3106- if (linked_global) {
3107- global->import_module = sub_module;
3108- global->import_global_linked = linked_global;
3109- global->is_linked = true;
3104+ if (sub_module) {
3105+ /* check sub modules */
3106+ linked_global = wasm_loader_resolve_global(
3107+ sub_module_name, global_name, declare_type, declare_mutable,
3108+ error_buf, error_buf_size);
3109+ if (linked_global) {
3110+ global->import_module = sub_module;
3111+ global->import_global_linked = linked_global;
3112+ global->is_linked = true;
3113+ }
31103114 }
31113115 }
31123116#endif
0 commit comments