From b522968b1ecbc5c000c2498d4ff8e796f5e3ab42 Mon Sep 17 00:00:00 2001 From: Florian Zaruba Date: Wed, 13 Nov 2024 13:25:39 +0000 Subject: [PATCH] fix(mem): Fix elf loading byte counting --- src/test/csrc/common/elfloader.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/csrc/common/elfloader.cpp b/src/test/csrc/common/elfloader.cpp index 62bd102f4..bfaae710f 100644 --- a/src/test/csrc/common/elfloader.cpp +++ b/src/test/csrc/common/elfloader.cpp @@ -120,5 +120,8 @@ long readFromElf(void *ptr, const char *file_name, long buf_size) { std::memcpy((uint8_t *)ptr + offset, section.data_src, section.data_len); len_written += len; } - return len_written; + // Since we are unpacking the sections, the total amount of bytes is the last + // section offset plus its size. + auto last_section = elf_file.sections.back(); + return last_section.data_dst - base_addr + last_section.data_len + last_section.zero_len; }