diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/JITSymbol.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/JITSymbol.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/JITSymbol.h @@ -0,0 +1,58 @@ +//===--- JITSymbol.h -- JIT symbol abstraction ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Abstraction for target process addresses. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_JITSYMBOL_H +#define LLVM_EXECUTIONENGINE_ORC_SHARED_JITSYMBOL_H + +#include +#include +#include + +namespace llvm { +namespace orc { + +/// Represents an address in the target process's address space. +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 T jitTargetAddressToPointer(JITTargetAddress Addr) { + static_assert(std::is_pointer::value, "T must be a pointer type"); + uintptr_t IntPtr = static_cast(Addr); + assert(IntPtr == Addr && "JITTargetAddress value out of range for uintptr_t"); + return reinterpret_cast(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 T jitTargetAddressToFunction(JITTargetAddress Addr) { + static_assert(std::is_pointer::value && + std::is_function>::value, + "T must be a function pointer type"); + return jitTargetAddressToPointer(Addr); +} + +/// Convert a pointer to a JITTargetAddress. +template JITTargetAddress pointerToJITTargetAddress(T *Ptr) { + return static_cast(reinterpret_cast(Ptr)); +} + +} // end namespace orc +} // end namespace llvm + +#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_JITSYMBOL_H diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h --- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h @@ -16,11 +16,14 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ExecutionEngine/JITSymbol.h" #include namespace llvm { + +/// Represents an address in the target process's address space. +using JITTargetAddress = uint64_t; + namespace orc { namespace tpctypes { diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h @@ -14,6 +14,7 @@ #define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H #include "llvm/ADT/BitmaskEnum.h" +#include "llvm/ExecutionEngine/Orc/Shared/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h" #include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h" #include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h" diff --git a/llvm/include/llvm/module.modulemap b/llvm/include/llvm/module.modulemap --- a/llvm/include/llvm/module.modulemap +++ b/llvm/include/llvm/module.modulemap @@ -195,6 +195,8 @@ exclude header "ExecutionEngine/Orc/RPC/RPCSerialization.h" exclude header "ExecutionEngine/Orc/RPC/RawByteChannel.h" + exclude header "ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h" + } module LLVM_FileCheck { diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt --- a/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt +++ b/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt @@ -5,9 +5,6 @@ ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/ExecutionEngine/Orc - DEPENDS - intrinsics_gen - LINK_COMPONENTS Support ) diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp --- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp @@ -10,7 +10,7 @@ #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h" #include "llvm/Config/config.h" -#include "llvm/ExecutionEngine/JITSymbol.h" +#include "llvm/ExecutionEngine/Orc/Shared/JITSymbol.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h"