|
86 | 86 | #include <unistd.h> |
87 | 87 | #endif // WIN32 |
88 | 88 |
|
| 89 | +extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This, void* OutVal, |
| 90 | + void* OpaqueType, ...); |
| 91 | + |
89 | 92 | namespace Cpp { |
90 | 93 |
|
91 | 94 | using namespace clang; |
@@ -3169,6 +3172,37 @@ CPPINTEROP_API JitCall MakeFunctionCallable(TCppConstFunction_t func) { |
3169 | 3172 | } |
3170 | 3173 |
|
3171 | 3174 | 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 | + |
3172 | 3206 | static std::string MakeResourcesPath() { |
3173 | 3207 | StringRef Dir; |
3174 | 3208 | #ifdef LLVM_BINARY_DIR |
@@ -3273,6 +3307,12 @@ TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/, |
3273 | 3307 |
|
3274 | 3308 | sInterpreters->emplace_back(I, /*Owned=*/true); |
3275 | 3309 |
|
| 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 | + |
3276 | 3316 | return I; |
3277 | 3317 | } |
3278 | 3318 |
|
|
0 commit comments