[aot] Load the container module from load_aot_module (), so its loaded after mscorlib...
authormonojenkins <jo.shields+jenkins@xamarin.com>
Tue, 2 Jun 2020 19:53:01 +0000 (15:53 -0400)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 19:53:01 +0000 (15:53 -0400)
If its loaded later, its loading could trigger the execution of managed code i.e. loader callbacks on netcore.

<!--
Thank you for your Pull Request!

If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed.

Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number
-->

Co-authored-by: vargaz <vargaz@users.noreply.github.com>
src/mono/mono/metadata/appdomain.c
src/mono/mono/metadata/metadata-internals.h
src/mono/mono/mini/aot-runtime.c

index fd18732..ceed387 100644 (file)
@@ -1678,7 +1678,8 @@ mono_domain_fire_assembly_load (MonoAssemblyLoadContext *alc, MonoAssembly *asse
 #endif
        mono_domain_assemblies_unlock (domain);
 
-       mono_domain_fire_assembly_load_event (domain, assembly, error_out);
+       if (assembly->context.kind != MONO_ASMCTX_INTERNAL)
+               mono_domain_fire_assembly_load_event (domain, assembly, error_out);
 
 leave:
        mono_error_cleanup (error);
index 879df18..97f6c2d 100644 (file)
@@ -197,8 +197,10 @@ typedef enum MonoAssemblyContextKind {
         * any context"): LoadFile(String) and Load(byte[]) are here.
         */
        MONO_ASMCTX_INDIVIDUAL = 3,
+       /* Used internally by the runtime, not visible to managed code */
+       MONO_ASMCTX_INTERNAL = 4,
 
-       MONO_ASMCTX_LAST = 3
+       MONO_ASMCTX_LAST = 4
 } MonoAssemblyContextKind;
 
 typedef struct _MonoAssemblyContext {
index df3f5b6..5e15661 100644 (file)
@@ -259,6 +259,9 @@ static MonoJumpInfo*
 decode_patches (MonoAotModule *amodule, MonoMemPool *mp, int n_patches, gboolean llvm, guint32 *got_offsets);
 
 static void
+load_container_amodule (MonoAssemblyLoadContext *alc);
+
+static void
 amodule_lock (MonoAotModule *amodule)
 {
        mono_os_mutex_lock (&amodule->mutex);
@@ -2573,6 +2576,10 @@ mono_aot_register_module (gpointer *aot_info)
        g_hash_table_insert (static_aot_modules, aname, info);
 
        if (info->flags & MONO_AOT_FILE_FLAG_EAGER_LOAD) {
+               /*
+                * This assembly contains shared generic instances/wrappers, etc. It needs be be loaded
+                * before AOT code is loaded.
+                */
                g_assert (!container_assm_name);
                container_assm_name = aname;
        }
@@ -2605,6 +2612,11 @@ mono_aot_cleanup (void)
        g_hash_table_destroy (aot_modules);
 }
 
+/*
+ * load_container_amodule:
+ *
+ *   Load the container assembly and its AOT image.
+ */
 static void
 load_container_amodule (MonoAssemblyLoadContext *alc)
 {
@@ -2618,7 +2630,11 @@ load_container_amodule (MonoAssemblyLoadContext *alc)
        MonoImageOpenStatus status = MONO_IMAGE_OK;
        MonoAssemblyOpenRequest req;
        gchar *dll = g_strdup_printf (          "%s.dll", local_ref);
-       mono_assembly_request_prepare_open (&req, MONO_ASMCTX_DEFAULT, alc);
+       /*
+        * Using INTERNAL avoids firing managed assembly load events
+        * whose execution might require this module to be already loaded.
+        */
+       mono_assembly_request_prepare_open (&req, MONO_ASMCTX_INTERNAL, alc);
        MonoAssembly *assm = mono_assembly_request_open (dll, &req, &status);
        if (!assm) {
                gchar *exe = g_strdup_printf ("%s.exe", local_ref);