Skip to content

Commit

Permalink
[mono][aot] Collect command line arguments and pass them to the aot c…
Browse files Browse the repository at this point in the history
…ompiler.
  • Loading branch information
vargaz committed Feb 21, 2024
1 parent 7403a06 commit 13c05e9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ typedef struct MonoAotOptions {
char *clangxx;
char *depfile;
char *runtime_init_callback;
GPtrArray *runtime_args;
const char *aot_options;
} MonoAotOptions;

typedef enum {
Expand Down Expand Up @@ -15528,13 +15530,15 @@ emit_aot_image (MonoAotCompile *acfg)
}

int
mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opts, const char *aot_options)
mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opts, GPtrArray *runtime_args, const char *aot_options)
{
int res = 0;
MonoAotOptions aot_opts;

init_options (&aot_opts);
mono_aot_parse_options (aot_options, &aot_opts);
aot_opts.runtime_args = runtime_args;
aot_opts.aot_options = aot_options;
if (aot_opts.direct_extern_calls && !(aot_opts.llvm && aot_opts.static_link)) {
fprintf (stderr, "The 'direct-extern-calls' option requires the 'llvm' and 'static' options.\n");
res = 1;
Expand Down Expand Up @@ -15636,7 +15640,7 @@ mono_aot_get_method_index (MonoMethod *method)
}

int
mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 opts, const char *aot_options)
mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opts, GPtrArray *runtime_args, const char *aot_options)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "mini.h"

int mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 opts, const char *aot_options);
int mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 opts, GPtrArray *runtime_args, const char *aot_options);
void* mono_aot_readonly_field_override (MonoClassField *field);
gboolean mono_aot_direct_icalls_enabled_for_method (MonoCompile *cfg, MonoMethod *method);
gboolean mono_aot_is_shared_got_offset (int offset);
Expand Down
15 changes: 11 additions & 4 deletions src/mono/mono/mini/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ typedef struct
char **argv;
guint32 opts;
char *aot_options;
GPtrArray *runtime_args;
} MainThreadArgs;

static void
Expand Down Expand Up @@ -1421,7 +1422,7 @@ main_thread_handler (gpointer user_data)
assemblies [i] = assembly;
}

res = mono_aot_assemblies (assemblies, main_args->argc, main_args->opts, main_args->aot_options);
res = mono_aot_assemblies (assemblies, main_args->argc, main_args->opts, main_args->runtime_args, main_args->aot_options);
if (res)
exit (1);
return;
Expand Down Expand Up @@ -1767,7 +1768,7 @@ mono_jit_parse_options (int argc, char * argv[])
memcpy (copy_argv, argv, sizeof (char*) * argc);
argv = copy_argv;

mono_options_parse_options ((const char**)argv, argc, &argc, error);
mono_options_parse_options ((const char**)argv, argc, &argc, NULL, error);
if (!is_ok (error)) {
g_printerr ("%s", mono_error_get_message (error));
mono_error_cleanup (error);
Expand Down Expand Up @@ -2067,6 +2068,7 @@ mono_main (int argc, char* argv[])
GPtrArray *agents = NULL;
char *extra_bindings_config_file = NULL;
GList *paths = NULL;
GPtrArray *args;
#ifdef MONO_JIT_INFO_TABLE_TEST
int test_jit_info_table = FALSE;
#endif
Expand Down Expand Up @@ -2095,17 +2097,21 @@ mono_main (int argc, char* argv[])

enable_debugging = TRUE;

mono_options_parse_options ((const char**)argv + 1, argc - 1, &argc, error);
args = g_ptr_array_new ();

mono_options_parse_options ((const char**)argv + 1, argc - 1, &argc, args, error);
argc ++;
if (!is_ok (error)) {
g_printerr ("%s", mono_error_get_message (error));
mono_error_cleanup (error);
return 1;
}

g_ptr_array_add (args, argv [0]);
for (i = 1; i < argc; ++i) {
if (argv [i] [0] != '-')
break;
g_ptr_array_add (args, argv [i]);
if (strcmp (argv [i], "--regression") == 0) {
action = DO_REGRESSION;
} else if (strncmp (argv [i], "--single-method=", 16) == 0) {
Expand Down Expand Up @@ -2464,7 +2470,7 @@ mono_main (int argc, char* argv[])

/* Parse newly added options */
int n = argc;
mono_options_parse_options ((const char**)(argv + orig_argc), argc - orig_argc, &n, error);
mono_options_parse_options ((const char**)(argv + orig_argc), argc - orig_argc, &n, args, error);
if (!is_ok (error)) {
g_printerr ("%s", mono_error_get_message (error));
mono_error_cleanup (error);
Expand Down Expand Up @@ -2649,6 +2655,7 @@ mono_main (int argc, char* argv[])
main_args.argv = argv + i;
main_args.opts = opt;
main_args.aot_options = aot_options;
main_args.runtime_args = args;
main_thread_handler (&main_args);
mono_thread_manage_internal ();

Expand Down
11 changes: 10 additions & 1 deletion src/mono/mono/utils/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ get_option_hash (void)
* Set options based on the command line arguments in ARGV/ARGC.
* Remove processed arguments from ARGV and set *OUT_ARGC to the
* number of remaining arguments.
* If PROCESSED is != NULL, add the processed arguments to it.
*
* NOTE: This only sets the variables, the caller might need to do
* additional processing based on the new values of the variables.
*/
void
mono_options_parse_options (const char **argv, int argc, int *out_argc, MonoError *error)
mono_options_parse_options (const char **argv, int argc, int *out_argc, GPtrArray *processed, MonoError *error)
{
int aindex = 0;
GHashTable *option_hash = NULL;
Expand Down Expand Up @@ -187,6 +188,8 @@ mono_options_parse_options (const char **argv, int argc, int *out_argc, MonoErro
break;
}
*(gboolean*)option->addr = negate ? FALSE : TRUE;
if (processed)
g_ptr_array_add (processed, (gpointer)argv [aindex]);
argv [aindex] = NULL;
break;
}
Expand All @@ -202,12 +205,18 @@ mono_options_parse_options (const char **argv, int argc, int *out_argc, MonoErro
break;
}
value = argv [aindex + 1];
if (processed) {
g_ptr_array_add (processed, (gpointer)argv [aindex]);
g_ptr_array_add (processed, (gpointer)argv [aindex + 1]);
}
argv [aindex] = NULL;
argv [aindex + 1] = NULL;
aindex ++;
} else if (equals_sign_index != -1) {
// option=value
value = arg + equals_sign_index + 1;
if (processed)
g_ptr_array_add (processed, (gpointer)argv [aindex]);
argv [aindex] = NULL;
} else {
g_assert_not_reached ();
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/utils/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern int mono_options_version;

void mono_options_print_usage (void);

void mono_options_parse_options (const char **args, int argc, int *out_argc, MonoError *error);
void mono_options_parse_options (const char **args, int argc, int *out_argc, GPtrArray *processed, MonoError *error);

/* returns a json blob representing the current values of all options */
char * mono_options_get_as_json (void);
Expand Down

0 comments on commit 13c05e9

Please sign in to comment.