Skip to content

Commit af3c606

Browse files
committed
[interp] Register runtime symbols for clang-repl
1 parent 5f25366 commit af3c606

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
#include <unistd.h>
8787
#endif // WIN32
8888

89+
extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This, void* OutVal,
90+
void* OpaqueType, ...);
91+
8992
namespace Cpp {
9093

9194
using namespace clang;
@@ -3169,6 +3172,37 @@ CPPINTEROP_API JitCall MakeFunctionCallable(TCppConstFunction_t func) {
31693172
}
31703173

31713174
namespace {
3175+
#ifndef CPPINTEROP_USE_CLING
3176+
static bool DefineAbsoluteSymbol(compat::Interpreter& I,
3177+
const char* linker_mangled_name,
3178+
uint64_t address) {
3179+
using namespace llvm;
3180+
using namespace llvm::orc;
3181+
3182+
llvm::orc::LLJIT& Jit = *compat::getExecutionEngine(I);
3183+
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession();
3184+
JITDylib& DyLib = *Jit.getProcessSymbolsJITDylib().get();
3185+
3186+
llvm::orc::SymbolMap InjectedSymbols;
3187+
auto& DL = compat::getExecutionEngine(I)->getDataLayout();
3188+
char GlobalPrefix = DL.getGlobalPrefix();
3189+
std::string tmp(linker_mangled_name);
3190+
if (GlobalPrefix != '\0') {
3191+
tmp = std::string(1, GlobalPrefix) + tmp;
3192+
}
3193+
auto Name = ES.intern(tmp);
3194+
InjectedSymbols[Name] =
3195+
ExecutorSymbolDef(ExecutorAddr(address), JITSymbolFlags::Exported);
3196+
3197+
if (Error Err = DyLib.define(absoluteSymbols(InjectedSymbols))) {
3198+
logAllUnhandledErrors(std::move(Err), errs(),
3199+
"DefineAbsoluteSymbol error: ");
3200+
return true;
3201+
}
3202+
return false;
3203+
}
3204+
#endif
3205+
31723206
static std::string MakeResourcesPath() {
31733207
StringRef Dir;
31743208
#ifdef LLVM_BINARY_DIR
@@ -3273,6 +3307,12 @@ TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/,
32733307

32743308
sInterpreters->emplace_back(I, /*Owned=*/true);
32753309

3310+
// define __clang_Interpreter_SetValueNoAlloc in the JIT dylib for clang-repl
3311+
#ifndef CPPINTEROP_USE_CLING
3312+
DefineAbsoluteSymbol(*I, "__clang_Interpreter_SetValueNoAlloc",
3313+
(uint64_t)&__clang_Interpreter_SetValueNoAlloc);
3314+
#endif
3315+
32763316
return I;
32773317
}
32783318

0 commit comments

Comments
 (0)