@@ -85,17 +85,36 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD,
85
85
cling::utils::Analyze::maybeMangleDeclName (GD, mangledName);
86
86
}
87
87
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
92
99
93
- // sizeof (m_Opts) + sizeof(m_LLVMContext)
100
+ # if CLANG_VERSION_MAJOR == 13
94
101
#ifdef __APPLE__
95
102
const unsigned m_ExecutorOffset = 62 ;
96
103
#else
97
104
const unsigned m_ExecutorOffset = 72 ;
98
105
#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
+
99
118
int * IncrementalExecutor =
100
119
((int *)(const_cast <cling::Interpreter*>(&I))) + m_ExecutorOffset;
101
120
int * IncrementalJit = *(int **)IncrementalExecutor + 0 ;
@@ -104,7 +123,7 @@ inline llvm::orc::LLJIT* getExecutionEngine(const cling::Interpreter& I) {
104
123
}
105
124
106
125
inline llvm::Expected<llvm::JITTargetAddress>
107
- getSymbolAddress (const cling::Interpreter& I, llvm::StringRef IRName) {
126
+ getSymbolAddress (cling::Interpreter& I, llvm::StringRef IRName) {
108
127
if (void * Addr = I.getAddressOfGlobal (IRName))
109
128
return (llvm::JITTargetAddress)Addr;
110
129
0 commit comments