Explorar o código

Fix align when emitting struct type (#2742)

Xu Jun %!s(int64=2) %!d(string=hai) anos
pai
achega
b4406fa8cc
Modificáronse 2 ficheiros con 5 adicións e 0 borrados
  1. 1 0
      core/iwasm/aot/aot_loader.c
  2. 4 0
      core/iwasm/compilation/aot_emit_aot_file.c

+ 1 - 0
core/iwasm/aot/aot_loader.c

@@ -1476,6 +1476,7 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
             }
 
             struct_type->total_size = offset;
+            buf = align_ptr(buf, 4);
 
             /* If ref_type_map is not empty, read ref_type_map */
             if (ref_type_map_count > 0) {

+ 4 - 0
core/iwasm/compilation/aot_emit_aot_file.c

@@ -459,6 +459,7 @@ get_struct_type_size(AOTCompContext *comp_ctx, AOTStructType *struct_type)
     size += struct_type->field_count * 2;
     /* ref_type_map_count */
     size += sizeof(struct_type->ref_type_map_count);
+    size = align_uint(size, 4);
     /* ref_type_map */
     size += struct_type->ref_type_map_count * 8;
     return size;
@@ -1796,6 +1797,9 @@ aot_emit_type_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
                     EMIT_U8(struct_type->fields[idx].field_flags);
                     EMIT_U8(struct_type->fields[idx].field_type);
                 }
+
+                offset = align_uint(offset, 4);
+
                 aot_emit_reftype_map(buf, buf_end, &offset,
                                      struct_type->ref_type_map_count,
                                      struct_type->ref_type_maps);