forked from OSchip/llvm-project
Make createObjectImage and createObjectImageFromFile static methods on the
relevant subclasses of RuntimeDyldImpl. This allows construction of RuntimeDyldImpl instances to be deferred until after the target architecture is known. llvm-svn: 203352
This commit is contained in:
parent
43027eb093
commit
951b235be2
|
@ -75,25 +75,7 @@ void RuntimeDyldImpl::mapSectionAddress(const void *LocalAddress,
|
|||
llvm_unreachable("Attempting to remap address of unknown section!");
|
||||
}
|
||||
|
||||
// Subclasses can implement this method to create specialized image instances.
|
||||
// The caller owns the pointer that is returned.
|
||||
ObjectImage *RuntimeDyldImpl::createObjectImage(ObjectBuffer *InputBuffer) {
|
||||
return new ObjectImageCommon(InputBuffer);
|
||||
}
|
||||
|
||||
ObjectImage *RuntimeDyldImpl::createObjectImageFromFile(ObjectFile *InputObject) {
|
||||
return new ObjectImageCommon(InputObject);
|
||||
}
|
||||
|
||||
ObjectImage *RuntimeDyldImpl::loadObject(ObjectFile *InputObject) {
|
||||
return loadObject(createObjectImageFromFile(InputObject));
|
||||
}
|
||||
|
||||
ObjectImage *RuntimeDyldImpl::loadObject(ObjectBuffer *InputBuffer) {
|
||||
return loadObject(createObjectImage(InputBuffer));
|
||||
}
|
||||
|
||||
ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
|
||||
ObjectImage* RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
|
||||
MutexGuard locked(lock);
|
||||
|
||||
std::unique_ptr<ObjectImage> Obj(InputObject);
|
||||
|
@ -155,7 +137,7 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
|
|||
if (SI == Obj->end_sections()) continue;
|
||||
Check(SI->getContents(SectionData));
|
||||
Check(SI->isText(IsCode));
|
||||
const uint8_t* SymPtr = (const uint8_t*)InputObject->getData().data() +
|
||||
const uint8_t* SymPtr = (const uint8_t*)Obj->getData().data() +
|
||||
(uintptr_t)FileOffset;
|
||||
uintptr_t SectOffset = (uintptr_t)(SymPtr -
|
||||
(const uint8_t*)SectionData.begin());
|
||||
|
@ -693,30 +675,38 @@ RuntimeDyld::~RuntimeDyld() {
|
|||
}
|
||||
|
||||
ObjectImage *RuntimeDyld::loadObject(ObjectFile *InputObject) {
|
||||
if (!Dyld) {
|
||||
if (InputObject->isELF())
|
||||
std::unique_ptr<ObjectImage> InputImage;
|
||||
|
||||
if (InputObject->isELF()) {
|
||||
InputImage.reset(RuntimeDyldELF::createObjectImageFromFile(InputObject));
|
||||
if (!Dyld)
|
||||
Dyld = new RuntimeDyldELF(MM);
|
||||
else if (InputObject->isMachO())
|
||||
} else if (InputObject->isMachO()) {
|
||||
InputImage.reset(RuntimeDyldMachO::createObjectImageFromFile(InputObject));
|
||||
if (!Dyld)
|
||||
Dyld = new RuntimeDyldMachO(MM);
|
||||
else
|
||||
} else
|
||||
report_fatal_error("Incompatible object format!");
|
||||
} else {
|
||||
|
||||
if (!Dyld->isCompatibleFile(InputObject))
|
||||
report_fatal_error("Incompatible object format!");
|
||||
}
|
||||
|
||||
return Dyld->loadObject(InputObject);
|
||||
Dyld->loadObject(InputImage.get());
|
||||
return InputImage.release();
|
||||
}
|
||||
|
||||
ObjectImage *RuntimeDyld::loadObject(ObjectBuffer *InputBuffer) {
|
||||
if (!Dyld) {
|
||||
std::unique_ptr<ObjectImage> InputImage;
|
||||
sys::fs::file_magic Type =
|
||||
sys::fs::identify_magic(InputBuffer->getBuffer());
|
||||
|
||||
switch (Type) {
|
||||
case sys::fs::file_magic::elf_relocatable:
|
||||
case sys::fs::file_magic::elf_executable:
|
||||
case sys::fs::file_magic::elf_shared_object:
|
||||
case sys::fs::file_magic::elf_core:
|
||||
InputImage.reset(RuntimeDyldELF::createObjectImage(InputBuffer));
|
||||
if (!Dyld)
|
||||
Dyld = new RuntimeDyldELF(MM);
|
||||
break;
|
||||
case sys::fs::file_magic::macho_object:
|
||||
|
@ -729,6 +719,8 @@ ObjectImage *RuntimeDyld::loadObject(ObjectBuffer *InputBuffer) {
|
|||
case sys::fs::file_magic::macho_bundle:
|
||||
case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
|
||||
case sys::fs::file_magic::macho_dsym_companion:
|
||||
InputImage.reset(RuntimeDyldMachO::createObjectImage(InputBuffer));
|
||||
if (!Dyld)
|
||||
Dyld = new RuntimeDyldMachO(MM);
|
||||
break;
|
||||
case sys::fs::file_magic::unknown:
|
||||
|
@ -741,12 +733,12 @@ ObjectImage *RuntimeDyld::loadObject(ObjectBuffer *InputBuffer) {
|
|||
case sys::fs::file_magic::windows_resource:
|
||||
report_fatal_error("Incompatible object format!");
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!Dyld->isCompatibleFormat(InputBuffer))
|
||||
report_fatal_error("Incompatible object format!");
|
||||
}
|
||||
|
||||
return Dyld->loadObject(InputBuffer);
|
||||
Dyld->loadObject(InputImage.get());
|
||||
return InputImage.release();
|
||||
}
|
||||
|
||||
void *RuntimeDyld::getSymbolAddress(StringRef Name) {
|
||||
|
|
|
@ -139,12 +139,13 @@ public:
|
|||
StubMap &Stubs) override;
|
||||
bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
|
||||
bool isCompatibleFile(const object::ObjectFile *Buffer) const override;
|
||||
ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) override;
|
||||
ObjectImage *createObjectImageFromFile(object::ObjectFile *Obj) override;
|
||||
void registerEHFrames() override;
|
||||
void deregisterEHFrames() override;
|
||||
void finalizeLoad(ObjSectionToIDMap &SectionMap) override;
|
||||
virtual ~RuntimeDyldELF();
|
||||
|
||||
static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer);
|
||||
static ObjectImage *createObjectImageFromFile(object::ObjectFile *Obj);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
|
|
@ -310,9 +310,6 @@ protected:
|
|||
// The base class does nothing. ELF overrides this.
|
||||
virtual void updateGOTEntries(StringRef Name, uint64_t Addr) {}
|
||||
|
||||
virtual ObjectImage *createObjectImage(ObjectBuffer *InputBuffer);
|
||||
virtual ObjectImage *createObjectImageFromFile(object::ObjectFile *InputObject);
|
||||
|
||||
// \brief Compute an upper bound of the memory that is required to load all sections
|
||||
void computeTotalAllocSize(ObjectImage &Obj,
|
||||
uint64_t& CodeSize,
|
||||
|
@ -322,16 +319,12 @@ protected:
|
|||
// \brief Compute the stub buffer size required for a section
|
||||
unsigned computeSectionStubBufSize(ObjectImage &Obj, const SectionRef &Section);
|
||||
|
||||
// This is the implementation for the two public overloads
|
||||
ObjectImage *loadObject(ObjectImage *InputObject);
|
||||
|
||||
public:
|
||||
RuntimeDyldImpl(RTDyldMemoryManager *mm) : MemMgr(mm), HasError(false) {}
|
||||
|
||||
virtual ~RuntimeDyldImpl();
|
||||
|
||||
ObjectImage *loadObject(ObjectBuffer *InputBuffer);
|
||||
ObjectImage *loadObject(object::ObjectFile *InputObject);
|
||||
ObjectImage* loadObject(ObjectImage* InputObject);
|
||||
|
||||
void *getSymbolAddress(StringRef Name) {
|
||||
// FIXME: Just look up as a function for now. Overly simple of course.
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#ifndef LLVM_RUNTIME_DYLD_MACHO_H
|
||||
#define LLVM_RUNTIME_DYLD_MACHO_H
|
||||
|
||||
#include "ObjectImageCommon.h"
|
||||
#include "RuntimeDyldImpl.h"
|
||||
#include "llvm/ADT/IndexedMap.h"
|
||||
#include "llvm/Object/MachO.h"
|
||||
|
@ -95,6 +96,15 @@ public:
|
|||
bool isCompatibleFile(const object::ObjectFile *Obj) const override;
|
||||
void registerEHFrames() override;
|
||||
void finalizeLoad(ObjSectionToIDMap &SectionMap) override;
|
||||
|
||||
|
||||
static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) {
|
||||
return new ObjectImageCommon(InputBuffer);
|
||||
}
|
||||
|
||||
static ObjectImage *createObjectImageFromFile(object::ObjectFile *InputObject) {
|
||||
return new ObjectImageCommon(InputObject);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
|
Loading…
Reference in New Issue