#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/MutexGuard.h"
#include "llvm/Target/TargetLowering.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
using namespace llvm;
ExecutionEngine *MCJIT::createJIT(Module *M,
std::string *ErrorStr,
RTDyldMemoryManager *MemMgr,
- bool GVsWithCode,
TargetMachine *TM) {
// Try to register the program as a source of symbols to resolve against.
//
// FIXME: Don't do this here.
sys::DynamicLibrary::LoadLibraryPermanently(nullptr, nullptr);
- return new MCJIT(M, TM, MemMgr ? MemMgr : new SectionMemoryManager(),
- GVsWithCode);
+ return new MCJIT(M, TM, MemMgr ? MemMgr : new SectionMemoryManager());
}
-MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM,
- bool AllocateGVsWithCode)
+MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM)
: ExecutionEngine(m), TM(tm), Ctx(nullptr), MemMgr(this, MM), Dyld(&MemMgr),
ObjCache(nullptr) {
OwnedModules.addModule(m);
- setDataLayout(TM->getDataLayout());
+ setDataLayout(TM->getSubtargetImpl()->getDataLayout());
}
MCJIT::~MCJIT() {
}
LoadedObjects.clear();
-
- SmallVector<object::Archive *, 2>::iterator ArIt, ArEnd;
- for (ArIt = Archives.begin(), ArEnd = Archives.end(); ArIt != ArEnd; ++ArIt) {
- object::Archive *A = *ArIt;
- delete A;
- }
Archives.clear();
delete TM;
-void MCJIT::addObjectFile(object::ObjectFile *Obj) {
- ObjectImage *LoadedObject = Dyld.loadObject(Obj);
+void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) {
+ ObjectImage *LoadedObject = Dyld.loadObject(std::move(Obj));
if (!LoadedObject || Dyld.hasError())
report_fatal_error(Dyld.getErrorString());
NotifyObjectEmitted(*LoadedObject);
}
-void MCJIT::addArchive(object::Archive *A) {
- Archives.push_back(A);
+void MCJIT::addArchive(std::unique_ptr<object::Archive> A) {
+ Archives.push_back(std::move(A));
}
PassManager PM;
- M->setDataLayout(TM->getDataLayout());
+ M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
PM.add(new DataLayoutPass(M));
// The RuntimeDyld will take ownership of this shortly
if (ObjCache) {
// MemoryBuffer is a thin wrapper around the actual memory, so it's OK
// to create a temporary object here and delete it after the call.
- std::unique_ptr<MemoryBuffer> MB(CompiledObject->getMemBuffer());
+ std::unique_ptr<MemoryBuffer> MB = CompiledObject->getMemBuffer();
ObjCache->notifyObjectCompiled(M, MB.get());
}
}
uint64_t MCJIT::getExistingSymbolAddress(const std::string &Name) {
- Mangler Mang(TM->getDataLayout());
+ Mangler Mang(TM->getSubtargetImpl()->getDataLayout());
SmallString<128> FullName;
Mang.getNameWithPrefix(FullName, Name);
return Dyld.getSymbolLoadAddress(FullName);
if (Addr)
return Addr;
- SmallVector<object::Archive*, 2>::iterator I, E;
- for (I = Archives.begin(), E = Archives.end(); I != E; ++I) {
- object::Archive *A = *I;
+ for (std::unique_ptr<object::Archive> &A : Archives) {
// Look for our symbols in each Archive
object::Archive::child_iterator ChildIt = A->findSym(Name);
if (ChildIt != A->child_end()) {
- std::unique_ptr<object::Binary> ChildBin;
// FIXME: Support nested archives?
- if (!ChildIt->getAsBinary(ChildBin) && ChildBin->isObject()) {
- object::ObjectFile *OF = reinterpret_cast<object::ObjectFile *>(
- ChildBin.release());
+ ErrorOr<std::unique_ptr<object::Binary>> ChildBinOrErr =
+ ChildIt->getAsBinary();
+ if (ChildBinOrErr.getError())
+ continue;
+ std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
+ if (ChildBin->isObject()) {
+ std::unique_ptr<object::ObjectFile> OF(
+ static_cast<object::ObjectFile *>(ChildBin.release()));
// This causes the object file to be loaded.
- addObjectFile(OF);
+ addObjectFile(std::move(OF));
// The address should be here now.
Addr = getExistingSymbolAddress(Name);
if (Addr)
// If it hasn't already been generated, see if it's in one of our modules.
Module *M = findModuleForSymbol(Name, CheckFunctionsOnly);
- if (!M)
- return 0;
+ if (M) {
+ generateCodeForModule(M);
- generateCodeForModule(M);
+ // Check the RuntimeDyld table again, it should be there now.
+ return getExistingSymbolAddress(Name);
+ }
+
+ // If a LazyFunctionCreator is installed, use it to get/create the function.
+ // FIXME: Should we instead have a LazySymbolCreator callback?
+ if (LazyFunctionCreator)
+ Addr = (uint64_t)LazyFunctionCreator(Name);
- // Check the RuntimeDyld table again, it should be there now.
- return getExistingSymbolAddress(Name);
+ return Addr;
}
uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
//
// This is the accessor for the target address, so make sure to check the
// load address of the symbol, not the local address.
- Mangler Mang(TM->getDataLayout());
+ Mangler Mang(TM->getSubtargetImpl()->getDataLayout());
SmallString<128> Name;
TM->getNameWithPrefix(Name, F, Mang);
return (void*)Dyld.getSymbolLoadAddress(Name);
Result = ParentEngine->getSymbolAddress(Name.substr(1), false);
if (Result)
return Result;
+ if (ParentEngine->isSymbolSearchingDisabled())
+ return 0;
return ClientMM->getSymbolAddress(Name);
}