Refuse to load AOT images using unsupported SIMD instructions
authorChristopher James Halse Rogers <raof@ubuntu.com>
Mon, 11 Jun 2012 11:55:51 +0000 (21:55 +1000)
committerChristopher James Halse Rogers <raof@ubuntu.com>
Mon, 11 Jun 2012 23:38:09 +0000 (09:38 +1000)
Contributed under MIT/X11 License

12 files changed:
mono/mini/aot-compiler.c
mono/mini/aot-runtime.c
mono/mini/mini-alpha.c
mono/mini/mini-arm.c
mono/mini/mini-hppa.c
mono/mini/mini-ia64.c
mono/mini/mini-mips.c
mono/mini/mini-ppc.c
mono/mini/mini-s390.c
mono/mini/mini-s390x.c
mono/mini/mini-sparc.c
mono/mini/mini.h

index 2d3e9663279fb778e0d854ac45e5eaa2b5ab9c7c..7717f8cd86186802976256fabc216ca03e31749b 100644 (file)
@@ -184,6 +184,7 @@ typedef struct MonoAotCompile {
        MonoAotOptions aot_opts;
        guint32 nmethods;
        guint32 opts;
+       guint32 simd_opts;
        MonoMemPool *mempool;
        MonoAotStats stats;
        int method_index;
@@ -7005,6 +7006,7 @@ emit_file_info (MonoAotCompile *acfg)
        emit_int32 (acfg, acfg->nmethods);
        emit_int32 (acfg, acfg->flags);
        emit_int32 (acfg, acfg->opts);
+       emit_int32 (acfg, acfg->simd_opts);
        emit_int32 (acfg, gc_name_offset);
 
        for (i = 0; i < MONO_AOT_TRAMP_NUM; ++i)
@@ -7373,6 +7375,8 @@ acfg_create (MonoAssembly *ass, guint32 opts)
        acfg->globals = g_ptr_array_new ();
        acfg->image = image;
        acfg->opts = opts;
+       /* TODO: Write out set of SIMD instructions used, rather than just those available */
+       acfg->simd_opts = mono_arch_cpu_enumerate_simd_versions ();
        acfg->mempool = mono_mempool_new ();
        acfg->extra_methods = g_ptr_array_new ();
        acfg->unwind_info_offsets = g_hash_table_new (NULL, NULL);
index 881922975a34a432613ea4c3488f7b38fcf17962..4a0e4b4567e80cf727f493698239dd93125a5452 100644 (file)
@@ -1365,6 +1365,11 @@ check_usable (MonoAssembly *assembly, MonoAotFileInfo *info, char **out_msg)
                usable = FALSE;
        }
 
+       if (info->simd_opts & ~mono_arch_cpu_enumerate_simd_versions ()) {
+               msg = g_strdup_printf ("compiled with unsupported SIMD extensions");
+               usable = FALSE;
+       }
+
        blob = info->blob;
 
        if (info->gc_name_index != -1) {
index 60477aaff157d5b0ac332c2c99e28fb406ca6789..18b05e07dc67def86911f1288b0e4cc89a947119 100644 (file)
@@ -3945,6 +3945,23 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
 }
 /*========================= End of Function ========================*/
 
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name         - mono_arch_cpu_enumerate_simd_versions             */
+/*                                                                  */
+/* Function     - Returns the SIMD instruction sets on this CPU     */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+/*========================= End of Function ========================*/
+
+
+
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name         -  mono_arch_flush_icache                           */
index 306461f5df12d9312d043e619f117bcef8b1b69e..d78bd911bd2080dbfbb4c48eb250be66e413c72f 100644 (file)
@@ -754,6 +754,20 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        return opts;
 }
 
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+
+
 #ifndef DISABLE_JIT
 
 static gboolean
index 23d801b040a3d6f8d08b1441da2d75cb6062728e..3f72c551723e9ab3dfcd7fb2f7c9e2d65b7ee3e6 100644 (file)
@@ -191,6 +191,19 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        return opts;
 }
 
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+
 void
 mono_arch_flush_icache (guint8 *code, gint size)
 {
index 13446a300c48764262cf41cc9927e8da2e793b3a..87c474f2e474275b7f36e8f2e7be14e6833da3ed 100644 (file)
@@ -632,6 +632,19 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        return 0;
 }
 
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+
 GList *
 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
 {
index bd9785814a812a732dbb80586f4ae4e2d962b803..d9a05f2620bab8a7c9b33c9933144f17b252351c 100644 (file)
@@ -725,6 +725,19 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        return opts;
 }
 
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+
 GList *
 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
 {
index 6b43a9c5bf310ddfe954c77bcf0bc3bd356e04a4..53b860e96a03b16d7a5118d6ea9f35dd98d40e56 100644 (file)
@@ -668,6 +668,19 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        return opts;
 }
 
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+
 #ifdef __mono_ppc64__
 #define CASE_PPC32(c)
 #define CASE_PPC64(c)  case c:
index 9eb27359d645da6637db4489f2f3b61e0a449ebb..c5fb2015b432accf6c88987f7def2f0a33d1f0bd 100644 (file)
@@ -1097,6 +1097,21 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
 
 /*========================= End of Function ========================*/
 
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name         - mono_arch_cpu_enumerate_simd_versions             */
+/*                                                                  */
+/* Function     - Returns the SIMD instruction sets on this CPU     */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+/*========================= End of Function ========================*/
+
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                -                                                   */
index 70209d4ab990312dc36091c8ece5f51f60f53202..e309a2c7ae0c9f441731cb7a7db53d54414f0655 100644 (file)
@@ -1376,6 +1376,21 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
 
 /*========================= End of Function ========================*/
 
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name         - mono_arch_cpu_enumerate_simd_versions             */
+/*                                                                  */
+/* Function     - Returns the SIMD instruction sets on this CPU     */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+/*========================= End of Function ========================*/
+
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                -                                                   */
index 62bcaca5c93a98e8fbc1415182063b6262482db8..d8390f57243a0324b77590db2b26a9216dfaadf2 100644 (file)
@@ -264,6 +264,19 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        return opts;
 }
 
+/*
+ * This function test for all SIMD functions supported.
+ *
+ * Returns a bitmask corresponding to all supported versions.
+ *
+ */
+guint32
+mono_arch_cpu_enumerate_simd_versions (void)
+{
+       /* SIMD is currently unimplemented */
+       return 0;
+}
+
 #ifdef __GNUC__
 #define flushi(addr)    __asm__ __volatile__ ("iflush %0"::"r"(addr):"memory")
 #else /* assume Sun's compiler */
index 084683c129bd1b9394f6778effabe8c829e98bf8..d6ac333cefe51e775c0b3576d8785302dcc2fe61 100644 (file)
 #endif
 
 /* Version number of the AOT file format */
-#define MONO_AOT_FILE_VERSION 82
+#define MONO_AOT_FILE_VERSION 83
 
 //TODO: This is x86/amd64 specific.
 #define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))
@@ -242,6 +242,8 @@ typedef struct MonoAotFileInfo
        guint32 flags;
        /* Optimization flags used to compile the module */
        guint32 opts;
+       /* SIMD flags used to compile the module */
+       guint32 simd_opts;
        /* Index of the blob entry holding the GC used by this module */
        gint32 gc_name_index;