Răsfoiți Sursa

Fix some typos and unify the AOT file format for init data (#2915)

Unify the emitting and loading logic for table/memory/global init data.
TianlongLiang 2 ani în urmă
părinte
comite
a210b97cb5

+ 29 - 45
core/iwasm/aot/aot_loader.c

@@ -1010,6 +1010,11 @@ destroy_mem_init_data_list(AOTMemInitData **data_list, uint32 count)
     wasm_runtime_free(data_list);
 }
 
+static bool
+load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
+               InitializerExpression *expr, char *error_buf,
+               uint32 error_buf_size);
+
 static bool
 load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
                         AOTModule *module, char *error_buf,
@@ -1029,15 +1034,17 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
 
     /* Create each memory data segment */
     for (i = 0; i < module->mem_init_data_count; i++) {
-        uint32 init_expr_type, byte_count;
-        uint64 init_expr_value;
+        uint32 byte_count;
         uint32 is_passive;
         uint32 memory_index;
+        InitializerExpression init_value;
 
         read_uint32(buf, buf_end, is_passive);
         read_uint32(buf, buf_end, memory_index);
-        read_uint32(buf, buf_end, init_expr_type);
-        read_uint64(buf, buf_end, init_expr_value);
+        if (!load_init_expr(&buf, buf_end, module, &init_value, error_buf,
+                            error_buf_size)) {
+            return false;
+        }
         read_uint32(buf, buf_end, byte_count);
         size = offsetof(AOTMemInitData, bytes) + (uint64)byte_count;
         if (!(data_list[i] = loader_malloc(size, error_buf, error_buf_size))) {
@@ -1049,8 +1056,8 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
         data_list[i]->is_passive = (bool)is_passive;
         data_list[i]->memory_index = memory_index;
 #endif
-        data_list[i]->offset.init_expr_type = (uint8)init_expr_type;
-        data_list[i]->offset.u.i64 = (int64)init_expr_value;
+        data_list[i]->offset.init_expr_type = init_value.init_expr_type;
+        data_list[i]->offset.u = init_value.u;
         data_list[i]->byte_count = byte_count;
         read_byte_array(buf, buf_end, data_list[i]->bytes,
                         data_list[i]->byte_count);
@@ -1143,7 +1150,6 @@ destroy_table_init_data_list(AOTTableInitData **data_list, uint32 count)
     wasm_runtime_free(data_list);
 }
 
-#if WASM_ENABLE_GC != 0
 static bool
 load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
                InitializerExpression *expr, char *error_buf,
@@ -1151,6 +1157,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
 {
     const uint8 *buf = *p_buf;
     uint32 init_expr_type = 0;
+    uint64 *i64x2 = NULL;
     bool free_if_fail = false;
 
     buf = (uint8 *)align_ptr(buf, 4);
@@ -1169,17 +1176,21 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
             read_uint64(buf, buf_end, expr->u.i64);
             break;
         case INIT_EXPR_TYPE_V128_CONST:
-            read_byte_array(buf, buf_end, &expr->u.v128, sizeof(expr->u.v128));
+            i64x2 = (uint64 *)expr->u.v128.i64x2;
+            CHECK_BUF(buf, buf_end, sizeof(uint64) * 2);
+            wasm_runtime_read_v128(buf, &i64x2[0], &i64x2[1]);
+            buf += sizeof(uint64) * 2;
             break;
         case INIT_EXPR_TYPE_GET_GLOBAL:
             read_uint32(buf, buf_end, expr->u.global_index);
             break;
-        case INIT_EXPR_TYPE_REFNULL_CONST:
-            read_uint32(buf, buf_end, expr->u.type_index);
-            break;
+#if WASM_ENABLE_GC != 0 || WASM_ENABLE_REF_TYPES != 0
         case INIT_EXPR_TYPE_FUNCREF_CONST:
+        case INIT_EXPR_TYPE_REFNULL_CONST:
             read_uint32(buf, buf_end, expr->u.ref_index);
             break;
+#endif /* end of WASM_ENABLE_GC != 0 || WASM_ENABLE_REF_TYPES != 0 */
+#if WASM_ENABLE_GC != 0
         case INIT_EXPR_TYPE_I31_NEW:
             read_uint32(buf, buf_end, expr->u.i32);
             break;
@@ -1301,6 +1312,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
             }
             break;
         }
