Skip to content

Commit 546fcb5

Browse files
committed
Add static DefineAbsoluteSymbol to define injected symbols
1 parent dbf6317 commit 546fcb5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,29 @@ CPPINTEROP_API JitCall MakeFunctionCallable(TCppConstFunction_t func) {
31753175
}
31763176

31773177
namespace {
3178+
#if !defined(CPPINTEROP_USE_CLING) && !defined(EMSCRIPTEN)
3179+
bool DefineAbsoluteSymbol(compat::Interpreter& I,
3180+
const char* linker_mangled_name, uint64_t address) {
3181+
using namespace llvm;
3182+
using namespace llvm::orc;
3183+
3184+
llvm::orc::LLJIT& Jit = *compat::getExecutionEngine(I);
3185+
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession();
3186+
JITDylib& DyLib = *Jit.getProcessSymbolsJITDylib().get();
3187+
3188+
llvm::orc::SymbolMap InjectedSymbols{
3189+
{ES.intern(linker_mangled_name),
3190+
ExecutorSymbolDef(ExecutorAddr(address), JITSymbolFlags::Exported)}};
3191+
3192+
if (Error Err = DyLib.define(absoluteSymbols(InjectedSymbols))) {
3193+
logAllUnhandledErrors(std::move(Err), errs(),
3194+
"DefineAbsoluteSymbol error: ");
3195+
return true;
3196+
}
3197+
return false;
3198+
}
3199+
#endif
3200+
31783201
static std::string MakeResourcesPath() {
31793202
StringRef Dir;
31803203
#ifdef LLVM_BINARY_DIR

0 commit comments

Comments
 (0)