From e7777cdc643d15671c5a7bc7c24753820298c100 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sat, 7 Dec 2013 03:05:51 +0000 Subject: Add support for archives and object file caching under MCJIT. Patch by Andy Kaylor, with minor edits to resolve merge conflicts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196639 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp') diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index f2c69fc99c..68e86d86b6 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -25,6 +25,8 @@ #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/MemoryBuffer.h" + using namespace llvm; using namespace llvm::object; @@ -178,6 +180,39 @@ void RuntimeDyldELF::deregisterEHFrames() { RegisteredEHFrameSections.clear(); } +ObjectImage *RuntimeDyldELF::createObjectImageFromFile(object::ObjectFile *ObjFile) { + if (!ObjFile) + return NULL; + + error_code ec; + MemoryBuffer* Buffer = MemoryBuffer::getMemBuffer(ObjFile->getData(), + "", + false); + + if (ObjFile->getBytesInAddress() == 4 && ObjFile->isLittleEndian()) { + DyldELFObject > *Obj = + new DyldELFObject >(Buffer, ec); + return new ELFObjectImage >(NULL, Obj); + } + else if (ObjFile->getBytesInAddress() == 4 && !ObjFile->isLittleEndian()) { + DyldELFObject > *Obj = + new DyldELFObject >(Buffer, ec); + return new ELFObjectImage >(NULL, Obj); + } + else if (ObjFile->getBytesInAddress() == 8 && !ObjFile->isLittleEndian()) { + DyldELFObject > *Obj = + new DyldELFObject >(Buffer, ec); + return new ELFObjectImage >(NULL, Obj); + } + else if (ObjFile->getBytesInAddress() == 8 && ObjFile->isLittleEndian()) { + DyldELFObject > *Obj = + new DyldELFObject >(Buffer, ec); + return new ELFObjectImage >(NULL, Obj); + } + else + llvm_unreachable("Unexpected ELF format"); +} + ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) { if (Buffer->getBufferSize() < ELF::EI_NIDENT) llvm_unreachable("Unexpected ELF object size"); @@ -1403,4 +1438,9 @@ bool RuntimeDyldELF::isCompatibleFormat(const ObjectBuffer *Buffer) const { return false; return (memcmp(Buffer->getBufferStart(), ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0; } + +bool RuntimeDyldELF::isCompatibleFile(const object::ObjectFile *Obj) const { + return Obj->isELF(); +} + } // namespace llvm -- cgit v1.2.3