From dd130fec927bb7860f642ed4d8e232b4cfaa521a Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 25 Sep 2020 00:59:12 -0700 Subject: [PATCH] base: When creating an ELF file memory image, ignore empty segments. Sometimes ELF files have segments in them which are marked as loadable, but which actually have zero size in memory. When setting up a memory image we should drop those to avoid confusing other code which tries to find the footprint of a memory image. No part of these segments, including their starting address or ending address, need to actually land on top of memory since they don't actually contain any data. Change-Id: If8b61d10db139e0f688b6ceabcb8e6a898557469 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35156 Reviewed-by: Giacomo Travaglini Reviewed-by: Jason Lowe-Power Maintainer: Gabe Black Tested-by: kokoro --- src/base/loader/elf_object.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc index 49fbd6dd7..3fce7daa0 100644 --- a/src/base/loader/elf_object.cc +++ b/src/base/loader/elf_object.cc @@ -328,6 +328,11 @@ ElfObject::handleLoadableSegment(GElf_Phdr phdr, int seg_num) { auto name = std::to_string(seg_num); + if (phdr.p_memsz == 0) { + warn("Ignoring empty loadable segment %s", name); + return; + } + image.addSegment({ name, phdr.p_paddr, imageData, phdr.p_offset, phdr.p_filesz }); Addr uninitialized = phdr.p_memsz - phdr.p_filesz; -- 2.30.2