LLVM API Documentation

MCJIT.cpp
Go to the documentation of this file.
00001 //===-- MCJIT.cpp - MC-based Just-in-Time Compiler ------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "MCJIT.h"
00011 #include "llvm/ExecutionEngine/GenericValue.h"
00012 #include "llvm/ExecutionEngine/JITEventListener.h"
00013 #include "llvm/ExecutionEngine/MCJIT.h"
00014 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
00015 #include "llvm/IR/DataLayout.h"
00016 #include "llvm/IR/DerivedTypes.h"
00017 #include "llvm/IR/Function.h"
00018 #include "llvm/IR/Mangler.h"
00019 #include "llvm/IR/Module.h"
00020 #include "llvm/MC/MCAsmInfo.h"
00021 #include "llvm/Object/Archive.h"
00022 #include "llvm/Object/ObjectFile.h"
00023 #include "llvm/PassManager.h"
00024 #include "llvm/Support/DynamicLibrary.h"
00025 #include "llvm/Support/ErrorHandling.h"
00026 #include "llvm/Support/MemoryBuffer.h"
00027 #include "llvm/Support/MutexGuard.h"
00028 
00029 using namespace llvm;
00030 
00031 void ObjectCache::anchor() {}
00032 
00033 namespace {
00034 
00035 static struct RegisterJIT {
00036   RegisterJIT() { MCJIT::Register(); }
00037 } JITRegistrator;
00038 
00039 }
00040 
00041 extern "C" void LLVMLinkInMCJIT() {
00042 }
00043 
00044 ExecutionEngine *MCJIT::createJIT(std::unique_ptr<Module> M,
00045                                   std::string *ErrorStr,
00046                                   std::unique_ptr<RTDyldMemoryManager> MemMgr,
00047                                   std::unique_ptr<TargetMachine> TM) {
00048   // Try to register the program as a source of symbols to resolve against.
00049   //
00050   // FIXME: Don't do this here.
00051   sys::DynamicLibrary::LoadLibraryPermanently(nullptr, nullptr);
00052 
00053   std::unique_ptr<RTDyldMemoryManager> MM = std::move(MemMgr);
00054   if (!MM)
00055     MM = std::unique_ptr<SectionMemoryManager>(new SectionMemoryManager());
00056 
00057   return new MCJIT(std::move(M), std::move(TM), std::move(MM));
00058 }
00059 
00060 MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> tm,
00061              std::unique_ptr<RTDyldMemoryManager> MM)
00062     : ExecutionEngine(std::move(M)), TM(std::move(tm)), Ctx(nullptr),
00063       MemMgr(this, std::move(MM)), Dyld(&MemMgr), ObjCache(nullptr) {
00064   // FIXME: We are managing our modules, so we do not want the base class
00065   // ExecutionEngine to manage them as well. To avoid double destruction
00066   // of the first (and only) module added in ExecutionEngine constructor
00067   // we remove it from EE and will destruct it ourselves.
00068   //
00069   // It may make sense to move our module manager (based on SmallStPtr) back
00070   // into EE if the JIT and Interpreter can live with it.
00071   // If so, additional functions: addModule, removeModule, FindFunctionNamed,
00072   // runStaticConstructorsDestructors could be moved back to EE as well.
00073   //
00074   std::unique_ptr<Module> First = std::move(Modules[0]);
00075   Modules.clear();
00076 
00077   OwnedModules.addModule(std::move(First));
00078   setDataLayout(TM->getDataLayout());
00079   RegisterJITEventListener(JITEventListener::createGDBRegistrationListener());
00080 }
00081 
00082 MCJIT::~MCJIT() {
00083   MutexGuard locked(lock);
00084 
00085   Dyld.deregisterEHFrames();
00086 
00087   for (auto &Obj : LoadedObjects)
00088     if (Obj)
00089       NotifyFreeingObject(*Obj);
00090 
00091   Archives.clear();
00092 }
00093 
00094 void MCJIT::addModule(std::unique_ptr<Module> M) {
00095   MutexGuard locked(lock);
00096   OwnedModules.addModule(std::move(M));
00097 }
00098 
00099 bool MCJIT::removeModule(Module *M) {
00100   MutexGuard locked(lock);
00101   return OwnedModules.removeModule(M);
00102 }
00103 
00104 void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) {
00105   std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L = Dyld.loadObject(*Obj);
00106   if (Dyld.hasError())
00107     report_fatal_error(Dyld.getErrorString());
00108 
00109   NotifyObjectEmitted(*Obj, *L);
00110 
00111   LoadedObjects.push_back(std::move(Obj));
00112 }
00113 
00114 void MCJIT::addObjectFile(object::OwningBinary<object::ObjectFile> Obj) {
00115   std::unique_ptr<object::ObjectFile> ObjFile;
00116   std::unique_ptr<MemoryBuffer> MemBuf;
00117   std::tie(ObjFile, MemBuf) = Obj.takeBinary();
00118   addObjectFile(std::move(ObjFile));
00119   Buffers.push_back(std::move(MemBuf));
00120 }
00121 
00122 void MCJIT::addArchive(object::OwningBinary<object::Archive> A) {
00123   Archives.push_back(std::move(A));
00124 }
00125 
00126 void MCJIT::setObjectCache(ObjectCache* NewCache) {
00127   MutexGuard locked(lock);
00128   ObjCache = NewCache;
00129 }
00130 
00131 std::unique_ptr<MemoryBuffer> MCJIT::emitObject(Module *M) {
00132   MutexGuard locked(lock);
00133 
00134   // This must be a module which has already been added but not loaded to this
00135   // MCJIT instance, since these conditions are tested by our caller,
00136   // generateCodeForModule.
00137 
00138   PassManager PM;
00139 
00140   M->setDataLayout(TM->getDataLayout());
00141   PM.add(new DataLayoutPass());
00142 
00143   // The RuntimeDyld will take ownership of this shortly
00144   SmallVector<char, 4096> ObjBufferSV;
00145   raw_svector_ostream ObjStream(ObjBufferSV);
00146 
00147   // Turn the machine code intermediate representation into bytes in memory
00148   // that may be executed.
00149   if (TM->addPassesToEmitMC(PM, Ctx, ObjStream, !getVerifyModules()))
00150     report_fatal_error("Target does not support MC emission!");
00151 
00152   // Initialize passes.
00153   PM.run(*M);
00154   // Flush the output buffer to get the generated code into memory
00155   ObjStream.flush();
00156 
00157   std::unique_ptr<MemoryBuffer> CompiledObjBuffer(
00158                                 new ObjectMemoryBuffer(std::move(ObjBufferSV)));
00159 
00160   // If we have an object cache, tell it about the new object.
00161   // Note that we're using the compiled image, not the loaded image (as below).
00162   if (ObjCache) {
00163     // MemoryBuffer is a thin wrapper around the actual memory, so it's OK
00164     // to create a temporary object here and delete it after the call.
00165     MemoryBufferRef MB = CompiledObjBuffer->getMemBufferRef();
00166     ObjCache->notifyObjectCompiled(M, MB);
00167   }
00168 
00169   return CompiledObjBuffer;
00170 }
00171 
00172 void MCJIT::generateCodeForModule(Module *M) {
00173   // Get a thread lock to make sure we aren't trying to load multiple times
00174   MutexGuard locked(lock);
00175 
00176   // This must be a module which has already been added to this MCJIT instance.
00177   assert(OwnedModules.ownsModule(M) &&
00178          "MCJIT::generateCodeForModule: Unknown module.");
00179 
00180   // Re-compilation is not supported
00181   if (OwnedModules.hasModuleBeenLoaded(M))
00182     return;
00183 
00184   std::unique_ptr<MemoryBuffer> ObjectToLoad;
00185   // Try to load the pre-compiled object from cache if possible
00186   if (ObjCache)
00187     ObjectToLoad = ObjCache->getObject(M);
00188 
00189   // If the cache did not contain a suitable object, compile the object
00190   if (!ObjectToLoad) {
00191     ObjectToLoad = emitObject(M);
00192     assert(ObjectToLoad && "Compilation did not produce an object.");
00193   }
00194 
00195   // Load the object into the dynamic linker.
00196   // MCJIT now owns the ObjectImage pointer (via its LoadedObjects list).
00197   ErrorOr<std::unique_ptr<object::ObjectFile>> LoadedObject =
00198     object::ObjectFile::createObjectFile(ObjectToLoad->getMemBufferRef());
00199   std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L =
00200     Dyld.loadObject(*LoadedObject.get());
00201 
00202   if (Dyld.hasError())
00203     report_fatal_error(Dyld.getErrorString());
00204 
00205   NotifyObjectEmitted(*LoadedObject.get(), *L);
00206 
00207   Buffers.push_back(std::move(ObjectToLoad));
00208   LoadedObjects.push_back(std::move(*LoadedObject));
00209 
00210   OwnedModules.markModuleAsLoaded(M);
00211 }
00212 
00213 void MCJIT::finalizeLoadedModules() {
00214   MutexGuard locked(lock);
00215 
00216   // Resolve any outstanding relocations.
00217   Dyld.resolveRelocations();
00218 
00219   OwnedModules.markAllLoadedModulesAsFinalized();
00220 
00221   // Register EH frame data for any module we own which has been loaded
00222   Dyld.registerEHFrames();
00223 
00224   // Set page permissions.
00225   MemMgr.finalizeMemory();
00226 }
00227 
00228 // FIXME: Rename this.
00229 void MCJIT::finalizeObject() {
00230   MutexGuard locked(lock);
00231 
00232   // Generate code for module is going to move objects out of the 'added' list,
00233   // so we need to copy that out before using it:
00234   SmallVector<Module*, 16> ModsToAdd;
00235   for (auto M : OwnedModules.added())
00236     ModsToAdd.push_back(M);
00237 
00238   for (auto M : ModsToAdd)
00239     generateCodeForModule(M);
00240 
00241   finalizeLoadedModules();
00242 }
00243 
00244 void MCJIT::finalizeModule(Module *M) {
00245   MutexGuard locked(lock);
00246 
00247   // This must be a module which has already been added to this MCJIT instance.
00248   assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module.");
00249 
00250   // If the module hasn't been compiled, just do that.
00251   if (!OwnedModules.hasModuleBeenLoaded(M))
00252     generateCodeForModule(M);
00253 
00254   finalizeLoadedModules();
00255 }
00256 
00257 uint64_t MCJIT::getExistingSymbolAddress(const std::string &Name) {
00258   Mangler Mang(TM->getDataLayout());
00259   SmallString<128> FullName;
00260   Mang.getNameWithPrefix(FullName, Name);
00261   return Dyld.getSymbolLoadAddress(FullName);
00262 }
00263 
00264 Module *MCJIT::findModuleForSymbol(const std::string &Name,
00265                                    bool CheckFunctionsOnly) {
00266   MutexGuard locked(lock);
00267 
00268   // If it hasn't already been generated, see if it's in one of our modules.
00269   for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
00270                               E = OwnedModules.end_added();
00271        I != E; ++I) {
00272     Module *M = *I;
00273     Function *F = M->getFunction(Name);
00274     if (F && !F->isDeclaration())
00275       return M;
00276     if (!CheckFunctionsOnly) {
00277       GlobalVariable *G = M->getGlobalVariable(Name);
00278       if (G && !G->isDeclaration())
00279         return M;
00280       // FIXME: Do we need to worry about global aliases?
00281     }
00282   }
00283   // We didn't find the symbol in any of our modules.
00284   return nullptr;
00285 }
00286 
00287 uint64_t MCJIT::getSymbolAddress(const std::string &Name,
00288                                  bool CheckFunctionsOnly)
00289 {
00290   MutexGuard locked(lock);
00291 
00292   // First, check to see if we already have this symbol.
00293   uint64_t Addr = getExistingSymbolAddress(Name);
00294   if (Addr)
00295     return Addr;
00296 
00297   for (object::OwningBinary<object::Archive> &OB : Archives) {
00298     object::Archive *A = OB.getBinary();
00299     // Look for our symbols in each Archive
00300     object::Archive::child_iterator ChildIt = A->findSym(Name);
00301     if (ChildIt != A->child_end()) {
00302       // FIXME: Support nested archives?
00303       ErrorOr<std::unique_ptr<object::Binary>> ChildBinOrErr =
00304           ChildIt->getAsBinary();
00305       if (ChildBinOrErr.getError())
00306         continue;
00307       std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
00308       if (ChildBin->isObject()) {
00309         std::unique_ptr<object::ObjectFile> OF(
00310             static_cast<object::ObjectFile *>(ChildBin.release()));
00311         // This causes the object file to be loaded.
00312         addObjectFile(std::move(OF));
00313         // The address should be here now.
00314         Addr = getExistingSymbolAddress(Name);
00315         if (Addr)
00316           return Addr;
00317       }
00318     }
00319   }
00320 
00321   // If it hasn't already been generated, see if it's in one of our modules.
00322   Module *M = findModuleForSymbol(Name, CheckFunctionsOnly);
00323   if (M) {
00324     generateCodeForModule(M);
00325 
00326     // Check the RuntimeDyld table again, it should be there now.
00327     return getExistingSymbolAddress(Name);
00328   }
00329 
00330   // If a LazyFunctionCreator is installed, use it to get/create the function.
00331   // FIXME: Should we instead have a LazySymbolCreator callback?
00332   if (LazyFunctionCreator)
00333     Addr = (uint64_t)LazyFunctionCreator(Name);
00334 
00335   return Addr;
00336 }
00337 
00338 uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
00339   MutexGuard locked(lock);
00340   uint64_t Result = getSymbolAddress(Name, false);
00341   if (Result != 0)
00342     finalizeLoadedModules();
00343   return Result;
00344 }
00345 
00346 uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
00347   MutexGuard locked(lock);
00348   uint64_t Result = getSymbolAddress(Name, true);
00349   if (Result != 0)
00350     finalizeLoadedModules();
00351   return Result;
00352 }
00353 
00354 // Deprecated.  Use getFunctionAddress instead.
00355 void *MCJIT::getPointerToFunction(Function *F) {
00356   MutexGuard locked(lock);
00357 
00358   Mangler Mang(TM->getDataLayout());
00359   SmallString<128> Name;
00360   TM->getNameWithPrefix(Name, F, Mang);
00361 
00362   if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
00363     bool AbortOnFailure = !F->hasExternalWeakLinkage();
00364     void *Addr = getPointerToNamedFunction(Name, AbortOnFailure);
00365     updateGlobalMapping(F, Addr);
00366     return Addr;
00367   }
00368 
00369   Module *M = F->getParent();
00370   bool HasBeenAddedButNotLoaded = OwnedModules.hasModuleBeenAddedButNotLoaded(M);
00371 
00372   // Make sure the relevant module has been compiled and loaded.
00373   if (HasBeenAddedButNotLoaded)
00374     generateCodeForModule(M);
00375   else if (!OwnedModules.hasModuleBeenLoaded(M)) {
00376     // If this function doesn't belong to one of our modules, we're done.
00377     // FIXME: Asking for the pointer to a function that hasn't been registered,
00378     //        and isn't a declaration (which is handled above) should probably
00379     //        be an assertion.
00380     return nullptr;
00381   }
00382 
00383   // FIXME: Should the Dyld be retaining module information? Probably not.
00384   //
00385   // This is the accessor for the target address, so make sure to check the
00386   // load address of the symbol, not the local address.
00387   return (void*)Dyld.getSymbolLoadAddress(Name);
00388 }
00389 
00390 void MCJIT::runStaticConstructorsDestructorsInModulePtrSet(
00391     bool isDtors, ModulePtrSet::iterator I, ModulePtrSet::iterator E) {
00392   for (; I != E; ++I) {
00393     ExecutionEngine::runStaticConstructorsDestructors(**I, isDtors);
00394   }
00395 }
00396 
00397 void MCJIT::runStaticConstructorsDestructors(bool isDtors) {
00398   // Execute global ctors/dtors for each module in the program.
00399   runStaticConstructorsDestructorsInModulePtrSet(
00400       isDtors, OwnedModules.begin_added(), OwnedModules.end_added());
00401   runStaticConstructorsDestructorsInModulePtrSet(
00402       isDtors, OwnedModules.begin_loaded(), OwnedModules.end_loaded());
00403   runStaticConstructorsDestructorsInModulePtrSet(
00404       isDtors, OwnedModules.begin_finalized(), OwnedModules.end_finalized());
00405 }
00406 
00407 Function *MCJIT::FindFunctionNamedInModulePtrSet(const char *FnName,
00408                                                  ModulePtrSet::iterator I,
00409                                                  ModulePtrSet::iterator E) {
00410   for (; I != E; ++I) {
00411     Function *F = (*I)->getFunction(FnName);
00412     if (F && !F->isDeclaration())
00413       return F;
00414   }
00415   return nullptr;
00416 }
00417 
00418 Function *MCJIT::FindFunctionNamed(const char *FnName) {
00419   Function *F = FindFunctionNamedInModulePtrSet(
00420       FnName, OwnedModules.begin_added(), OwnedModules.end_added());
00421   if (!F)
00422     F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_loaded(),
00423                                         OwnedModules.end_loaded());
00424   if (!F)
00425     F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_finalized(),
00426                                         OwnedModules.end_finalized());
00427   return F;
00428 }
00429 
00430 GenericValue MCJIT::runFunction(Function *F,
00431                                 const std::vector<GenericValue> &ArgValues) {
00432   assert(F && "Function *F was null at entry to run()");
00433 
00434   void *FPtr = getPointerToFunction(F);
00435   assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
00436   FunctionType *FTy = F->getFunctionType();
00437   Type *RetTy = FTy->getReturnType();
00438 
00439   assert((FTy->getNumParams() == ArgValues.size() ||
00440           (FTy->isVarArg() && FTy->getNumParams() <= ArgValues.size())) &&
00441          "Wrong number of arguments passed into function!");
00442   assert(FTy->getNumParams() == ArgValues.size() &&
00443          "This doesn't support passing arguments through varargs (yet)!");
00444 
00445   // Handle some common cases first.  These cases correspond to common `main'
00446   // prototypes.
00447   if (RetTy->isIntegerTy(32) || RetTy->isVoidTy()) {
00448     switch (ArgValues.size()) {
00449     case 3:
00450       if (FTy->getParamType(0)->isIntegerTy(32) &&
00451           FTy->getParamType(1)->isPointerTy() &&
00452           FTy->getParamType(2)->isPointerTy()) {
00453         int (*PF)(int, char **, const char **) =
00454           (int(*)(int, char **, const char **))(intptr_t)FPtr;
00455 
00456         // Call the function.
00457         GenericValue rv;
00458         rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
00459                                  (char **)GVTOP(ArgValues[1]),
00460                                  (const char **)GVTOP(ArgValues[2])));
00461         return rv;
00462       }
00463       break;
00464     case 2:
00465       if (FTy->getParamType(0)->isIntegerTy(32) &&
00466           FTy->getParamType(1)->isPointerTy()) {
00467         int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr;
00468 
00469         // Call the function.
00470         GenericValue rv;
00471         rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
00472                                  (char **)GVTOP(ArgValues[1])));
00473         return rv;
00474       }
00475       break;
00476     case 1:
00477       if (FTy->getNumParams() == 1 &&
00478           FTy->getParamType(0)->isIntegerTy(32)) {
00479         GenericValue rv;
00480         int (*PF)(int) = (int(*)(int))(intptr_t)FPtr;
00481         rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue()));
00482         return rv;
00483       }
00484       break;
00485     }
00486   }
00487 
00488   // Handle cases where no arguments are passed first.
00489   if (ArgValues.empty()) {
00490     GenericValue rv;
00491     switch (RetTy->getTypeID()) {
00492     default: llvm_unreachable("Unknown return type for function call!");
00493     case Type::IntegerTyID: {
00494       unsigned BitWidth = cast<IntegerType>(RetTy)->getBitWidth();
00495       if (BitWidth == 1)
00496         rv.IntVal = APInt(BitWidth, ((bool(*)())(intptr_t)FPtr)());
00497       else if (BitWidth <= 8)
00498         rv.IntVal = APInt(BitWidth, ((char(*)())(intptr_t)FPtr)());
00499       else if (BitWidth <= 16)
00500         rv.IntVal = APInt(BitWidth, ((short(*)())(intptr_t)FPtr)());
00501       else if (BitWidth <= 32)
00502         rv.IntVal = APInt(BitWidth, ((int(*)())(intptr_t)FPtr)());
00503       else if (BitWidth <= 64)
00504         rv.IntVal = APInt(BitWidth, ((int64_t(*)())(intptr_t)FPtr)());
00505       else
00506         llvm_unreachable("Integer types > 64 bits not supported");
00507       return rv;
00508     }
00509     case Type::VoidTyID:
00510       rv.IntVal = APInt(32, ((int(*)())(intptr_t)FPtr)());
00511       return rv;
00512     case Type::FloatTyID:
00513       rv.FloatVal = ((float(*)())(intptr_t)FPtr)();
00514       return rv;
00515     case Type::DoubleTyID:
00516       rv.DoubleVal = ((double(*)())(intptr_t)FPtr)();
00517       return rv;
00518     case Type::X86_FP80TyID:
00519     case Type::FP128TyID:
00520     case Type::PPC_FP128TyID:
00521       llvm_unreachable("long double not supported yet");
00522     case Type::PointerTyID:
00523       return PTOGV(((void*(*)())(intptr_t)FPtr)());
00524     }
00525   }
00526 
00527   llvm_unreachable("Full-featured argument passing not supported yet!");
00528 }
00529 
00530 void *MCJIT::getPointerToNamedFunction(StringRef Name, bool AbortOnFailure) {
00531   if (!isSymbolSearchingDisabled()) {
00532     void *ptr = MemMgr.getPointerToNamedFunction(Name, false);
00533     if (ptr)
00534       return ptr;
00535   }
00536 
00537   /// If a LazyFunctionCreator is installed, use it to get/create the function.
00538   if (LazyFunctionCreator)
00539     if (void *RP = LazyFunctionCreator(Name))
00540       return RP;
00541 
00542   if (AbortOnFailure) {
00543     report_fatal_error("Program used external function '"+Name+
00544                        "' which could not be resolved!");
00545   }
00546   return nullptr;
00547 }
00548 
00549 void MCJIT::RegisterJITEventListener(JITEventListener *L) {
00550   if (!L)
00551     return;
00552   MutexGuard locked(lock);
00553   EventListeners.push_back(L);
00554 }
00555 
00556 void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
00557   if (!L)
00558     return;
00559   MutexGuard locked(lock);
00560   auto I = std::find(EventListeners.rbegin(), EventListeners.rend(), L);
00561   if (I != EventListeners.rend()) {
00562     std::swap(*I, EventListeners.back());
00563     EventListeners.pop_back();
00564   }
00565 }
00566 
00567 void MCJIT::NotifyObjectEmitted(const object::ObjectFile& Obj,
00568                                 const RuntimeDyld::LoadedObjectInfo &L) {
00569   MutexGuard locked(lock);
00570   MemMgr.notifyObjectLoaded(this, Obj);
00571   for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
00572     EventListeners[I]->NotifyObjectEmitted(Obj, L);
00573   }
00574 }
00575 
00576 void MCJIT::NotifyFreeingObject(const object::ObjectFile& Obj) {
00577   MutexGuard locked(lock);
00578   for (JITEventListener *L : EventListeners)
00579     L->NotifyFreeingObject(Obj);
00580 }
00581 
00582 uint64_t LinkingMemoryManager::getSymbolAddress(const std::string &Name) {
00583   uint64_t Result = ParentEngine->getSymbolAddress(Name, false);
00584   // If the symbols wasn't found and it begins with an underscore, try again
00585   // without the underscore.
00586   if (!Result && Name[0] == '_')
00587     Result = ParentEngine->getSymbolAddress(Name.substr(1), false);
00588   if (Result)
00589     return Result;
00590   if (ParentEngine->isSymbolSearchingDisabled())
00591     return 0;
00592   return ClientMM->getSymbolAddress(Name);
00593 }