base: Add byte order attribute for object files
This adds byte order as an attribute for object files by introducing new members to the ObjectFile class. This is populated by the looking at the ELF headers. Change-Id: Ibe55699175cc0295e0c9d49bdbe02e580988bc4f Signed-off-by: Sandipan Das <sandipan@linux.ibm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40939 Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Maintainer: Daniel Carvalho <odanrc@yahoo.com.br> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Boris Shingarov
parent
a947b45fcf
commit
b91cfc14bd
@@ -114,6 +114,7 @@ ElfObject::ElfObject(ImageFileDataPtr ifd) : ObjectFile(ifd)
|
||||
|
||||
determineArch();
|
||||
determineOpSys();
|
||||
determineByteOrder();
|
||||
|
||||
entry = ehdr.e_entry;
|
||||
_programHeaderCount = ehdr.e_phnum;
|
||||
@@ -325,6 +326,15 @@ ElfObject::determineOpSys()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ElfObject::determineByteOrder()
|
||||
{
|
||||
auto edata = ehdr.e_ident[EI_DATA];
|
||||
if (edata == ELFDATANONE)
|
||||
panic("invalid ELF data encoding");
|
||||
byteOrder = (edata == ELFDATA2MSB) ? ByteOrder::big : ByteOrder::little;
|
||||
}
|
||||
|
||||
void
|
||||
ElfObject::handleLoadableSegment(GElf_Phdr phdr, int seg_num)
|
||||
{
|
||||
|
||||
@@ -66,6 +66,7 @@ class ElfObject : public ObjectFile
|
||||
|
||||
void determineArch();
|
||||
void determineOpSys();
|
||||
void determineByteOrder();
|
||||
void handleLoadableSegment(GElf_Phdr phdr, int seg_num);
|
||||
|
||||
// These values are provided to a linux process by the kernel, so we
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "base/loader/symtab.hh"
|
||||
#include "base/logging.hh"
|
||||
#include "base/types.hh"
|
||||
#include "enums/ByteOrder.hh"
|
||||
|
||||
GEM5_DEPRECATED_NAMESPACE(Loader, loader);
|
||||
namespace loader
|
||||
@@ -80,6 +81,7 @@ class ObjectFile : public ImageFile
|
||||
protected:
|
||||
Arch arch = UnknownArch;
|
||||
OpSys opSys = UnknownOpSys;
|
||||
ByteOrder byteOrder = ByteOrder::little;
|
||||
|
||||
SymbolTable _symtab;
|
||||
|
||||
@@ -106,6 +108,7 @@ class ObjectFile : public ImageFile
|
||||
|
||||
Arch getArch() const { return arch; }
|
||||
OpSys getOpSys() const { return opSys; }
|
||||
ByteOrder getByteOrder() const { return byteOrder; }
|
||||
|
||||
const SymbolTable &symtab() const { return _symtab; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user