@@ -85,17 +85,36 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD,
8585 cling::utils::Analyze::maybeMangleDeclName (GD, mangledName);
8686}
8787
88- inline llvm::orc::LLJIT* getExecutionEngine (const cling::Interpreter& I) {
89- // FIXME: This is a horrible hack finding the llvm::orc::LLJIT by computing
90- // the object offsets in Cling. We should add getExecutionEngine interface
91- // to directly.
88+ // / For Cling <= LLVM 16, this is a horrible hack obtaining the private
89+ // / llvm::orc::LLJIT by computing the object offsets in the cling::Interpreter
90+ // / instance(IncrementalExecutor): sizeof (m_Opts) + sizeof(m_LLVMContext). The
91+ // / IncrementalJIT and JIT itself have an offset of 0 as the first datamember.
92+ // /
93+ // / The getExecutionEngine() interface has been added for Cling based on LLVM
94+ // / >=18 and should be used in future releases.
95+ inline llvm::orc::LLJIT* getExecutionEngine (cling::Interpreter& I) {
96+ #if CLANG_VERSION_MAJOR >= 18
97+ return I.getExecutionEngine ();
98+ #endif
9299
93- // sizeof (m_Opts) + sizeof(m_LLVMContext)
100+ # if CLANG_VERSION_MAJOR == 13
94101#ifdef __APPLE__
95102 const unsigned m_ExecutorOffset = 62 ;
96103#else
97104 const unsigned m_ExecutorOffset = 72 ;
98105#endif // __APPLE__
106+ #endif
107+
108+ // Note: The offsets changed in Cling based on LLVM 16 with the introduction of
109+ // a thread safe context - llvm::orc::ThreadSafeContext
110+ #if CLANG_VERSION_MAJOR == 16
111+ #ifdef __APPLE__
112+ const unsigned m_ExecutorOffset = 68 ;
113+ #else
114+ const unsigned m_ExecutorOffset = 78 ;
115+ #endif // __APPLE__
116+ #endif
117+
99118 int * IncrementalExecutor =
100119 ((int *)(const_cast <cling::Interpreter*>(&I))) + m_ExecutorOffset;
101120 int * IncrementalJit = *(int **)IncrementalExecutor + 0 ;
@@ -104,7 +123,7 @@ inline llvm::orc::LLJIT* getExecutionEngine(const cling::Interpreter& I) {
104123}
105124
106125inline llvm::Expected<llvm::JITTargetAddress>
107- getSymbolAddress (const cling::Interpreter& I, llvm::StringRef IRName) {
126+ getSymbolAddress (cling::Interpreter& I, llvm::StringRef IRName) {
108127 if (void * Addr = I.getAddressOfGlobal (IRName))
109128 return (llvm::JITTargetAddress)Addr;
110129
0 commit comments