+#endif /* end of WASM_ENABLE_GC != 0 */
         default:
             set_error_buf(error_buf, error_buf_size, "invalid init expr type.");
             return false;
@@ -1311,12 +1323,15 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
     *p_buf = buf;
     return true;
 fail:
+#if WASM_ENABLE_GC != 0
     if (free_if_fail) {
         wasm_runtime_free(expr->u.data);
     }
+#else
+    (void)free_if_fail;
+#endif
     return false;
 }
-#endif /* end of WASM_ENABLE_GC != 0 */
 
 static bool
 load_import_table_list(const uint8 **p_buf, const uint8 *buf_end,
@@ -1505,20 +1520,10 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
         data_list[i]->offset.u.i64 = (int64)init_expr_value;
         data_list[i]->value_count = value_count;
         for (j = 0; j < data_list[i]->value_count; j++) {
-#if WASM_ENABLE_GC != 0
             if (!load_init_expr(&buf, buf_end, module,
                                 &data_list[i]->init_values[j], error_buf,
                                 error_buf_size))
                 return false;
-#else
-            data_list[i]->init_values[j].init_expr_type =
-                INIT_EXPR_TYPE_FUNCREF_CONST;
-#if UINTPTR_MAX == UINT64_MAX
-            read_uint64(buf, buf_end, data_list[i]->init_values[j].u.ref_index);
-#else
-            read_uint32(buf, buf_end, data_list[i]->init_values[j].u.ref_index);
-#endif
-#endif /* end of WASM_ENABLE_GC != 0 */
         }
     }
 
@@ -1947,9 +1952,6 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
 
         buf = align_ptr(buf, 4);
         read_uint16(buf, buf_end, type_flag);
-        /* Dummy read to ignore the is_sub_final and parent_type_idx */
-        read_uint16(buf, buf_end, param_count);
-        read_uint32(buf, buf_end, param_count);
         read_uint16(buf, buf_end, param_count);
         read_uint16(buf, buf_end, result_count);
 
