From d3d1c61d824abe1db74b1670573c69eaf0ab2f23 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Sat, 22 Aug 2020 09:02:10 -0400 Subject: [PATCH] [java-interop] try using RTLD_NOW|RTLD_LOCAL Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=4002003&view=logs&j=65486226-8c87-5153-e73a-d57909d6ac16&t=d3853860-5663-595d-ac96-d10e64bcf850 The story so far: 2cf8ac92 conjectured that requiring RTLD_LAZY|RTLD_LOCAL was causing the macOS Designer tests to fail, and allowed the caller to provide the desired flags *and log them*. Eventually, we got a log: 5 [monodroid] # jonp: java_interop_load_library: path=`/Library/Frameworks/Xamarin.Android.framework/Versions/11.1.99.69/lib/xamarin.android/xbuild/Xamarin/Android/lib/host-Darwin/libxa-internal-api.dylib` 5 [monodroid] # jonp: java_interop_load_library flags= RTLD_NOW Unfortunately, 2cf8ac92 had a bug in which it didn't check for RTLD_LOCAL; all we know is that RTLD_NOW was specified, and that possibly RTLD_LOCAL was specifed (maybe); RTLD_GLOBAL was NOT used. Also interesting from the log file is what was *missing*: no mentions of `java_interop_get_symbol_address` were present! Thus, the next conjecture: whatever codepath was trying to lookup `java_interop_jnienv_get_java_vm` within 2cf8ac92 *isn't* using `java_interop_get_symbol_address()` to do so, and is instead relying on the normal dynamic linker (somehow). Next test: let's once again "ignore" the `flags` value provided to `java_interop_load_library()`, and instead always use RTLD_LOCAL|RTLD_NOW. Perhaps that's the magic pixie dust needed? --- src/java-interop/java-interop-dlfcn.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/java-interop/java-interop-dlfcn.cc b/src/java-interop/java-interop-dlfcn.cc index f67983bb8..2b3e1010c 100644 --- a/src/java-interop/java-interop-dlfcn.cc +++ b/src/java-interop/java-interop-dlfcn.cc @@ -104,8 +104,10 @@ java_interop_load_library (const char *path, unsigned int flags, char **error) buf[0] = '\0'; if ((flags & RTLD_LAZY) == RTLD_LAZY) strcat (buf, " RTLD_LAZY"); if ((flags & RTLD_GLOBAL) == RTLD_GLOBAL) strcat (buf, " RTLD_GLOBAL"); + if ((flags & RTLD_LOCAL) == RTLD_LOCAL) strcat (buf, " RTLD_LOCAL"); if ((flags & RTLD_NOW) == RTLD_NOW) strcat (buf, " RTLD_NOW"); - log_warn (LOG_DEFAULT, "# jonp: java_interop_load_library flags=%s", buf); + log_warn (LOG_DEFAULT, "# jonp: java_interop_load_library requested flags=%s; using RTLD_LOCAL|RTLD_NOW", buf); + flags = RTLD_LOCAL | RTLD_NOW; #endif void *handle = nullptr;