From 98d7ad045e6661e4c2e428fe4acc4fc733d44fdc Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 21 Dec 2016 19:30:27 -0500 Subject: [PATCH] [aot] Cleanup the AOT loading code a bit. Add a --aot-path= command line option to specify additional directories to search for AOT images. (#4191) --- man/mono.1 | 3 +++ mono/mini/aot-runtime.c | 58 +++++++++++++++++++++++++++++----------- mono/mini/driver.c | 11 ++++++++ mono/mini/mini-runtime.c | 1 + mono/mini/mini.h | 1 + 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/man/mono.1 b/man/mono.1 index 08a93ac9182..bea38842eb3 100644 --- a/man/mono.1 +++ b/man/mono.1 @@ -257,6 +257,9 @@ The default files are /etc/mono/config and ~/.mono/config or the file specified in the MONO_CONFIG environment variable, if set. See the mono-config(5) man page for details on the format of this file. .TP +\fB--aot-path=PATH\fR +List of additional directories to search for AOT images. +.TP \fB--debugger-agent=[options]\fR This instructs the Mono runtime to start a debugging agent inside the Mono runtime and connect it to a diff --git a/mono/mini/aot-runtime.c b/mono/mini/aot-runtime.c index 23a3357d335..bdb67524c78 100644 --- a/mono/mini/aot-runtime.c +++ b/mono/mini/aot-runtime.c @@ -1918,7 +1918,7 @@ init_amodule_got (MonoAotModule *amodule) static void load_aot_module (MonoAssembly *assembly, gpointer user_data) { - char *aot_name; + char *aot_name, *found_aot_name; MonoAotModule *amodule; MonoDl *sofile; gboolean usable = TRUE; @@ -1953,6 +1953,8 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data) sofile = NULL; + found_aot_name = NULL; + if (info) { /* Statically linked AOT module */ aot_name = g_strdup_printf ("%s", assembly->aname.name); @@ -1962,34 +1964,59 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data) g_assert (globals); } } else { + char *err; + if (enable_aot_cache) sofile = aot_cache_load_module (assembly, &aot_name); if (!sofile) { - char *err; aot_name = g_strdup_printf ("%s%s", assembly->image->name, MONO_SOLIB_EXT); sofile = mono_dl_open (aot_name, MONO_DL_LAZY, &err); - + if (sofile) { + found_aot_name = g_strdup (aot_name); + } else { + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: image '%s' not found: %s", aot_name, err); + g_free (err); + } + g_free (aot_name); + } + if (!sofile) { + char *basename = g_path_get_basename (assembly->image->name); + aot_name = g_strdup_printf ("%s/mono/aot-cache/%s/%s%s", mono_assembly_getrootdir(), MONO_ARCHITECTURE, basename, MONO_SOLIB_EXT); + g_free (basename); + sofile = mono_dl_open (aot_name, MONO_DL_LAZY, &err); if (!sofile) { - mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module '%s' not found: %s", aot_name, err); + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: image '%s' not found: %s", aot_name, err); g_free (err); + } + } + if (!sofile) { + GList *l; + + for (l = mono_aot_paths; l; l = l->next) { + char *path = l->data; - g_free (aot_name); char *basename = g_path_get_basename (assembly->image->name); - aot_name = g_strdup_printf ("%s/mono/aot-cache/%s/%s%s", mono_assembly_getrootdir(), MONO_ARCHITECTURE, basename, MONO_SOLIB_EXT); - g_free (basename); + aot_name = g_strdup_printf ("%s/%s%s", path, basename, MONO_SOLIB_EXT); sofile = mono_dl_open (aot_name, MONO_DL_LAZY, &err); - if (!sofile) { - mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module '%s' not found: %s", aot_name, err); + if (sofile) { + found_aot_name = g_strdup (aot_name); + } else { + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: image '%s' not found: %s", aot_name, err); g_free (err); } - + g_free (basename); + g_free (aot_name); + if (sofile) + break; } } if (!sofile) { - if (mono_aot_only && assembly->image->tables [MONO_TABLE_METHOD].rows) + if (mono_aot_only && assembly->image->tables [MONO_TABLE_METHOD].rows) { + aot_name = g_strdup_printf ("%s%s", assembly->image->name, MONO_SOLIB_EXT); g_error ("Failed to load AOT module '%s' in aot-only mode.\n", aot_name); - g_free (aot_name); + g_free (aot_name); + } return; } } @@ -2272,10 +2299,11 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data) if (amodule->out_of_date) { mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: Module %s is unusable because a dependency is out-of-date.", assembly->image->name); if (mono_aot_only) - g_error ("Failed to load AOT module '%s' while running in aot-only mode because a dependency cannot be found or it is out of date.\n", aot_name); + g_error ("Failed to load AOT module '%s' while running in aot-only mode because a dependency cannot be found or it is out of date.\n", found_aot_name); + } else { + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: image '%s' found.", found_aot_name); } - else - mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: loaded AOT Module for %s.", assembly->image->name); + g_free (found_aot_name); } /* diff --git a/mono/mini/driver.c b/mono/mini/driver.c index 7d0716dad90..02c2ca86816 100644 --- a/mono/mini/driver.c +++ b/mono/mini/driver.c @@ -1276,6 +1276,7 @@ mini_usage (void) " --mixed-mode Enable mixed-mode image support.\n" #endif " --handlers Install custom handlers, use --help-handlers for details.\n" + " --aot-path=PATH List of additional directories to search for AOT images.\n" ); } @@ -1779,6 +1780,16 @@ mono_main (int argc, char* argv[]) mono_compile_aot = TRUE; aot_options = &argv [i][6]; #endif + } else if (strncmp (argv [i], "--aot-path=", 11) == 0) { + char **splitted; + + splitted = g_strsplit (argv [i] + 11, G_SEARCHPATH_SEPARATOR_S, 1000); + while (*splitted) { + char *tmp = *splitted; + mono_aot_paths = g_list_append (mono_aot_paths, g_strdup (tmp)); + g_free (tmp); + splitted++; + } } else if (strncmp (argv [i], "--compile-all=", 14) == 0) { action = DO_COMPILE; recompilation_times = atoi (argv [i] + 14); diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c index edc8feb4982..98cd4f6cbea 100644 --- a/mono/mini/mini-runtime.c +++ b/mono/mini/mini-runtime.c @@ -121,6 +121,7 @@ MonoDebugOptions debug_options; #ifdef VALGRIND_JIT_REGISTER_MAP int valgrind_register; #endif +GList* mono_aot_paths; static GSList *tramp_infos; diff --git a/mono/mini/mini.h b/mono/mini/mini.h index 113b3c50a48..643d6c748d2 100644 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -570,6 +570,7 @@ extern GHashTable *mono_single_method_hash; extern gboolean mono_using_xdebug; extern int mini_verbose; extern int valgrind_register; +extern GList* mono_aot_paths; #define INS_INFO(opcode) (&ins_info [((opcode) - OP_START - 1) * 4]) -- 2.25.1