Skip to content

Commit b912765

Browse files
committed
[interp] Register runtime symbols for clang-repl
1 parent bcde755 commit b912765

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
#include <unistd.h>
9191
#endif // WIN32
9292

93+
extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This, void* OutVal,
94+
void* OpaqueType, ...);
95+
9396
namespace Cpp {
9497

9598
using namespace clang;
@@ -3330,6 +3333,37 @@ CPPINTEROP_API JitCall MakeFunctionCallable(TCppConstFunction_t func) {
33303333
}
33313334

33323335
namespace {
3336+
#ifndef CPPINTEROP_USE_CLING
3337+
static bool DefineAbsoluteSymbol(compat::Interpreter& I,
3338+
const char* linker_mangled_name,
3339+
uint64_t address) {
3340+
using namespace llvm;
3341+
using namespace llvm::orc;
3342+
3343+
llvm::orc::LLJIT& Jit = *compat::getExecutionEngine(I);
3344+
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession();
3345+
JITDylib& DyLib = *Jit.getProcessSymbolsJITDylib().get();
3346+
3347+
llvm::orc::SymbolMap InjectedSymbols;
3348+
auto& DL = compat::getExecutionEngine(I)->getDataLayout();
3349+
char GlobalPrefix = DL.getGlobalPrefix();
3350+
std::string tmp(linker_mangled_name);
3351+
if (GlobalPrefix != '\0') {
3352+
tmp = std::string(1, GlobalPrefix) + tmp;
3353+
}
3354+
auto Name = ES.intern(tmp);
3355+
InjectedSymbols[Name] =
3356+
ExecutorSymbolDef(ExecutorAddr(address), JITSymbolFlags::Exported);
3357+
3358+
if (Error Err = DyLib.define(absoluteSymbols(InjectedSymbols))) {
3359+
logAllUnhandledErrors(std::move(Err), errs(),
3360+
"DefineAbsoluteSymbol error: ");
3361+
return true;
3362+
}
3363+
return false;
3364+
}
3365+
#endif
3366+
33333367
static std::string MakeResourcesPath() {
33343368
StringRef Dir;
33353369
#ifdef LLVM_BINARY_DIR
@@ -3442,6 +3476,11 @@ TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/,
34423476
sInterpreters->back().get()});
34433477

34443478
assert(sInterpreters->size() == sInterpreterASTMap->size());
3479+
// define __clang_Interpreter_SetValueNoAlloc in the JIT dylib for clang-repl
3480+
#ifndef CPPINTEROP_USE_CLING
3481+
DefineAbsoluteSymbol(*I, "__clang_Interpreter_SetValueNoAlloc",
3482+
(uint64_t)&__clang_Interpreter_SetValueNoAlloc);
3483+
#endif
34453484
return I;
34463485
}
34473486

0 commit comments

Comments
 (0)