Skip to content

Commit 4d6898f

Browse files
committed
Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=3998131&view=logs&j=db00894d-3ef4-5d97-073c-254fbd613a41&t=379a81d4-3138-5f28-ec7b-ce4074947b64 The xamarin-android integration PR is experiencing integration test failures with the Android Designer: Renderer >> 4 [monodroid] Calling into managed runtime init Renderer (error) >> Renderer (error) >> Unhandled Exception: Renderer (error) >> System.EntryPointNotFoundException: java_interop_jnienv_get_java_vm assembly:<unknown assembly> type:<unknown type> member:(null) Renderer (error) >> at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_get_java_vm(intptr,intptr&) Renderer (error) >> at Java.Interop.JniEnvironment+References.GetJavaVM (System.IntPtr jnienv, System.IntPtr& vm) [0x00000] in <0f003a4904fd44d0a8cc6a63962ab40b>:0 Renderer (error) >> at Java.Interop.JniEnvironmentInfo.set_EnvironmentPointer (System.IntPtr value) [0x00037] in <0f003a4904fd44d0a8cc6a63962ab40b>:0 Renderer (error) >> at Java.Interop.JniEnvironmentInfo..ctor (System.IntPtr environmentPointer, Java.Interop.JniRuntime runtime) [0x00006] in <0f003a4904fd44d0a8cc6a63962ab40b>:0 Renderer (error) >> at Java.Interop.JniRuntime..ctor (Java.Interop.JniRuntime+CreationOptions options) [0x0017b] in <0f003a4904fd44d0a8cc6a63962ab40b>:0 Renderer (error) >> at Android.Runtime.AndroidRuntime..ctor (System.IntPtr jnienv, System.IntPtr vm, System.Boolean allocNewObjectSupported, System.IntPtr classLoader, System.IntPtr classLoader_loadClass, System.Boolean jniAddNativeMethodRegistrationAttributePresent) [0x00000] in /Users/builder/azdo/_work/4/s/xamarin-android/src/Mono.Android/Android.Runtime/AndroidRuntime.cs:25 The question is, *why*. @jonpryor still isn't sure, but has a conjecture: among the changes involved is a "forced" change to always use `RTLD_LAZY | RTLD_LOCAL`, no matter what the calling code actually specified. For test purposes, update `java_interop_load_library()` to "pass through" the flags value on Unix, so that the calling code can continue to use e.g. `RTLD_GLOBAL`, if desired. Let's see if that fixes anything? Additionally, add MOAR LOGGING MESSAGES to help see what's happening.
1 parent 482a3f5 commit 4d6898f

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

external/Java.Interop

src/monodroid/jni/android-system.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ AndroidSystem::load_dso (const char *path, int dl_flags, bool skip_exists_check)
360360
}
361361

362362
char *error = nullptr;
363-
void *handle = java_interop_load_library (path, 0, &error);
363+
void *handle = java_interop_load_library (path, dl_flags, &error);
364+
log_warn (LOG_DEFAULT, "# jonp: AndroidSystem::load_dso(`%s`): handle=%p error=%s", path, handle, error);
364365
if (handle == nullptr && utils.should_log (LOG_ASSEMBLY))
365366
log_info_nocheck (LOG_ASSEMBLY, "Failed to load shared library '%s'. %s", path, error);
366367
java_interop_free (error);

src/monodroid/jni/debug.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#include <android/log.h>
3434
#endif
3535

36+
#if defined (APPLE_OS_X)
37+
#include <dlfcn.h>
38+
#else
39+
#define RTLD_LAZY 0
40+
#endif // def APPLE_OX_X
41+
3642
#include "java-interop-util.h"
3743

3844
#include "monodroid.h"
@@ -80,14 +86,15 @@ Debug::monodroid_profiler_load (const char *libmono_path, const char *desc, cons
8086
}
8187
simple_pointer_guard<char[]> mname (mname_ptr);
8288

89+
int dlopen_flags = RTLD_LAZY;
8390
simple_pointer_guard<char[]> libname (utils.string_concat ("libmono-profiler-", mname.get (), ".so"));
8491
bool found = false;
85-
void *handle = androidSystem.load_dso_from_any_directories (libname, 0);
92+
void *handle = androidSystem.load_dso_from_any_directories (libname, dlopen_flags);
8693
found = load_profiler_from_handle (handle, desc, mname);
8794

8895
if (!found && libmono_path != nullptr) {
8996
simple_pointer_guard<char[]> full_path (utils.path_combine (libmono_path, libname));
90-
handle = androidSystem.load_dso (full_path, 0, FALSE);
97+
handle = androidSystem.load_dso (full_path, dlopen_flags, FALSE);
9198
found = load_profiler_from_handle (handle, desc, mname);
9299
}
93100

