Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono] AssemblyLoadContext.Default must be instantiated in the runtime for embedding scenarios #48610

Closed
grendello opened this issue Feb 22, 2021 · 2 comments · Fixed by #53308
Assignees
Milestone

Comments

@grendello
Copy link
Contributor

In Xamarin.Android we are loading managed assemblies directly from the APK archive on the runtime, without unpacking them to the filesystem. This is done inside a preload hook we install with the Mono runtime.
For .NET6 we want/need to switch to the ALC-enabled native assembly/image loading APIs, however all attempts to load an assembly image using the ALC APIs ends up in a segfault because the default ACL handle
doesn't exist yet.
The default ALC handle is not created until the managed code touches AssemblyLoadContext.Default, however we cannot hand control over to the managed runtime because the first assembly requested by Mono
on initialization is System.Private.CoreLib.dll and the attempt to use mono_image_open_from_data_alc (via a preload callback registered with mono_install_assembly_preload_hook_v3) ends up with the following
sigsegv:

02-22 15:56:59.510  5727  5727 F DEBUG   : Build fingerprint: 'google/crosshatch/crosshatch:11/RQ1A.210105.003/7005429:user/release-keys'
02-22 15:56:59.510  5727  5727 F DEBUG   : Revision: 'MP1.0'
02-22 15:56:59.510  5727  5727 F DEBUG   : ABI: 'arm64'
02-22 15:56:59.511  5727  5727 F DEBUG   : Timestamp: 2021-02-22 15:56:59+0100
02-22 15:56:59.511  5727  5727 F DEBUG   : pid: 5675, tid: 5675, name: net6.helloforms  >>> com.microsoft.net6.helloforms <<<
02-22 15:56:59.511  5727  5727 F DEBUG   : uid: 10267
02-22 15:56:59.511  5727  5727 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
02-22 15:56:59.511  5727  5727 F DEBUG   : Cause: null pointer dereference
02-22 15:56:59.511  5727  5727 F DEBUG   :     x0  0000007208518da0  x1  000000709e2b143f  x2  0000000000000003  x3  0000000000000002
02-22 15:56:59.511  5727  5727 F DEBUG   :     x4  0000007fd88cc8a0  x5  00000071d8538938  x6  0000000000000000  x7  0000007fd88cca58
02-22 15:56:59.511  5727  5727 F DEBUG   :     x8  0000000000000000  x9  0000000000000002  x10 0000000000000001  x11 0000000000000000
02-22 15:56:59.511  5727  5727 F DEBUG   :     x12 0000000000000020  x13 0000000000000138  x14 000000000000001a  x15 000000709e109b48
02-22 15:56:59.511  5727  5727 F DEBUG   :     x16 000000709e2f4848  x17 000000739b4f9520  x18 000000739e0f2000  x19 000000724850f550
02-22 15:56:59.511  5727  5727 F DEBUG   :     x20 0000000000000008  x21 0000007208518d80  x22 0000000000000001  x23 000000709c831bc4
02-22 15:56:59.511  5727  5727 F DEBUG   :     x24 0000000000000008  x25 0000000000000000  x26 0000007fd88cc938  x27 0000007fd88cc920
02-22 15:56:59.511  5727  5727 F DEBUG   :     x28 0000007fd88cca58  x29 0000007fd88cc880
02-22 15:56:59.511  5727  5727 F DEBUG   :     lr  000000709e0c8cc8  sp  0000007fd88cc860  pc  000000709e0c8ccc  pst 0000000080000000
02-22 15:56:59.514  5727  5727 F DEBUG   : backtrace:
02-22 15:56:59.514  5727  5727 F DEBUG   :       #00 pc 00000000000fbccc  /data/app/~~-clFrEXSMMc1T2VXtd1V4A==/com.microsoft.net6.helloforms-qvYuL4tG8kJz0fTpRsRvLg==/lib/arm64/libmonosgen-2.0.so (mono_alc_from_gchandle+60) (BuildId: de7c924ea2f7b4c6e23b7318a24a0bbbba175cc6)

Therefore, we would need the runtime to create the default ALC handle before it calls the preload hook for the first time.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Feb 22, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@CoffeeFlux CoffeeFlux self-assigned this Feb 22, 2021
@CoffeeFlux CoffeeFlux added area-AssemblyLoader-mono and removed untriaged New issue has not been triaged by the area owner labels Feb 22, 2021
@ghost
Copy link

