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
This commit is contained in:
parent
e347b49a4e
commit
5c1d631f36
5 changed files with 53 additions and 0 deletions
|
@ -340,3 +340,41 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
|
||||||
{
|
{
|
||||||
return loadSomeSymbols(symtab, STB_LOCAL);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ class ElfObject : public ObjectFile
|
||||||
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
|
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
|
||||||
std::numeric_limits<Addr>::max());
|
std::numeric_limits<Addr>::max());
|
||||||
|
|
||||||
|
virtual bool isDynamic();
|
||||||
|
|
||||||
static ObjectFile *tryFile(const std::string &fname, int fd,
|
static ObjectFile *tryFile(const std::string &fname, int fd,
|
||||||
size_t len, uint8_t *data);
|
size_t len, uint8_t *data);
|
||||||
Addr programHeaderTable() {return _programHeaderTable;}
|
Addr programHeaderTable() {return _programHeaderTable;}
|
||||||
|
|
|
@ -150,3 +150,9 @@ createObjectFile(const string &fname, bool raw)
|
||||||
munmap(fileData, len);
|
munmap(fileData, len);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ObjectFile::isDynamic()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -83,6 +83,8 @@ class ObjectFile
|
||||||
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
|
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
|
||||||
std::numeric_limits<Addr>::max()) = 0;
|
std::numeric_limits<Addr>::max()) = 0;
|
||||||
|
|
||||||
|
virtual bool isDynamic();
|
||||||
|
|
||||||
Arch getArch() const { return arch; }
|
Arch getArch() const { return arch; }
|
||||||
OpSys getOpSys() const { return opSys; }
|
OpSys getOpSys() const { return opSys; }
|
||||||
|
|
||||||
|
|
|
@ -440,6 +440,11 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd,
|
||||||
fatal("Can't load object file %s", executable);
|
fatal("Can't load object file %s", 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 THE_ISA == ALPHA_ISA
|
||||||
if (objFile->getArch() != ObjectFile::Alpha)
|
if (objFile->getArch() != ObjectFile::Alpha)
|
||||||
fatal("Object file architecture does not match compiled ISA (Alpha).");
|
fatal("Object file architecture does not match compiled ISA (Alpha).");
|
||||||
|
|
Loading…
Reference in a new issue