@@ -85,17 +85,34 @@ 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* llvm::orc::LLJIT by computing
89
+ // / the object offsets in the cling::Interpreter instance(IncrementalExecutor):
90
+ // / sizeof (m_Opts) + sizeof(m_LLVMContext)
91
+ // / The IncrementalJIT and JIT itself have an offset of 0 as the first datamember.
92
+ // /
93
+ // / The getExecutionEngine() interface has been added for Cling >=18 and should be used in future releases.
94
+ inline llvm::orc::LLJIT* getExecutionEngine (cling::Interpreter& I) {
95
+ #if CLANG_VERSION_MAJOR >= 18
96
+ return I.getExecutionEngine ();
97
+ #endif
92
98
93
- // sizeof (m_Opts) + sizeof(m_LLVMContext)
99
+ #if CLANG_VERSION_MAJOR == 13
100
+ #ifdef __APPLE__
101
+ const unsigned m_ExecutorOffset = 62 ;
102
+ #else
103
+ const unsigned m_ExecutorOffset = 72 ;
104
+ #endif // __APPLE__
105
+ #endif
106
+
107
+ // Note: The offsets changed in LLVM 16 with the introduction of
108
+ #if CLANG_VERSION_MAJOR == 16
94
109
#ifdef __APPLE__
95
110
const unsigned m_ExecutorOffset = 62 ;
96
111
#else
97
112
const unsigned m_ExecutorOffset = 72 ;
98
113
#endif // __APPLE__
114
+ #endif
115
+
99
116
int * IncrementalExecutor =
100
117
((int *)(const_cast <cling::Interpreter*>(&I))) + m_ExecutorOffset;
101
118
int * IncrementalJit = *(int **)IncrementalExecutor + 0 ;
@@ -104,7 +121,7 @@ inline llvm::orc::LLJIT* getExecutionEngine(const cling::Interpreter& I) {
104
121
}
105
122
106
123
inline llvm::Expected<llvm::JITTargetAddress>
107
- getSymbolAddress (const cling::Interpreter& I, llvm::StringRef IRName) {
124
+ getSymbolAddress (cling::Interpreter& I, llvm::StringRef IRName) {
108
125
if (void * Addr = I.getAddressOfGlobal (IRName))
109
126
return (llvm::JITTargetAddress)Addr;
110
127
0 commit comments