Просмотр исходного кода

Specify wasm features supported by feature_flags (#2302)

Huang Qi 2 лет назад
Родитель
Сommit
6e76300d2f

+ 60 - 2
core/iwasm/aot/aot_loader.c

@@ -460,6 +460,61 @@ check_machine_info(AOTTargetInfo *target_info, char *error_buf,
     return true;
 }
 
+static bool
+check_feature_flags(char *error_buf, uint32 error_buf_size,
+                    uint64 feature_flags)
+{
+#if WASM_ENABLE_SIMD == 0
+    if (feature_flags & WASM_FEATURE_SIMD_128BIT) {
+        set_error_buf(error_buf, error_buf_size,
+                      "SIMD is not enabled in this build");
+        return false;
+    }
+#endif
+
+#if WASM_ENABLE_BULK_MEMORY == 0
+    if (feature_flags & WASM_FEATURE_BULK_MEMORY) {
+        set_error_buf(error_buf, error_buf_size,
+                      "bulk memory is not enabled in this build");
+        return false;
+    }
+#endif
+
+#if WASM_ENABLE_THREAD_MGR == 0
+    if (feature_flags & WASM_FEATURE_THREADS) {
+        set_error_buf(error_buf, error_buf_size,
+                      "thread is not enabled in this build");
+        return false;
+    }
+#endif
+
+#if WASM_ENABLE_REF_TYPES == 0
+    if (feature_flags & WASM_FEATURE_REF_TYPES) {
+        set_error_buf(error_buf, error_buf_size,
+                      "reference types is not enabled in this build");
+        return false;
+    }
+#endif
+
+#if WASM_ENABLE_TAIL_CALL == 0
+    if (feature_flags & WASM_FEATURE_TAIL_CALL) {
+        set_error_buf(error_buf, error_buf_size,
+                      "tail call is not enabled in this build");
+        return false;
+    }
+#endif
+
+#if WASM_ENABLE_GC == 0
+    if (feature_flags & WASM_FEATURE_GARBAGE_COLLECTION) {
+        set_error_buf(error_buf, error_buf_size,
+                      "garbage collection is not enabled in this build");
+        return false;
+    }
+#endif
+
+    return true;
+}
+
 static bool
 load_target_info_section(const uint8 *buf, const uint8 *buf_end,
                          AOTModule *module, char *error_buf,
@@ -475,7 +530,8 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
     read_uint16(p, p_end, target_info.e_machine);
     read_uint32(p, p_end, target_info.e_version);
     read_uint32(p, p_end, target_info.e_flags);
-    read_uint32(p, p_end, target_info.reserved);
+    read_uint64(p, p_end, target_info.feature_flags);
+    read_uint64(p, p_end, target_info.reserved);
     read_byte_array(p, p_end, target_info.arch, sizeof(target_info.arch));
 
     if (p != buf_end) {
@@ -522,7 +578,9 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
         return false;
     }
 
-    return true;
+    /* Finally, check feature flags */
+    return check_feature_flags(error_buf, error_buf_size,
+                               target_info.feature_flags);
 fail:
     return false;
 }

+ 17 - 1
core/iwasm/aot/aot_runtime.h

@@ -22,6 +22,20 @@
 extern "C" {
 #endif
 
+/* Wasm feature supported, mainly used by AOTTargetInfo now */
+#define WASM_FEATURE_SIMD_128BIT (1 << 0)
+#define WASM_FEATURE_BULK_MEMORY (1 << 1)
+#define WASM_FEATURE_THREADS (1 << 2)
+#define WASM_FEATURE_REF_TYPES (1 << 3)
+#define WASM_FEATURE_TAIL_CALL (1 << 4)
+#define WASM_FEATURE_EXCEPTION_HANDLING (1 << 5)
+#define WASM_FEATURE_GARBAGE_COLLECTION (1 << 6)
+#define WASM_FEATURE_COMPONENT_MODEL (1 << 7)
+#define WASM_FEATURE_MULTIPLE_MEMORY (1 << 8)
+#define WASM_FEATURE_RELAXED_SIMD (1 << 9)
+#define WASM_FEATURE_FLEXIBLE_VECTORS (1 << 10)
+#define WASM_FEATURE_STRING_REF (1 << 11)
+
 typedef enum AOTSectionType {
     AOT_SECTION_TYPE_TARGET_INFO = 0,
     AOT_SECTION_TYPE_INIT_DATA = 1,
@@ -298,8 +312,10 @@ typedef struct AOTTargetInfo {
     uint32 e_version;
     /* Processor-specific flags */
     uint32 e_flags;
+    /* Specify wasm features supported */
+    uint64 feature_flags;
     /* Reserved */
-    uint32 reserved;
+    uint64 reserved;
     /* Arch name */
     char arch[16];
 } AOTTargetInfo;

+ 2 - 1
core/iwasm/compilation/aot_emit_aot_file.c

@@ -1363,7 +1363,8 @@ aot_emit_target_info_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
     EMIT_U16(target_info->e_machine);
     EMIT_U32(target_info->e_version);
     EMIT_U32(target_info->e_flags);
-    EMIT_U32(target_info->reserved);
+    EMIT_U64(target_info->feature_flags);
+    EMIT_U64(target_info->reserved);
     EMIT_BUF(target_info->arch, sizeof(target_info->arch));
 
     if (offset - *p_offset != section_size + sizeof(uint32) * 2) {