@@ -2119,32 +2121,14 @@ load_globals(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
 
     /* Create each global */
     for (i = 0; i < module->global_count; i++) {
-#if WASM_ENABLE_GC == 0
-        uint16 init_expr_type;
-#endif
-
         read_uint8(buf, buf_end, globals[i].type);
         read_uint8(buf, buf_end, globals[i].is_mutable);
 
-#if WASM_ENABLE_GC != 0
+        buf = align_ptr(buf, 4);
+
         if (!load_init_expr(&buf, buf_end, module, &globals[i].init_expr,
                             error_buf, error_buf_size))
             return false;
-#else
-        read_uint16(buf, buf_end, init_expr_type);
-
-        if (init_expr_type != INIT_EXPR_TYPE_V128_CONST) {
-            read_uint64(buf, buf_end, globals[i].init_expr.u.i64);
-        }
-        else {
-            uint64 *i64x2 = (uint64 *)globals[i].init_expr.u.v128.i64x2;
-            CHECK_BUF(buf, buf_end, sizeof(uint64) * 2);
-            wasm_runtime_read_v128(buf, &i64x2[0], &i64x2[1]);
-            buf += sizeof(uint64) * 2;
-        }
-
-        globals[i].init_expr.init_expr_type = (uint8)init_expr_type;
-#endif /* end of WASM_ENABLE_GC != 0 */
 
         globals[i].size = wasm_value_type_size(globals[i].type);
         globals[i].data_offset = data_offset;

+ 87 - 134
core/iwasm/compilation/aot_emit_aot_file.c

@@ -205,12 +205,19 @@ get_target_info_section_size()
 }
 
 static uint32
-get_mem_init_data_size(AOTMemInitData *mem_init_data)
+get_init_expr_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data,
+                   InitializerExpression *expr);
+
+static uint32
+get_mem_init_data_size(AOTCompContext *comp_ctx, AOTMemInitData *mem_init_data)
 {
-    /* init expr type (4 bytes) + init expr value (8 bytes)
-       + byte count (4 bytes) + bytes */
-    uint32 total_size = (uint32)(sizeof(uint32) + sizeof(uint64)
-                                 + sizeof(uint32) + mem_init_data->byte_count);
+    /* init expr type (4 bytes)
+     * + init expr value (4 bytes, valid value can only be i32/get_global)
+     * + byte count (4 bytes) + bytes */
+    uint32 total_size =
+        (uint32)(get_init_expr_size(comp_ctx, comp_ctx->comp_data,
+                                    &mem_init_data->offset)
+                 + sizeof(uint32) + mem_init_data->byte_count);
 
     /* bulk_memory enabled:
         is_passive (4 bytes) + memory_index (4 bytes)
@@ -223,7 +230,8 @@ get_mem_init_data_size(AOTMemInitData *mem_init_data)
 }
 
 static uint32
-get_mem_init_data_list_size(AOTMemInitData **mem_init_data_list,
+get_mem_init_data_list_size(AOTCompContext *comp_ctx,
+                            AOTMemInitData **mem_init_data_list,
                             uint32 mem_init_data_count)
 {
     AOTMemInitData **mem_init_data = mem_init_data_list;
@@ -231,7 +239,7 @@ get_mem_init_data_list_size(AOTMemInitData **mem_init_data_list,
 
     for (i = 0; i < mem_init_data_count; i++, mem_init_data++) {
         size = align_uint(size, 4);
-        size += get_mem_init_data_size(*mem_init_data);
+        size += get_mem_init_data_size(comp_ctx, *mem_init_data);
     }
     return size;
 }
@@ -253,17 +261,17 @@ get_memory_size(AOTCompData *comp_data)
 }
 
 static uint32
-get_mem_info_size(AOTCompData *comp_data)
+get_mem_info_size(AOTCompContext *comp_ctx, AOTCompData *comp_data)
 {
     /* import_memory_size + memory_size
        + init_data_count + init_data_list */
     return get_import_memory_size(comp_data) + get_memory_size(comp_data)
            + (uint32)sizeof(uint32)
-           + get_mem_init_data_list_size(comp_data->mem_init_data_list,
+           + get_mem_init_data_list_size(comp_ctx,
+                                         comp_data->mem_init_data_list,
                                          comp_data->mem_init_data_count);
 }
 
-#if WASM_ENABLE_GC != 0
 static uint32
 get_init_expr_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data,
                    InitializerExpression *expr)
@@ -280,8 +288,6 @@ get_init_expr_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data,
         case INIT_EXPR_TYPE_I32_CONST:
         case INIT_EXPR_TYPE_F32_CONST:
         case INIT_EXPR_TYPE_GET_GLOBAL:
-        case INIT_EXPR_TYPE_FUNCREF_CONST:
-        case INIT_EXPR_TYPE_I31_NEW:
             size += sizeof(uint32);
             break;
         case INIT_EXPR_TYPE_I64_CONST:
@@ -291,8 +297,14 @@ get_init_expr_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data,
         case INIT_EXPR_TYPE_V128_CONST:
             size += sizeof(uint64) * 2;
             break;
+        case INIT_EXPR_TYPE_FUNCREF_CONST:
         case INIT_EXPR_TYPE_REFNULL_CONST:
-            /* type_index */
+            /* ref_index */
+            size += sizeof(uint32);
+            break;
+#if WASM_ENABLE_GC != 0
+        case INIT_EXPR_TYPE_I31_NEW:
+            /* i32 */
             size += sizeof(uint32);
             break;
         case INIT_EXPR_TYPE_STRUCT_NEW:
@@ -350,56 +362,40 @@ get_init_expr_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data,
                               array_type->elem_type, comp_ctx->pointer_size);
             break;
         }
+#endif /* end of WASM_ENABLE_GC != 0 */
         default:
             bh_assert(0);
     }
 
     return size;
 }