src/monodroid/jni/monodroid-glue.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
#if defined (APPLE_OS_X)
1414
#include <dlfcn.h>
15+
#else
16+
#define RTLD_LAZY 0
17+
#define RTLD_GLOBAL 0
18+
#define RTLD_NOW 0
1519
#endif // def APPLE_OX_X
1620

1721
#include <fcntl.h>
@@ -156,11 +160,12 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name)
156160
if (!application_config.is_a_bundled_app)
157161
return;
158162

163+
static int dlopen_flags = RTLD_LAZY;
159164
void *libapp = nullptr;
160165

161166
if (androidSystem.is_embedded_dso_mode_enabled ()) {
162167
log_info (LOG_DEFAULT, "bundle app: embedded DSO mode");
163-
libapp = androidSystem.load_dso_from_any_directories (dso_name, 0);
168+
libapp = androidSystem.load_dso_from_any_directories (dso_name, dlopen_flags);
164169
} else {
165170
bool needs_free = false;
166171
log_info (LOG_DEFAULT, "bundle app: normal mode");
@@ -169,7 +174,7 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name)
169174
if (bundle_path == nullptr)
170175
return;
171176
log_info (LOG_BUNDLE, "Attempting to load bundled app from %s", bundle_path);
172-
libapp = androidSystem.load_dso (bundle_path, 0, true);
177+
libapp = androidSystem.load_dso (bundle_path, dlopen_flags, true);
173178
if (needs_free)
174179
delete[] bundle_path;
175180
}
@@ -1071,7 +1076,13 @@ setup_gc_logging (void)
10711076
force_inline int
10721077
MonodroidRuntime::convert_dl_flags (int flags)
10731078
{
1074-
return 0;
1079+
int lflags = flags & static_cast<int> (MONO_DL_LOCAL) ? 0: RTLD_GLOBAL;
1080+
1081+
if (flags & static_cast<int> (MONO_DL_LAZY))
1082+
lflags |= RTLD_LAZY;
1083+
else
1084+
lflags |= RTLD_NOW;
1085+
return lflags;
10751086
}
10761087

10771088
force_inline void
@@ -1191,6 +1202,7 @@ MonodroidRuntime::monodroid_dlsym (void *handle, const char *name, char **err, [
11911202
char *e = nullptr;
11921203

11931204
s = java_interop_get_symbol_address (handle, name, &e);
1205+
log_warn (LOG_DEFAULT, "# jonp: monodroid_dlsym(%p, '%s') s=%p e=%s", handle, name, s, e);
11941206

11951207
if (!s && err) {
11961208
*err = utils.monodroid_strdup_printf ("Could not find symbol '%s': %s", name, e);
@@ -1372,7 +1384,7 @@ MonodroidRuntime::disable_external_signal_handlers (void)
13721384
if (!androidSystem.is_mono_llvm_enabled ())
13731385
return;
13741386

1375-
void *llvm = androidSystem.load_dso ("libLLVM.so", 0, TRUE);
1387+
void *llvm = androidSystem.load_dso ("libLLVM.so", RTLD_LAZY, TRUE);
13761388
if (llvm) {
13771389
bool *disable_signals = reinterpret_cast<bool*> (java_interop_get_symbol_address (llvm, "_ZN4llvm23DisablePrettyStackTraceE", nullptr));
13781390
if (disable_signals) {
@@ -1607,7 +1619,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16071619
if (my_location != nullptr) {
16081620
simple_pointer_guard<char, false> dso_path (utils.path_combine (my_location, API_DSO_NAME));
16091621
log_info (LOG_DEFAULT, "Attempting to load %s", dso_path.get ());
1610-
api_dso_handle = java_interop_load_library (dso_path.get (), 0, nullptr);
1622+
api_dso_handle = java_interop_load_library (dso_path.get (), RTLD_NOW, nullptr);
16111623
#if defined (APPLE_OS_X)
16121624
delete[] my_location;
16131625
#else // !defined(APPLE_OS_X)
@@ -1617,11 +1629,11 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16171629

16181630
if (api_dso_handle == nullptr) {
16191631
log_info (LOG_DEFAULT, "Attempting to load %s with \"bare\" dlopen", API_DSO_NAME);
1620-
api_dso_handle = java_interop_load_library (API_DSO_NAME, 0, nullptr);
1632+
api_dso_handle = java_interop_load_library (API_DSO_NAME, RTLD_NOW, nullptr);
16211633
}
16221634
#endif // defined(WINDOWS) || defined(APPLE_OS_X)
16231635
if (api_dso_handle == nullptr)
1624-
api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, 0);
1636+
api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, RTLD_NOW);
16251637
init_internal_api_dso (api_dso_handle);
16261638

16271639
mono_dl_fallback_register (monodroid_dlopen, monodroid_dlsym, nullptr, nullptr);

0 commit comments

Comments
 (0)