Loader: Error if a TLS section is found in the binary.
--HG-- extra : convert_revision : d763c0382f3cbcc9786510f5a8e521ec9d55eff1
This commit is contained in:
parent
0f57b407a3
commit
19fbdcd30b
5 changed files with 29 additions and 14 deletions
|
@ -343,8 +343,8 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
|
||||||
return loadSomeSymbols(symtab, STB_LOCAL);
|
return loadSomeSymbols(symtab, STB_LOCAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
ElfObject::isDynamic()
|
ElfObject::getSections()
|
||||||
{
|
{
|
||||||
Elf *elf;
|
Elf *elf;
|
||||||
int sec_idx = 1; // there is a 0 but it is nothing, go figure
|
int sec_idx = 1; // there is a 0 but it is nothing, go figure
|
||||||
|
@ -353,6 +353,8 @@ ElfObject::isDynamic()
|
||||||
|
|
||||||
GElf_Ehdr ehdr;
|
GElf_Ehdr ehdr;
|
||||||
|
|
||||||
|
assert(!sectionNames.size());
|
||||||
|
|
||||||
// check that header matches library version
|
// check that header matches library version
|
||||||
if (elf_version(EV_CURRENT) == EV_NONE)
|
if (elf_version(EV_CURRENT) == EV_NONE)
|
||||||
panic("wrong elf version number!");
|
panic("wrong elf version number!");
|
||||||
|
@ -372,11 +374,17 @@ ElfObject::isDynamic()
|
||||||
// While there are no more sections
|
// While there are no more sections
|
||||||
while (section != NULL) {
|
while (section != NULL) {
|
||||||
gelf_getshdr(section, &shdr);
|
gelf_getshdr(section, &shdr);
|
||||||
if (!strcmp(".interp", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name)))
|
sectionNames.insert(elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name));
|
||||||
return true;
|
|
||||||
section = elf_getscn(elf, ++sec_idx);
|
section = elf_getscn(elf, ++sec_idx);
|
||||||
} // while sections
|
} // while sections
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ElfObject::sectionExists(string sec)
|
||||||
|
{
|
||||||
|
if (!sectionNames.size())
|
||||||
|
getSections();
|
||||||
|
return sectionNames.find(sec) != sectionNames.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define __ELF_OBJECT_HH__
|
#define __ELF_OBJECT_HH__
|
||||||
|
|
||||||
#include "base/loader/object_file.hh"
|
#include "base/loader/object_file.hh"
|
||||||
|
#include <set>
|
||||||
|
|
||||||
class ElfObject : public ObjectFile
|
class ElfObject : public ObjectFile
|
||||||
{
|
{
|
||||||
|
@ -42,6 +43,7 @@ class ElfObject : public ObjectFile
|
||||||
Addr _programHeaderTable;
|
Addr _programHeaderTable;
|
||||||
uint16_t _programHeaderSize;
|
uint16_t _programHeaderSize;
|
||||||
uint16_t _programHeaderCount;
|
uint16_t _programHeaderCount;
|
||||||
|
std::set<std::string> sectionNames;
|
||||||
|
|
||||||
/// Helper functions for loadGlobalSymbols() and loadLocalSymbols().
|
/// Helper functions for loadGlobalSymbols() and loadLocalSymbols().
|
||||||
bool loadSomeSymbols(SymbolTable *symtab, int binding);
|
bool loadSomeSymbols(SymbolTable *symtab, int binding);
|
||||||
|
@ -50,6 +52,9 @@ class ElfObject : public ObjectFile
|
||||||
size_t _len, uint8_t *_data,
|
size_t _len, uint8_t *_data,
|
||||||
Arch _arch, OpSys _opSys);
|
Arch _arch, OpSys _opSys);
|
||||||
|
|
||||||
|
void getSections();
|
||||||
|
bool sectionExists(std::string sec);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ElfObject() {}
|
virtual ~ElfObject() {}
|
||||||
|
|
||||||
|
@ -58,7 +63,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();
|
virtual bool isDynamic() { return sectionExists(".interp"); }
|
||||||
|
virtual bool hasTLS() { return sectionExists(".tbss"); }
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -150,9 +150,3 @@ createObjectFile(const string &fname, bool raw)
|
||||||
munmap((char*)fileData, len);
|
munmap((char*)fileData, len);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
ObjectFile::isDynamic()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
@ -85,7 +85,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();
|
virtual bool isDynamic() { return false; }
|
||||||
|
virtual bool hasTLS() { return false; }
|
||||||
|
|
||||||
Arch getArch() const { return arch; }
|
Arch getArch() const { return arch; }
|
||||||
OpSys getOpSys() const { return opSys; }
|
OpSys getOpSys() const { return opSys; }
|
||||||
|
|
|
@ -453,9 +453,15 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd,
|
||||||
|
|
||||||
if (objFile->isDynamic())
|
if (objFile->isDynamic())
|
||||||
fatal("Object file is a dynamic executable however only static "
|
fatal("Object file is a dynamic executable however only static "
|
||||||
"executables are supported!\n Please recompile your "
|
"executables are supported!\n Please recompile your "
|
||||||
"executable as a static binary and try again.\n");
|
"executable as a static binary and try again.\n");
|
||||||
|
|
||||||
|
if (objFile->hasTLS())
|
||||||
|
fatal("Object file has a TLS section and loading of TLS sections "
|
||||||
|
"are not currently supported!\n Please recompile your "
|
||||||
|
"executable with a non-TLS toolchain or add TLS support to "
|
||||||
|
"M5 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