arch,base: Separate the idea of a memory image and object file.

A memory image can be described by an object file, but an object file
is more than a memory image. Also, it makes sense to manipulate a
memory image to, for instance, change how it's loaded into memory. That
takes on larger implications (relocations, the entry point, symbols,
etc.) when talking about the whole object file, and also modifies
aspects which may not need to change. For instance if an image needs
to be loaded into memory at addresses different from what's in the
object file, but other things like symbols need to stay unmodified.

Change-Id: Ia360405ffb2c1c48e0cc201ac0a0764357996a54
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21466
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Brandon Potter <Brandon.Potter@amd.com>
Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
Gabe Black
2019-10-01 21:15:06 -07:00
parent 211869ea95
commit 6ee86bf497
34 changed files with 424 additions and 338 deletions

View File

@@ -339,26 +339,25 @@ ElfObject::ElfObject(const std::string &_filename, size_t _len,
section = elf_getscn(elf, ++sec_idx);
}
addSegment(name, phdr.p_paddr, fileData + phdr.p_offset,
phdr.p_filesz);
image.addSegment(name, phdr.p_paddr, fileData + phdr.p_offset,
phdr.p_filesz);
Addr uninitialized = phdr.p_memsz - phdr.p_filesz;
if (uninitialized) {
// There may be parts of a segment which aren't included in the
// file. In those cases, we need to create a new segment with no
// data to take up the extra space. This should be zeroed when
// loaded into memory.
addSegment(name + "(uninitialized)", phdr.p_paddr + phdr.p_filesz,
nullptr, uninitialized);
image.addSegment(name + "(uninitialized)",
phdr.p_paddr + phdr.p_filesz, nullptr, uninitialized);
}
}
// should have found at least one loadable segment
warn_if(segments.empty(),
"No loadable segments in '%s'. ELF file corrupted?\n",
filename);
warn_if(image.segments().empty(),
"No loadable segments in '%s'. ELF file corrupted?\n", filename);
for (auto &seg: segments)
DPRINTFR(Loader, "%s\n", *seg);
for (auto &seg: image.segments())
DPRINTFR(Loader, "%s\n", seg);
elf_end(elf);
@@ -518,6 +517,5 @@ ElfObject::updateBias(Addr bias_addr)
entry += bias_addr;
// Patch segments with the bias_addr.
for (auto &segment : segments)
segment->base += bias_addr;
image.offset(bias_addr);
}