-#endif /* end of WASM_ENABLE_GC != 0 */
 
 static uint32
 get_table_init_data_size(AOTCompContext *comp_ctx,
                          AOTTableInitData *table_init_data)
 {
-#if WASM_ENABLE_GC != 0
-    if (comp_ctx->enable_gc) {
-        uint32 size, i;
+    uint32 size, i;
 
-        /*
-         * mode (4 bytes), elem_type (4 bytes)
-         *
-         * table_index(4 bytes) + init expr type (4 bytes) + init expr value (8
-         * bytes) + sizeof(WASMRefType)
-         * + value count (4 bytes) + init_values
-         */
-        size = (uint32)(sizeof(uint32) * 2 + sizeof(uint32) + sizeof(uint32)
-                        + sizeof(uint64) + sizeof(uint32))
-               /* Size of WasmRefType - inner padding (ref type + nullable +
-                  heap_type) */
-               + 8;
-
-        for (i = 0; i < table_init_data->value_count; i++) {
-            size += get_init_expr_size(comp_ctx, comp_ctx->comp_data,
-                                       &table_init_data->init_values[i]);
-        }
-
-        return size;
-    }
-#endif
     /*
      * mode (4 bytes), elem_type (4 bytes)
      *
      * table_index(4 bytes) + init expr type (4 bytes) + init expr value (8
-     * bytes) + sizeof(WASMRefType)
-     * + func index count (4 bytes) + func indexes
+     * bytes)
      */
-    return (uint32)(sizeof(uint32) * 2 + sizeof(uint32) + sizeof(uint32)
-                    + sizeof(uint64) + sizeof(uint32)
-                    + comp_ctx->pointer_size * table_init_data->value_count)
+    size = (uint32)(sizeof(uint32) * 2 + sizeof(uint32) + sizeof(uint32)
+                    + sizeof(uint64))
            /* Size of WasmRefType - inner padding (ref type + nullable +
               heap_type) */
            + 8;
+
+    /* + value count/func index count (4 bytes) + init_values */
+    size += sizeof(uint32);
+    for (i = 0; i < table_init_data->value_count; i++) {
+        size += get_init_expr_size(comp_ctx, comp_ctx->comp_data,
+                                   &table_init_data->init_values[i]);
+    }
+
+    return size;
 }
 
 static uint32
