diff --git a/.gitmodules b/.gitmodules index ac526ae946c..f0c5a302755 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,10 +6,6 @@ path = external/debugger-libs url = https://github.com/mono/debugger-libs branch = master -[submodule "external/dlfcn-win32"] - path = external/dlfcn-win32 - url = https://github.com/dlfcn-win32/dlfcn-win32.git - branch = v1.1.1 [submodule "external/Java.Interop"] path = external/Java.Interop url = https://github.com/xamarin/java.interop.git diff --git a/build-tools/installers/create-installers.targets b/build-tools/installers/create-installers.targets index e418382234d..23c8819b339 100644 --- a/build-tools/installers/create-installers.targets +++ b/build-tools/installers/create-installers.targets @@ -135,6 +135,8 @@ <_MSBuildFiles Include="$(MSBuildSrcDir)\javadoc-to-mdoc.pdb" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.pdb" /> + <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.Localization.dll" /> + <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.Localization.pdb" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.dll.config" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.Export.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Java.Interop.Export.pdb" /> @@ -228,6 +230,7 @@ <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Bindings.JarToXml.targets" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Build.Tasks.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Build.Tasks.pdb" /> + <_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\Java.Interop.Localization.resources.dll')" /> <_MSBuildFiles Include="@(_LocalizationLanguages->'$(MSBuildSrcDir)\%(Identity)\Xamarin.Android.Build.Tasks.resources.dll')" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.BuildInfo.txt" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Cecil.dll" /> diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_BuildMingwDependencies.cs b/build-tools/xaprepare/xaprepare/Steps/Step_BuildMingwDependencies.cs index 44b3e92b644..0e9b30be0f9 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_BuildMingwDependencies.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_BuildMingwDependencies.cs @@ -8,7 +8,6 @@ namespace Xamarin.Android.Prepare class Step_BuildMingwDependencies : Step { static readonly SortedDictionary dependencies = new SortedDictionary (StringComparer.Ordinal) { - { "dlfcn-win32", (description: "libdl for Windows", libraryName: "libdl.a") }, { "mman-win32", (description: "mmap for Windows", libraryName: "libmman.a") }, }; diff --git a/build-tools/xaprepare/xaprepare/ThirdPartyNotices/dlfcn.cs b/build-tools/xaprepare/xaprepare/ThirdPartyNotices/dlfcn.cs deleted file mode 100644 index 07ddf0b1c57..00000000000 --- a/build-tools/xaprepare/xaprepare/ThirdPartyNotices/dlfcn.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace Xamarin.Android.Prepare -{ - [TPN] - class dlfcn_TPN : ThirdPartyNotice - { - static readonly Uri url = new Uri ("https://github.com/dlfcn-win32/dlfcn-win32/"); - static readonly string licenseFile = Path.Combine (Configurables.Paths.ExternalDir, "dlfcn-win32", "COPYING"); - - - public override string LicenseFile => licenseFile; - public override string Name => "dlfcn-win32/dlfcn-win32"; - public override Uri SourceUrl => url; - public override string LicenseText => ""; - - public override bool Include (bool includeExternalDeps, bool includeBuildDeps) => includeExternalDeps; - } -} diff --git a/build-tools/xaprepare/xaprepare/xaprepare.csproj b/build-tools/xaprepare/xaprepare/xaprepare.csproj index 417fec407c8..1a5fcd5a07c 100644 --- a/build-tools/xaprepare/xaprepare/xaprepare.csproj +++ b/build-tools/xaprepare/xaprepare/xaprepare.csproj @@ -157,7 +157,6 @@ - diff --git a/external/Java.Interop b/external/Java.Interop index 007b35b4891..08ff4db1887 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit 007b35b489173010de038c95cb2a0d3ec514f30d +Subproject commit 08ff4db188787b7d72fb1976f1511d0b76125415 diff --git a/external/dlfcn-win32 b/external/dlfcn-win32 deleted file mode 160000 index ef7e412d3fa..00000000000 --- a/external/dlfcn-win32 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ef7e412d3fa2b511e660342e237536c235e51ee4 diff --git a/src/monodroid/CMakeLists.txt b/src/monodroid/CMakeLists.txt index 191a4e2f55f..f777f00b3d7 100644 --- a/src/monodroid/CMakeLists.txt +++ b/src/monodroid/CMakeLists.txt @@ -196,7 +196,7 @@ else() if(WIN32 OR MINGW) message(STATUS "Win32 or MinGW") set(EXTRA_COMPILER_FLAGS "${EXTRA_COMPILER_FLAGS} -DWINDOWS -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA -fomit-frame-pointer") - set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} -ldl -lmman -static -pthread -dynamic -lmincore -lmswsock -lwsock32 -lshlwapi -lpsapi -lwinmm") + set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} -lmman -static -pthread -dynamic -lmincore -lmswsock -lwsock32 -lshlwapi -lpsapi -lwinmm") if (MINGW_TARGET_32) set(ANDROID_ABI "host-mxe-Win32") @@ -298,6 +298,7 @@ set(MONODROID_SOURCES ${JAVA_INTEROP_SRC_PATH}/java-interop.cc ${JAVA_INTEROP_SRC_PATH}/java-interop-mono.cc ${JAVA_INTEROP_SRC_PATH}/java-interop-util.cc + ${JAVA_INTEROP_SRC_PATH}/java-interop-dlfcn.cc ) set(XA_INTERNAL_API_SOURCES @@ -392,11 +393,13 @@ else() set(LINK_LIBS "-lmonosgen-2.0 -lz ${EXTRA_LINKER_FLAGS}") endif() -set(DEBUG_HELPER_LINK_LIBS "-ldl") +if(NOT MINGW AND NOT WIN32) + set(DEBUG_HELPER_LINK_LIBS "-ldl") +endif() if(ENABLE_NDK) set(LINK_LIBS "${LINK_LIBS} -llog") set(DEBUG_HELPER_LINK_LIBS "${DEBUG_HELPER_LINK_LIBS} -llog") -elseif(NOT ANDROID) +elseif(NOT ANDROID AND NOT MINGW AND NOT WIN32) set(LINK_LIBS "-pthread ${LINK_LIBS} -ldl") endif() diff --git a/src/monodroid/jni/android-system.cc b/src/monodroid/jni/android-system.cc index 99e8bf8398f..d7f83a97d96 100644 --- a/src/monodroid/jni/android-system.cc +++ b/src/monodroid/jni/android-system.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include #ifdef ANDROID @@ -27,6 +26,8 @@ #include "jni-wrappers.hh" #include "xamarin-app.hh" #include "cpp-util.hh" +#include "java-interop-dlfcn.h" +#include "java-interop.h" #if defined (DEBUG) || !defined (ANDROID) namespace xamarin::android::internal { @@ -39,6 +40,7 @@ namespace xamarin::android::internal { } #endif // DEBUG || !ANDROID +using namespace microsoft::java_interop; using namespace xamarin::android; using namespace xamarin::android::internal; @@ -347,7 +349,7 @@ AndroidSystem::get_full_dso_path (const char *base_dir, const char *dso_path, bo } void* -AndroidSystem::load_dso (const char *path, int dl_flags, bool skip_exists_check) +AndroidSystem::load_dso (const char *path, unsigned int dl_flags, bool skip_exists_check) { if (path == nullptr || *path == '\0') return nullptr; @@ -358,14 +360,16 @@ AndroidSystem::load_dso (const char *path, int dl_flags, bool skip_exists_check) return nullptr; } - void *handle = dlopen (path, dl_flags); + char *error = nullptr; + void *handle = java_interop_lib_load (path, dl_flags, &error); if (handle == nullptr && utils.should_log (LOG_ASSEMBLY)) - log_info_nocheck (LOG_ASSEMBLY, "Failed to load shared library '%s'. %s", path, dlerror ()); + log_info_nocheck (LOG_ASSEMBLY, "Failed to load shared library '%s'. %s", path, error); + java_interop_free (error); return handle; } void* -AndroidSystem::load_dso_from_specified_dirs (const char **directories, size_t num_entries, const char *dso_name, int dl_flags) +AndroidSystem::load_dso_from_specified_dirs (const char **directories, size_t num_entries, const char *dso_name, unsigned int dl_flags) { assert (directories != nullptr); if (dso_name == nullptr) @@ -386,13 +390,13 @@ AndroidSystem::load_dso_from_specified_dirs (const char **directories, size_t nu } void* -AndroidSystem::load_dso_from_app_lib_dirs (const char *name, int dl_flags) +AndroidSystem::load_dso_from_app_lib_dirs (const char *name, unsigned int dl_flags) { return load_dso_from_specified_dirs (static_cast (app_lib_directories), app_lib_directories_size, name, dl_flags); } void* -AndroidSystem::load_dso_from_override_dirs ([[maybe_unused]] const char *name, [[maybe_unused]] int dl_flags) +AndroidSystem::load_dso_from_override_dirs ([[maybe_unused]] const char *name, [[maybe_unused]] unsigned int dl_flags) { #ifdef RELEASE return nullptr; @@ -402,7 +406,7 @@ AndroidSystem::load_dso_from_override_dirs ([[maybe_unused]] const char *name, [ } void* -AndroidSystem::load_dso_from_any_directories (const char *name, int dl_flags) +AndroidSystem::load_dso_from_any_directories (const char *name, unsigned int dl_flags) { void *handle = load_dso_from_override_dirs (name, dl_flags); if (handle == nullptr) diff --git a/src/monodroid/jni/android-system.hh b/src/monodroid/jni/android-system.hh index 020d893aabf..2d494975e11 100644 --- a/src/monodroid/jni/android-system.hh +++ b/src/monodroid/jni/android-system.hh @@ -48,8 +48,8 @@ namespace xamarin::android::internal char* get_bundled_app (JNIEnv *env, jstring dir); int count_override_assemblies (); long get_gref_gc_threshold (); - void* load_dso (const char *path, int dl_flags, bool skip_exists_check); - void* load_dso_from_any_directories (const char *name, int dl_flags); + void* load_dso (const char *path, unsigned int dl_flags, bool skip_exists_check); + void* load_dso_from_any_directories (const char *name, unsigned int dl_flags); char* get_full_dso_path_on_disk (const char *dso_name, bool &needs_free); monodroid_dirent_t* readdir (monodroid_dir_t *dir); @@ -118,9 +118,9 @@ namespace xamarin::android::internal size_t _monodroid_get_system_property_from_file (const char *path, char **value); #endif char* get_full_dso_path (const char *base_dir, const char *dso_path, bool &needs_free); - void* load_dso_from_specified_dirs (const char **directories, size_t num_entries, const char *dso_name, int dl_flags); - void* load_dso_from_app_lib_dirs (const char *name, int dl_flags); - void* load_dso_from_override_dirs (const char *name, int dl_flags); + void* load_dso_from_specified_dirs (const char **directories, size_t num_entries, const char *dso_name, unsigned int dl_flags); + void* load_dso_from_app_lib_dirs (const char *name, unsigned int dl_flags); + void* load_dso_from_override_dirs (const char *name, unsigned int dl_flags); char* get_existing_dso_path_on_disk (const char *base_dir, const char *dso_name, bool &needs_free); #if defined (WINDOWS) diff --git a/src/monodroid/jni/debug.cc b/src/monodroid/jni/debug.cc index 293d3ab8b6d..4ddca5d9a30 100644 --- a/src/monodroid/jni/debug.cc +++ b/src/monodroid/jni/debug.cc @@ -27,13 +27,16 @@ #include #include #include -#include #include #ifdef ANDROID #include #endif +#if defined (APPLE_OS_X) +#include +#endif // def APPLE_OX_X + #include "java-interop-util.h" #include "monodroid.h" @@ -42,6 +45,9 @@ #include "globals.hh" #include "cpp-util.hh" +#include "java-interop-dlfcn.h" + +using namespace microsoft::java_interop; using namespace xamarin::android; // @@ -79,7 +85,7 @@ Debug::monodroid_profiler_load (const char *libmono_path, const char *desc, cons } simple_pointer_guard mname (mname_ptr); - int dlopen_flags = RTLD_LAZY; + unsigned int dlopen_flags = JAVA_INTEROP_LIB_LOAD_LOCALLY; simple_pointer_guard libname (utils.string_concat ("libmono-profiler-", mname.get (), ".so")); bool found = false; void *handle = androidSystem.load_dso_from_any_directories (libname, dlopen_flags); @@ -108,7 +114,7 @@ typedef void (*ProfilerInitializer) (const char*); bool Debug::load_profiler (void *handle, const char *desc, const char *symbol) { - ProfilerInitializer func = reinterpret_cast (dlsym (handle, symbol)); + ProfilerInitializer func = reinterpret_cast (java_interop_lib_symbol (handle, symbol, nullptr)); log_warn (LOG_DEFAULT, "Looking for profiler init symbol '%s'? %p", symbol, func); if (func != nullptr) { @@ -129,7 +135,7 @@ Debug::load_profiler_from_handle (void *dso_handle, const char *desc, const char if (result) return true; - dlclose (dso_handle); + java_interop_lib_close (dso_handle, nullptr); return false; } diff --git a/src/monodroid/jni/monodroid-glue-internal.hh b/src/monodroid/jni/monodroid-glue-internal.hh index ec30921eff0..028b3278c13 100644 --- a/src/monodroid/jni/monodroid-glue-internal.hh +++ b/src/monodroid/jni/monodroid-glue-internal.hh @@ -137,7 +137,7 @@ namespace xamarin::android::internal char* get_java_class_name_for_TypeManager (jclass klass); private: - int convert_dl_flags (int flags); + unsigned int convert_dl_flags (int flags); #if defined (WINDOWS) || defined (APPLE_OS_X) static const char* get_my_location (); #endif // defined(WINDOWS) || defined(APPLE_OS_X) diff --git a/src/monodroid/jni/monodroid-glue.cc b/src/monodroid/jni/monodroid-glue.cc index 75e5003f2a0..cdb5ab3f49c 100644 --- a/src/monodroid/jni/monodroid-glue.cc +++ b/src/monodroid/jni/monodroid-glue.cc @@ -10,7 +10,10 @@ #include #include +#if defined (APPLE_OS_X) #include +#endif // def APPLE_OX_X + #include #include #include @@ -82,6 +85,9 @@ #include "cpp-util.hh" +#include "java-interop-dlfcn.h" + +using namespace microsoft::java_interop; using namespace xamarin::android; using namespace xamarin::android::internal; @@ -151,7 +157,7 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name) if (!application_config.is_a_bundled_app) return; - static int dlopen_flags = RTLD_LAZY; + static unsigned int dlopen_flags = JAVA_INTEROP_LIB_LOAD_LOCALLY; void *libapp = nullptr; if (androidSystem.is_embedded_dso_mode_enabled ()) { @@ -181,11 +187,11 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name) } } - mono_mkbundle_initialize_mono_api = reinterpret_cast (dlsym (libapp, "initialize_mono_api")); + mono_mkbundle_initialize_mono_api = reinterpret_cast (java_interop_lib_symbol (libapp, "initialize_mono_api", nullptr)); if (!mono_mkbundle_initialize_mono_api) log_error (LOG_BUNDLE, "Missing initialize_mono_api in the application"); - mono_mkbundle_init = reinterpret_cast (dlsym (libapp, "mono_mkbundle_init")); + mono_mkbundle_init = reinterpret_cast (java_interop_lib_symbol (libapp, "mono_mkbundle_init", nullptr)); if (!mono_mkbundle_init) log_error (LOG_BUNDLE, "Missing mono_mkbundle_init in the application"); log_info (LOG_BUNDLE, "Bundled app loaded: %s", dso_name); @@ -1064,15 +1070,12 @@ setup_gc_logging (void) } #endif -force_inline int +force_inline unsigned int MonodroidRuntime::convert_dl_flags (int flags) { - int lflags = flags & static_cast (MONO_DL_LOCAL) ? 0: RTLD_GLOBAL; - - if (flags & static_cast (MONO_DL_LAZY)) - lflags |= RTLD_LAZY; - else - lflags |= RTLD_NOW; + unsigned int lflags = (flags & static_cast (MONO_DL_LOCAL)) + ? JAVA_INTEROP_LIB_LOAD_LOCALLY + : JAVA_INTEROP_LIB_LOAD_GLOBALLY; return lflags; } @@ -1099,7 +1102,7 @@ MonodroidRuntime::init_internal_api_dso (void *handle) std::lock_guard lock (api_init_lock); if (api_dso_handle != nullptr) { - auto api_shutdown = reinterpret_cast (dlsym (api_dso_handle, MonoAndroidInternalCalls::SHUTDOWN_FUNCTION_NAME)); + auto api_shutdown = reinterpret_cast (java_interop_lib_symbol (api_dso_handle, MonoAndroidInternalCalls::SHUTDOWN_FUNCTION_NAME, nullptr)); if (api_shutdown == nullptr) { // We COULD ignore this situation, but if the function is missing it means we messed something up and thus // it *is* a fatal error. @@ -1111,7 +1114,7 @@ MonodroidRuntime::init_internal_api_dso (void *handle) api_dso_handle = handle; auto api = new MonoAndroidInternalCalls_Impl (); - auto api_init = reinterpret_cast(dlsym (handle, MonoAndroidInternalCalls::INIT_FUNCTION_NAME)); + auto api_init = reinterpret_cast(java_interop_lib_symbol (handle, MonoAndroidInternalCalls::INIT_FUNCTION_NAME, nullptr)); if (api_init == nullptr) { log_fatal (LOG_DEFAULT, "Unable to initialize Internal API library, init function '%s' not found in the module", MonoAndroidInternalCalls::INIT_FUNCTION_NAME); exit (FATAL_EXIT_MONO_MISSING_SYMBOLS); @@ -1146,7 +1149,7 @@ MonodroidRuntime::monodroid_dlopen_log_and_return (void *handle, char **err, con void* MonodroidRuntime::monodroid_dlopen (const char *name, int flags, char **err, [[maybe_unused]] void *user_data) { - int dl_flags = monodroidRuntime.convert_dl_flags (flags); + unsigned int dl_flags = monodroidRuntime.convert_dl_flags (flags); bool libmonodroid_fallback = false; /* name is nullptr when we're P/Invoking __Internal, so remap to libxa-internal-api */ @@ -1190,11 +1193,15 @@ void* MonodroidRuntime::monodroid_dlsym (void *handle, const char *name, char **err, [[maybe_unused]] void *user_data) { void *s; + char *e = nullptr; - s = dlsym (handle, name); + s = java_interop_lib_symbol (handle, name, &e); if (!s && err) { - *err = utils.monodroid_strdup_printf ("Could not find symbol '%s'.", name); + *err = utils.monodroid_strdup_printf ("Could not find symbol '%s': %s", name, e); + } + if (e) { + java_interop_free (e); } return s; @@ -1370,9 +1377,9 @@ MonodroidRuntime::disable_external_signal_handlers (void) if (!androidSystem.is_mono_llvm_enabled ()) return; - void *llvm = androidSystem.load_dso ("libLLVM.so", RTLD_LAZY, TRUE); + void *llvm = androidSystem.load_dso ("libLLVM.so", JAVA_INTEROP_LIB_LOAD_GLOBALLY, TRUE); if (llvm) { - bool *disable_signals = reinterpret_cast (dlsym (llvm, "_ZN4llvm23DisablePrettyStackTraceE")); + bool *disable_signals = reinterpret_cast (java_interop_lib_symbol (llvm, "_ZN4llvm23DisablePrettyStackTraceE", nullptr)); if (disable_signals) { *disable_signals = true; log_info (LOG_DEFAULT, "Disabled LLVM signal trapping"); @@ -1605,7 +1612,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl if (my_location != nullptr) { simple_pointer_guard dso_path (utils.path_combine (my_location, API_DSO_NAME)); log_info (LOG_DEFAULT, "Attempting to load %s", dso_path.get ()); - api_dso_handle = dlopen (dso_path.get (), RTLD_NOW); + api_dso_handle = java_interop_lib_load (dso_path.get (), JAVA_INTEROP_LIB_LOAD_GLOBALLY, nullptr); #if defined (APPLE_OS_X) delete[] my_location; #else // !defined(APPLE_OS_X) @@ -1615,11 +1622,11 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl if (api_dso_handle == nullptr) { log_info (LOG_DEFAULT, "Attempting to load %s with \"bare\" dlopen", API_DSO_NAME); - api_dso_handle = dlopen (API_DSO_NAME, RTLD_NOW); + api_dso_handle = java_interop_lib_load (API_DSO_NAME, JAVA_INTEROP_LIB_LOAD_GLOBALLY, nullptr); } #endif // defined(WINDOWS) || defined(APPLE_OS_X) if (api_dso_handle == nullptr) - api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, RTLD_NOW); + api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, JAVA_INTEROP_LIB_LOAD_GLOBALLY); init_internal_api_dso (api_dso_handle); mono_dl_fallback_register (monodroid_dlopen, monodroid_dlsym, nullptr, nullptr);