From 9b4249410ec18cac9df2c7e9c0a4a6ce5459233d Mon Sep 17 00:00:00 2001 From: Brandon Potter Date: Thu, 17 Mar 2016 10:31:03 -0700 Subject: base: support dynamic loading of Linux ELF objects in SE mode --- src/sim/process.cc | 47 ++++++++++++++++++++++++++++++++++++++++++----- src/sim/process.hh | 8 ++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) (limited to 'src/sim') diff --git a/src/sim/process.cc b/src/sim/process.cc index 81a7ec89e..7fa160995 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -518,6 +518,48 @@ LiveProcess::findDriver(std::string filename) return NULL; } +void +LiveProcess::updateBias() +{ + ObjectFile *interp = objFile->getInterpreter(); + + if (!interp || !interp->relocatable()) + return; + + // Determine how large the interpreters footprint will be in the process + // address space. + Addr interp_mapsize = roundUp(interp->mapSize(), TheISA::PageBytes); + + // We are allocating the memory area; set the bias to the lowest address + // in the allocated memory region. + Addr ld_bias = mmapGrowsDown() ? mmap_end - interp_mapsize : mmap_end; + + // Adjust the process mmap area to give the interpreter room; the real + // execve system call would just invoke the kernel's internal mmap + // functions to make these adjustments. + mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize; + + interp->updateBias(ld_bias); +} + + +Addr +LiveProcess::getBias() +{ + ObjectFile *interp = objFile->getInterpreter(); + + return interp ? interp->bias() : objFile->bias(); +} + + +Addr +LiveProcess::getStartPC() +{ + ObjectFile *interp = objFile->getInterpreter(); + + return interp ? interp->entryPoint() : objFile->entryPoint(); +} + LiveProcess * LiveProcess::create(LiveProcessParams * params) @@ -535,11 +577,6 @@ LiveProcess::create(LiveProcessParams * params) fatal("Can't load object file %s", params->executable); } - if (objFile->isDynamic()) - fatal("Object file is a dynamic executable however only static " - "executables are supported!\n Please recompile your " - "executable as a static binary and try again.\n"); - #if THE_ISA == ALPHA_ISA if (objFile->getArch() != ObjectFile::Alpha) fatal("Object file architecture does not match compiled ISA (Alpha)."); diff --git a/src/sim/process.hh b/src/sim/process.hh index 72f789ec7..aa4c7a008 100644 --- a/src/sim/process.hh +++ b/src/sim/process.hh @@ -336,6 +336,14 @@ class LiveProcess : public Process */ EmulatedDriver *findDriver(std::string filename); + // This function acts as a callback to update the bias value in + // the object file because the parameters needed to calculate the + // bias are not available when the object file is created. + void updateBias(); + + Addr getBias(); + Addr getStartPC(); + // this function is used to create the LiveProcess object, since // we can't tell which subclass of LiveProcess to use until we // open and look at the object file. -- cgit v1.2.3