@@ -423,6 +419,7 @@ get_table_init_data_list_size(AOTCompContext *comp_ctx,
     AOTTableInitData **table_init_data = table_init_data_list;
     uint32 size = 0, i;
 
+    /* table_init_data_count(4 bytes) */
     size = (uint32)sizeof(uint32);
 
     for (i = 0; i < table_init_data_count; i++, table_init_data++) {
@@ -440,13 +437,13 @@ get_import_table_size(const AOTCompContext *comp_ctx,
      * ------------------------------
      * | import_table_count
      * ------------------------------
-     * |                  | U8 elem_type
-     * |                  | U8 table_flags
-     * |                  | U8 possible_grow
-     * | AOTImpotTable[N] | U8 elem_ref_type.nullable (for GC only)
-     * |                  | U32 table_init_size
-     * |                  | U32 table_max_size
-     * |                  | U32 elem_ref_type.heap_type (for GC only)
+     * |                   | U8 elem_type
+     * |                   | U8 table_flags
+     * |                   | U8 possible_grow
+     * | AOTImportTable[N] | U8 elem_ref_type.nullable (for GC only)
+     * |                   | U32 table_init_size
+     * |                   | U32 table_max_size
+     * |                   | U32 elem_ref_type.heap_type (for GC only)
      * ------------------------------
      */
     uint32 size = 0, i;
@@ -528,10 +525,10 @@ get_table_info_size(AOTCompContext *comp_ctx, AOTCompData *comp_data)
                                            comp_data->table_init_data_count);
 }
 
-#if WASM_ENABLE_GC != 0
 static uint32
 get_func_type_size(AOTCompContext *comp_ctx, AOTFuncType *func_type)
 {
+#if WASM_ENABLE_GC != 0
     /* type flag + is_sub_final + parent_type_idx + rec_count + rec_idx + param
      * count + result count
      * + ref_type_map_count + types + context of ref_type_map */
@@ -563,14 +560,16 @@ get_func_type_size(AOTCompContext *comp_ctx, AOTFuncType *func_type)
 
         return size;
     }
-    else {
-        /* type flag + is_sub_final + parent_type_idx + param count + result
-         * count + types */
-        return (uint32)sizeof(uint16) * 6 + func_type->param_count
+    else
+#endif
+    {
+        /* type flag + param count + result count + types */
+        return (uint32)sizeof(uint16) * 3 + func_type->param_count
                + func_type->result_count;
     }
 }
 
+#if WASM_ENABLE_GC != 0
 static uint32
 get_struct_type_size(AOTCompContext *comp_ctx, AOTStructType *struct_type)
 {
@@ -631,16 +630,6 @@ get_array_type_size(AOTCompContext *comp_ctx, AOTArrayType *array_type)
 
     return size;
 }
-
-#else
-static uint32
-get_func_type_size(AOTCompContext *comp_ctx, AOTFuncType *func_type)
-{
-    /* type flags + parent type idx + is_sub_final + param count + result count
-     * + types */
-    return (uint32)sizeof(uint16) * 6 + func_type->param_count
-           + func_type->result_count;
-}
 #endif
 
 static uint32
@@ -718,23 +707,11 @@ get_import_global_info_size(AOTCompContext *comp_ctx, AOTCompData *comp_data)
 static uint32
 get_global_size(AOTCompContext *comp_ctx, AOTGlobal *global)
 {
-#if WASM_ENABLE_GC != 0
-    if (comp_ctx->enable_gc) {
-        /* type (1 byte) + is_mutable (1 byte) + padding (2 bytes)
-                + init expr value (include init expr type) */
-        return sizeof(uint8) * 2 + sizeof(uint8) * 2
-               + get_init_expr_size(comp_ctx, comp_ctx->comp_data,
-                                    &global->init_expr);
-    }
-#endif
-    if (global->init_expr.init_expr_type != INIT_EXPR_TYPE_V128_CONST)
-        /* type (1 byte) + is_mutable (1 byte)
-        + init expr type (2 bytes) + init expr value (8 bytes) */
-        return sizeof(uint8) * 2 + sizeof(uint16) + sizeof(uint64);
-    else
-        /* type (1 byte) + is_mutable (1 byte)
-           + init expr type (2 bytes) + v128 value (16 bytes) */
-        return sizeof(uint8) * 2 + sizeof(uint16) + sizeof(uint64) * 2;
+    /* type (1 byte) + is_mutable (1 byte) + padding (2 bytes)
+            + init expr value (include init expr type) */
+    return sizeof(uint8) * 2 + sizeof(uint8) * 2
+           + get_init_expr_size(comp_ctx, comp_ctx->comp_data,
+                                &global->init_expr);
 }
 
 static uint32
@@ -829,7 +806,7 @@ get_init_data_section_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
 {
     uint32 size = 0;
 
-    size += get_mem_info_size(comp_data);
+    size += get_mem_info_size(comp_ctx, comp_data);
 
     size = align_uint(size, 4);
     size += get_table_info_size(comp_ctx, comp_data);
@@ -1745,6 +1722,10 @@ aot_emit_target_info_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
     return true;
 }
 
+static bool
+aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
+                   AOTCompContext *comp_ctx, InitializerExpression *expr);
+
 static bool
 aot_emit_mem_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
                   AOTCompContext *comp_ctx, AOTCompData *comp_data,
@@ -1787,13 +1768,14 @@ aot_emit_mem_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
             EMIT_U32(0);
             EMIT_U32(0);
         }
-        EMIT_U32(init_datas[i]->offset.init_expr_type);
-        EMIT_U64(init_datas[i]->offset.u.i64);
+        if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
+                                &init_datas[i]->offset))
+            return false;
         EMIT_U32(init_datas[i]->byte_count);
         EMIT_BUF(init_datas[i]->bytes, init_datas[i]->byte_count);
     }
 
