/* AOT RUNTIME */
/*****************************************************/
+/*
+ * load_image:
+ *
+ * Load one of the images referenced by AMODULE. Returns NULL if the image is not
+ * found, and sets the loader error if SET_ERROR is TRUE.
+ */
static MonoImage *
-load_image (MonoAotModule *module, int index)
+load_image (MonoAotModule *amodule, int index, gboolean set_error)
{
MonoAssembly *assembly;
MonoImageOpenStatus status;
- g_assert (index < module->image_table_len);
+ g_assert (index < amodule->image_table_len);
- if (module->image_table [index])
- return module->image_table [index];
- if (module->out_of_date)
+ if (amodule->image_table [index])
+ return amodule->image_table [index];
+ if (amodule->out_of_date)
return NULL;
- assembly = mono_assembly_load (&module->image_names [index], NULL, &status);
+ assembly = mono_assembly_load (&amodule->image_names [index], NULL, &status);
if (!assembly) {
- mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is unusable because dependency %s is not found.\n", module->aot_name, module->image_names [index].name);
- module->out_of_date = TRUE;
+ mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is unusable because dependency %s is not found.\n", amodule->aot_name, amodule->image_names [index].name);
+ amodule->out_of_date = TRUE;
+
+ if (set_error) {
+ char *full_name = mono_stringify_assembly_name (&amodule->image_names [index]);
+ mono_loader_set_error_assembly_load (full_name, FALSE);
+ g_free (full_name);
+ }
return NULL;
}
- if (strcmp (assembly->image->guid, module->image_guids [index])) {
- mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is out of date (Older than dependency %s).\n", module->aot_name, module->image_names [index].name);
- module->out_of_date = TRUE;
+ if (strcmp (assembly->image->guid, amodule->image_guids [index])) {
+ mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is out of date (Older than dependency %s).\n", amodule->aot_name, amodule->image_names [index].name);
+ amodule->out_of_date = TRUE;
return NULL;
}
- module->image_table [index] = assembly->image;
+ amodule->image_table [index] = assembly->image;
return assembly->image;
}
-
static inline gint32
decode_value (guint8 *ptr, guint8 **rptr)
{
return NULL;
}
if (mono_metadata_token_table (token) == 0) {
- image = load_image (module, decode_value (p, &p));
+ image = load_image (module, decode_value (p, &p), TRUE);
if (!image)
return NULL;
klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF + token);
g_assert_not_reached ();
}
} else {
- image = load_image (module, decode_value (p, &p));
+ image = load_image (module, decode_value (p, &p), TRUE);
if (!image)
return NULL;
klass = mono_class_get (image, token);
}
} else if (token == MONO_TOKEN_TYPE_DEF) {
/* Array */
- image = load_image (module, decode_value (p, &p));
+ image = load_image (module, decode_value (p, &p), TRUE);
if (!image)
return NULL;
rank = decode_value (p, &p);
g_assert_not_reached ();
}
g_assert (klass);
- mono_class_init (klass);
*endbuf = p;
return klass;
*method = mono_marshal_get_runtime_invoke (m, FALSE);
break;
}
+ case MONO_WRAPPER_MANAGED_TO_MANAGED: {
+ int subtype = decode_value (p, &p);
+
+ if (subtype == MONO_AOT_WRAPPER_ELEMENT_ADDR) {
+ int rank = decode_value (p, &p);
+ int elem_size = decode_value (p, &p);
+
+ *method = mono_marshal_get_array_address (rank, elem_size);
+ } else {
+ g_assert_not_reached ();
+ }
+ break;
+ }
default:
g_assert_not_reached ();
}
image_index = decode_value (p, &p);
*token = decode_value (p, &p);
- image = load_image (module, image_index);
+ image = load_image (module, image_index, TRUE);
if (!image)
return NULL;
} else if (image_index == MONO_AOT_METHODREF_GINST) {
image_index = decode_value (p, &p);
*token = decode_value (p, &p);
- image = load_image (module, image_index);
+ image = load_image (module, image_index, TRUE);
if (!image)
return NULL;
g_assert (image_index < MONO_AOT_METHODREF_MIN);
*token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
- image = load_image (module, image_index);
+ image = load_image (module, image_index, TRUE);
if (!image)
return NULL;
}
table_size = table [0];
table ++;
- hash = mono_aot_str_hash (name) % table_size;
+ hash = mono_metadata_str_hash (name) % table_size;
entry = &table [hash * 2];
* referenced assemblies, we depend on the exact versions of the referenced assemblies.
* MS calls this 'hard binding'. This means we have to load all referenced assemblies
* non-lazily, since we can't handle out-of-date errors later.
+ * The cached class info also depends on the exact assemblies.
*/
for (i = 0; i < amodule->image_table_len; ++i)
- load_image (amodule, i);
+ load_image (amodule, i, FALSE);
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.\n", assembly->image->name);
full_name = g_strdup_printf ("%s.%s", name_space, name);
}
}
- hash = mono_aot_str_hash (full_name) % table_size;
+ hash = mono_metadata_str_hash (full_name) % table_size;
if (full_name != full_name_buf)
g_free (full_name);
eh_frame = amodule->eh_frame_hdr + table [(pos * 2) + 1];
- unwind_info = mono_unwind_decode_fde (eh_frame, &unw_len, &code_len, &ei, &ei_len);
+ unwind_info = mono_unwind_decode_fde (eh_frame, &unw_len, &code_len, &ei, &ei_len, NULL);
jinfo->code_size = code_len;
jinfo->used_regs = mono_cache_unwind_info (unwind_info, unw_len);
#else
decode_eh_frame (amodule, domain, method, code, jinfo);
#endif
+ jinfo->from_llvm = 1;
} else {
jinfo->code_size = code_len;
jinfo->used_regs = used_int_regs;
goto cleanup;
break;
case MONO_PATCH_INFO_IMAGE:
- ji->data.image = load_image (aot_module, decode_value (p, &p));
+ ji->data.image = load_image (aot_module, decode_value (p, &p), TRUE);
if (!ji->data.image)
goto cleanup;
break;
break;
}
case MONO_PATCH_INFO_LDSTR:
- image = load_image (aot_module, decode_value (p, &p));
+ image = load_image (aot_module, decode_value (p, &p), TRUE);
if (!image)
goto cleanup;
ji->data.token = mono_jump_info_token_new (mp, image, MONO_TOKEN_STRING + decode_value (p, &p));
case MONO_PATCH_INFO_LDTOKEN:
case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
/* Shared */
- image = load_image (aot_module, decode_value (p, &p));
+ image = load_image (aot_module, decode_value (p, &p), TRUE);
if (!image)
goto cleanup;
ji->data.token = mono_jump_info_token_new (mp, image, decode_value (p, &p));
if (mono_jit_stats.methods_aot >= mono_last_aot_method)
return NULL;
else if (mono_jit_stats.methods_aot == mono_last_aot_method - 1) {
- if (method)
- printf ("LAST AOT METHOD: %s%s%s.%s.\n", method->klass->name_space, method->klass->name_space [0] ? "." : "", method->klass->name, method->name);
- else
+ if (!method)
+ method = mono_get_method (image, token, NULL);
+ if (method) {
+ char *name = mono_method_full_name (method, TRUE);
+ printf ("LAST AOT METHOD: %s.\n", name);
+ g_free (name);
+ } else {
printf ("LAST AOT METHOD: %p %d\n", code, method_index);
+ }
}
}
}
static guint32
-find_extra_method_in_amodule (MonoAotModule *amodule, MonoMethod *method)
+find_extra_method_in_amodule (MonoAotModule *amodule, MonoMethod *method, const char *name)
{
guint32 table_size, entry_size, hash;
guint32 *table, *entry;
- char *name = NULL;
guint32 index;
static guint32 n_extra_decodes;
table = amodule->extra_method_table + 1;
entry_size = 3;
- if (method->wrapper_type) {
- name = mono_aot_wrapper_name (method);
- }
-
hash = mono_aot_method_hash (method) % table_size;
entry = &table [hash * entry_size];
break;
}
- g_free (name);
return index;
}
guint32 index;
GPtrArray *modules;
int i;
+ char *name = NULL;
+
+ if (method->wrapper_type)
+ name = mono_aot_wrapper_name (method);
/* Try the method's module first */
*out_amodule = method->klass->image->aot_module;
- index = find_extra_method_in_amodule (method->klass->image->aot_module, method);
- if (index != 0xffffff)
+ index = find_extra_method_in_amodule (method->klass->image->aot_module, method, name);
+ if (index != 0xffffff) {
+ g_free (name);
return index;
+ }
/*
* Try all other modules.
MonoAotModule *amodule = g_ptr_array_index (modules, i);
if (amodule != method->klass->image->aot_module)
- index = find_extra_method_in_amodule (amodule, method);
+ index = find_extra_method_in_amodule (amodule, method, name);
if (index != 0xffffff) {
*out_amodule = amodule;
break;
g_ptr_array_free (modules, TRUE);
+ g_free (name);
return index;
}
code = mono_aot_get_method (domain, m);
if (code) {
- if (mono_method_needs_static_rgctx_invoke (m, FALSE))
- code = mono_create_static_rgctx_trampoline (m, code);
+ if (mono_method_needs_static_rgctx_invoke (m, FALSE)) {
+ code = mono_create_static_rgctx_trampoline (m, mono_create_ftnptr (domain, code));
+ /* The call above returns an ftnptr */
+ code = mono_get_addr_from_ftnptr (code);
+ }
return code;
}
*
* This function is called by the entries in the PLT to resolve the actual method that
* needs to be called. It returns a trampoline to the method and patches the PLT entry.
+ * Returns NULL if the something cannot be loaded.
*/
gpointer
mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code)
mp = mono_mempool_new_size (512);
res = decode_patch (module, mp, &ji, p, &p);
- // FIXME: Error handling (how ?)
- g_assert (res);
+
+ if (!res) {
+ mono_mempool_destroy (mp);
+ return NULL;
+ }
/*
* Avoid calling resolve_patch_target in the full-aot case if possible, since
if (ji.type == MONO_PATCH_INFO_ABS || ji.type == MONO_PATCH_INFO_INTERNAL_METHOD || ji.type == MONO_PATCH_INFO_CLASS_INIT || ji.type == MONO_PATCH_INFO_ICALL_ADDR || ji.type == MONO_PATCH_INFO_JIT_ICALL_ADDR || ji.type == MONO_PATCH_INFO_RGCTX_FETCH) {
/* These should already have a function descriptor */
#ifdef PPC_USES_FUNCTION_DESCRIPTOR
- g_assert (((gpointer*)target) [2] == 0);
+ /* Our function descriptors have a 0 environment, gcc created ones don't */
+ if (ji.type != MONO_PATCH_INFO_INTERNAL_METHOD && ji.type != MONO_PATCH_INFO_JIT_ICALL_ADDR && ji.type != MONO_PATCH_INFO_ICALL_ADDR)
+ g_assert (((gpointer*)target) [2] == 0);
#endif
+ /* Empty */
} else if (!no_ftnptr) {
#ifdef PPC_USES_FUNCTION_DESCRIPTOR
g_assert (((gpointer*)target) [2] != 0);
symbol = g_strdup_printf ("rgctx_fetch_trampoline_%u", slot);
code = load_function (mono_defaults.corlib->aot_module, symbol);
g_free (symbol);
- return code;
+ /* The caller expects an ftnptr */
+ return mono_create_ftnptr (mono_domain_get (), code);
}
gpointer