@@ -92,7 +92,7 @@ mono_dllmap_lookup_list (MonoDllMap *dll_map, const char *dll, const char* func,
9292 if (!dll_map )
9393 goto exit ;
9494
95- /*
95+ /*
9696 * we use the first entry we find that matches, since entries from
9797 * the config file are prepended to the list and we document that the
9898 * later entries win.
@@ -254,7 +254,7 @@ mono_global_dllmap_cleanup (void)
254254 * This function is used to programatically add \c DllImport remapping in either
255255 * a specific assembly, or as a global remapping. This is done by remapping
256256 * references in a \c DllImport attribute from the \p dll library name into the \p tdll
257- * name. If the \p dll name contains the prefix <code>i:</code>, the comparison of the
257+ * name. If the \p dll name contains the prefix <code>i:</code>, the comparison of the
258258 * library name is done without case sensitivity.
259259 *
260260 * If you pass \p func, this is the name of the \c EntryPoint in a \c DllImport if specified
@@ -518,21 +518,33 @@ netcore_probe_for_module (MonoImage *image, const char *file_name, int flags)
518518 // TODO: this algorithm doesn't quite match CoreCLR, so respecting DLLIMPORTSEARCHPATH_LEGACY_BEHAVIOR makes little sense
519519 // If the difference becomes a problem, overhaul this algorithm to match theirs exactly
520520
521- // Try without any path additions
521+ #if defined(HOST_ANDROID )
522+ // On Android, try without any path additions first. It is sensitive to probing that will always miss
523+ // and lookup for some libraries is required to use a relative path
522524 module = netcore_probe_for_module_variations (NULL , file_name , lflags );
525+ #endif
523526
524527 // Check the NATIVE_DLL_SEARCH_DIRECTORIES
525528 for (int i = 0 ; i < pinvoke_search_directories_count && module == NULL ; ++ i )
526529 module = netcore_probe_for_module_variations (pinvoke_search_directories [i ], file_name , lflags );
527530
528531 // Check the assembly directory if the search flag is set and the image exists
529- if (flags & DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY && image != NULL && module == NULL ) {
532+ if ((flags & DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY ) != 0 && image != NULL &&
533+ module == NULL && (image -> filename != NULL )) {
530534 char * mdirname = g_path_get_dirname (image -> filename );
531535 if (mdirname )
532536 module = netcore_probe_for_module_variations (mdirname , file_name , lflags );
533537 g_free (mdirname );
534538 }
535539
540+ #if !defined(HOST_ANDROID )
541+ // Try without any path additions
542+ if (module == NULL )
543+ {
544+ module = netcore_probe_for_module_variations (NULL , file_name , lflags );
545+ }
546+ #endif
547+
536548 // TODO: Pass remaining flags on to LoadLibraryEx on Windows where appropriate, see https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportsearchpath?view=netcore-3.1
537549
538550 return module ;
@@ -1048,7 +1060,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
10481060 mono_custom_attrs_free (cinfo );
10491061 }
10501062 if (flags < 0 )
1051- flags = 0 ;
1063+ flags = DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY ;
10521064 module = netcore_lookup_native_library (alc , image , new_scope , flags );
10531065
10541066 if (!module ) {
@@ -1154,7 +1166,7 @@ pinvoke_probe_for_symbol (MonoDl *module, MonoMethodPInvoke *piinfo, const char
11541166
11551167#if HOST_WIN32 && HOST_X86
11561168 /* Try the stdcall mangled name */
1157- /*
1169+ /*
11581170 * gcc under windows creates mangled names without the underscore, but MS.NET
11591171 * doesn't support it, so we doesn't support it either.
11601172 */
@@ -1394,7 +1406,7 @@ mono_loader_save_bundled_library (int fd, uint64_t offset, uint64_t size, const
13941406 char * file , * buffer , * err , * internal_path ;
13951407 if (!bundle_save_library_initialized )
13961408 bundle_save_library_initialize ();
1397-
1409+
13981410 file = g_build_filename (bundled_dylibrary_directory , destfname , (const char * )NULL );
13991411 buffer = g_str_from_file_region (fd , offset , size );
14001412 g_file_set_contents (file , buffer , size , NULL );
@@ -1409,7 +1421,7 @@ mono_loader_save_bundled_library (int fd, uint64_t offset, uint64_t size, const
14091421 mono_loader_register_module (internal_path , lib );
14101422 g_free (internal_path );
14111423 bundle_library_paths = g_slist_append (bundle_library_paths , file );
1412-
1424+
14131425 g_free (buffer );
14141426}
14151427
0 commit comments