From 68d72c300ff11dd14b32f58f502e21ae13baf676 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 19 Oct 2021 18:11:24 +0900 Subject: [PATCH] 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". --- core/iwasm/compilation/aot_emit_aot_file.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_aot_file.c b/core/iwasm/compilation/aot_emit_aot_file.c index 789935d4..8e68ccae 100644 --- a/core/iwasm/compilation/aot_emit_aot_file.c +++ b/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; }