llvm.org GIT mirror llvm / 017f7df
Revert r333147 "[ORC] Add findSymbolIn() wrapper to C bindings." This reverts r333147 until https://reviews.llvm.org/D47308 is ready to be reviewed. r333147 exposed a behavioural difference between OrcCBindingsStack::findSymbolIn() and OrcCBindingsStack::findSymbol(), where only the latter does name mangling. After r333147 that causes a test failure on OSX, because the new test looks for main using findSymbolIn() but the mangled name is _main. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333152 91177308-0d34-0410-b5e6-96231b3b80d8 Andres Freund 1 year, 3 months ago
4 changed file(s) with 6 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
140140 const char *SymbolName);
141141
142142 /**
143 * Get symbol address from JIT instance, searching only the specified
144 * handle.
145 */
146 LLVMOrcErrorCode LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
147 LLVMOrcTargetAddress *RetAddr,
148 LLVMOrcModuleHandle H,
149 const char *SymbolName);
150
151 /**
152143 * Dispose of an ORC JIT stack.
153144 */
154145 LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
111111 return J.findSymbolAddress(*RetAddr, SymbolName, true);
112112 }
113113
114 LLVMOrcErrorCode LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
115 LLVMOrcTargetAddress *RetAddr,
116 LLVMOrcModuleHandle H,
117 const char *SymbolName) {
118 OrcCBindingsStack &J = *unwrap(JITStack);
119 return J.findSymbolAddressIn(*RetAddr, H, SymbolName, true);
120 }
121
122114 LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack) {
123115 auto *J = unwrap(JITStack);
124116 auto Err = J->shutdown();
379379
380380 JITSymbol findSymbolIn(orc::VModuleKey K, const std::string &Name,
381381 bool ExportedSymbolsOnly) {
382 assert(KeyLayers.count(K) && "looking up symbol in unknown module");
383382 return KeyLayers[K]->findSymbolIn(K, Name, ExportedSymbolsOnly);
384383 }
385384
403402 return LLVMOrcErrSuccess;
404403 }
405404
406 LLVMOrcErrorCode findSymbolAddressIn(JITTargetAddress &RetAddr,
407 orc::VModuleKey K,
408 const std::string &Name,
409 bool ExportedSymbolsOnly) {
410 RetAddr = 0;
411 if (auto Sym = findSymbolIn(K, Name, ExportedSymbolsOnly)) {
412 // Successful lookup, non-null symbol:
413 if (auto AddrOrErr = Sym.getAddress()) {
414 RetAddr = *AddrOrErr;
415 return LLVMOrcErrSuccess;
416 } else
417 return mapError(AddrOrErr.takeError());
418 } else if (auto Err = Sym.takeError()) {
419 // Lookup failure - report error.
420 return mapError(std::move(Err));
421 }
422 // Otherwise we had a successful lookup but got a null result. We already
423 // set RetAddr to '0' above, so just return success.
424 return LLVMOrcErrSuccess;
425 }
426
427405 const std::string &getErrorMessage() const { return ErrMsg; }
428406
429407 private:
9797
9898 LLVMOrcModuleHandle H;
9999 LLVMOrcAddEagerlyCompiledIR(JIT, &H, wrap(M.release()), myResolver, nullptr);
100
101 // get symbol address searching the entire stack
102 {
103 LLVMOrcTargetAddress MainAddr;
104 LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
105 MainFnTy MainFn = (MainFnTy)MainAddr;
106 int Result = MainFn();
107 EXPECT_EQ(Result, 42)
108 << "Eagerly JIT'd code did not return expected result";
109 }
110
111 // and then just searching a single handle
112 {
113 LLVMOrcTargetAddress MainAddr;
114 LLVMOrcGetSymbolAddressIn(JIT, &MainAddr, H, "main");
115 MainFnTy MainFn = (MainFnTy)MainAddr;
116 int Result = MainFn();
117 EXPECT_EQ(Result, 42)
118 << "Eagerly JIT'd code did not return expected result";
119 }
100 LLVMOrcTargetAddress MainAddr;
101 LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
102 MainFnTy MainFn = (MainFnTy)MainAddr;
103 int Result = MainFn();
104 EXPECT_EQ(Result, 42)
105 << "Eagerly JIT'd code did not return expected result";
120106
121107 LLVMOrcRemoveModule(JIT, H);
122108