From 225e7cc2e9c180d150f908947e141ccebc4d8b1d Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Mon, 3 May 2021 03:53:41 -0400 Subject: [PATCH] [aot] Avoid associating the same AOT image with multiple assemblies loaded in different ALCs. This caused crashes in the generic sharing code on wasm. --- src/mono/mono/mini/aot-runtime.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index 8a6eaf88d00c65..23b79eb38ca09b 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -193,6 +193,7 @@ static GHashTable *static_aot_modules; */ static char *container_assm_name; static MonoAotModule *container_amodule; +static GHashTable *loaded_static_aot_modules; /* * Maps MonoJitInfo* to the aot module they belong to, this can be different @@ -1909,13 +1910,30 @@ load_aot_module (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, gpointer if (image_is_dynamic (assembly->image)) return; + gboolean loaded = FALSE; + mono_aot_lock (); if (static_aot_modules) info = (MonoAotFileInfo *)g_hash_table_lookup (static_aot_modules, assembly->aname.name); + if (info) { + if (!loaded_static_aot_modules) + loaded_static_aot_modules = g_hash_table_new (NULL, NULL); + if (g_hash_table_lookup (loaded_static_aot_modules, info)) + loaded = TRUE; + else + g_hash_table_insert (loaded_static_aot_modules, info, info); + } mono_aot_unlock (); + if (loaded) + /* + * Already loaded by another assembly with the same name, or the same assembly loaded + * in another ALC. + */ + return; + sofile = NULL; found_aot_name = NULL;