Registry Mirror
Skip to content

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

Closed

Description

@grendello

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.

Activity

  1. ghost added
    untriaged
    on Feb 22, 2021
  2. self-assigned this
    on Feb 22, 2021
  3. added and removed
    untriaged
    on Feb 22, 2021
  4. added this to the 6.0.0 milestone on Feb 22, 2021
  5. ghost added
    in-pr
    on May 26, 2021
  6. ghost removed
    in-pr
    on Jun 5, 2021
  7. ghost locked as resolved and limited conversation to collaborators on Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions