diff options
author | Gabe Black <gabeblack@google.com> | 2019-05-02 22:51:09 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2019-05-18 10:20:39 +0000 |
commit | c1b748d691fe407c7cd43330658fba83e3435247 (patch) | |
tree | 1b14ed823f371e31aae73c92099752e4b7f4d159 /src/base/loader/object_file.cc | |
parent | 972c38b1cc5f6f6c649a0e9923695447bc5d6255 (diff) | |
download | gem5-c1b748d691fe407c7cd43330658fba83e3435247.tar.xz |
base: Add a type for keeping track of object file loaders.
This avoids having a big pile of #if-s in sim/process.cc and allows
dynamically adding new types of object file loaders which might
recognize new arch/OS combinations.
Change-Id: Ie3b9c1aa2974d30a61afc4fcc529ffd6a74d43e0
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18583
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/base/loader/object_file.cc')
-rw-r--r-- | src/base/loader/object_file.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc index a82314e68..86278e44f 100644 --- a/src/base/loader/object_file.cc +++ b/src/base/loader/object_file.cc @@ -40,6 +40,7 @@ #include <cstdio> #include <list> #include <string> +#include <vector> #include "base/cprintf.hh" #include "base/loader/aout_object.hh" @@ -97,6 +98,37 @@ ObjectFile::loadSections(PortProxy& mem_proxy, Addr addr_mask, Addr offset) && loadSection(&bss, mem_proxy, addr_mask, offset)); } +namespace +{ + +typedef std::vector<ObjectFile::Loader *> LoaderList; + +LoaderList & +object_file_loaders() +{ + static LoaderList loaders; + return loaders; +} + +} // anonymous namespace + +ObjectFile::Loader::Loader() +{ + object_file_loaders().emplace_back(this); +} + +Process * +ObjectFile::tryLoaders(ProcessParams *params, ObjectFile *obj_file) +{ + for (auto &loader: object_file_loaders()) { + Process *p = loader->load(params, obj_file); + if (p) + return p; + } + + return nullptr; +} + static bool hasGzipMagic(int fd) { |