MCJIT.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. //===-- MCJIT.cpp - MC-based Just-in-Time Compiler ------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "MCJIT.h"
  10. #include "llvm/ExecutionEngine/GenericValue.h"
  11. #include "llvm/ExecutionEngine/JITEventListener.h"
  12. #include "llvm/ExecutionEngine/JITMemoryManager.h"
  13. #include "llvm/ExecutionEngine/MCJIT.h"
  14. #include "llvm/ExecutionEngine/ObjectBuffer.h"
  15. #include "llvm/ExecutionEngine/ObjectImage.h"
  16. #include "llvm/ExecutionEngine/SectionMemoryManager.h"
  17. #include "llvm/IR/DataLayout.h"
  18. #include "llvm/IR/DerivedTypes.h"
  19. #include "llvm/IR/Function.h"
  20. #include "llvm/IR/Mangler.h"
  21. #include "llvm/IR/Module.h"
  22. #include "llvm/MC/MCAsmInfo.h"
  23. #include "llvm/Object/Archive.h"
  24. #include "llvm/PassManager.h"
  25. #include "llvm/Support/DynamicLibrary.h"
  26. #include "llvm/Support/ErrorHandling.h"
  27. #include "llvm/Support/MemoryBuffer.h"
  28. #include "llvm/Support/MutexGuard.h"
  29. #include "llvm/Target/TargetLowering.h"
  30. #include "llvm/Target/TargetSubtargetInfo.h"
  31. using namespace llvm;
  32. namespace {
  33. static struct RegisterJIT {
  34. RegisterJIT() { MCJIT::Register(); }
  35. } JITRegistrator;
  36. }
  37. extern "C" void LLVMLinkInMCJIT() {
  38. }
  39. ExecutionEngine *MCJIT::createJIT(Module *M,
  40. std::string *ErrorStr,
  41. RTDyldMemoryManager *MemMgr,
  42. TargetMachine *TM) {
  43. // Try to register the program as a source of symbols to resolve against.
  44. //
  45. // FIXME: Don't do this here.
  46. sys::DynamicLibrary::LoadLibraryPermanently(nullptr, nullptr);
  47. return new MCJIT(M, TM, MemMgr ? MemMgr : new SectionMemoryManager());
  48. }
  49. MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM)
  50. : ExecutionEngine(m), TM(tm), Ctx(nullptr), MemMgr(this, MM), Dyld(&MemMgr),
  51. ObjCache(nullptr) {
  52. OwnedModules.addModule(m);
  53. setDataLayout(TM->getSubtargetImpl()->getDataLayout());
  54. }
  55. MCJIT::~MCJIT() {
  56. MutexGuard locked(lock);
  57. // FIXME: We are managing our modules, so we do not want the base class
  58. // ExecutionEngine to manage them as well. To avoid double destruction
  59. // of the first (and only) module added in ExecutionEngine constructor
  60. // we remove it from EE and will destruct it ourselves.
  61. //
  62. // It may make sense to move our module manager (based on SmallStPtr) back
  63. // into EE if the JIT and Interpreter can live with it.
  64. // If so, additional functions: addModule, removeModule, FindFunctionNamed,
  65. // runStaticConstructorsDestructors could be moved back to EE as well.
  66. //
  67. Modules.clear();
  68. Dyld.deregisterEHFrames();
  69. LoadedObjectList::iterator it, end;
  70. for (it = LoadedObjects.begin(), end = LoadedObjects.end(); it != end; ++it) {
  71. ObjectImage *Obj = *it;
  72. if (Obj) {
  73. NotifyFreeingObject(*Obj);
  74. delete Obj;
  75. }
  76. }
  77. LoadedObjects.clear();
  78. Archives.clear();
  79. delete TM;
  80. }
  81. void MCJIT::addModule(Module *M) {
  82. MutexGuard locked(lock);
  83. OwnedModules.addModule(M);
  84. }
  85. bool MCJIT::removeModule(Module *M) {
  86. MutexGuard locked(lock);
  87. return OwnedModules.removeModule(M);
  88. }
  89. void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) {
  90. ObjectImage *LoadedObject = Dyld.loadObject(std::move(Obj));
  91. if (!LoadedObject || Dyld.hasError())
  92. report_fatal_error(Dyld.getErrorString());
  93. LoadedObjects.push_back(LoadedObject);
  94. NotifyObjectEmitted(*LoadedObject);
  95. }
  96. void MCJIT::addArchive(std::unique_ptr<object::Archive> A) {
  97. Archives.push_back(std::move(A));
  98. }
  99. void MCJIT::setObjectCache(ObjectCache* NewCache) {
  100. MutexGuard locked(lock);
  101. ObjCache = NewCache;
  102. }
  103. ObjectBufferStream* MCJIT::emitObject(Module *M) {
  104. MutexGuard locked(lock);
  105. // This must be a module which has already been added but not loaded to this
  106. // MCJIT instance, since these conditions are tested by our caller,
  107. // generateCodeForModule.
  108. PassManager PM;
  109. M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
  110. PM.add(new DataLayoutPass(M));
  111. // The RuntimeDyld will take ownership of this shortly
  112. std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
  113. // Turn the machine code intermediate representation into bytes in memory
  114. // that may be executed.
  115. if (TM->addPassesToEmitMC(PM, Ctx, CompiledObject->getOStream(),
  116. !getVerifyModules())) {
  117. report_fatal_error("Target does not support MC emission!");
  118. }
  119. // Initialize passes.
  120. PM.run(*M);
  121. // Flush the output buffer to get the generated code into memory
  122. CompiledObject->flush();
  123. // If we have an object cache, tell it about the new object.
  124. // Note that we're using the compiled image, not the loaded image (as below).
  125. if (ObjCache) {
  126. // MemoryBuffer is a thin wrapper around the actual memory, so it's OK
  127. // to create a temporary object here and delete it after the call.
  128. std::unique_ptr<MemoryBuffer> MB(CompiledObject->getMemBuffer());
  129. ObjCache->notifyObjectCompiled(M, MB.get());
  130. }
  131. return CompiledObject.release();
  132. }
  133. void MCJIT::generateCodeForModule(Module *M) {
  134. // Get a thread lock to make sure we aren't trying to load multiple times
  135. MutexGuard locked(lock);
  136. // This must be a module which has already been added to this MCJIT instance.
  137. assert(OwnedModules.ownsModule(M) &&
  138. "MCJIT::generateCodeForModule: Unknown module.");
  139. // Re-compilation is not supported
  140. if (OwnedModules.hasModuleBeenLoaded(M))
  141. return;
  142. std::unique_ptr<ObjectBuffer> ObjectToLoad;
  143. // Try to load the pre-compiled object from cache if possible
  144. if (ObjCache) {
  145. std::unique_ptr<MemoryBuffer> PreCompiledObject(ObjCache->getObject(M));
  146. if (PreCompiledObject.get())
  147. ObjectToLoad.reset(new ObjectBuffer(PreCompiledObject.release()));
  148. }
  149. // If the cache did not contain a suitable object, compile the object
  150. if (!ObjectToLoad) {
  151. ObjectToLoad.reset(emitObject(M));
  152. assert(ObjectToLoad.get() && "Compilation did not produce an object.");
  153. }
  154. // Load the object into the dynamic linker.
  155. // MCJIT now owns the ObjectImage pointer (via its LoadedObjects list).
  156. ObjectImage *LoadedObject = Dyld.loadObject(ObjectToLoad.release());
  157. LoadedObjects.push_back(LoadedObject);
  158. if (!LoadedObject)
  159. report_fatal_error(Dyld.getErrorString());
  160. // FIXME: Make this optional, maybe even move it to a JIT event listener
  161. LoadedObject->registerWithDebugger();
  162. NotifyObjectEmitted(*LoadedObject);
  163. OwnedModules.markModuleAsLoaded(M);
  164. }
  165. void MCJIT::finalizeLoadedModules() {
  166. MutexGuard locked(lock);
  167. // Resolve any outstanding relocations.
  168. Dyld.resolveRelocations();
  169. OwnedModules.markAllLoadedModulesAsFinalized();
  170. // Register EH frame data for any module we own which has been loaded
  171. Dyld.registerEHFrames();
  172. // Set page permissions.
  173. MemMgr.finalizeMemory();
  174. }
  175. // FIXME: Rename this.
  176. void MCJIT::finalizeObject() {
  177. MutexGuard locked(lock);
  178. for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
  179. E = OwnedModules.end_added();
  180. I != E; ++I) {
  181. Module *M = *I;
  182. generateCodeForModule(M);
  183. }
  184. finalizeLoadedModules();
  185. }
  186. void MCJIT::finalizeModule(Module *M) {
  187. MutexGuard locked(lock);
  188. // This must be a module which has already been added to this MCJIT instance.
  189. assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module.");
  190. // If the module hasn't been compiled, just do that.
  191. if (!OwnedModules.hasModuleBeenLoaded(M))
  192. generateCodeForModule(M);
  193. finalizeLoadedModules();
  194. }
  195. void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) {
  196. report_fatal_error("not yet implemented");
  197. }
  198. uint64_t MCJIT::getExistingSymbolAddress(const std::string &Name) {
  199. Mangler Mang(TM->getSubtargetImpl()->getDataLayout());
  200. SmallString<128> FullName;
  201. Mang.getNameWithPrefix(FullName, Name);
  202. return Dyld.getSymbolLoadAddress(FullName);
  203. }
  204. Module *MCJIT::findModuleForSymbol(const std::string &Name,
  205. bool CheckFunctionsOnly) {
  206. MutexGuard locked(lock);
  207. // If it hasn't already been generated, see if it's in one of our modules.
  208. for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
  209. E = OwnedModules.end_added();
  210. I != E; ++I) {
  211. Module *M = *I;
  212. Function *F = M->getFunction(Name);
  213. if (F && !F->isDeclaration())
  214. return M;
  215. if (!CheckFunctionsOnly) {
  216. GlobalVariable *G = M->getGlobalVariable(Name);
  217. if (G && !G->isDeclaration())
  218. return M;
  219. // FIXME: Do we need to worry about global aliases?
  220. }
  221. }
  222. // We didn't find the symbol in any of our modules.
  223. return nullptr;
  224. }
  225. uint64_t MCJIT::getSymbolAddress(const std::string &Name,
  226. bool CheckFunctionsOnly)
  227. {
  228. MutexGuard locked(lock);
  229. // First, check to see if we already have this symbol.
  230. uint64_t Addr = getExistingSymbolAddress(Name);
  231. if (Addr)
  232. return Addr;
  233. for (std::unique_ptr<object::Archive> &A : Archives) {
  234. // Look for our symbols in each Archive
  235. object::Archive::child_iterator ChildIt = A->findSym(Name);
  236. if (ChildIt != A->child_end()) {
  237. // FIXME: Support nested archives?
  238. ErrorOr<std::unique_ptr<object::Binary>> ChildBinOrErr =
  239. ChildIt->getAsBinary();
  240. if (ChildBinOrErr.getError())
  241. continue;
  242. std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
  243. if (ChildBin->isObject()) {
  244. std::unique_ptr<object::ObjectFile> OF(
  245. static_cast<object::ObjectFile *>(ChildBin.release()));
  246. // This causes the object file to be loaded.
  247. addObjectFile(std::move(OF));
  248. // The address should be here now.
  249. Addr = getExistingSymbolAddress(Name);
  250. if (Addr)
  251. return Addr;
  252. }
  253. }
  254. }
  255. // If it hasn't already been generated, see if it's in one of our modules.
  256. Module *M = findModuleForSymbol(Name, CheckFunctionsOnly);
  257. if (!M)
  258. return 0;
  259. generateCodeForModule(M);
  260. // Check the RuntimeDyld table again, it should be there now.
  261. return getExistingSymbolAddress(Name);
  262. }
  263. uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
  264. MutexGuard locked(lock);
  265. uint64_t Result = getSymbolAddress(Name, false);
  266. if (Result != 0)
  267. finalizeLoadedModules();
  268. return Result;
  269. }
  270. uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
  271. MutexGuard locked(lock);
  272. uint64_t Result = getSymbolAddress(Name, true);
  273. if (Result != 0)
  274. finalizeLoadedModules();
  275. return Result;
  276. }
  277. // Deprecated. Use getFunctionAddress instead.
  278. void *MCJIT::getPointerToFunction(Function *F) {
  279. MutexGuard locked(lock);
  280. if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
  281. bool AbortOnFailure = !F->hasExternalWeakLinkage();
  282. void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure);
  283. addGlobalMapping(F, Addr);
  284. return Addr;
  285. }
  286. Module *M = F->getParent();
  287. bool HasBeenAddedButNotLoaded = OwnedModules.hasModuleBeenAddedButNotLoaded(M);
  288. // Make sure the relevant module has been compiled and loaded.
  289. if (HasBeenAddedButNotLoaded)
  290. generateCodeForModule(M);
  291. else if (!OwnedModules.hasModuleBeenLoaded(M))
  292. // If this function doesn't belong to one of our modules, we're done.
  293. return nullptr;
  294. // FIXME: Should the Dyld be retaining module information? Probably not.
  295. //
  296. // This is the accessor for the target address, so make sure to check the
  297. // load address of the symbol, not the local address.
  298. Mangler Mang(TM->getSubtargetImpl()->getDataLayout());
  299. SmallString<128> Name;
  300. TM->getNameWithPrefix(Name, F, Mang);
  301. return (void*)Dyld.getSymbolLoadAddress(Name);
  302. }
  303. void *MCJIT::recompileAndRelinkFunction(Function *F) {
  304. report_fatal_error("not yet implemented");
  305. }
  306. void MCJIT::freeMachineCodeForFunction(Function *F) {
  307. report_fatal_error("not yet implemented");
  308. }
  309. void MCJIT::runStaticConstructorsDestructorsInModulePtrSet(
  310. bool isDtors, ModulePtrSet::iterator I, ModulePtrSet::iterator E) {
  311. for (; I != E; ++I) {
  312. ExecutionEngine::runStaticConstructorsDestructors(*I, isDtors);
  313. }
  314. }
  315. void MCJIT::runStaticConstructorsDestructors(bool isDtors) {
  316. // Execute global ctors/dtors for each module in the program.
  317. runStaticConstructorsDestructorsInModulePtrSet(
  318. isDtors, OwnedModules.begin_added(), OwnedModules.end_added());
  319. runStaticConstructorsDestructorsInModulePtrSet(
  320. isDtors, OwnedModules.begin_loaded(), OwnedModules.end_loaded());
  321. runStaticConstructorsDestructorsInModulePtrSet(
  322. isDtors, OwnedModules.begin_finalized(), OwnedModules.end_finalized());
  323. }
  324. Function *MCJIT::FindFunctionNamedInModulePtrSet(const char *FnName,
  325. ModulePtrSet::iterator I,
  326. ModulePtrSet::iterator E) {
  327. for (; I != E; ++I) {
  328. if (Function *F = (*I)->getFunction(FnName))
  329. return F;
  330. }
  331. return nullptr;
  332. }
  333. Function *MCJIT::FindFunctionNamed(const char *FnName) {
  334. Function *F = FindFunctionNamedInModulePtrSet(
  335. FnName, OwnedModules.begin_added(), OwnedModules.end_added());
  336. if (!F)
  337. F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_loaded(),
  338. OwnedModules.end_loaded());
  339. if (!F)
  340. F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_finalized(),
  341. OwnedModules.end_finalized());
  342. return F;
  343. }
  344. GenericValue MCJIT::runFunction(Function *F,
  345. const std::vector<GenericValue> &ArgValues) {
  346. assert(F && "Function *F was null at entry to run()");
  347. void *FPtr = getPointerToFunction(F);
  348. assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
  349. FunctionType *FTy = F->getFunctionType();
  350. Type *RetTy = FTy->getReturnType();
  351. assert((FTy->getNumParams() == ArgValues.size() ||
  352. (FTy->isVarArg() && FTy->getNumParams() <= ArgValues.size())) &&
  353. "Wrong number of arguments passed into function!");
  354. assert(FTy->getNumParams() == ArgValues.size() &&
  355. "This doesn't support passing arguments through varargs (yet)!");
  356. // Handle some common cases first. These cases correspond to common `main'
  357. // prototypes.
  358. if (RetTy->isIntegerTy(32) || RetTy->isVoidTy()) {
  359. switch (ArgValues.size()) {
  360. case 3:
  361. if (FTy->getParamType(0)->isIntegerTy(32) &&
  362. FTy->getParamType(1)->isPointerTy() &&
  363. FTy->getParamType(2)->isPointerTy()) {
  364. int (*PF)(int, char **, const char **) =
  365. (int(*)(int, char **, const char **))(intptr_t)FPtr;
  366. // Call the function.
  367. GenericValue rv;
  368. rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
  369. (char **)GVTOP(ArgValues[1]),
  370. (const char **)GVTOP(ArgValues[2])));
  371. return rv;
  372. }
  373. break;
  374. case 2:
  375. if (FTy->getParamType(0)->isIntegerTy(32) &&
  376. FTy->getParamType(1)->isPointerTy()) {
  377. int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr;
  378. // Call the function.
  379. GenericValue rv;
  380. rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
  381. (char **)GVTOP(ArgValues[1])));
  382. return rv;
  383. }
  384. break;
  385. case 1:
  386. if (FTy->getNumParams() == 1 &&
  387. FTy->getParamType(0)->isIntegerTy(32)) {
  388. GenericValue rv;
  389. int (*PF)(int) = (int(*)(int))(intptr_t)FPtr;
  390. rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue()));
  391. return rv;
  392. }
  393. break;
  394. }
  395. }
  396. // Handle cases where no arguments are passed first.
  397. if (ArgValues.empty()) {
  398. GenericValue rv;
  399. switch (RetTy->getTypeID()) {
  400. default: llvm_unreachable("Unknown return type for function call!");
  401. case Type::IntegerTyID: {
  402. unsigned BitWidth = cast<IntegerType>(RetTy)->getBitWidth();
  403. if (BitWidth == 1)
  404. rv.IntVal = APInt(BitWidth, ((bool(*)())(intptr_t)FPtr)());
  405. else if (BitWidth <= 8)
  406. rv.IntVal = APInt(BitWidth, ((char(*)())(intptr_t)FPtr)());
  407. else if (BitWidth <= 16)
  408. rv.IntVal = APInt(BitWidth, ((short(*)())(intptr_t)FPtr)());
  409. else if (BitWidth <= 32)
  410. rv.IntVal = APInt(BitWidth, ((int(*)())(intptr_t)FPtr)());
  411. else if (BitWidth <= 64)
  412. rv.IntVal = APInt(BitWidth, ((int64_t(*)())(intptr_t)FPtr)());
  413. else
  414. llvm_unreachable("Integer types > 64 bits not supported");
  415. return rv;
  416. }
  417. case Type::VoidTyID:
  418. rv.IntVal = APInt(32, ((int(*)())(intptr_t)FPtr)());
  419. return rv;
  420. case Type::FloatTyID:
  421. rv.FloatVal = ((float(*)())(intptr_t)FPtr)();
  422. return rv;
  423. case Type::DoubleTyID:
  424. rv.DoubleVal = ((double(*)())(intptr_t)FPtr)();
  425. return rv;
  426. case Type::X86_FP80TyID:
  427. case Type::FP128TyID:
  428. case Type::PPC_FP128TyID:
  429. llvm_unreachable("long double not supported yet");
  430. case Type::PointerTyID:
  431. return PTOGV(((void*(*)())(intptr_t)FPtr)());
  432. }
  433. }
  434. llvm_unreachable("Full-featured argument passing not supported yet!");
  435. }
  436. void *MCJIT::getPointerToNamedFunction(const std::string &Name,
  437. bool AbortOnFailure) {
  438. if (!isSymbolSearchingDisabled()) {
  439. void *ptr = MemMgr.getPointerToNamedFunction(Name, false);
  440. if (ptr)
  441. return ptr;
  442. }
  443. /// If a LazyFunctionCreator is installed, use it to get/create the function.
  444. if (LazyFunctionCreator)
  445. if (void *RP = LazyFunctionCreator(Name))
  446. return RP;
  447. if (AbortOnFailure) {
  448. report_fatal_error("Program used external function '"+Name+
  449. "' which could not be resolved!");
  450. }
  451. return nullptr;
  452. }
  453. void MCJIT::RegisterJITEventListener(JITEventListener *L) {
  454. if (!L)
  455. return;
  456. MutexGuard locked(lock);
  457. EventListeners.push_back(L);
  458. }
  459. void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
  460. if (!L)
  461. return;
  462. MutexGuard locked(lock);
  463. SmallVector<JITEventListener*, 2>::reverse_iterator I=
  464. std::find(EventListeners.rbegin(), EventListeners.rend(), L);
  465. if (I != EventListeners.rend()) {
  466. std::swap(*I, EventListeners.back());
  467. EventListeners.pop_back();
  468. }
  469. }
  470. void MCJIT::NotifyObjectEmitted(const ObjectImage& Obj) {
  471. MutexGuard locked(lock);
  472. MemMgr.notifyObjectLoaded(this, &Obj);
  473. for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
  474. EventListeners[I]->NotifyObjectEmitted(Obj);
  475. }
  476. }
  477. void MCJIT::NotifyFreeingObject(const ObjectImage& Obj) {
  478. MutexGuard locked(lock);
  479. for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
  480. EventListeners[I]->NotifyFreeingObject(Obj);
  481. }
  482. }
  483. uint64_t LinkingMemoryManager::getSymbolAddress(const std::string &Name) {
  484. uint64_t Result = ParentEngine->getSymbolAddress(Name, false);
  485. // If the symbols wasn't found and it begins with an underscore, try again
  486. // without the underscore.
  487. if (!Result && Name[0] == '_')
  488. Result = ParentEngine->getSymbolAddress(Name.substr(1), false);
  489. if (Result)
  490. return Result;
  491. return ClientMM->getSymbolAddress(Name);
  492. }