Skip to content

Commit 75b5293

Browse files
grendellojonathanpeppers
authored andcommitted
[monodroid] Disable loading of libLLVM at runtime (#7499)
Context: xamarin/monodroid@d887d87d8f Context: llvm/llvm-project@c10ca90 Way back in 2014-Feb-26, private bug [#18016][0] was filed against Xamarin.Android 4.10.2: when a project contained RenderScript and ran on an Android 4.0.4 device, it could eventually hang. No exception, no error message, no nothing. After investigation, the cause of the hang was that the RenderScript compiler would use the same Unix signals as the Mono for Android GC, and did not properly chain those signals. Thus, if the on-device RenderScript compiler hit particular code paths which caused it to register those Unix signals, the Mono for Android GC would no longer work from that point onward. It was determined that the `llvm::DisablePrettyStackTrace` global variable within `libLLVM.so` could control this behavior. The "fix"/workaround was to *prevent* the RenderScript compiler from subscribing to those Unix signals by: 1. Loading `libLLVM.so` at runtime, 2. Looking for the symbol `_ZN4llvm23DisablePrettyStackTraceE`, which is the name mangled form of `bool llvm::DisablePrettyStackTrace`. 3. Set the value to 1/`true`. xamarin/monodroid@d887d87d8f commit message contents: > Disable LLVM signal handlers. Fixes #18016. > > This happens when RenderScript needs to be compiled. > See https://bugzilla.xamarin.com/show_bug.cgi?id=18016 > > This happens only on first run of the app. LLVM is used to compiled > the RenderScript scripts. LLVM, been a nice and smart library > installs a ton of signal handlers and don't chain at all, completely > breaking us. > > This is a hack to set llvm::DisablePrettyStackTrace to true and > avoid this source of signal handlers. The `llvm::DisablePrettyStackTrace` variable was *removed* from LLVM in 2013-Nov-3 via llvm/llvm-project@c10ca903, but Android continued to redistribute a version of LLVM which contained that symbol until Android 5.0 / API-21. Update `MonodroidRuntime::disable_external_signal_handlers()` to do nothing for .NET 6+ -- as .NET 6 has API-21 as a minimum API level -- and update Classic Xamarin.Android to only look for `libLLVM.so!_ZN4llvm23DisablePrettyStackTraceE` on pre-API-21 targets. This removes the warning message: Failed to load shared library 'libLLVM.so' when running .NET Android apps. [0]: https://bugzilla.xamarin.com/18/18016/bug.html
1 parent 02fbfa7 commit 75b5293

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/monodroid/jni/monodroid-glue.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,12 +1838,19 @@ a nice and smart library installs a ton of signal handlers and don't chain at al
18381838
18391839
This is a hack to set llvm::DisablePrettyStackTrace to true and avoid this source of signal handlers.
18401840
1841+
As of Android 5.0 (API 21) the symbol no longer exists in libLLVM.so and stack pretty printing is an opt-in
1842+
instead of an opt-out feature. LLVM change which removed the symbol is at
1843+
1844+
https://github.com/llvm/llvm-project/commit/c10ca903243f97cbc8014f20c64f1318a57a2936
1845+
18411846
*/
18421847
void
18431848
MonodroidRuntime::disable_external_signal_handlers (void)
18441849
{
1845-
if (!androidSystem.is_mono_llvm_enabled ())
1850+
#if !defined (NET)
1851+
if (android_api_level >= 21) {
18461852
return;
1853+
}
18471854

18481855
void *llvm = androidSystem.load_dso ("libLLVM.so", JAVA_INTEROP_LIB_LOAD_GLOBALLY, TRUE);
18491856
if (llvm) {
@@ -1854,6 +1861,7 @@ MonodroidRuntime::disable_external_signal_handlers (void)
18541861
}
18551862
//MUST NOT dlclose to ensure we don't lose the hack
18561863
}
1864+
#endif // ndef NET
18571865
}
18581866

18591867
#if defined (NET)

0 commit comments

Comments
 (0)