diff options
-rw-r--r-- | llvm/include/llvm/ExecutionEngine/JITSymbol.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/JITSymbol.h b/llvm/include/llvm/ExecutionEngine/JITSymbol.h index c0f1ca4b987..7a2a6cfa520 100644 --- a/llvm/include/llvm/ExecutionEngine/JITSymbol.h +++ b/llvm/include/llvm/ExecutionEngine/JITSymbol.h @@ -41,6 +41,11 @@ class SymbolRef; using JITTargetAddress = uint64_t; /// Convert a JITTargetAddress to a pointer. +/// +/// Note: This is a raw cast of the address bit pattern to the given pointer +/// type. When casting to a function pointer in order to execute JIT'd code +/// jitTargetAddressToFunction should be preferred, as it will also perform +/// pointer signing on targets that require it. template <typename T> T jitTargetAddressToPointer(JITTargetAddress Addr) { static_assert(std::is_pointer<T>::value, "T must be a pointer type"); uintptr_t IntPtr = static_cast<uintptr_t>(Addr); @@ -48,6 +53,19 @@ template <typename T> T jitTargetAddressToPointer(JITTargetAddress Addr) { return reinterpret_cast<T>(IntPtr); } +/// Convert a JITTargetAddress to a callable function pointer. +/// +/// Casts the given address to a callable function pointer. This operation +/// will perform pointer signing for platforms that require it (e.g. arm64e). +template <typename T> T jitTargetAddressToFunction(JITTargetAddress Addr) { + static_assert( + std::is_pointer<T>::value && + std::is_function<typename std::remove_pointer<T>::type>::value, + "T must be a function pointer type"); + return jitTargetAddressToPointer<T>(Addr); +} + +/// Convert a pointer to a JITTargetAddress. template <typename T> JITTargetAddress pointerToJITTargetAddress(T *Ptr) { return static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Ptr)); } |