diff options
author | Lang Hames <lhames@gmail.com> | 2019-12-02 01:40:54 -0800 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2019-12-02 01:52:52 -0800 |
commit | 0e7ecc651a47f818abafdfe5f928923f789fe0bc (patch) | |
tree | 77164d7a31d6b786ecbadd0da4ea4c24751619e5 | |
parent | 5c05b4a279f51d7eaa91f008bc5dc2155d98061a (diff) | |
download | bcm5719-llvm-0e7ecc651a47f818abafdfe5f928923f789fe0bc.tar.gz bcm5719-llvm-0e7ecc651a47f818abafdfe5f928923f789fe0bc.zip |
[ExecutionEngine] Add a jitTargetAddressToFunction utility function.
jitTargetAddressToFunction takes a JITTargetAddress and returns a pointer of
the given function pointer type suitable for calling to invoke the function
at the target address.
jitTargetAddressToFunction currently behaves the same as
jitTargetAddressToPointer, but in the near future will be updated to perform
pointer signing on architectures that require it (e.g. arm64e). For this
reason it should always be preferred when generating callable pointers for
JIT'd functions.
-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)); } |