From 8d75e4ac3f3eb06733e85079e852f64576553519 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Tue, 16 Jan 2007 19:09:27 -0500 Subject: Don't add symbols for loaded files to symbol table since they are pretty much meaningless with all the copying that goes on --HG-- extra : convert_revision : 4d2c1bb72c0344d78d9c3d5958feb3de247102a0 --- src/base/loader/raw_object.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/base') diff --git a/src/base/loader/raw_object.cc b/src/base/loader/raw_object.cc index 2a52b0d6e..d002d9005 100644 --- a/src/base/loader/raw_object.cc +++ b/src/base/loader/raw_object.cc @@ -63,19 +63,19 @@ RawObject::RawObject(const std::string &_filename, int _fd, size_t _len, bool RawObject::loadGlobalSymbols(SymbolTable *symtab, Addr addrMask) { - int fnameStart = filename.rfind('/',filename.size()) + 1; +/* int fnameStart = filename.rfind('/',filename.size()) + 1; int extStart = filename.rfind('.',filename.size()); symtab->insert(text.baseAddr & addrMask, filename.substr(fnameStart, - extStart-fnameStart) + "_start"); + extStart-fnameStart) + "_start");*/ return true; } bool RawObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask) { - int fnameStart = filename.rfind('/',filename.size()) + 1; +/* int fnameStart = filename.rfind('/',filename.size()) + 1; int extStart = filename.rfind('.',filename.size()); symtab->insert(text.baseAddr & addrMask, filename.substr(fnameStart, - extStart-fnameStart) + "_start"); + extStart-fnameStart) + "_start");*/ return true; } -- cgit v1.2.3 From 5c1d631f36bc0d1a99875fb54b92a5df510fa9e3 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 22 Jan 2007 16:14:06 -0500 Subject: 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 --- src/base/loader/elf_object.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/base/loader/elf_object.hh | 2 ++ src/base/loader/object_file.cc | 6 ++++++ src/base/loader/object_file.hh | 2 ++ 4 files changed, 48 insertions(+) (limited to 'src/base') 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::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::max()) = 0; + virtual bool isDynamic(); + Arch getArch() const { return arch; } OpSys getOpSys() const { return opSys; } -- cgit v1.2.3 From 3011fc63111735bc3de000f121661ee60631cb4c Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 22 Jan 2007 21:45:29 -0500 Subject: we decided to check for .interp instead of .dynamic --HG-- extra : convert_revision : 4f5c7f9c7653e1e9ebbd488c07426d9f944bb25f --- src/base/loader/elf_object.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/base') diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc index 89a5d4512..d59affe85 100644 --- a/src/base/loader/elf_object.cc +++ b/src/base/loader/elf_object.cc @@ -370,7 +370,7 @@ ElfObject::isDynamic() // 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))) + if (!strcmp(".interp", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name))) return true; section = elf_getscn(elf, ++sec_idx); } // while sections -- cgit v1.2.3