summaryrefslogtreecommitdiff
path: root/src/base/loader
diff options
context:
space:
mode:
authorAli Saidi <saidi@eecs.umich.edu>2007-09-11 00:01:24 -0400
committerAli Saidi <saidi@eecs.umich.edu>2007-09-11 00:01:24 -0400
commit19fbdcd30bfcbfe11b2a1a315039f0e3b68025a1 (patch)
tree851314640efc3d6864bcd5d9ad40c1d270a3514d /src/base/loader
parent0f57b407a3df68f93e73e0635569d7bf5dd151b0 (diff)
downloadgem5-19fbdcd30bfcbfe11b2a1a315039f0e3b68025a1.tar.xz
Loader: Error if a TLS section is found in the binary.
--HG-- extra : convert_revision : d763c0382f3cbcc9786510f5a8e521ec9d55eff1
Diffstat (limited to 'src/base/loader')
-rw-r--r--src/base/loader/elf_object.cc18
-rw-r--r--src/base/loader/elf_object.hh8
-rw-r--r--src/base/loader/object_file.cc6
-rw-r--r--src/base/loader/object_file.hh3
4 files changed, 22 insertions, 13 deletions
diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc
index f76ea593b..ecce175b2 100644
--- a/src/base/loader/elf_object.cc
+++ b/src/base/loader/elf_object.cc
@@ -343,8 +343,8 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
return loadSomeSymbols(symtab, STB_LOCAL);
}
-bool
-ElfObject::isDynamic()
+void
+ElfObject::getSections()
{
Elf *elf;
int sec_idx = 1; // there is a 0 but it is nothing, go figure
@@ -353,6 +353,8 @@ ElfObject::isDynamic()
GElf_Ehdr ehdr;
+ assert(!sectionNames.size());
+
// check that header matches library version
if (elf_version(EV_CURRENT) == EV_NONE)
panic("wrong elf version number!");
@@ -372,11 +374,17 @@ ElfObject::isDynamic()
// While there are no more sections
while (section != NULL) {
gelf_getshdr(section, &shdr);
- if (!strcmp(".interp", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name)))
- return true;
+ sectionNames.insert(elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name));
section = elf_getscn(elf, ++sec_idx);
} // while sections
- return false;
+}
+
+bool
+ElfObject::sectionExists(string sec)
+{
+ if (!sectionNames.size())
+ getSections();
+ return sectionNames.find(sec) != sectionNames.end();
}
diff --git a/src/base/loader/elf_object.hh b/src/base/loader/elf_object.hh
index d909140f3..3e7c85874 100644
--- a/src/base/loader/elf_object.hh
+++ b/src/base/loader/elf_object.hh
@@ -32,6 +32,7 @@
#define __ELF_OBJECT_HH__
#include "base/loader/object_file.hh"
+#include <set>
class ElfObject : public ObjectFile
{
@@ -42,6 +43,7 @@ class ElfObject : public ObjectFile
Addr _programHeaderTable;
uint16_t _programHeaderSize;
uint16_t _programHeaderCount;
+ std::set<std::string> sectionNames;
/// Helper functions for loadGlobalSymbols() and loadLocalSymbols().
bool loadSomeSymbols(SymbolTable *symtab, int binding);
@@ -50,6 +52,9 @@ class ElfObject : public ObjectFile
size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys);
+ void getSections();
+ bool sectionExists(std::string sec);
+
public:
virtual ~ElfObject() {}
@@ -58,7 +63,8 @@ class ElfObject : public ObjectFile
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max());
- virtual bool isDynamic();
+ virtual bool isDynamic() { return sectionExists(".interp"); }
+ virtual bool hasTLS() { return sectionExists(".tbss"); }
static ObjectFile *tryFile(const std::string &fname, int fd,
size_t len, uint8_t *data);
diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc
index 7424b9305..2273b6c4e 100644
--- a/src/base/loader/object_file.cc
+++ b/src/base/loader/object_file.cc
@@ -150,9 +150,3 @@ createObjectFile(const string &fname, bool raw)
munmap((char*)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 4b44a6e22..4f0c17cc8 100644
--- a/src/base/loader/object_file.hh
+++ b/src/base/loader/object_file.hh
@@ -85,7 +85,8 @@ class ObjectFile
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max()) = 0;
- virtual bool isDynamic();
+ virtual bool isDynamic() { return false; }
+ virtual bool hasTLS() { return false; }
Arch getArch() const { return arch; }
OpSys getOpSys() const { return opSys; }