| 163 | } |
| 164 | |
| 165 | void AddAbsoluteSymbol(llvm::orc::LLJIT& lljit, const std::string& name, |
| 166 | void* function_ptr) { |
| 167 | llvm::orc::MangleAndInterner mangle(lljit.getExecutionSession(), lljit.getDataLayout()); |
| 168 | |
| 169 | // https://github.com/llvm/llvm-project/commit/8b1771bd9f304be39d4dcbdcccedb6d3bcd18200#diff-77984a824d9182e5c67a481740f3bc5da78d5bd4cf6e1716a083ddb30a4a4931 |
| 170 | // LLVM 17 introduced ExecutorSymbolDef and move most of ORC APIs to ExecutorAddr |
| 171 | #if LLVM_VERSION_MAJOR >= 17 |
| 172 | llvm::orc::ExecutorSymbolDef symbol( |
| 173 | llvm::orc::ExecutorAddr(reinterpret_cast<uint64_t>(function_ptr)), |
| 174 | llvm::JITSymbolFlags::Exported); |
| 175 | #else |
| 176 | llvm::JITEvaluatedSymbol symbol(reinterpret_cast<llvm::JITTargetAddress>(function_ptr), |
| 177 | llvm::JITSymbolFlags::Exported); |
| 178 | #endif |
| 179 | |
| 180 | auto error = lljit.getMainJITDylib().define( |
| 181 | llvm::orc::absoluteSymbols({{mangle(name), symbol}})); |
| 182 | llvm::cantFail(std::move(error)); |
| 183 | } |
| 184 | |
| 185 | // add current process symbol to dylib |
| 186 | // LLVM >= 18 does this automatically |
no test coverage detected