summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorAli Saidi <saidi@eecs.umich.edu>2007-01-22 16:14:06 -0500
committerAli Saidi <saidi@eecs.umich.edu>2007-01-22 16:14:06 -0500
commit5c1d631f36bc0d1a99875fb54b92a5df510fa9e3 (patch)
tree1417488f2cbc8509f495cf1ca54c3fd46652c518 /src/base
parente347b49a4edfe89ed5c5352b6c1b93b69ab00134 (diff)
downloadgem5-5c1d631f36bc0d1a99875fb54b92a5df510fa9e3.tar.xz
check if an executable is dynamic and die if it is
Only implemented for ELf. Someone might want to implement it for ecoff and some point src/base/loader/elf_object.cc: src/base/loader/elf_object.hh: src/base/loader/object_file.cc: src/base/loader/object_file.hh: add a function to check if an executable is dynamic src/sim/process.cc: check if an executable is dynamic and die if it is --HG-- extra : convert_revision : 830b1b50b08a5abaf895ce6251bbc702c986eebf
Diffstat (limited to 'src/base')
-rw-r--r--src/base/loader/elf_object.cc38
-rw-r--r--src/base/loader/elf_object.hh2
-rw-r--r--src/base/loader/object_file.cc6
-rw-r--r--src/base/loader/object_file.hh2
4 files changed, 48 insertions, 0 deletions
diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc
index 7339507f6..89a5d4512 100644
--- a/src/base/loader/elf_object.cc
+++ b/src/base/loader/elf_object.cc
@@ -340,3 +340,41 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
{
return loadSomeSymbols(symtab, STB_LOCAL);
}
+
+bool
+ElfObject::isDynamic()
+{
+ Elf *elf;
+ int sec_idx = 1; // there is a 0 but it is nothing, go figure
+ Elf_Scn *section;
+ GElf_Shdr shdr;
+
+ GElf_Ehdr ehdr;
+
+ // check that header matches library version
+ if (elf_version(EV_CURRENT) == EV_NONE)
+ panic("wrong elf version number!");
+
+ // get a pointer to elf structure
+ elf = elf_memory((char*)fileData,len);
+ assert(elf != NULL);
+
+ // Check that we actually have a elf file
+ if (gelf_getehdr(elf, &ehdr) ==0) {
+ panic("Not ELF, shouldn't be here");
+ }
+
+ // Get the first section
+ section = elf_getscn(elf, sec_idx);
+
+ // While there are no more sections
+ while (section != NULL) {
+ gelf_getshdr(section, &shdr);
+ if (!strcmp(".dynamic", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name)))
+ return true;
+ section = elf_getscn(elf, ++sec_idx);
+ } // while sections
+ return false;
+}
+
+
diff --git a/src/base/loader/elf_object.hh b/src/base/loader/elf_object.hh
index fb728b3c5..d909140f3 100644
--- a/src/base/loader/elf_object.hh
+++ b/src/base/loader/elf_object.hh
@@ -58,6 +58,8 @@ class ElfObject : public ObjectFile
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max());
+ virtual bool isDynamic();
+
static ObjectFile *tryFile(const std::string &fname, int fd,
size_t len, uint8_t *data);
Addr programHeaderTable() {return _programHeaderTable;}
diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc
index ad2cd34ba..da5aa9552 100644
--- a/src/base/loader/object_file.cc
+++ b/src/base/loader/object_file.cc
@@ -150,3 +150,9 @@ createObjectFile(const string &fname, bool raw)
munmap(fileData, len);
return NULL;
}
+
+bool
+ObjectFile::isDynamic()
+{
+ return false;
+}
diff --git a/src/base/loader/object_file.hh b/src/base/loader/object_file.hh
index 6e98332c5..18e6482be 100644
--- a/src/base/loader/object_file.hh
+++ b/src/base/loader/object_file.hh
@@ -83,6 +83,8 @@ class ObjectFile
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max()) = 0;
+ virtual bool isDynamic();
+
Arch getArch() const { return arch; }
OpSys getOpSys() const { return opSys; }