Test case for bug#325444.
[mono.git] / mono / mini / aot-runtime.c
index beb08db57550c720bfccec833df038f1d8034c87..6da4f6e00f4e1c85c51a40cec484839c6ab2d9a2 100644 (file)
@@ -10,7 +10,9 @@
 
 #include "config.h"
 #include <sys/types.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <string.h>
 #ifndef PLATFORM_WIN32
@@ -44,6 +46,7 @@
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/marshal.h>
+#include <mono/metadata/gc-internal.h>
 #include <mono/utils/mono-logger.h>
 #include "mono/utils/mono-compiler.h"
 
@@ -235,9 +238,12 @@ decode_klass_info (MonoAotModule *module, guint8 *buf, guint8 **endbuf)
        image = load_image (module, image_index);
        if (!image)
                return NULL;
-       if (mono_metadata_token_code (token) == 0) {
+       if (mono_metadata_token_table (token) == 0) {
                klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF + token);
+       } else if (mono_metadata_token_table (token) == MONO_TABLE_TYPESPEC) {
+               klass = mono_class_get (image, token);
        } else {
+               g_assert (mono_metadata_token_table (token) == MONO_TABLE_TYPEDEF);
                token = MONO_TOKEN_TYPE_DEF + decode_value (buf, &buf);
                rank = decode_value (buf, &buf);
                if (token == MONO_TOKEN_TYPE_DEF) {
@@ -289,6 +295,12 @@ decode_method_ref (MonoAotModule *module, guint32 *token, guint8 *buf, guint8 **
        image_index = value >> 24;
        *token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
 
+       if (image_index == 255) {
+               /* Methodspec */
+               image_index = decode_value (buf, &buf);
+               *token = decode_value (buf, &buf);
+       }
+
        image = load_image (module, image_index);
        if (!image)
                return NULL;
@@ -456,6 +468,7 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
        gpointer *got_addr = NULL;
        gpointer *got = NULL;
        guint32 *got_size_ptr = NULL;
+       int i;
 
        if (mono_compile_aot)
                return;
@@ -623,7 +636,19 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
 
        mono_jit_info_add_aot_module (assembly->image, info->code, info->code_end);
 
-       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT loaded AOT Module for %s.\n", assembly->image->name);
+       /*
+        * Since we store methoddef and classdef tokens when referring to methods/classes in
+        * 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.
+        */
+       for (i = 0; i < info->image_table_len; ++i)
+               load_image (info, i);
+
+       if (info->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);
+       else
+               mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT loaded AOT Module for %s.\n", assembly->image->name);
 }
 
 void
@@ -646,6 +671,9 @@ decode_cached_class_info (MonoAotModule *module, MonoCachedClassInfo *info, guin
        guint32 flags;
 
        info->vtable_size = decode_value (buf, &buf);
+       if (info->vtable_size == -1)
+               /* Generic type */
+               return FALSE;
        flags = decode_value (buf, &buf);
        info->ghcimpl = (flags >> 0) & 0x1;
        info->has_finalize = (flags >> 1) & 0x1;
@@ -1083,18 +1111,14 @@ decode_patch_info (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji,
        case MONO_PATCH_INFO_METHOD:
        case MONO_PATCH_INFO_METHODCONST:
        case MONO_PATCH_INFO_METHOD_JUMP: {
-               guint32 image_index, token, value;
-
-               value = decode_value (p, &p);
-               image_index = value >> 24;
-               token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
+               guint32 token;
 
-               image = load_image (aot_module, image_index);
+               image = decode_method_ref (aot_module, &token, p, &p);
                if (!image)
                        goto cleanup;
 
 #ifdef MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN
-               if (ji->type == MONO_PATCH_INFO_METHOD) {
+               if ((ji->type == MONO_PATCH_INFO_METHOD) && (mono_metadata_token_table (token) == MONO_TABLE_METHOD)) {
                        ji->data.target = mono_create_jit_trampoline_from_token (image, token);
                        ji->type = MONO_PATCH_INFO_ABS;
                }
@@ -1169,6 +1193,13 @@ decode_patch_info (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji,
                                g_assert_not_reached ();
                        break;
                }
+               case MONO_WRAPPER_ALLOC: {
+                       int atype = decode_value (p, &p);
+
+                       ji->type = MONO_PATCH_INFO_METHOD;
+                       ji->data.method = mono_gc_get_managed_allocator_by_type (atype);
+                       break;
+               }
                case MONO_WRAPPER_STELEMREF:
                        ji->type = MONO_PATCH_INFO_METHOD;
                        ji->data.method = mono_marshal_get_stelemref ();
@@ -1875,7 +1906,7 @@ mono_aot_handle_pagefault (void *ptr)
 }
 
 /*
- * aot_dyn_resolve:
+ * mono_aot_plt_resolve:
  *
  *   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.
@@ -2005,7 +2036,7 @@ mono_aot_init (void)
 {
 }
 
-MonoJitInfo*
+gpointer
 mono_aot_get_method (MonoDomain *domain, MonoMethod *method)
 {
        return NULL;
@@ -2075,4 +2106,10 @@ mono_aot_get_plt_entry (guint8 *code)
        return NULL;
 }
 
+gpointer
+mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code)
+{
+       return NULL;
+}
+
 #endif