ghost commented Feb 22, 2021

Tagging subscribers to this area: @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

Issue Details

In Xamarin.Android we are loading managed assemblies directly from the APK archive on the runtime, without unpacking them to the filesystem. This is done inside a preload hook we install with the Mono runtime.
For .NET6 we want/need to switch to the ALC-enabled native assembly/image loading APIs, however all attempts to load an assembly image using the ALC APIs ends up in a segfault because the default ACL handle
doesn't exist yet.
The default ALC handle is not created until the managed code touches AssemblyLoadContext.Default, however we cannot hand control over to the managed runtime because the first assembly requested by Mono
on initialization is System.Private.CoreLib.dll and the attempt to use mono_image_open_from_data_alc (via a preload callback registered with mono_install_assembly_preload_hook_v3) ends up with the following
sigsegv:

02-22 15:56:59.510  5727  5727 F DEBUG   : Build fingerprint: 'google/crosshatch/crosshatch:11/RQ1A.210105.003/7005429:user/release-keys'
02-22 15:56:59.510  5727  5727 F DEBUG   : Revision: 'MP1.0'
02-22 15:56:59.510  5727  5727 F DEBUG   : ABI: 'arm64'
02-22 15:56:59.511  5727  5727 F DEBUG   : Timestamp: 2021-02-22 15:56:59+0100
02-22 15:56:59.511  5727  5727 F DEBUG   : pid: 5675, tid: 5675, name: net6.helloforms  >>> com.microsoft.net6.helloforms <<<
02-22 15:56:59.511  5727  5727 F DEBUG   : uid: 10267
02-22 15:56:59.511  5727  5727 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
02-22 15:56:59.511  5727  5727 F DEBUG   : Cause: null pointer dereference
02-22 15:56:59.511  5727  5727 F DEBUG   :     x0  0000007208518da0  x1  000000709e2b143f  x2  0000000000000003  x3  0000000000000002
02-22 15:56:59.511  5727  5727 F DEBUG   :     x4  0000007fd88cc8a0  x5  00000071d8538938  x6  0000000000000000  x7  0000007fd88cca58
02-22 15:56:59.511  5727  5727 F DEBUG   :     x8  0000000000000000  x9  0000000000000002  x10 0000000000000001  x11 0000000000000000
02-22 15:56:59.511  5727  5727 F DEBUG   :     x12 0000000000000020  x13 0000000000000138  x14 000000000000001a  x15 000000709e109b48
02-22 15:56:59.511  5727  5727 F DEBUG   :     x16 000000709e2f4848  x17 000000739b4f9520  x18 000000739e0f2000  x19 000000724850f550
02-22 15:56:59.511  5727  5727 F DEBUG   :     x20 0000000000000008  x21 0000007208518d80  x22 0000000000000001  x23 000000709c831bc4
02-22 15:56:59.511  5727  5727 F DEBUG   :     x24 0000000000000008  x25 0000000000000000  x26 0000007fd88cc938  x27 0000007fd88cc920
02-22 15:56:59.511  5727  5727 F DEBUG   :     x28 0000007fd88cca58  x29 0000007fd88cc880
02-22 15:56:59.511  5727  5727 F DEBUG   :     lr  000000709e0c8cc8  sp  0000007fd88cc860  pc  000000709e0c8ccc  pst 0000000080000000
02-22 15:56:59.514  5727  5727 F DEBUG   : backtrace:
02-22 15:56:59.514  5727  5727 F DEBUG   :       #00 pc 00000000000fbccc  /data/app/~~-clFrEXSMMc1T2VXtd1V4A==/com.microsoft.net6.helloforms-qvYuL4tG8kJz0fTpRsRvLg==/lib/arm64/libmonosgen-2.0.so (mono_alc_from_gchandle+60) (BuildId: de7c924ea2f7b4c6e23b7318a24a0bbbba175cc6)

Therefore, we would need the runtime to create the default ALC handle before it calls the preload hook for the first time.

Author: grendello
Assignees: CoffeeFlux
Labels:

area-AssemblyLoader-mono

Milestone: -

@CoffeeFlux CoffeeFlux added this to the 6.0.0 milestone Feb 22, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 26, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 5, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants