Gabe Black has submitted this change and it was merged. (
https://gem5-review.googlesource.com/c/public/gem5/+/18583 )
Change subject: base: Add a type for keeping track of object file loaders.
......................................................................
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.sandb...@arm.com>
Maintainer: Andreas Sandberg <andreas.sandb...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/loader/object_file.cc
M src/base/loader/object_file.hh
2 files changed, 66 insertions(+), 0 deletions(-)
Approvals:
Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc
index a82314e..86278e4 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 @@
&& 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)
{
diff --git a/src/base/loader/object_file.hh b/src/base/loader/object_file.hh
index 09c453b..5da7e3c 100644
--- a/src/base/loader/object_file.hh
+++ b/src/base/loader/object_file.hh
@@ -39,6 +39,8 @@
#include "base/types.hh"
class PortProxy;
+class Process;
+class ProcessParams;
class SymbolTable;
class ObjectFile
@@ -150,6 +152,38 @@
* @param a address to load the binary/text section at
*/
void setTextBase(Addr a) { text.baseAddr = a; }
+
+ /**
+ * Each instance of a Loader subclass will have a chance to try to load
+ * an object file when tryLoaders is called. If they can't because they
+ * aren't compatible with it (wrong arch, wrong OS, etc), then they
+ * silently fail by returning nullptr so other loaders can try.
+ */
+ class Loader
+ {
+ public:
+ Loader();
+
+ /* Loader instances are singletons. */
+ Loader(const Loader &) = delete;
+ void operator=(const Loader &) = delete;
+
+ virtual ~Loader() {}
+
+ /**
+ * Each subclass needs to implement this method. If the loader is
+ * compatible with the passed in object file, it should return the
+ * created Process object corresponding to it. If not, it should
fail
+ * silently and return nullptr. If there's a non-compatibliity
related
+ * error like file IO errors, etc., those should fail non-silently
+ * with a panic or fail as normal.
+ */
+ virtual Process *load(ProcessParams *params, ObjectFile *obj_file)
= 0;
+ };
+
+ // Try all the Loader instance's "load" methods one by one until one is
+ // successful. If none are, complain and fail.
+ static Process *tryLoaders(ProcessParams *params, ObjectFile
*obj_file);
};
ObjectFile *createObjectFile(const std::string &fname, bool raw = false);
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/18583
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ie3b9c1aa2974d30a61afc4fcc529ffd6a74d43e0
Gerrit-Change-Number: 18583
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Brandon Potter <brandon.pot...@amd.com>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev