Przeglądaj źródła

Fix a wrong alignment assumption when emitting aot file (#792)

The size used to apply "size = align_uint(size, 4)" may be different
when calculating total size (in get_object_data_sections_size) and
emitting actual data (in aot_emit_object_data_section_info) for the
object data section.

This patch fixes the "Error: emit object data section info failed".
YAMAMOTO Takashi 4 lat temu
rodzic
commit
68d72c300f
1 zmienionych plików z 5 dodań i 12 usunięć
  1. 5 12
      core/iwasm/compilation/aot_emit_aot_file.c

+ 5 - 12
core/iwasm/compilation/aot_emit_aot_file.c

@@ -423,17 +423,6 @@ get_import_func_info_size(AOTCompData *comp_data)
                                    comp_data->import_func_count);
 }
 
-static uint32
-get_object_data_section_size(AOTObjectDataSection *data_section)
-{
-    /* name + size + data */
-    uint32 size = get_string_size(data_section->name);
-    size = align_uint(size, 4);
-    size += (uint32)sizeof(uint32);
-    size += data_section->size;
-    return size;
-}
-
 static uint32
 get_object_data_sections_size(AOTObjectDataSection *data_sections,
                               uint32 data_sections_count)
@@ -442,8 +431,12 @@ get_object_data_sections_size(AOTObjectDataSection *data_sections,
     uint32 size = 0, i;
 
     for (i = 0; i < data_sections_count; i++, data_section++) {
+        /* name + size + data */
         size = align_uint(size, 2);
-        size += get_object_data_section_size(data_section);
+        size += get_string_size(data_section->name);
+        size = align_uint(size, 4);
+        size += (uint32)sizeof(uint32);
+        size += data_section->size;
     }
     return size;
 }