runtime: Mono does not implement coreclr_create_delegate hosting API or ComponentActivator
Update the hosting API has been added to Mono. This issue is mainly open now to track the remaining work needed in order to run the DllImportGenerator tests on mobile platforms (or indeed other apps that may want the desktop hosting API on mobile). See https://github.com/dotnet/runtime/issues/59815#issuecomment-932456674 for one path forward.
Mono does not implement the coreclr_create_delegate
hosting API method nor the ComponentActivator class used by the nethost library. This is blocking us from running the DllImportGenerator.Tests suite, since we use DNNE to enable easier managed->native testing in the libraries suite by implementing the “native” side primarily in managed code.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 24 (23 by maintainers)
Commits related to this issue
- [mono] Implement coreclr_create_delegate hosting API Related to https://github.com/dotnet/runtime/issues/59815 — committed to lambdageek/runtime by lambdageek 3 years ago
- [mono] Implement coreclr_create_delegate hosting API Related to https://github.com/dotnet/runtime/issues/59815 — committed to lambdageek/runtime by lambdageek 3 years ago
- [mono] Implement coreclr_create_delegate hosting API Related to https://github.com/dotnet/runtime/issues/59815 — committed to lambdageek/runtime by lambdageek 3 years ago
- [mono] Implement coreclr_create_delegate and move ComponentActivator to shared CoreLib (#59962) * [CoreLib] Move ComponentActivator to the shared area * [mono] Implement coreclr_create_delegate ho... — committed to dotnet/runtime by lambdageek 3 years ago
- [reflection] Return n2m wrapper from RuntimeMethodHandle.GetFunctionPointer for functions marked with UnmanagedCallersOnlyAttribute, return a pointer to the n2m wrapper for calls to GetFunctionPointe... — committed to lambdageek/runtime by lambdageek 3 years ago
- [reflection] Return n2m wrapper from RuntimeMethodHandle.GetFunctionPointer for functions marked with UnmanagedCallersOnlyAttribute, return a pointer to the n2m wrapper for calls to GetFunctionPointe... — committed to lambdageek/runtime by lambdageek 3 years ago
- [reflection] Return n2m wrapper from RuntimeMethodHandle.GetFunctionPointer (#60200) for functions marked with UnmanagedCallersOnlyAttribute, return a pointer to the n2m wrapper for calls to GetFunc... — committed to dotnet/runtime by lambdageek 3 years ago
- Re-enable running DllImportGenerator.Tests suite on Mono. Now that #59815 and #60200 are merged, the DllImportGenerator tests pass on Mono in desktop form factors (where hostfxr and hostpolicy exist)... — committed to jkoritzinsky/runtime by jkoritzinsky 3 years ago
- [mono] Implement coreclr_create_delegate and move ComponentActivator to shared CoreLib (#59962) * [CoreLib] Move ComponentActivator to the shared area * [mono] Implement coreclr_create_delegate ho... — committed to kronic/runtime by lambdageek 3 years ago
- [reflection] Return n2m wrapper from RuntimeMethodHandle.GetFunctionPointer (#60200) for functions marked with UnmanagedCallersOnlyAttribute, return a pointer to the n2m wrapper for calls to GetFunc... — committed to kronic/runtime by lambdageek 3 years ago
@AaronRobinsonMSFT My assumption is: we want to run the dll import generator tests on Android,ios and wasm, not just on Linux & mac desktops with Mono instead of CoreCLR as the underlying runtime.
If we only want to run on desktops then (4) is sufficient.
I’d say it’s the hosting model, rather than something specific to mono. There’s no nethost, hostfxr or hostpolicy on mobile and any code that depends on them will not work.
The DNNE generated native libraries are probably ok (assuming we compile them with the right toolchain). But they depend on nethost, hostfxr and hostpolicy, right? So the functions that
platform.c
depends onget_hostfxr_path
,hostfxr_get_runtime_delegate
etc are not present on mobile.We haven’t tried the desktop versions of
hostfxr
andhostpolicy
on mobile - I have no idea how much work is required to get them working. (If I had to guess… Android and iOS Simulator are probably not too much work - they may even just work if we start building them and bundling them into the tests; iOS device and WebAssembly probably require moderate to significant changes since they’re static linking platforms).My guess is that the most straightforward way would be to build a mobile
hostfxr
library that exports the symbols that DNNE needs but implements them by directly calling thecoreclr_
functions in the current process (ie there’s no hostpolicy layer, and the implementation assumes the runtime is already loaded in the current process). Then the only other change needed isplatform.c
would need to skipget_hostfxr_path
and get the symbols fromRTLD_DEFAULT
.With #60200, the DllImportGenerator.Tests suite passes for me on desktop (macOS) MonoVM with both the JIT or the interpreter.
Mainly non-production/xamarin; I was coming from:
src/tests
with real corehost on mobile.Yup, there are still some implementation details even in self-contained e.g. how it uses user configuration json files, finds the hook in (coreclr) runtime and exports symbols for sos/diagnostics etc. I think making the same (familiar) hosts work on various platforms will open avenues for broader scenarios.
@jkoritzinsky thanks I’ll take a look.
Best guess so far is that
ComponentActivator.InternalGetFunctionPointer
isn’t doing the right thing on Mono - either wrapping a managed method too many times or not enough times. I suspect we’re missing a check forUnmanagedCallersOnly
somewhere on the native side in mono formethodInfo.MethodHandle.GetFunctionPointer()
. Probably won’t be a difficult fix once I find where the problem is.+1 for corehost support on mobile (simulators for the starters). and +2 for a true static linking support (e.g.
$ file singlefilehost_static
to return... statically linked, with debug_info, not stripped
) 🙂