@@ -634,73 +634,6 @@ str2uint32(const char *buf, uint32 *p_res);
634634static bool
635635str2uint64 (const char * buf , uint64 * p_res );
636636
637- #if WASM_ENABLE_MULTI_MODULE != 0
638- static void *
639- aot_loader_resolve_function (const AOTModule * module , const char * function_name ,
640- const AOTFuncType * expected_function_type ,
641- char * error_buf , uint32 error_buf_size );
642-
643- static void *
644- aot_loader_resolve_function_ex (const char * module_name ,
645- const char * function_name ,
646- const AOTFuncType * expected_function_type ,
647- char * error_buf , uint32 error_buf_size )
648- {
649- WASMModuleCommon * module_reg ;
650-
651- module_reg = wasm_runtime_find_module_registered (module_name );
652- if (!module_reg || module_reg -> module_type != Wasm_Module_AoT ) {
653- LOG_DEBUG ("can not find a module named %s for function %s" , module_name ,
654- function_name );
655- set_error_buf (error_buf , error_buf_size , "unknown import" );
656- return NULL ;
657- }
658- return aot_loader_resolve_function ((AOTModule * )module_reg , function_name ,
659- expected_function_type , error_buf ,
660- error_buf_size );
661- }
662-
663- static void *
664- aot_loader_resolve_function (const AOTModule * module , const char * function_name ,
665- const AOTFuncType * expected_function_type ,
666- char * error_buf , uint32 error_buf_size )
667- {
668- void * function = NULL ;
669- AOTExport * export = NULL ;
670- AOTFuncType * target_function_type = NULL ;
671-
672- export = loader_find_export ((WASMModuleCommon * )module , module -> name ,
673- function_name , EXPORT_KIND_FUNC , error_buf ,
674- error_buf_size );
675- if (!export ) {
676- return NULL ;
677- }
678-
679- /* resolve function type and function */
680- if (export -> index < module -> import_func_count ) {
681- target_function_type = module -> import_funcs [export -> index ].func_type ;
682- function = module -> import_funcs [export -> index ].func_ptr_linked ;
683- }
684- else {
685- target_function_type =
686- (AOTFuncType * )module
687- -> types [module -> func_type_indexes [export -> index
688- - module -> import_func_count ]];
689- function =
690- (module -> func_ptrs [export -> index - module -> import_func_count ]);
691- }
692- /* check function type */
693- if (!wasm_type_equal ((WASMType * )expected_function_type ,
694- (WASMType * )target_function_type , module -> types ,
695- module -> type_count )) {
696- LOG_DEBUG ("%s.%s failed the type check" , module -> name , function_name );
697- set_error_buf (error_buf , error_buf_size , "incompatible import type" );
698- return NULL ;
699- }
700- return function ;
701- }
702- #endif /* end of WASM_ENABLE_MULTI_MODULE */
703-
704637static bool
705638load_native_symbol_section (const uint8 * buf , const uint8 * buf_end ,
706639 AOTModule * module , bool is_load_from_file_buf ,
@@ -2285,19 +2218,13 @@ destroy_import_funcs(AOTImportFunc *import_funcs)
22852218
22862219static bool
22872220load_import_funcs (const uint8 * * p_buf , const uint8 * buf_end , AOTModule * module ,
2288- bool is_load_from_file_buf , char * error_buf ,
2221+ bool is_load_from_file_buf , bool no_resolve , char * error_buf ,
22892222 uint32 error_buf_size )
22902223{
2291- char * module_name , * field_name ;
22922224 const uint8 * buf = * p_buf ;
22932225 AOTImportFunc * import_funcs ;
22942226 uint64 size ;
22952227 uint32 i ;
2296- #if WASM_ENABLE_MULTI_MODULE != 0
2297- AOTModule * sub_module = NULL ;
2298- AOTFunc * linked_func = NULL ;
2299- AOTFuncType * declare_func_type = NULL ;
2300- #endif
23012228
23022229 /* Allocate memory */
23032230 size = sizeof (AOTImportFunc ) * (uint64 )module -> import_func_count ;
@@ -2314,53 +2241,17 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
23142241 return false;
23152242 }
23162243
2317- #if WASM_ENABLE_MULTI_MODULE != 0
2318- declare_func_type =
2319- (AOTFuncType * )module -> types [import_funcs [i ].func_type_index ];
2320- read_string (buf , buf_end , module_name );
2321- read_string (buf , buf_end , field_name );
2322-
2323- import_funcs [i ].module_name = module_name ;
2324- import_funcs [i ].func_name = field_name ;
2325- linked_func = wasm_native_resolve_symbol (
2326- module_name , field_name , declare_func_type ,
2327- & import_funcs [i ].signature , & import_funcs [i ].attachment ,
2328- & import_funcs [i ].call_conv_raw );
2329- if (!linked_func ) {
2330- sub_module = NULL ;
2331- if (!wasm_runtime_is_built_in_module (module_name )) {
2332- sub_module = (AOTModule * )wasm_runtime_load_depended_module (
2333- (WASMModuleCommon * )module , module_name , error_buf ,
2334- error_buf_size );
2335- if (!sub_module ) {
2336- LOG_ERROR ("failed to load sub module: %s" , error_buf );
2337- return false;
2338- }
2339- }
2340- if (!sub_module )
2341- linked_func = aot_loader_resolve_function_ex (
2342- module_name , field_name , declare_func_type , error_buf ,
2343- error_buf_size );
2344- else
2345- linked_func = aot_loader_resolve_function (
2346- sub_module , field_name , declare_func_type , error_buf ,
2347- error_buf_size );
2348- }
2349- import_funcs [i ].func_ptr_linked = linked_func ;
2350- import_funcs [i ].func_type = declare_func_type ;
2351-
2352- #else
23532244 import_funcs [i ].func_type =
23542245 (AOTFuncType * )module -> types [import_funcs [i ].func_type_index ];
23552246 read_string (buf , buf_end , import_funcs [i ].module_name );
23562247 read_string (buf , buf_end , import_funcs [i ].func_name );
2357- module_name = import_funcs [i ].module_name ;
2358- field_name = import_funcs [i ].func_name ;
2359- import_funcs [i ].func_ptr_linked = wasm_native_resolve_symbol (
2360- module_name , field_name , import_funcs [ i ]. func_type ,
2361- & import_funcs [ i ]. signature , & import_funcs [ i ]. attachment ,
2362- & import_funcs [i ]. call_conv_raw );
2363- #endif
2248+ import_funcs [i ].attachment = NULL ;
2249+ import_funcs [i ].signature = NULL ;
2250+ import_funcs [i ].call_conv_raw = false;
2251+
2252+ if (! no_resolve ) {
2253+ aot_resolve_import_func ( module , & import_funcs [i ]);
2254+ }
23642255
23652256#if WASM_ENABLE_LIBC_WASI != 0
23662257 if (!strcmp (import_funcs [i ].module_name , "wasi_unstable" )
@@ -2378,7 +2269,7 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
23782269static bool
23792270load_import_func_info (const uint8 * * p_buf , const uint8 * buf_end ,
23802271 AOTModule * module , bool is_load_from_file_buf ,
2381- char * error_buf , uint32 error_buf_size )
2272+ bool no_resolve , char * error_buf , uint32 error_buf_size )
23822273{
23832274 const uint8 * buf = * p_buf ;
23842275
@@ -2387,7 +2278,7 @@ load_import_func_info(const uint8 **p_buf, const uint8 *buf_end,
23872278 /* load import funcs */
23882279 if (module -> import_func_count > 0
23892280 && !load_import_funcs (& buf , buf_end , module , is_load_from_file_buf ,
2390- error_buf , error_buf_size ))
2281+ no_resolve , error_buf , error_buf_size ))
23912282 return false;
23922283
23932284 * p_buf = buf ;
@@ -2514,7 +2405,7 @@ load_object_data_sections_info(const uint8 **p_buf, const uint8 *buf_end,
25142405static bool
25152406load_init_data_section (const uint8 * buf , const uint8 * buf_end ,
25162407 AOTModule * module , bool is_load_from_file_buf ,
2517- char * error_buf , uint32 error_buf_size )
2408+ bool no_resolve , char * error_buf , uint32 error_buf_size )
25182409{
25192410 const uint8 * p = buf , * p_end = buf_end ;
25202411
@@ -2525,7 +2416,7 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,
25252416 error_buf , error_buf_size )
25262417 || !load_global_info (& p , p_end , module , error_buf , error_buf_size )
25272418 || !load_import_func_info (& p , p_end , module , is_load_from_file_buf ,
2528- error_buf , error_buf_size ))
2419+ no_resolve , error_buf , error_buf_size ))
25292420 return false;
25302421
25312422 /* load function count and start function index */
@@ -3819,7 +3710,7 @@ has_module_memory64(AOTModule *module)
38193710
38203711static bool
38213712load_from_sections (AOTModule * module , AOTSection * sections ,
3822- bool is_load_from_file_buf , char * error_buf ,
3713+ bool is_load_from_file_buf , bool no_resolve , char * error_buf ,
38233714 uint32 error_buf_size )
38243715{
38253716 AOTSection * section = sections ;
@@ -3852,8 +3743,8 @@ load_from_sections(AOTModule *module, AOTSection *sections,
38523743 break ;
38533744 case AOT_SECTION_TYPE_INIT_DATA :
38543745 if (!load_init_data_section (buf , buf_end , module ,
3855- is_load_from_file_buf , error_buf ,
3856- error_buf_size ))
3746+ is_load_from_file_buf , no_resolve ,
3747+ error_buf , error_buf_size ))
38573748 return false;
38583749 break ;
38593750 case AOT_SECTION_TYPE_TEXT :
@@ -4076,7 +3967,7 @@ aot_load_from_sections(AOTSection *section_list, char *error_buf,
40763967 if (!module )
40773968 return NULL ;
40783969
4079- if (!load_from_sections (module , section_list , false, error_buf ,
3970+ if (!load_from_sections (module , section_list , false, false, error_buf ,
40803971 error_buf_size )) {
40813972 aot_unload (module );
40823973 return NULL ;
@@ -4246,7 +4137,8 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
42464137
42474138static bool
42484139load (const uint8 * buf , uint32 size , AOTModule * module ,
4249- bool wasm_binary_freeable , char * error_buf , uint32 error_buf_size )
4140+ bool wasm_binary_freeable , bool no_resolve , char * error_buf ,
4141+ uint32 error_buf_size )
42504142{
42514143 const uint8 * buf_end = buf + size ;
42524144 const uint8 * p = buf , * p_end = buf_end ;
@@ -4273,7 +4165,7 @@ load(const uint8 *buf, uint32 size, AOTModule *module,
42734165 return false;
42744166
42754167 ret = load_from_sections (module , section_list , !wasm_binary_freeable ,
4276- error_buf , error_buf_size );
4168+ no_resolve , error_buf , error_buf_size );
42774169 if (!ret ) {
42784170 /* If load_from_sections() fails, then aot text is destroyed
42794171 in destroy_sections() */
@@ -4321,8 +4213,8 @@ aot_load_from_aot_file(const uint8 *buf, uint32 size, const LoadArgs *args,
43214213 return NULL ;
43224214
43234215 os_thread_jit_write_protect_np (false); /* Make memory writable */
4324- if (!load (buf , size , module , args -> wasm_binary_freeable , error_buf ,
4325- error_buf_size )) {
4216+ if (!load (buf , size , module , args -> wasm_binary_freeable , args -> no_resolve ,
4217+ error_buf , error_buf_size )) {
43264218 aot_unload (module );
43274219 return NULL ;
43284220 }
0 commit comments