Enable 64bit elf object handling.
Change-Id: Ib952abf882fd9bd0d5cadaa3b204a100bd71aa1e
diff --git a/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp b/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
index 603695d..a470021 100644
--- a/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
+++ b/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
@@ -33,15 +33,24 @@
ArchiveReaderLE reader(reinterpret_cast<const unsigned char *>(pMem),
pMemSize);
+#ifdef __LP64__
+ mObject = ELFObject<64>::read(reader);
+#else
mObject = ELFObject<32>::read(reader);
+#endif
if (mObject == NULL) {
ALOGE("Unable to load the ELF object!");
return false;
}
// Retrive the pointer to the symbol table.
- mSymTab = static_cast<ELFSectionSymTab<32> *>(
+#ifdef __LP64__
+ mSymTab = static_cast<ELFSectionSymTab<64> *>(
mObject->getSectionByName(".symtab"));
+#else
+ mSymTab = static_cast<ELFSectionSymTab<32> *>(
+ mObject->getSectionByName(".symtab"));
+#endif
if (mSymTab == NULL) {
ALOGW("Object doesn't contain any symbol table.");
}
@@ -64,35 +73,67 @@
size_t pDebugImgSize) {
// Update the value of sh_addr in pDebugImg to its corresponding section in
// the mObject.
+#ifdef __LP64__
+ llvm::ELF::Elf64_Ehdr *elf_header =
+ reinterpret_cast<llvm::ELF::Elf64_Ehdr *>(pDebugImg);
+#else
llvm::ELF::Elf32_Ehdr *elf_header =
- reinterpret_cast<llvm::ELF::Elf32_Ehdr *>(pDebugImg);
+ reinterpret_cast<llvm::ELF::Elf32_Ehdr *>(pDebugImg);
+#endif
if (elf_header->e_shoff > pDebugImgSize) {
+#ifdef __LP64__
+ ALOGE("Invalid section header table offset found! (e_shoff = %ld)",
+ elf_header->e_shoff);
+#else
ALOGE("Invalid section header table offset found! (e_shoff = %d)",
elf_header->e_shoff);
+#endif
return false;
}
if ((elf_header->e_shoff +
sizeof(llvm::ELF::Elf32_Shdr) * elf_header->e_shnum) > pDebugImgSize) {
+#ifdef __LP64__
+ ALOGE("Invalid image supplied (debug image doesn't contain all the section"
+ "header or corrupted image)! (e_shoff = %ld, e_shnum = %d)",
+ elf_header->e_shoff, elf_header->e_shnum);
+#else
ALOGE("Invalid image supplied (debug image doesn't contain all the section"
"header or corrupted image)! (e_shoff = %d, e_shnum = %d)",
elf_header->e_shoff, elf_header->e_shnum);
+#endif
return false;
}
+#ifdef __LP64__
+ llvm::ELF::Elf64_Shdr *section_header_table =
+ reinterpret_cast<llvm::ELF::Elf64_Shdr *>(
+ reinterpret_cast<uint8_t*>(pDebugImg) + elf_header->e_shoff);
+#else
llvm::ELF::Elf32_Shdr *section_header_table =
reinterpret_cast<llvm::ELF::Elf32_Shdr *>(
reinterpret_cast<uint8_t*>(pDebugImg) + elf_header->e_shoff);
+#endif
for (unsigned i = 0; i < elf_header->e_shnum; i++) {
if (section_header_table[i].sh_flags & llvm::ELF::SHF_ALLOC) {
+#ifdef __LP64__
+ ELFSectionBits<64> *section =
+ static_cast<ELFSectionBits<64> *>(mObject->getSectionByIndex(i));
+#else
ELFSectionBits<32> *section =
static_cast<ELFSectionBits<32> *>(mObject->getSectionByIndex(i));
+#endif
if (section != NULL) {
uintptr_t address = reinterpret_cast<uintptr_t>(section->getBuffer());
+#ifdef __LP64__
+ LOG_FATAL_IF(address > 0xFFFFFFFFFFFFFFFFu, "Out of bound address for Elf64_Addr");
+ section_header_table[i].sh_addr = static_cast<llvm::ELF::Elf64_Addr>(address);
+#else
LOG_FATAL_IF(address > 0xFFFFFFFFu, "Out of bound address for Elf32_Addr");
section_header_table[i].sh_addr = static_cast<llvm::ELF::Elf32_Addr>(address);
+#endif
}
}
}
@@ -105,7 +146,11 @@
return NULL;
}
+#ifdef __LP64__
+ const ELFSymbol<64> *symbol = mSymTab->getByName(pName);
+#else
const ELFSymbol<32> *symbol = mSymTab->getByName(pName);
+#endif
if (symbol == NULL) {
ALOGV("Request symbol '%s' is not found in the object!", pName);
return NULL;
@@ -120,7 +165,11 @@
return 0;
}
+#ifdef __LP64__
+ const ELFSymbol<64> *symbol = mSymTab->getByName(pName);
+#else
const ELFSymbol<32> *symbol = mSymTab->getByName(pName);
+#endif
if (symbol == NULL) {
ALOGV("Request symbol '%s' is not found in the object!", pName);
@@ -154,7 +203,11 @@
}
for (size_t i = 0, e = mSymTab->size(); i != e; i++) {
+#ifdef __LP64__
+ ELFSymbol<64> *symbol = (*mSymTab)[i];
+#else
ELFSymbol<32> *symbol = (*mSymTab)[i];
+#endif
if (symbol == NULL) {
continue;
}
diff --git a/lib/ExecutionEngine/ELFObjectLoaderImpl.h b/lib/ExecutionEngine/ELFObjectLoaderImpl.h
index bc96eb4..52719e7 100644
--- a/lib/ExecutionEngine/ELFObjectLoaderImpl.h
+++ b/lib/ExecutionEngine/ELFObjectLoaderImpl.h
@@ -31,8 +31,13 @@
class ELFObjectLoaderImpl : public ObjectLoaderImpl {
private:
+#ifdef __LP64__
+ ELFObject<64> *mObject;
+ ELFSectionSymTab<64> *mSymTab;
+#else
ELFObject<32> *mObject;
ELFSectionSymTab<32> *mSymTab;
+#endif
public:
ELFObjectLoaderImpl() : ObjectLoaderImpl(), mObject(NULL), mSymTab(NULL) { }