From 7038cbeccdff0b19a544d6866b1b20297bc28aa8 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 3 Jun 2022 01:36:07 -0400 Subject: [PATCH 1/6] [mono] Add non_executable field to MonoImage to properly load MethodRef in .mibc files --- src/mono/mono/metadata/assembly.c | 2 +- src/mono/mono/metadata/image-internals.h | 3 +++ src/mono/mono/metadata/image.c | 8 ++++++++ src/mono/mono/metadata/metadata-internals.h | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index e0756bf2cecf73..0332f36aae49a1 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -969,7 +969,7 @@ mono_assembly_load_reference (MonoImage *image, int index) goto commit_reference; } - if (image->assembly) { + if (image->assembly || image->not_executable) { if (mono_trace_is_traced (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY)) { char *aname_str = mono_stringify_assembly_name (&aname); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Loading reference %d of %s (%s), looking for %s", diff --git a/src/mono/mono/metadata/image-internals.h b/src/mono/mono/metadata/image-internals.h index d22b85bdce1e6e..099a2e80a2cb45 100644 --- a/src/mono/mono/metadata/image-internals.h +++ b/src/mono/mono/metadata/image-internals.h @@ -21,4 +21,7 @@ mono_image_load_module_checked (MonoImage *image, int idx, MonoError *error); MonoImage * mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status); +MonoImage * +mono_image_open_mibc (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status); + #endif /* __MONO_METADATA_IMAGE_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/image.c b/src/mono/mono/metadata/image.c index 0bb317c3e5c88e..d9e2a3d0eb29cc 100644 --- a/src/mono/mono/metadata/image.c +++ b/src/mono/mono/metadata/image.c @@ -1881,6 +1881,14 @@ mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImag return mono_image_open_a_lot_parameterized (li, alc, fname, status); } +MonoImage * +mono_image_open_mibc (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status) +{ + MonoImage *mibcImage = mono_image_open_a_lot (alc, fname, status); + mibcImage->not_executable = TRUE; + return mibcImage; +} + /** * mono_image_open: * \param fname filename that points to the module we want to open diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index d2b0e98aedbac2..039f1a0d31fccf 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -305,6 +305,9 @@ struct _MonoImage { /* Whenever this is a dynamically emitted module */ guint8 dynamic : 1; + /* Whenever this image is not an executable, such as .mibc */ + gboolean not_executable; + /* Whenever this image contains uncompressed metadata */ guint8 uncompressed_metadata : 1; From 46d2e03f518ce89a2a5d6d4f5ed5e56ae79f866a Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 3 Jun 2022 01:37:55 -0400 Subject: [PATCH 2/6] [mono][aot] Extend mono-aot-compiler to handle .mibc profile --- src/mono/mono/mini/aot-compiler.c | 131 ++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 2d1a4b2957156f..bf93af7334aff4 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -43,11 +43,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -186,6 +188,7 @@ typedef struct MonoAotOptions { char *llvm_outfile; char *data_outfile; GList *profile_files; + GList *mibc_profile_files; gboolean save_temps; gboolean write_symbols; gboolean metadata_only; @@ -8522,6 +8525,8 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts) opts->profile_files = g_list_append (opts->profile_files, g_strdup (arg + strlen ("profile="))); } else if (!strcmp (arg, "profile-only")) { opts->profile_only = TRUE; + } else if (str_begins_with (arg, "mibc-profile=")) { + opts->mibc_profile_files = g_list_append (opts->mibc_profile_files, g_strdup (arg + strlen ("mibc-profile="))); } else if (!strcmp (arg, "verbose")) { opts->verbose = TRUE; } else if (!strcmp (arg, "allow-errors")) { @@ -13215,6 +13220,124 @@ add_profile_instances (MonoAotCompile *acfg, ProfileData *data) printf ("Added %d methods from profile.\n", count); } +static int +add_single_mibc_profile_method (MonoAotCompile *acfg, MonoMethod *method) +{ + if (!method->is_inflated || mono_method_is_generic_sharable_full (method, FALSE, FALSE, FALSE)) { + if (!acfg->aot_opts.profile_only) + return 0; + if (m_class_get_image (method->klass) != acfg->image) + return 0; + add_profile_method (acfg, method); + return 1; + } + + if (acfg->aot_opts.dedup_include) { + add_profile_method (acfg, method); + return 1; + } + + MonoGenericContext *ctx = mono_method_get_context (method); + if ((ctx->class_inst && inst_references_image (ctx->class_inst, acfg->image)) || + (ctx->method_inst && inst_references_image (ctx->method_inst, acfg->image))) { + add_profile_method (acfg, method); + return 1; + } + + if (m_class_get_image (method->klass) == acfg->image && + ((ctx->class_inst && is_local_inst (ctx->class_inst, acfg->image)) || + (ctx->method_inst && is_local_inst (ctx->method_inst, acfg->image)))) { + add_profile_method (acfg, method); + return 1; + } + + return 0; +} + +static int +add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod, MonoImage *image, MonoClass *mibcModuleClass, MonoGenericContext *context) +{ + ERROR_DECL (error); + + MonoMethodHeader *mibcGroupMethodHeader = mono_method_get_header_internal (mibcGroupMethod, error); + mono_error_assert_ok (error); + + int count = 0; + uint8_t *cur = (uint8_t*)mibcGroupMethodHeader->code; + uint8_t *end = (uint8_t*)mibcGroupMethodHeader->code + mibcGroupMethodHeader->code_size; + while (cur < end) { + MonoOpcodeEnum il_op; + const unsigned char *opcodeIp = (unsigned char*)cur; + const unsigned char *opcodeEnd = (unsigned char*)end; + cur += mono_opcode_value_and_size (&opcodeIp, opcodeEnd, &il_op); + if (il_op != MONO_CEE_LDTOKEN) + continue; + + g_assert (opcodeIp + 4 < opcodeEnd); + guint32 mibcGroupMethodEntryToken = *(guint32 *)(opcodeIp + 1); + + MonoMethod *methodEntry = mono_get_method_checked (image, mibcGroupMethodEntryToken, mibcModuleClass, context, error); + mono_error_assert_ok (error); + + MonoClass *method_class = mono_method_get_class (methodEntry); + if (!method_class) + continue; + + MonoImage *method_image = mono_class_get_image (method_class); + if (!method_image) + continue; + + count += add_single_mibc_profile_method (acfg, methodEntry); + } + return count; +} + +static void +add_mibc_profile_methods (MonoAotCompile *acfg, char *filename) +{ + MonoImageOpenStatus status = MONO_IMAGE_OK; + MonoImage *image = mono_image_open_mibc (mono_alc_get_default (), filename, &status); + g_assert (image != NULL); + g_assert (status == MONO_IMAGE_OK); + + ERROR_DECL (error); + + MonoClass *mibcModuleClass = mono_class_from_name_checked (image, "", "", error); + mono_error_assert_ok (error); + + MonoMethod *assemblyDictionary = mono_class_get_method_from_name_checked (mibcModuleClass, "AssemblyDictionary", 0, 0, error); + MonoGenericContext *context = mono_method_get_context (assemblyDictionary); + mono_error_assert_ok (error); + + MonoMethodHeader *header = mono_method_get_header_internal (assemblyDictionary, error); + mono_error_assert_ok (error); + + int count = 0; + uint8_t *cur = (uint8_t*)header->code; + uint8_t *end = (uint8_t*)header->code + header->code_size; + while (cur < end) { + MonoOpcodeEnum il_op; + const unsigned char *opcodeIp = (unsigned char*)cur; + const unsigned char *opcodeEnd = (unsigned char*)end; + cur += mono_opcode_value_and_size (&opcodeIp, opcodeEnd, &il_op); + // opcodeIp gets moved to point at end of opcode + // il opcode arg is opcodeIp + 1 + // we only care about args of ldtoken's, which are 32bits/4bytes + if (il_op != MONO_CEE_LDTOKEN) + continue; + + g_assert (opcodeIp + 4 < opcodeEnd); + guint32 token = *(guint32 *)(opcodeIp + 1); + + MonoMethod *mibcGroupMethod = mono_get_method_checked (image, token, mibcModuleClass, context, error); + mono_error_assert_ok (error); + + count += add_mibc_group_method_methods (acfg, mibcGroupMethod, image, mibcModuleClass, context); + } + + printf ("Added %d methods from mibc profile.\n", count); +} + static void init_got_info (GotInfo *info) { @@ -14201,6 +14324,14 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options, add_profile_instances (acfg, (ProfileData*)l->data); } + if (acfg->aot_opts.mibc_profile_files) { + GList *l; + + for (l = acfg->aot_opts.mibc_profile_files; l; l = l->next) { + add_mibc_profile_methods (acfg, (char*)l->data); + } + } + /* PLT offset 0 is reserved for the PLT trampoline */ acfg->plt_offset = 1; add_preinit_got_slots (acfg); From 406ced357c87516848c0a1ca1d14788d9226a367 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 3 Jun 2022 01:39:10 -0400 Subject: [PATCH 3/6] [tasks] Extend MonoAOTCompiler task to handle .mibc profiles --- src/tasks/AotCompilerTask/MonoAOTCompiler.cs | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs index 66cf3ec06e8bc8..fcc24b6111b807 100644 --- a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs +++ b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs @@ -116,6 +116,11 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task /// public string[]? AotProfilePath { get; set; } + /// + /// Mibc file to use for profile-guided optimization, *only* the methods described in the file will be AOT compiled. + /// + public string[]? MibcProfilePath { get; set; } + /// /// List of profilers to use. /// @@ -278,6 +283,18 @@ private bool ProcessAndValidateArguments() } } + if (MibcProfilePath != null) + { + foreach (var path in MibcProfilePath) + { + if (!File.Exists(path)) + { + Log.LogError($"MibcProfilePath '{path}' doesn't exist."); + return false; + } + } + } + if (UseLLVM) { if (string.IsNullOrEmpty(LLVMPath)) @@ -739,6 +756,15 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st } } + if (MibcProfilePath?.Length > 0) + { + aotArgs.Add("profile-only"); + foreach (var path in MibcProfilePath) + { + aotArgs.Add($"mibc-profile={path}"); + } + } + if (!string.IsNullOrEmpty(AotArguments)) { aotArgs.Add(AotArguments); From 742823985a6c44ae1abe7aa9bda414629b96e171 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 3 Jun 2022 15:36:57 -0400 Subject: [PATCH 4/6] Address feedback --- src/mono/mono/metadata/assembly.c | 31 ++--- src/mono/mono/metadata/image-internals.h | 16 ++- src/mono/mono/metadata/image.c | 70 +++++----- src/mono/mono/metadata/metadata-internals.h | 2 +- src/mono/mono/mini/aot-compiler.c | 137 ++++++++------------ 5 files changed, 117 insertions(+), 139 deletions(-) diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index 0332f36aae49a1..556752d6970c95 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -969,24 +969,21 @@ mono_assembly_load_reference (MonoImage *image, int index) goto commit_reference; } - if (image->assembly || image->not_executable) { - if (mono_trace_is_traced (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY)) { - char *aname_str = mono_stringify_assembly_name (&aname); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Loading reference %d of %s (%s), looking for %s", - index, image->name, mono_alc_is_default (mono_image_get_alc (image)) ? "default ALC" : "custom ALC" , - aname_str); - g_free (aname_str); - } - - MonoAssemblyByNameRequest req; - mono_assembly_request_prepare_byname (&req, mono_image_get_alc (image)); - req.requesting_assembly = image->assembly; - //req.no_postload_search = TRUE; // FIXME: should this be set? - reference = mono_assembly_request_byname (&aname, &req, NULL); - } else { - g_assertf (image->assembly, "While loading reference %d MonoImage %s doesn't have a MonoAssembly", index, image->name); + g_assertf (image->assembly || image->not_executable, "While loading reference %d, executable MonoImage %s doesn't have a MonoAssembly", index, image->name); + if (mono_trace_is_traced (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY)) { + char *aname_str = mono_stringify_assembly_name (&aname); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Loading reference %d of %s (%s), looking for %s", + index, image->name, mono_alc_is_default (mono_image_get_alc (image)) ? "default ALC" : "custom ALC" , + aname_str); + g_free (aname_str); } + MonoAssemblyByNameRequest req; + mono_assembly_request_prepare_byname (&req, mono_image_get_alc (image)); + req.requesting_assembly = image->assembly; + //req.no_postload_search = TRUE; // FIXME: should this be set? + reference = mono_assembly_request_byname (&aname, &req, NULL); + if (reference == NULL){ char *extra_msg; @@ -1603,7 +1600,7 @@ mono_assembly_request_open (const char *filename, const MonoAssemblyOpenRequest } if (!image) - image = mono_image_open_a_lot (load_req.alc, fname, status); + image = mono_image_open_a_lot (load_req.alc, fname, status, FALSE); if (!image){ if (*status == MONO_IMAGE_OK) diff --git a/src/mono/mono/metadata/image-internals.h b/src/mono/mono/metadata/image-internals.h index 099a2e80a2cb45..8320009593ef98 100644 --- a/src/mono/mono/metadata/image-internals.h +++ b/src/mono/mono/metadata/image-internals.h @@ -9,6 +9,17 @@ #include #include +typedef struct { + int care_about_cli : 1; + int care_about_pecoff : 1; +} ImageLoadOptions; + +typedef struct { + ImageLoadOptions load_options; + int not_executable : 1; + int metadata_only : 1; +} ImageOpenOptions; + MonoImage* mono_image_loaded_internal (MonoAssemblyLoadContext *alc, const char *name); @@ -19,9 +30,6 @@ MonoImage* mono_image_load_module_checked (MonoImage *image, int idx, MonoError *error); MonoImage * -mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status); - -MonoImage * -mono_image_open_mibc (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status); +mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable); #endif /* __MONO_METADATA_IMAGE_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/image.c b/src/mono/mono/metadata/image.c index d9e2a3d0eb29cc..565de314205241 100644 --- a/src/mono/mono/metadata/image.c +++ b/src/mono/mono/metadata/image.c @@ -104,7 +104,7 @@ mono_images_unlock(void) } static MonoImage * -mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status); +mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable); /* Maps string keys to MonoImageStorage values. * @@ -1174,8 +1174,7 @@ dump_encmap (MonoImage *image) } static MonoImage * -do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, - gboolean care_about_cli, gboolean care_about_pecoff) +do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, const ImageLoadOptions *options) { ERROR_DECL (error); GSList *l; @@ -1201,7 +1200,7 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, if (status) *status = MONO_IMAGE_IMAGE_INVALID; - if (care_about_pecoff == FALSE) + if (options->care_about_pecoff == FALSE) goto done; if (!mono_image_load_pe_data (image)) @@ -1210,7 +1209,7 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, image->loader = (MonoImageLoader*)&pe_loader; } - if (care_about_cli == FALSE) { + if (options->care_about_cli == FALSE) { goto done; } @@ -1409,8 +1408,7 @@ mono_image_storage_new_raw_data (char *datac, guint32 data_len, gboolean raw_dat } static MonoImage * -do_mono_image_open (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, - gboolean care_about_cli, gboolean care_about_pecoff, gboolean metadata_only) +do_mono_image_open (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const ImageOpenOptions *options) { MonoCLIImageInfo *iinfo; MonoImage *image; @@ -1424,6 +1422,7 @@ do_mono_image_open (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOp } image = g_new0 (MonoImage, 1); + image->ref_count = 1; image->storage = storage; mono_image_init_raw_data (image, storage); if (!image->raw_data) { @@ -1433,14 +1432,14 @@ do_mono_image_open (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOp *status = MONO_IMAGE_IMAGE_INVALID; return NULL; } - iinfo = g_new0 (MonoCLIImageInfo, 1); - image->image_info = iinfo; + image->not_executable = !!options->not_executable; + image->metadata_only = !!options->metadata_only; image->name = mono_path_resolve_symlinks (fname); image->filename = g_strdup (image->name); - image->metadata_only = !!metadata_only; - image->ref_count = 1; + iinfo = g_new0 (MonoCLIImageInfo, 1); + image->image_info = iinfo; image->alc = alc; - return do_mono_image_load (image, status, care_about_cli, care_about_pecoff); + return do_mono_image_load (image, status, &options->load_options); } /** @@ -1627,7 +1626,10 @@ mono_image_open_from_data_internal (MonoAssemblyLoadContext *alc, char *data, gu image->ref_count = 1; image->alc = alc; - image = do_mono_image_load (image, status, TRUE, TRUE); + ImageLoadOptions options = {0, }; + options.care_about_cli = 1; + options.care_about_pecoff = 1; + image = do_mono_image_load (image, status, &options); if (image == NULL) return NULL; @@ -1742,7 +1744,10 @@ mono_image_open_from_module_handle (MonoAssemblyLoadContext *alc, HMODULE module image->ref_count = has_entry_point ? 0 : 1; image->alc = alc; - image = do_mono_image_load (image, status, TRUE, TRUE); + ImageLoadOptions options = {0, }; + options.care_about_cli = 1; + options.care_about_pecoff = 1; + image = do_mono_image_load (image, status, &options); if (image == NULL) return NULL; @@ -1761,11 +1766,11 @@ mono_image_open_full (const char *fname, MonoImageOpenStatus *status, gboolean r *status = MONO_IMAGE_NOT_SUPPORTED; return NULL; } - return mono_image_open_a_lot (mono_alc_get_default (), fname, status); + return mono_image_open_a_lot (mono_alc_get_default (), fname, status, FALSE); } static MonoImage * -mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status) +mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable) { MonoImage *image; GHashTable *loaded_images = mono_loaded_images_get_hash (li); @@ -1867,7 +1872,11 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte mono_images_unlock (); // Image not loaded, load it now - image = do_mono_image_open (alc, fname, status, TRUE, TRUE, FALSE); + ImageOpenOptions options = {0, }; + options.load_options.care_about_cli = 1; + options.load_options.care_about_pecoff = 1; + options.not_executable = !!not_executable; + image = do_mono_image_open (alc, fname, status, &options); if (image == NULL) return NULL; @@ -1875,18 +1884,10 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte } MonoImage * -mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status) +mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable) { MonoLoadedImages *li = mono_alc_get_loaded_images (alc); - return mono_image_open_a_lot_parameterized (li, alc, fname, status); -} - -MonoImage * -mono_image_open_mibc (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status) -{ - MonoImage *mibcImage = mono_image_open_a_lot (alc, fname, status); - mibcImage->not_executable = TRUE; - return mibcImage; + return mono_image_open_a_lot_parameterized (li, alc, fname, status, not_executable); } /** @@ -1901,7 +1902,7 @@ mono_image_open_mibc (MonoAssemblyLoadContext *alc, const char *fname, MonoImage MonoImage * mono_image_open (const char *fname, MonoImageOpenStatus *status) { - return mono_image_open_a_lot (mono_alc_get_default (), fname, status); + return mono_image_open_a_lot (mono_alc_get_default (), fname, status, FALSE); } /** @@ -1919,7 +1920,9 @@ mono_pe_file_open (const char *fname, MonoImageOpenStatus *status) { g_return_val_if_fail (fname != NULL, NULL); - return do_mono_image_open (mono_alc_get_default (), fname, status, FALSE, TRUE, FALSE); + ImageOpenOptions options = {0, }; + options.load_options.care_about_pecoff = 1; + return do_mono_image_open (mono_alc_get_default (), fname, status, &options); } /** @@ -1934,7 +1937,8 @@ mono_image_open_raw (MonoAssemblyLoadContext *alc, const char *fname, MonoImageO { g_return_val_if_fail (fname != NULL, NULL); - return do_mono_image_open (alc, fname, status, FALSE, FALSE, FALSE); + ImageOpenOptions options = {0, }; + return do_mono_image_open (alc, fname, status, &options); } /* @@ -1945,7 +1949,11 @@ mono_image_open_raw (MonoAssemblyLoadContext *alc, const char *fname, MonoImageO MonoImage * mono_image_open_metadata_only (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status) { - return do_mono_image_open (alc, fname, status, TRUE, TRUE, TRUE); + ImageOpenOptions options = {0, }; + options.load_options.care_about_cli = 1; + options.load_options.care_about_pecoff = 1; + options.metadata_only = 1; + return do_mono_image_open (alc, fname, status, &options); } /** diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index 039f1a0d31fccf..7539845aa17e3b 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -306,7 +306,7 @@ struct _MonoImage { guint8 dynamic : 1; /* Whenever this image is not an executable, such as .mibc */ - gboolean not_executable; + guint8 not_executable : 1; /* Whenever this image contains uncompressed metadata */ guint8 uncompressed_metadata : 1; diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index bf93af7334aff4..1a7922c614c69a 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -13137,92 +13137,16 @@ add_profile_method (MonoAotCompile *acfg, MonoMethod *m) add_extra_method (acfg, m); } -static void -add_profile_instances (MonoAotCompile *acfg, ProfileData *data) +static int +add_single_profile_method (MonoAotCompile *acfg, MonoMethod *method) { - GHashTableIter iter; - gpointer key, value; - int count = 0; - - if (!data) - return; - - if (acfg->aot_opts.profile_only) { - /* Add methods referenced by the profile */ - g_hash_table_iter_init (&iter, data->methods); - while (g_hash_table_iter_next (&iter, &key, &value)) { - MethodProfileData *mdata = (MethodProfileData*)value; - MonoMethod *m = mdata->method; - - if (!m) - continue; - if (m->is_inflated) - continue; - if (m_class_get_image (m->klass) != acfg->image) - continue; - add_profile_method (acfg, m); - count ++; - } - } + if (!method) + return 0; /* - * Add method instances 'related' to this assembly to the AOT image. - */ - g_hash_table_iter_init (&iter, data->methods); - while (g_hash_table_iter_next (&iter, &key, &value)) { - MethodProfileData *mdata = (MethodProfileData*)value; - MonoMethod *m = mdata->method; - MonoGenericContext *ctx; - - if (!m) - continue; - if (!m->is_inflated) - continue; - if (mono_method_is_generic_sharable_full (m, FALSE, FALSE, FALSE)) { - if (acfg->aot_opts.profile_only && m_class_get_image (m->klass) == acfg->image) { - // Add the fully shared version to its home image - add_profile_method (acfg, m); - count ++; - } - continue; - } - - if (acfg->aot_opts.dedup_include) { - /* Add all instances from the profile */ - add_profile_method (acfg, m); - count ++; - } else { - ctx = mono_method_get_context (m); - /* For simplicity, add instances which reference the assembly we are compiling */ - if (((ctx->class_inst && inst_references_image (ctx->class_inst, acfg->image)) || - (ctx->method_inst && inst_references_image (ctx->method_inst, acfg->image)))) { - //printf ("%s\n", mono_method_full_name (m, TRUE)); - add_profile_method (acfg, m); - count ++; - } else if (m_class_get_image (m->klass) == acfg->image && - ((ctx->class_inst && is_local_inst (ctx->class_inst, acfg->image)) || - (ctx->method_inst && is_local_inst (ctx->method_inst, acfg->image)))) { - /* Add instances where the gtd is in the assembly and its inflated with types from this assembly or corlib */ - //printf ("%s\n", mono_method_full_name (m, TRUE)); - add_profile_method (acfg, m); - count ++; - } else { - //printf ("SKIP: %s (%s)\n", mono_method_get_full_name (m), acfg->image->name); - } - /* - * FIXME: We might skip some instances, for example: - * Foo won't be compiled when compiling Foo's assembly since it doesn't match the first case, - * and it won't be compiled when compiling Bar's assembly if Foo's assembly is not loaded. - */ - } - } - - printf ("Added %d methods from profile.\n", count); -} - -static int -add_single_mibc_profile_method (MonoAotCompile *acfg, MonoMethod *method) -{ + * Add methods referenced by the profile and + * Add fully shared version of method instances 'related' to this assembly to the AOT image. + */ if (!method->is_inflated || mono_method_is_generic_sharable_full (method, FALSE, FALSE, FALSE)) { if (!acfg->aot_opts.profile_only) return 0; @@ -13232,18 +13156,21 @@ add_single_mibc_profile_method (MonoAotCompile *acfg, MonoMethod *method) return 1; } + /* Add all instances from the profile */ if (acfg->aot_opts.dedup_include) { add_profile_method (acfg, method); return 1; } MonoGenericContext *ctx = mono_method_get_context (method); + /* For simplicity, add instances which reference the assembly we are compiling */ if ((ctx->class_inst && inst_references_image (ctx->class_inst, acfg->image)) || (ctx->method_inst && inst_references_image (ctx->method_inst, acfg->image))) { add_profile_method (acfg, method); return 1; } + /* Add instances where the gtd is in the assembly and its inflated with types from this assembly or corlib */ if (m_class_get_image (method->klass) == acfg->image && ((ctx->class_inst && is_local_inst (ctx->class_inst, acfg->image)) || (ctx->method_inst && is_local_inst (ctx->method_inst, acfg->image)))) { @@ -13251,9 +13178,40 @@ add_single_mibc_profile_method (MonoAotCompile *acfg, MonoMethod *method) return 1; } + /* + * FIXME: We might skip some instances, for example: + * Foo won't be compiled when compiling Foo's assembly since it doesn't match the first case, + * and it won't be compiled when compiling Bar's assembly if Foo's assembly is not loaded. + */ + return 0; } +static void +add_profile_instances (MonoAotCompile *acfg, ProfileData *data) +{ + GHashTableIter iter; + gpointer key, value; + int count = 0; + + if (!data) + return; + + g_hash_table_iter_init (&iter, data->methods); + while (g_hash_table_iter_next (&iter, &key, &value)) { + MethodProfileData *mdata = (MethodProfileData*)value; + MonoMethod *m = mdata->method; + count += add_single_profile_method (acfg, m); + } + + printf ("Added %d methods from profile.\n", count); +} + +typedef enum { + FIND_METHOD_TYPE_ENTRY_START, + FIND_METHOD_TYPE_ENTRY_END, +} MibcGroupMethodEntryState; + static int add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod, MonoImage *image, MonoClass *mibcModuleClass, MonoGenericContext *context) { @@ -13263,6 +13221,7 @@ add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod mono_error_assert_ok (error); int count = 0; + MibcGroupMethodEntryState state = FIND_METHOD_TYPE_ENTRY_START; uint8_t *cur = (uint8_t*)mibcGroupMethodHeader->code; uint8_t *end = (uint8_t*)mibcGroupMethodHeader->code + mibcGroupMethodHeader->code_size; while (cur < end) { @@ -13270,11 +13229,17 @@ add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod const unsigned char *opcodeIp = (unsigned char*)cur; const unsigned char *opcodeEnd = (unsigned char*)end; cur += mono_opcode_value_and_size (&opcodeIp, opcodeEnd, &il_op); - if (il_op != MONO_CEE_LDTOKEN) + + if (state == FIND_METHOD_TYPE_ENTRY_END) { + if (il_op == MONO_CEE_POP) + state = FIND_METHOD_TYPE_ENTRY_START; continue; + } + state = FIND_METHOD_TYPE_ENTRY_END; g_assert (opcodeIp + 4 < opcodeEnd); guint32 mibcGroupMethodEntryToken = *(guint32 *)(opcodeIp + 1); + g_assertf ((mono_metadata_token_table (mibcGroupMethodEntryToken) == MONO_TABLE_MEMBERREF || mono_metadata_token_table (mibcGroupMethodEntryToken) == MONO_TABLE_METHODSPEC), "token %x is not MemberRef or MethodSpec.\n", mibcGroupMethodEntryToken); MonoMethod *methodEntry = mono_get_method_checked (image, mibcGroupMethodEntryToken, mibcModuleClass, context, error); mono_error_assert_ok (error); @@ -13287,7 +13252,7 @@ add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod if (!method_image) continue; - count += add_single_mibc_profile_method (acfg, methodEntry); + count += add_single_profile_method (acfg, methodEntry); } return count; } @@ -13296,7 +13261,7 @@ static void add_mibc_profile_methods (MonoAotCompile *acfg, char *filename) { MonoImageOpenStatus status = MONO_IMAGE_OK; - MonoImage *image = mono_image_open_mibc (mono_alc_get_default (), filename, &status); + MonoImage *image = mono_image_open_a_lot (mono_alc_get_default (), filename, &status, TRUE); g_assert (image != NULL); g_assert (status == MONO_IMAGE_OK); From b1fb61eceaf5363f7ae72e66596c40509f6a1d7e Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 3 Jun 2022 23:32:32 -0400 Subject: [PATCH 5/6] Add method descriptions --- src/mono/mono/mini/aot-compiler.c | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 1a7922c614c69a..272d5793868138 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -13137,6 +13137,20 @@ add_profile_method (MonoAotCompile *acfg, MonoMethod *m) add_extra_method (acfg, m); } +//--------------------------------------------------------------------------------------- +// +// add_single_profile_method filters MonoMethods to be added for AOT compilation. +// The filter logic is extracted from add_profile_instances and comments are retained +// from there. +// +// Arguments: +// * acfg - MonoAotCompiler instance +// * method - MonoMethod to attempt to add for AOT compilation +// +// Return Value: +// int pertaining whether or not the method was added to be AOT'd +// + static int add_single_profile_method (MonoAotCompile *acfg, MonoMethod *method) { @@ -13212,6 +13226,38 @@ typedef enum { FIND_METHOD_TYPE_ENTRY_END, } MibcGroupMethodEntryState; +//--------------------------------------------------------------------------------------- +// +// add_mibc_group_method_methods iterates over a mibcGroupMethod MonoMethod to obtain +// each method/type entry in that group. Each entry begins with LDTOKEN opcode, followed +// by a series of instructions including another LDTOKEN opcode but excluding a POP opcode +// ending with a POP opcode to denote the end of the entry. To iterate over entries, +// a MibcGroupMethodEntryState state is tracked, identifying whether we are looking for +// an entry starting LDTOKEN opcode or entry ending POP opcode. Each LDTOKEN opcode's +// argument denotes a methodref or methodspec. Before ultimately adding the entry's method +// for AOT compilation, checks for the method's class and image are used to skip methods +// whose class and images cannot be resolved. +// +// Sample mibcGroupMethod format +// +// Method 'Assemblies_HelloWorld;_1' (#11b) (0x06000001) +// { +// IL_0000: ldtoken 0x0A0002B5 // Method/Type Entry token +// IL_0005: pop +// } +// +// Arguments: +// * acfg - MonoAotCompiler instance +// * mibcGroupMethod - MonoMethod representing the group of assemblies that +// describes each Method/Type entry with the .mibc file +// * image - MonoImage representing the .mibc file +// * mibcModuleClass - MonoClass containing the AssemblyDictionary +// * context - MonoGenericContext of the AssemblyDictionary MonoMethod +// +// Return Value: +// int pertaining to the number of methods added within the mibcGroupMethod +// + static int add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod, MonoImage *image, MonoClass *mibcModuleClass, MonoGenericContext *context) { @@ -13257,6 +13303,30 @@ add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod return count; } +//--------------------------------------------------------------------------------------- +// +// add_mibc_profile_methods is the overarching method that adds methods within a .mibc +// profile file to be compiled ahead of time. .mibc is a portable executable with +// methods grouped under mibcGroupMethods, which are summarized within the global +// function AssemblyDictionary. This method obtains the AssemblyDictionary and iterates +// over il opcodes and arguments to retrieve mibcGroupMethods and thereafter calls +// add_mibc_group_method_methods. +// +// Sample AssemblyDictionary format +// +// Method 'AssemblyDictionary' (#2f67) (0x06000006) +// { +// IL_0000: ldstr 0x70000001 +// IL_0005: ldtoken 0x06000001 // mibcGroupMethod +// IL_000a: pop +// ... +// } +// +// Arguments: +// * acfg - MonoAotCompiler instance +// * filename - the .mibc profile file containing the methods to AOT compile +// + static void add_mibc_profile_methods (MonoAotCompile *acfg, char *filename) { From 47744390ad9ebbed1baecdf43bb8c79a30d18682 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Mon, 6 Jun 2022 13:19:59 -0400 Subject: [PATCH 6/6] Address more feedback --- src/mono/mono/metadata/assembly.c | 6 ++- src/mono/mono/metadata/image-internals.h | 12 +++--- src/mono/mono/metadata/image.c | 48 +++++++++++------------- src/mono/mono/mini/aot-compiler.c | 9 +++-- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index 556752d6970c95..56d206467bfa09 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -1599,8 +1599,10 @@ mono_assembly_request_open (const char *filename, const MonoAssemblyOpenRequest loaded_from_bundle = image != NULL; } - if (!image) - image = mono_image_open_a_lot (load_req.alc, fname, status, FALSE); + if (!image) { + MonoImageOpenOptions options = {0, }; + image = mono_image_open_a_lot (load_req.alc, fname, status, &options); + } if (!image){ if (*status == MONO_IMAGE_OK) diff --git a/src/mono/mono/metadata/image-internals.h b/src/mono/mono/metadata/image-internals.h index 8320009593ef98..d9433dda2a3b9b 100644 --- a/src/mono/mono/metadata/image-internals.h +++ b/src/mono/mono/metadata/image-internals.h @@ -10,15 +10,15 @@ #include typedef struct { - int care_about_cli : 1; - int care_about_pecoff : 1; -} ImageLoadOptions; + int dont_care_about_cli : 1; + int dont_care_about_pecoff : 1; +} MonoImageLoadOptions; typedef struct { - ImageLoadOptions load_options; + MonoImageLoadOptions load_options; int not_executable : 1; int metadata_only : 1; -} ImageOpenOptions; +} MonoImageOpenOptions; MonoImage* mono_image_loaded_internal (MonoAssemblyLoadContext *alc, const char *name); @@ -30,6 +30,6 @@ MonoImage* mono_image_load_module_checked (MonoImage *image, int idx, MonoError *error); MonoImage * -mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable); +mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const MonoImageOpenOptions *options); #endif /* __MONO_METADATA_IMAGE_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/image.c b/src/mono/mono/metadata/image.c index 565de314205241..2dbcf88cc27740 100644 --- a/src/mono/mono/metadata/image.c +++ b/src/mono/mono/metadata/image.c @@ -104,7 +104,7 @@ mono_images_unlock(void) } static MonoImage * -mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable); +mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const MonoImageOpenOptions *options); /* Maps string keys to MonoImageStorage values. * @@ -1174,7 +1174,7 @@ dump_encmap (MonoImage *image) } static MonoImage * -do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, const ImageLoadOptions *options) +do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, const MonoImageLoadOptions *options) { ERROR_DECL (error); GSList *l; @@ -1200,7 +1200,7 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, const ImageLo if (status) *status = MONO_IMAGE_IMAGE_INVALID; - if (options->care_about_pecoff == FALSE) + if (options->dont_care_about_pecoff == TRUE) goto done; if (!mono_image_load_pe_data (image)) @@ -1209,7 +1209,7 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status, const ImageLo image->loader = (MonoImageLoader*)&pe_loader; } - if (options->care_about_cli == FALSE) { + if (options->dont_care_about_cli == TRUE) { goto done; } @@ -1408,7 +1408,7 @@ mono_image_storage_new_raw_data (char *datac, guint32 data_len, gboolean raw_dat } static MonoImage * -do_mono_image_open (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const ImageOpenOptions *options) +do_mono_image_open (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const MonoImageOpenOptions *options) { MonoCLIImageInfo *iinfo; MonoImage *image; @@ -1626,9 +1626,7 @@ mono_image_open_from_data_internal (MonoAssemblyLoadContext *alc, char *data, gu image->ref_count = 1; image->alc = alc; - ImageLoadOptions options = {0, }; - options.care_about_cli = 1; - options.care_about_pecoff = 1; + MonoImageLoadOptions options = {0, }; image = do_mono_image_load (image, status, &options); if (image == NULL) return NULL; @@ -1744,9 +1742,7 @@ mono_image_open_from_module_handle (MonoAssemblyLoadContext *alc, HMODULE module image->ref_count = has_entry_point ? 0 : 1; image->alc = alc; - ImageLoadOptions options = {0, }; - options.care_about_cli = 1; - options.care_about_pecoff = 1; + MonoImageLoadOptions options = {0, }; image = do_mono_image_load (image, status, &options); if (image == NULL) return NULL; @@ -1766,11 +1762,12 @@ mono_image_open_full (const char *fname, MonoImageOpenStatus *status, gboolean r *status = MONO_IMAGE_NOT_SUPPORTED; return NULL; } - return mono_image_open_a_lot (mono_alc_get_default (), fname, status, FALSE); + MonoImageOpenOptions options = {0, }; + return mono_image_open_a_lot (mono_alc_get_default (), fname, status, &options); } static MonoImage * -mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable) +mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const MonoImageOpenOptions *options) { MonoImage *image; GHashTable *loaded_images = mono_loaded_images_get_hash (li); @@ -1872,11 +1869,7 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte mono_images_unlock (); // Image not loaded, load it now - ImageOpenOptions options = {0, }; - options.load_options.care_about_cli = 1; - options.load_options.care_about_pecoff = 1; - options.not_executable = !!not_executable; - image = do_mono_image_open (alc, fname, status, &options); + image = do_mono_image_open (alc, fname, status, options); if (image == NULL) return NULL; @@ -1884,10 +1877,10 @@ mono_image_open_a_lot_parameterized (MonoLoadedImages *li, MonoAssemblyLoadConte } MonoImage * -mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, gboolean not_executable) +mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status, const MonoImageOpenOptions *options) { MonoLoadedImages *li = mono_alc_get_loaded_images (alc); - return mono_image_open_a_lot_parameterized (li, alc, fname, status, not_executable); + return mono_image_open_a_lot_parameterized (li, alc, fname, status, options); } /** @@ -1902,7 +1895,8 @@ mono_image_open_a_lot (MonoAssemblyLoadContext *alc, const char *fname, MonoImag MonoImage * mono_image_open (const char *fname, MonoImageOpenStatus *status) { - return mono_image_open_a_lot (mono_alc_get_default (), fname, status, FALSE); + MonoImageOpenOptions options = {0, }; + return mono_image_open_a_lot (mono_alc_get_default (), fname, status, &options); } /** @@ -1920,8 +1914,8 @@ mono_pe_file_open (const char *fname, MonoImageOpenStatus *status) { g_return_val_if_fail (fname != NULL, NULL); - ImageOpenOptions options = {0, }; - options.load_options.care_about_pecoff = 1; + MonoImageOpenOptions options = {0, }; + options.load_options.dont_care_about_cli = 1; return do_mono_image_open (mono_alc_get_default (), fname, status, &options); } @@ -1937,7 +1931,9 @@ mono_image_open_raw (MonoAssemblyLoadContext *alc, const char *fname, MonoImageO { g_return_val_if_fail (fname != NULL, NULL); - ImageOpenOptions options = {0, }; + MonoImageOpenOptions options = {0, }; + options.load_options.dont_care_about_cli = 1; + options.load_options.dont_care_about_pecoff = 1; return do_mono_image_open (alc, fname, status, &options); } @@ -1949,9 +1945,7 @@ mono_image_open_raw (MonoAssemblyLoadContext *alc, const char *fname, MonoImageO MonoImage * mono_image_open_metadata_only (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status) { - ImageOpenOptions options = {0, }; - options.load_options.care_about_cli = 1; - options.load_options.care_about_pecoff = 1; + MonoImageOpenOptions options = {0, }; options.metadata_only = 1; return do_mono_image_open (alc, fname, status, &options); } diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 272d5793868138..3c551b139facbd 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -13281,10 +13281,11 @@ add_mibc_group_method_methods (MonoAotCompile *acfg, MonoMethod *mibcGroupMethod state = FIND_METHOD_TYPE_ENTRY_START; continue; } + g_assert (il_op == MONO_CEE_LDTOKEN); state = FIND_METHOD_TYPE_ENTRY_END; g_assert (opcodeIp + 4 < opcodeEnd); - guint32 mibcGroupMethodEntryToken = *(guint32 *)(opcodeIp + 1); + guint32 mibcGroupMethodEntryToken = read32 (opcodeIp + 1); g_assertf ((mono_metadata_token_table (mibcGroupMethodEntryToken) == MONO_TABLE_MEMBERREF || mono_metadata_token_table (mibcGroupMethodEntryToken) == MONO_TABLE_METHODSPEC), "token %x is not MemberRef or MethodSpec.\n", mibcGroupMethodEntryToken); MonoMethod *methodEntry = mono_get_method_checked (image, mibcGroupMethodEntryToken, mibcModuleClass, context, error); @@ -13331,7 +13332,9 @@ static void add_mibc_profile_methods (MonoAotCompile *acfg, char *filename) { MonoImageOpenStatus status = MONO_IMAGE_OK; - MonoImage *image = mono_image_open_a_lot (mono_alc_get_default (), filename, &status, TRUE); + MonoImageOpenOptions options = {0, }; + options.not_executable = 1; + MonoImage *image = mono_image_open_a_lot (mono_alc_get_default (), filename, &status, &options); g_assert (image != NULL); g_assert (status == MONO_IMAGE_OK); @@ -13362,7 +13365,7 @@ add_mibc_profile_methods (MonoAotCompile *acfg, char *filename) continue; g_assert (opcodeIp + 4 < opcodeEnd); - guint32 token = *(guint32 *)(opcodeIp + 1); + guint32 token = read32 (opcodeIp + 1); MonoMethod *mibcGroupMethod = mono_get_method_checked (image, token, mibcModuleClass, context, error); mono_error_assert_ok (error);