-    if (offset - *p_offset != get_mem_info_size(comp_data)) {
+    if (offset - *p_offset != get_mem_info_size(comp_ctx, comp_data)) {
         aot_set_last_error("emit memory info failed.");
         return false;
     }
@@ -1803,7 +1785,6 @@ aot_emit_mem_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
     return true;
 }
 
-#if WASM_ENABLE_GC != 0
 static bool
 aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
                    AOTCompContext *comp_ctx, InitializerExpression *expr)
@@ -1831,12 +1812,11 @@ aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
         case INIT_EXPR_TYPE_GET_GLOBAL:
             EMIT_U32(expr->u.global_index);
             break;
-        case INIT_EXPR_TYPE_REFNULL_CONST:
-            EMIT_U32(expr->u.type_index);
-            break;
         case INIT_EXPR_TYPE_FUNCREF_CONST:
+        case INIT_EXPR_TYPE_REFNULL_CONST:
             EMIT_U32(expr->u.ref_index);
             break;
+#if WASM_ENABLE_GC != 0
         case INIT_EXPR_TYPE_I31_NEW:
             EMIT_U32(expr->u.i32);
             break;
@@ -1912,6 +1892,7 @@ aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
             }
             break;
         }
+#endif /* end of WASM_ENABLE_GC != 0 */
         default:
             aot_set_last_error("invalid init expr type.");
             return false;
@@ -1920,7 +1901,6 @@ aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
     *p_offset = offset;
     return true;
 }
-#endif /* end of WASM_ENABLE_GC != 0 */
 
 static bool
 aot_emit_table_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
@@ -2026,26 +2006,9 @@ aot_emit_table_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
         }
         EMIT_U32(init_datas[i]->value_count);
         for (j = 0; j < init_datas[i]->value_count; j++) {
-#if WASM_ENABLE_GC != 0
-            if (comp_ctx->enable_gc) {
-                if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
-                                        &init_datas[i]->init_values[j]))
-                    return false;
-            }
-            else
-#endif
-            {
-                bh_assert(init_datas[i]->init_values[j].init_expr_type
-                              == INIT_EXPR_TYPE_REFNULL_CONST
-                          || init_datas[i]->init_values[j].init_expr_type
-                                 == INIT_EXPR_TYPE_FUNCREF_CONST);
-                if (comp_ctx->pointer_size == 4) {
-                    EMIT_U32(init_datas[i]->init_values[j].u.ref_index);
-                }
-                else {
-                    EMIT_U64(init_datas[i]->init_values[j].u.ref_index);
-                }
-            }
+            if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
+                                    &init_datas[i]->init_values[j]))
+                return false;
         }
     }
 
@@ -2173,14 +2136,14 @@ aot_emit_type_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
 
         for (i = 0; i < comp_data->type_count; i++) {
             offset = align_uint(offset, 4);
-            /* If GC enabled, only emit function type info */
+            /* If GC is disabled, only emit function type info */
             EMIT_U16(WASM_TYPE_FUNC);
-            /* Emit dummy is_sub_final */
-            EMIT_U16(0);
-            /* Emit parent_type_index */
-            EMIT_U32(0);
+            /* Omit to emit dummy padding for is_sub_final,
+             * parent_type_index, rec_count, rec_idx, 10 bytes in total */
             EMIT_U16(func_types[i]->param_count);
             EMIT_U16(func_types[i]->result_count);
+            /* Omit to emit dummy padding for ref_type_map_count, 2 bytes in
+             * total */
             EMIT_BUF(func_types[i]->types,
                      func_types[i]->param_count + func_types[i]->result_count);
         }
@@ -2244,21 +2207,11 @@ aot_emit_global_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
         offset = align_uint(offset, 4);
         EMIT_U8(global->type);
         EMIT_U8(global->is_mutable);
