Skip to content

Commit b449a4c

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

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#include "llvm/ADT/SmallVector.h"
4949
#include "llvm/ADT/StringRef.h"
5050
#include "llvm/Demangle/Demangle.h"
51+
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
52+
#include "llvm/ExecutionEngine/Orc/Core.h"
53+
#include "llvm/ExecutionEngine/Orc/CoreContainers.h"
5154
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
5255
#include "llvm/IR/GlobalValue.h"
5356
#include "llvm/Support/Casting.h"
@@ -3175,6 +3178,29 @@ CPPINTEROP_API JitCall MakeFunctionCallable(TCppConstFunction_t func) {
31753178
}
31763179

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

0 commit comments

Comments
 (0)