From 72eb2ee84a4f397c5887159e288894778ea316a9 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Thu, 23 May 2019 10:56:37 -0400 Subject: [PATCH] [Android] Fix runtime loading of DSOs for 64-bit processes (#14577) [Android] Fix runtime loading of DSOs for 64-bit processes Context: https://github.com/xamarin/xamarin-android/issues/2780 On Android the executable for the application is going to be `/system/bin/app_process{32,64}` depending on the application's architecture. However, libraries for the different architectures live in different subdirectories of `/system`: `lib` for 32-bit apps and `lib64` for 64-bit ones. Thus appending `/lib` below will fail to load the DSO for a 64-bit app, even if it exists there, because it will have a different architecture. The quickest fix is to use `lib64` explicitly for 64-bit Android apps. Backport of #13281. /cc @lambdageek @grendello --- mono/metadata/loader.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mono/metadata/loader.c b/mono/metadata/loader.c index b6072e55e6a..dac5ee298ec 100644 --- a/mono/metadata/loader.c +++ b/mono/metadata/loader.c @@ -1667,8 +1667,20 @@ pinvoke_probe_for_module_relative_directories (MonoImage *image, const char *fil base = g_path_get_dirname (resolvedname); newbase = g_path_get_dirname(base); - mdirname = g_strdup_printf ("%s/lib", newbase); + // On Android the executable for the application is going to be /system/bin/app_process{32,64} depending on + // the application's architecture. However, libraries for the different architectures live in different + // subdirectories of `/system`: `lib` for 32-bit apps and `lib64` for 64-bit ones. Thus appending `/lib` below + // will fail to load the DSO for a 64-bit app, even if it exists there, because it will have a different + // architecture. This is the cause of https://github.com/xamarin/xamarin-android/issues/2780 and the ifdef + // below is the fix. + mdirname = g_strdup_printf ( +#if defined(TARGET_ANDROID) && (defined(TARGET_ARM64) || defined(TARGET_AMD64)) + "%s/lib64", +#else + "%s/lib", +#endif + newbase); g_free (resolvedname); g_free (base); g_free (newbase); -- 2.11.4.GIT