-#if WASM_ENABLE_GC != 0
-        if (comp_ctx->enable_gc) {
-            if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
-                                    &global->init_expr))
-                return false;
-        }
-        else
-#endif /* end of WASM_ENABLE_GC != 0 */
-        {
-            EMIT_U16(global->init_expr.init_expr_type);
-            if (global->init_expr.init_expr_type != INIT_EXPR_TYPE_V128_CONST)
-                EMIT_U64(global->init_expr.u.i64);
-            else
-                EMIT_V128(global->init_expr.u.v128);
-        }
+
+        offset = align_uint(offset, 4);
+        if (!aot_emit_init_expr(buf, buf_end, &offset, comp_ctx,
+                                &global->init_expr))
+            return false;
     }
 
     if (offset - *p_offset != get_global_info_size(comp_ctx, comp_data)) {
@@ -3439,7 +3392,7 @@ aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
             }
             /*
              * Note: We can't always modify stack_sizes in-place.
-             * Eg. When WAMRC_LLC_COMPILER is used, LLVM sometimes uses
+             * E.g. When WAMRC_LLC_COMPILER is used, LLVM sometimes uses
              * read-only mmap of the temporary file to back
              * LLVMGetSectionContents.
              */
@@ -3737,7 +3690,7 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
             goto fail;
         }
 
-        /* parse relocation addend from reloction content */
+        /* parse relocation addend from relocation content */
         if (has_addend) {
             if (is_binary_32bit) {
                 int32 addend =
@@ -4183,7 +4136,7 @@ aot_obj_data_create(AOTCompContext *comp_ctx)
         aot_set_last_error("emit object file on Windows is unsupported.");
         goto fail;
 #else
-        /* Emit to assmelby file instead for arc target
+        /* Emit to assembly file instead for arc target
            as it cannot emit to object file */
         char file_name[] = "wasm-XXXXXX", buf[128];
         int fd, ret;

+ 5 - 0
core/iwasm/interpreter/wasm.h

@@ -208,6 +208,11 @@ typedef union WASMValue {
         uint32 type_index;
         uint32 N;
     } array_new_default;
+    /* pointer to a memory space holding more data, current usage:
+     *  struct.new init value: WASMStructNewInitValues *
+     *  array.new init value: WASMArrayNewInitValues *
+     */
+    void *data;
 #endif
 } WASMValue;
 #endif /* end of WASM_VALUE_DEFINED */

+ 15 - 0
tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch

@@ -211,6 +211,21 @@ index 1ea2b06..8eded37 100644
  (assert_return (invoke $module1 "call-8") (i32.const 69))
  (assert_return (invoke $module1 "call-9") (i32.const 70))
 +;)
+diff --git a/test/core/table.wast b/test/core/table.wast
+index 0bc43ca6..ee5209ec 100644
+--- a/test/core/table.wast
++++ b/test/core/table.wast
+@@ -8,8 +8,8 @@
+ (module (table 0 65536 funcref))
+ (module (table 0 0xffff_ffff funcref))
+ 
+-(assert_invalid (module (table 0 funcref) (table 0 funcref)) "multiple tables")
+-(assert_invalid (module (table (import "spectest" "table") 0 funcref) (table 0 funcref)) "multiple tables")
++(module (table 0 funcref) (table 0 funcref))
++(module (table (import "spectest" "table") 0 funcref) (table 0 funcref))
+ 
+ (assert_invalid (module (elem (i32.const 0))) "unknown table")
+ (assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table")
 diff --git a/test/core/thread.wast b/test/core/thread.wast
 index c3456a6..83fc281 100644
 --- a/test/core/thread.wast

+ 1 - 4
tests/wamr-test-suites/test_wamr.sh

@@ -789,6 +789,7 @@ function trigger()
     local EXTRA_COMPILE_FLAGS=""
     # default enabled features
     EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
+    EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
 
     if [[ ${ENABLE_MULTI_MODULE} == 1 ]];then
         EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=1"
@@ -798,9 +799,6 @@ function trigger()
 
     if [[ ${ENABLE_MULTI_THREAD} == 1 ]];then
         EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_PTHREAD=1"
-        EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=0"
-    else
-        EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
     fi
 
     if [[ ${ENABLE_SIMD} == 1 ]]; then
@@ -811,7 +809,6 @@ function trigger()
 
     if [[ ${ENABLE_GC} == 1 ]]; then
         EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC=1"
-        EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
         EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
         EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_TAIL_CALL=1"
     fi