base: When creating an ELF file memory image, ignore empty segments.
authorGabe Black <gabeblack@google.com>
Fri, 25 Sep 2020 07:59:12 +0000 (00:59 -0700)
committerGabe Black <gabeblack@google.com>
Fri, 25 Sep 2020 23:50:59 +0000 (23:50 +0000)
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 <giacomo.travaglini@arm.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/loader/elf_object.cc

index 49fbd6dd7b0195981a54b6c3eeb36c0003ec5b22..3fce7daa0e59b1f8e606050e643bda6943c9f86e 100644 (file)
@@ -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;