diff options
Diffstat (limited to 'llvm/include')
21 files changed, 313 insertions, 305 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h index ab13028b3ae..9bada02d569 100644 --- a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h +++ b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h @@ -137,13 +137,13 @@ protected: std::unique_ptr<Module> M, std::string *ErrorStr, std::shared_ptr<MCJITMemoryManager> MM, - std::shared_ptr<RuntimeDyld::SymbolResolver> SR, + std::shared_ptr<JITSymbolResolver> SR, std::unique_ptr<TargetMachine> TM); static ExecutionEngine *(*OrcMCJITReplacementCtor)( std::string *ErrorStr, std::shared_ptr<MCJITMemoryManager> MM, - std::shared_ptr<RuntimeDyld::SymbolResolver> SR, + std::shared_ptr<JITSymbolResolver> SR, std::unique_ptr<TargetMachine> TM); static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M, @@ -516,7 +516,7 @@ private: std::string *ErrorStr; CodeGenOpt::Level OptLevel; std::shared_ptr<MCJITMemoryManager> MemMgr; - std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver; + std::shared_ptr<JITSymbolResolver> Resolver; TargetOptions Options; Optional<Reloc::Model> RelocModel; CodeModel::Model CMModel; @@ -555,7 +555,7 @@ public: setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM); EngineBuilder& - setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR); + setSymbolResolver(std::unique_ptr<JITSymbolResolver> SR); /// setErrorStr - Set the error string to write to on error. This option /// defaults to NULL. diff --git a/llvm/include/llvm/ExecutionEngine/JITSymbol.h b/llvm/include/llvm/ExecutionEngine/JITSymbol.h new file mode 100644 index 00000000000..135b51f0301 --- /dev/null +++ b/llvm/include/llvm/ExecutionEngine/JITSymbol.h @@ -0,0 +1,132 @@ +//===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Abstraction for target process addresses. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_EXECUTIONENGINE_JITSYMBOL_H +#define LLVM_EXECUTIONENGINE_JITSYMBOL_H + +#include "llvm/ExecutionEngine/JITSymbolFlags.h" +#include "llvm/Support/DataTypes.h" +#include <cassert> +#include <functional> + +namespace llvm { + +/// @brief Represents an address in the target process's address space. +typedef uint64_t JITTargetAddress; + +/// @brief Represents a symbol that has been evaluated to an address already. +class JITEvaluatedSymbol : public JITSymbolBase { +public: + + /// @brief Create a 'null' symbol. + JITEvaluatedSymbol(std::nullptr_t) + : JITSymbolBase(JITSymbolFlags::None), Address(0) {} + + /// @brief Create a symbol for the given address and flags. + JITEvaluatedSymbol(JITTargetAddress Address, JITSymbolFlags Flags) + : JITSymbolBase(Flags), Address(Address) {} + + /// @brief An evaluated symbol converts to 'true' if its address is non-zero. + explicit operator bool() const { return Address != 0; } + + /// @brief Return the address of this symbol. + JITTargetAddress getAddress() const { return Address; } + +private: + JITTargetAddress Address; +}; + +/// @brief Represents a symbol in the JIT. +class JITSymbol : public JITSymbolBase { +public: + + typedef std::function<JITTargetAddress()> GetAddressFtor; + + /// @brief Create a 'null' symbol that represents failure to find a symbol + /// definition. + JITSymbol(std::nullptr_t) + : JITSymbolBase(JITSymbolFlags::None), CachedAddr(0) {} + + /// @brief Create a symbol for a definition with a known address. + JITSymbol(JITTargetAddress Addr, JITSymbolFlags Flags) + : JITSymbolBase(Flags), CachedAddr(Addr) {} + + /// @brief Construct a JITSymbol from a JITEvaluatedSymbol. + JITSymbol(JITEvaluatedSymbol Sym) + : JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {} + + /// @brief Create a symbol for a definition that doesn't have a known address + /// yet. + /// @param GetAddress A functor to materialize a definition (fixing the + /// address) on demand. + /// + /// This constructor allows a JIT layer to provide a reference to a symbol + /// definition without actually materializing the definition up front. The + /// user can materialize the definition at any time by calling the getAddress + /// method. + JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags) + : JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {} + + /// @brief Returns true if the symbol exists, false otherwise. + explicit operator bool() const { return CachedAddr || GetAddress; } + + /// @brief Get the address of the symbol in the target address space. Returns + /// '0' if the symbol does not exist. + JITTargetAddress getAddress() { + if (GetAddress) { + CachedAddr = GetAddress(); + assert(CachedAddr && "Symbol could not be materialized."); + GetAddress = nullptr; + } + return CachedAddr; + } + +private: + GetAddressFtor GetAddress; + JITTargetAddress CachedAddr; +}; + +/// \brief Symbol resolution. +class JITSymbolResolver { +public: + virtual ~JITSymbolResolver() {} + + /// This method returns the address of the specified symbol if it exists + /// within the logical dynamic library represented by this JITSymbolResolver. + /// Unlike findSymbol, queries through this interface should return addresses + /// for hidden symbols. + /// + /// This is of particular importance for the Orc JIT APIs, which support lazy + /// compilation by breaking up modules: Each of those broken out modules + /// must be able to resolve hidden symbols provided by the others. Clients + /// writing memory managers for MCJIT can usually ignore this method. + /// + /// This method will be queried by RuntimeDyld when checking for previous + /// definitions of common symbols. + virtual JITSymbol findSymbolInLogicalDylib(const std::string &Name) = 0; + + /// This method returns the address of the specified function or variable. + /// It is used to resolve symbols during module linking. + /// + /// If the returned symbol's address is equal to ~0ULL then RuntimeDyld will + /// skip all relocations for that symbol, and the client will be responsible + /// for handling them manually. + virtual JITSymbol findSymbol(const std::string &Name) = 0; + +private: + virtual void anchor(); +}; + +} // End namespace llvm. + +#endif // LLVM_EXECUTIONENGINE_JITSYMBOL_H diff --git a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h index 9a6a9de6df4..d3dfbe5f6a6 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -120,13 +120,12 @@ private: }; struct LogicalDylibResources { - typedef std::function<RuntimeDyld::SymbolInfo(const std::string&)> - SymbolResolverFtor; + typedef std::function<JITSymbol(const std::string&)> SymbolResolverFtor; typedef std::function<typename BaseLayerT::ModuleSetHandleT( BaseLayerT&, std::unique_ptr<Module>, - std::unique_ptr<RuntimeDyld::SymbolResolver>)> + std::unique_ptr<JITSymbolResolver>)> ModuleAdderFtor; LogicalDylibResources() = default; @@ -145,7 +144,7 @@ private: return *this; } - std::unique_ptr<RuntimeDyld::SymbolResolver> ExternalSymbolResolver; + std::unique_ptr<JITSymbolResolver> ExternalSymbolResolver; std::unique_ptr<ResourceOwner<RuntimeDyld::MemoryManager>> MemMgr; ModuleAdderFtor ModuleAdder; }; @@ -196,7 +195,7 @@ public: LDResources.ModuleAdder = [&MemMgrRef](BaseLayerT &B, std::unique_ptr<Module> M, - std::unique_ptr<RuntimeDyld::SymbolResolver> R) { + std::unique_ptr<JITSymbolResolver> R) { std::vector<std::unique_ptr<Module>> Ms; Ms.push_back(std::move(M)); return B.addModuleSet(std::move(Ms), &MemMgrRef, std::move(R)); @@ -245,7 +244,7 @@ public: // callbacks, uncompiled IR, and no-longer-needed/reachable function // implementations). // FIXME: Return Error once the JIT APIs are Errorized. - bool updatePointer(std::string FuncName, TargetAddress FnBodyAddr) { + bool updatePointer(std::string FuncName, JITTargetAddress FnBodyAddr) { //Find out which logical dylib contains our symbol auto LDI = LogicalDylibs.begin(); for (auto LDE = LogicalDylibs.end(); LDI != LDE; ++LDI) { @@ -386,7 +385,7 @@ private: [&LD, LMH](const std::string &Name) { auto &LMResources = LD.getLogicalModuleResources(LMH); if (auto Sym = LMResources.StubsMgr->findStub(Name, false)) - return Sym.toRuntimeDyldSymbol(); + return Sym; auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver; return LDResolver->findSymbolInLogicalDylib(Name); }, @@ -409,9 +408,9 @@ private: return MangledName; } - TargetAddress extractAndCompile(CODLogicalDylib &LD, - LogicalModuleHandle LMH, - Function &F) { + JITTargetAddress extractAndCompile(CODLogicalDylib &LD, + LogicalModuleHandle LMH, + Function &F) { auto &LMResources = LD.getLogicalModuleResources(LMH); Module &SrcM = LMResources.SourceModule->getResource(); @@ -425,13 +424,13 @@ private: auto Part = Partition(F); auto PartH = emitPartition(LD, LMH, Part); - TargetAddress CalledAddr = 0; + JITTargetAddress CalledAddr = 0; for (auto *SubF : Part) { std::string FnName = mangle(SubF->getName(), SrcM.getDataLayout()); auto FnBodySym = BaseLayer.findSymbolIn(PartH, FnName, false); assert(FnBodySym && "Couldn't find function body."); - TargetAddress FnBodyAddr = FnBodySym.getAddress(); + JITTargetAddress FnBodyAddr = FnBodySym.getAddress(); // If this is the function we're calling record the address so we can // return it from this function. @@ -513,7 +512,7 @@ private: auto Resolver = createLambdaResolver( [this, &LD, LMH](const std::string &Name) { if (auto Sym = LD.findSymbolInternally(LMH, Name)) - return Sym.toRuntimeDyldSymbol(); + return Sym; auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver; return LDResolver->findSymbolInLogicalDylib(Name); }, diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h index c10508cc8a6..21d4f81a124 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h @@ -14,9 +14,9 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H #define LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H -#include "JITSymbol.h" #include "llvm/ADT/iterator_range.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include <vector> @@ -144,10 +144,10 @@ public: } /// Search overrided symbols. - RuntimeDyld::SymbolInfo searchOverrides(const std::string &Name) { + JITEvaluatedSymbol searchOverrides(const std::string &Name) { auto I = CXXRuntimeOverrides.find(Name); if (I != CXXRuntimeOverrides.end()) - return RuntimeDyld::SymbolInfo(I->second, JITSymbolFlags::Exported); + return JITEvaluatedSymbol(I->second, JITSymbolFlags::Exported); return nullptr; } @@ -158,15 +158,15 @@ public: private: template <typename PtrTy> - TargetAddress toTargetAddress(PtrTy* P) { - return static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(P)); + JITTargetAddress toTargetAddress(PtrTy* P) { + return static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(P)); } - void addOverride(const std::string &Name, TargetAddress Addr) { + void addOverride(const std::string &Name, JITTargetAddress Addr) { CXXRuntimeOverrides.insert(std::make_pair(Name, Addr)); } - StringMap<TargetAddress> CXXRuntimeOverrides; + StringMap<JITTargetAddress> CXXRuntimeOverrides; typedef void (*DestructorPtr)(void*); typedef std::pair<DestructorPtr, void*> CXXDestructorDataPair; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h index 9fa222c340f..634d1480ae4 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h @@ -15,7 +15,7 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H #define LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H -#include "JITSymbol.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include <map> namespace llvm { @@ -52,7 +52,7 @@ public: void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeModuleSet(H); } /// @brief Manually set the address to return for the given symbol. - void setGlobalMapping(const std::string &Name, TargetAddress Addr) { + void setGlobalMapping(const std::string &Name, JITTargetAddress Addr) { SymbolTable[Name] = Addr; } @@ -99,7 +99,7 @@ public: private: BaseLayerT &BaseLayer; - std::map<std::string, TargetAddress> SymbolTable; + std::map<std::string, JITTargetAddress> SymbolTable; }; } // End namespace orc. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h index e6ce18a42b8..f16dd021ea5 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h @@ -14,9 +14,8 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H #define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H -#include "JITSymbol.h" #include "llvm/ExecutionEngine/ObjectCache.h" -#include "llvm/ExecutionEngine/RTDyldMemoryManager.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/Object/ObjectFile.h" #include <memory> diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h index 4dabb9a4149..c67297b111b 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h @@ -14,7 +14,7 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H -#include "JITSymbol.h" +#include "llvm/ExecutionEngine/JITSymbol.h" namespace llvm { namespace orc { diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h index 51172c51e13..bce0e990ef0 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h @@ -14,8 +14,8 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H #define LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H -#include "JITSymbol.h" #include "LambdaResolver.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Mangler.h" @@ -29,37 +29,37 @@ namespace orc { /// @brief Target-independent base class for compile callback management. class JITCompileCallbackManager { public: - typedef std::function<TargetAddress()> CompileFtor; + typedef std::function<JITTargetAddress()> CompileFtor; /// @brief Handle to a newly created compile callback. Can be used to get an /// IR constant representing the address of the trampoline, and to set /// the compile action for the callback. class CompileCallbackInfo { public: - CompileCallbackInfo(TargetAddress Addr, CompileFtor &Compile) + CompileCallbackInfo(JITTargetAddress Addr, CompileFtor &Compile) : Addr(Addr), Compile(Compile) {} - TargetAddress getAddress() const { return Addr; } + JITTargetAddress getAddress() const { return Addr; } void setCompileAction(CompileFtor Compile) { this->Compile = std::move(Compile); } private: - TargetAddress Addr; + JITTargetAddress Addr; CompileFtor &Compile; }; /// @brief Construct a JITCompileCallbackManager. /// @param ErrorHandlerAddress The address of an error handler in the target /// process to be used if a compile callback fails. - JITCompileCallbackManager(TargetAddress ErrorHandlerAddress) + JITCompileCallbackManager(JITTargetAddress ErrorHandlerAddress) : ErrorHandlerAddress(ErrorHandlerAddress) {} virtual ~JITCompileCallbackManager() {} /// @brief Execute the callback for the given trampoline id. Called by the JIT /// to compile functions on demand. - TargetAddress executeCompileCallback(TargetAddress TrampolineAddr) { + JITTargetAddress executeCompileCallback(JITTargetAddress TrampolineAddr) { auto I = ActiveTrampolines.find(TrampolineAddr); // FIXME: Also raise an error in the Orc error-handler when we finally have // one. @@ -86,13 +86,13 @@ public: /// @brief Reserve a compile callback. CompileCallbackInfo getCompileCallback() { - TargetAddress TrampolineAddr = getAvailableTrampolineAddr(); + JITTargetAddress TrampolineAddr = getAvailableTrampolineAddr(); auto &Compile = this->ActiveTrampolines[TrampolineAddr]; return CompileCallbackInfo(TrampolineAddr, Compile); } /// @brief Get a CompileCallbackInfo for an existing callback. - CompileCallbackInfo getCompileCallbackInfo(TargetAddress TrampolineAddr) { + CompileCallbackInfo getCompileCallbackInfo(JITTargetAddress TrampolineAddr) { auto I = ActiveTrampolines.find(TrampolineAddr); assert(I != ActiveTrampolines.end() && "Not an active trampoline."); return CompileCallbackInfo(I->first, I->second); @@ -103,7 +103,7 @@ public: /// Note: Callbacks are auto-released after they execute. This method should /// only be called to manually release a callback that is not going to /// execute. - void releaseCompileCallback(TargetAddress TrampolineAddr) { + void releaseCompileCallback(JITTargetAddress TrampolineAddr) { auto I = ActiveTrampolines.find(TrampolineAddr); assert(I != ActiveTrampolines.end() && "Not an active trampoline."); ActiveTrampolines.erase(I); @@ -111,19 +111,19 @@ public: } protected: - TargetAddress ErrorHandlerAddress; + JITTargetAddress ErrorHandlerAddress; - typedef std::map<TargetAddress, CompileFtor> TrampolineMapT; + typedef std::map<JITTargetAddress, CompileFtor> TrampolineMapT; TrampolineMapT ActiveTrampolines; - std::vector<TargetAddress> AvailableTrampolines; + std::vector<JITTargetAddress> AvailableTrampolines; private: - TargetAddress getAvailableTrampolineAddr() { + JITTargetAddress getAvailableTrampolineAddr() { if (this->AvailableTrampolines.empty()) grow(); assert(!this->AvailableTrampolines.empty() && "Failed to grow available trampolines."); - TargetAddress TrampolineAddr = this->AvailableTrampolines.back(); + JITTargetAddress TrampolineAddr = this->AvailableTrampolines.back(); this->AvailableTrampolines.pop_back(); return TrampolineAddr; } @@ -141,7 +141,7 @@ public: /// @brief Construct a InProcessJITCompileCallbackManager. /// @param ErrorHandlerAddress The address of an error handler in the target /// process to be used if a compile callback fails. - LocalJITCompileCallbackManager(TargetAddress ErrorHandlerAddress) + LocalJITCompileCallbackManager(JITTargetAddress ErrorHandlerAddress) : JITCompileCallbackManager(ErrorHandlerAddress) { /// Set up the resolver block. @@ -161,11 +161,12 @@ public: } private: - static TargetAddress reenter(void *CCMgr, void *TrampolineId) { + static JITTargetAddress reenter(void *CCMgr, void *TrampolineId) { JITCompileCallbackManager *Mgr = static_cast<JITCompileCallbackManager *>(CCMgr); return Mgr->executeCompileCallback( - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(TrampolineId))); + static_cast<JITTargetAddress>( + reinterpret_cast<uintptr_t>(TrampolineId))); } void grow() override { @@ -188,7 +189,7 @@ private: for (unsigned I = 0; I < NumTrampolines; ++I) this->AvailableTrampolines.push_back( - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>( + static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>( TrampolineMem + (I * TargetT::TrampolineSize)))); EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(), @@ -207,12 +208,12 @@ private: class IndirectStubsManager { public: /// @brief Map type for initializing the manager. See init. - typedef StringMap<std::pair<TargetAddress, JITSymbolFlags>> StubInitsMap; + typedef StringMap<std::pair<JITTargetAddress, JITSymbolFlags>> StubInitsMap; virtual ~IndirectStubsManager() {} /// @brief Create a single stub with the given name, target address and flags. - virtual Error createStub(StringRef StubName, TargetAddress StubAddr, + virtual Error createStub(StringRef StubName, JITTargetAddress StubAddr, JITSymbolFlags StubFlags) = 0; /// @brief Create StubInits.size() stubs with the given names, target @@ -228,7 +229,7 @@ public: virtual JITSymbol findPointer(StringRef Name) = 0; /// @brief Change the value of the implementation pointer for the stub. - virtual Error updatePointer(StringRef Name, TargetAddress NewAddr) = 0; + virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr) = 0; private: virtual void anchor(); @@ -239,7 +240,7 @@ private: template <typename TargetT> class LocalIndirectStubsManager : public IndirectStubsManager { public: - Error createStub(StringRef StubName, TargetAddress StubAddr, + Error createStub(StringRef StubName, JITTargetAddress StubAddr, JITSymbolFlags StubFlags) override { if (auto Err = reserveStubs(1)) return Err; @@ -268,7 +269,7 @@ public: void *StubAddr = IndirectStubsInfos[Key.first].getStub(Key.second); assert(StubAddr && "Missing stub address"); auto StubTargetAddr = - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(StubAddr)); + static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(StubAddr)); auto StubSymbol = JITSymbol(StubTargetAddr, I->second.second); if (ExportedStubsOnly && !StubSymbol.isExported()) return nullptr; @@ -283,11 +284,11 @@ public: void *PtrAddr = IndirectStubsInfos[Key.first].getPtr(Key.second); assert(PtrAddr && "Missing pointer address"); auto PtrTargetAddr = - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr)); + static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr)); return JITSymbol(PtrTargetAddr, I->second.second); } - Error updatePointer(StringRef Name, TargetAddress NewAddr) override { + Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override { auto I = StubIndexes.find(Name); assert(I != StubIndexes.end() && "No stub pointer for symbol"); auto Key = I->second.first; @@ -313,7 +314,7 @@ private: return Error::success(); } - void createStubInternal(StringRef StubName, TargetAddress InitAddr, + void createStubInternal(StringRef StubName, JITTargetAddress InitAddr, JITSymbolFlags StubFlags) { auto Key = FreeStubs.back(); FreeStubs.pop_back(); @@ -335,7 +336,7 @@ private: /// manager if a compile callback fails. std::unique_ptr<JITCompileCallbackManager> createLocalCompileCallbackManager(const Triple &T, - TargetAddress ErrorHandlerAddress); + JITTargetAddress ErrorHandlerAddress); /// @brief Create a local indriect stubs manager builder. /// @@ -348,7 +349,7 @@ createLocalIndirectStubsManagerBuilder(const Triple &T); /// /// Usage example: Turn a trampoline address into a function pointer constant /// for use in a stub. -Constant *createIRTypedAddress(FunctionType &FT, TargetAddress Addr); +Constant *createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr); /// @brief Create a function pointer with the given type, name, and initializer /// in the given Module. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/JITSymbol.h b/llvm/include/llvm/ExecutionEngine/Orc/JITSymbol.h deleted file mode 100644 index 464417e4e6d..00000000000 --- a/llvm/include/llvm/ExecutionEngine/Orc/JITSymbol.h +++ /dev/null @@ -1,87 +0,0 @@ -//===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Abstraction for target process addresses. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H -#define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H - -#include "llvm/ExecutionEngine/JITSymbolFlags.h" -#include "llvm/ExecutionEngine/RuntimeDyld.h" -#include "llvm/Support/DataTypes.h" -#include <cassert> -#include <functional> - -namespace llvm { -namespace orc { - -/// @brief Represents an address in the target process's address space. -typedef uint64_t TargetAddress; - -/// @brief Represents a symbol in the JIT. -class JITSymbol : public JITSymbolBase { -public: - - typedef std::function<TargetAddress()> GetAddressFtor; - - /// @brief Create a 'null' symbol that represents failure to find a symbol - /// definition. - JITSymbol(std::nullptr_t) - : JITSymbolBase(JITSymbolFlags::None), CachedAddr(0) {} - - /// @brief Create a symbol for a definition with a known address. - JITSymbol(TargetAddress Addr, JITSymbolFlags Flags) - : JITSymbolBase(Flags), CachedAddr(Addr) {} - - /// @brief Create a symbol for a definition that doesn't have a known address - /// yet. - /// @param GetAddress A functor to materialize a definition (fixing the - /// address) on demand. - /// - /// This constructor allows a JIT layer to provide a reference to a symbol - /// definition without actually materializing the definition up front. The - /// user can materialize the definition at any time by calling the getAddress - /// method. - JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags) - : JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {} - - /// @brief Create a JITSymbol from a RuntimeDyld::SymbolInfo. - JITSymbol(const RuntimeDyld::SymbolInfo &Sym) - : JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {} - - /// @brief Returns true if the symbol exists, false otherwise. - explicit operator bool() const { return CachedAddr || GetAddress; } - - /// @brief Get the address of the symbol in the target address space. Returns - /// '0' if the symbol does not exist. - TargetAddress getAddress() { - if (GetAddress) { - CachedAddr = GetAddress(); - assert(CachedAddr && "Symbol could not be materialized."); - GetAddress = nullptr; - } - return CachedAddr; - } - - /// @brief Convert this JITSymbol to a RuntimeDyld::SymbolInfo. - RuntimeDyld::SymbolInfo toRuntimeDyldSymbol() { - return RuntimeDyld::SymbolInfo(getAddress(), getFlags()); - } - -private: - GetAddressFtor GetAddress; - TargetAddress CachedAddr; -}; - -} // End namespace orc. -} // End namespace llvm. - -#endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LambdaResolver.h b/llvm/include/llvm/ExecutionEngine/Orc/LambdaResolver.h index a42b9d5c29d..cbe2a80edf1 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LambdaResolver.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LambdaResolver.h @@ -23,7 +23,7 @@ namespace llvm { namespace orc { template <typename DylibLookupFtorT, typename ExternalLookupFtorT> -class LambdaResolver : public RuntimeDyld::SymbolResolver { +class LambdaResolver : public JITSymbolResolver { public: LambdaResolver(DylibLookupFtorT DylibLookupFtor, @@ -31,12 +31,11 @@ public: : DylibLookupFtor(DylibLookupFtor), ExternalLookupFtor(ExternalLookupFtor) {} - RuntimeDyld::SymbolInfo - findSymbolInLogicalDylib(const std::string &Name) final { + JITSymbol findSymbolInLogicalDylib(const std::string &Name) final { return DylibLookupFtor(Name); } - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) final { + JITSymbol findSymbol(const std::string &Name) final { return ExternalLookupFtor(Name); } diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h index c5fb6b847b3..f992be97b50 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h @@ -14,8 +14,7 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H #define LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H -#include "JITSymbol.h" -#include "llvm/ExecutionEngine/RTDyldMemoryManager.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" @@ -52,7 +51,7 @@ private: std::string PName = Name; JITSymbolFlags Flags = JITSymbolBase::flagsFromGlobalValue(*GV); auto GetAddress = - [this, ExportedSymbolsOnly, PName, &B]() -> TargetAddress { + [this, ExportedSymbolsOnly, PName, &B]() -> JITTargetAddress { if (this->EmitState == Emitting) return 0; else if (this->EmitState == NotEmitted) { diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h b/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h index 914b112b7b6..af10b357235 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h @@ -14,7 +14,7 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H #define LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include <string> #include <vector> diff --git a/llvm/include/llvm/ExecutionEngine/Orc/NullResolver.h b/llvm/include/llvm/ExecutionEngine/Orc/NullResolver.h index 1560c6d86e0..957b94912b3 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/NullResolver.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/NullResolver.h @@ -22,12 +22,11 @@ namespace orc { /// SymbolResolver impliementation that rejects all resolution requests. /// Useful for clients that have no cross-object fixups. -class NullResolver : public RuntimeDyld::SymbolResolver { +class NullResolver : public JITSymbolResolver { public: - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) final; + JITSymbol findSymbol(const std::string &Name) final; - RuntimeDyld::SymbolInfo - findSymbolInLogicalDylib(const std::string &Name) final; + JITSymbol findSymbolInLogicalDylib(const std::string &Name) final; }; } // End namespace orc. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h index a7798d8beb8..1435c86326e 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h @@ -14,9 +14,9 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H #define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H -#include "JITSymbol.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include <list> #include <memory> @@ -46,7 +46,7 @@ protected: getSymbolMaterializer(std::string Name) = 0; virtual void mapSectionAddress(const void *LocalAddress, - TargetAddress TargetAddr) const = 0; + JITTargetAddress TargetAddr) const = 0; JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly) { auto SymEntry = SymbolTable.find(Name); @@ -60,7 +60,7 @@ protected: return JITSymbol(SymEntry->second); } protected: - StringMap<RuntimeDyld::SymbolInfo> SymbolTable; + StringMap<JITEvaluatedSymbol> SymbolTable; bool Finalized = false; }; @@ -144,7 +144,7 @@ private: } void mapSectionAddress(const void *LocalAddress, - TargetAddress TargetAddr) const override { + JITTargetAddress TargetAddr) const override { assert(PFC && "mapSectionAddress called on finalized LinkedObjectSet"); assert(PFC->RTDyld && "mapSectionAddress called on raw LinkedObjectSet"); PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr); @@ -165,7 +165,7 @@ private: } auto Flags = JITSymbol::flagsFromObjectSymbol(Symbol); SymbolTable.insert( - std::make_pair(*SymbolName, RuntimeDyld::SymbolInfo(0, Flags))); + std::make_pair(*SymbolName, JITEvaluatedSymbol(0, Flags))); } } @@ -322,7 +322,7 @@ public: /// @brief Map section addresses for the objects associated with the handle H. void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress, - TargetAddress TargetAddr) { + JITTargetAddress TargetAddr) { (*H)->mapSectionAddress(LocalAddress, TargetAddr); } diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h index 2ffe71c9435..173c106cd3e 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h @@ -14,7 +14,7 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H #define LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H -#include "JITSymbol.h" +#include "llvm/ExecutionEngine/JITSymbol.h" namespace llvm { namespace orc { @@ -83,7 +83,7 @@ public: /// @brief Map section addresses for the objects associated with the handle H. void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress, - TargetAddress TargetAddr) { + JITTargetAddress TargetAddr) { BaseLayer.mapSectionAddress(H, LocalAddress, TargetAddr); } diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcABISupport.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcABISupport.h index 4a8d0b0b801..fa236b0de88 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcABISupport.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcABISupport.h @@ -37,7 +37,8 @@ public: static const unsigned TrampolineSize = 1; static const unsigned ResolverCodeSize = 1; - typedef TargetAddress (*JITReentryFn)(void *CallbackMgr, void *TrampolineId); + typedef JITTargetAddress (*JITReentryFn)(void *CallbackMgr, + void *TrampolineId); static void writeResolverCode(uint8_t *ResolveMem, JITReentryFn Reentry, void *CallbackMgr) { @@ -115,7 +116,8 @@ public: typedef GenericIndirectStubsInfo<8> IndirectStubsInfo; - typedef TargetAddress (*JITReentryFn)(void *CallbackMgr, void *TrampolineId); + typedef JITTargetAddress (*JITReentryFn)(void *CallbackMgr, + void *TrampolineId); /// @brief Write the resolver code into the given memory. The user is be /// responsible for allocating the memory and setting permissions. @@ -170,7 +172,8 @@ public: class OrcX86_64_SysV : public OrcX86_64_Base { public: static const unsigned ResolverCodeSize = 0x6C; - typedef TargetAddress(*JITReentryFn)(void *CallbackMgr, void *TrampolineId); + typedef JITTargetAddress (*JITReentryFn)(void *CallbackMgr, + void *TrampolineId); /// @brief Write the resolver code into the given memory. The user is be /// responsible for allocating the memory and setting permissions. @@ -184,7 +187,8 @@ public: class OrcX86_64_Win32 : public OrcX86_64_Base { public: static const unsigned ResolverCodeSize = 0x74; - typedef TargetAddress(*JITReentryFn)(void *CallbackMgr, void *TrampolineId); + typedef JITTargetAddress (*JITReentryFn)(void *CallbackMgr, + void *TrampolineId); /// @brief Write the resolver code into the given memory. The user is be /// responsible for allocating the memory and setting permissions. @@ -203,7 +207,8 @@ public: typedef GenericIndirectStubsInfo<8> IndirectStubsInfo; - typedef TargetAddress (*JITReentryFn)(void *CallbackMgr, void *TrampolineId); + typedef JITTargetAddress (*JITReentryFn)(void *CallbackMgr, + void *TrampolineId); /// @brief Write the resolver code into the given memory. The user is be /// responsible for allocating the memory and setting permissions. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h index 12705aff9e1..4b31e860912 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h @@ -185,7 +185,7 @@ public: DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n"); for (auto &ObjAllocs : Unmapped) { { - TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr; + JITTargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr; for (auto &Alloc : ObjAllocs.CodeAllocs) { NextCodeAddr = alignTo(NextCodeAddr, Alloc.getAlign()); Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr); @@ -197,7 +197,7 @@ public: } } { - TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr; + JITTargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr; for (auto &Alloc : ObjAllocs.RODataAllocs) { NextRODataAddr = alignTo(NextRODataAddr, Alloc.getAlign()); Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr); @@ -210,7 +210,7 @@ public: } } { - TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr; + JITTargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr; for (auto &Alloc : ObjAllocs.RWDataAllocs) { NextRWDataAddr = alignTo(NextRWDataAddr, Alloc.getAlign()); Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr); @@ -389,17 +389,17 @@ public: return reinterpret_cast<char *>(LocalAddr); } - void setRemoteAddress(TargetAddress RemoteAddr) { + void setRemoteAddress(JITTargetAddress RemoteAddr) { this->RemoteAddr = RemoteAddr; } - TargetAddress getRemoteAddress() const { return RemoteAddr; } + JITTargetAddress getRemoteAddress() const { return RemoteAddr; } private: uint64_t Size; unsigned Align; std::unique_ptr<char[]> Contents; - TargetAddress RemoteAddr = 0; + JITTargetAddress RemoteAddr = 0; }; struct ObjectAllocs { @@ -423,9 +423,9 @@ public: return *this; } - TargetAddress RemoteCodeAddr = 0; - TargetAddress RemoteRODataAddr = 0; - TargetAddress RemoteRWDataAddr = 0; + JITTargetAddress RemoteCodeAddr = 0; + JITTargetAddress RemoteRODataAddr = 0; + JITTargetAddress RemoteRWDataAddr = 0; std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs; }; @@ -450,7 +450,7 @@ public: } } - Error createStub(StringRef StubName, TargetAddress StubAddr, + Error createStub(StringRef StubName, JITTargetAddress StubAddr, JITSymbolFlags StubFlags) override { if (auto Err = reserveStubs(1)) return Err; @@ -491,7 +491,7 @@ public: return JITSymbol(getPtrAddr(Key), Flags); } - Error updatePointer(StringRef Name, TargetAddress NewAddr) override { + Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override { auto I = StubIndexes.find(Name); assert(I != StubIndexes.end() && "No stub pointer for symbol"); auto Key = I->second.first; @@ -500,8 +500,8 @@ public: private: struct RemoteIndirectStubsInfo { - TargetAddress StubBase; - TargetAddress PtrBase; + JITTargetAddress StubBase; + JITTargetAddress PtrBase; unsigned NumStubs; }; @@ -517,8 +517,8 @@ public: return Error::success(); unsigned NewStubsRequired = NumStubs - FreeStubs.size(); - TargetAddress StubBase; - TargetAddress PtrBase; + JITTargetAddress StubBase; + JITTargetAddress PtrBase; unsigned NumStubsEmitted; if (auto StubInfoOrErr = Remote.emitIndirectStubs(Id, NewStubsRequired)) @@ -535,7 +535,7 @@ public: return Error::success(); } - Error createStubInternal(StringRef StubName, TargetAddress InitAddr, + Error createStubInternal(StringRef StubName, JITTargetAddress InitAddr, JITSymbolFlags StubFlags) { auto Key = FreeStubs.back(); FreeStubs.pop_back(); @@ -543,14 +543,14 @@ public: return Remote.writePointer(getPtrAddr(Key), InitAddr); } - TargetAddress getStubAddr(StubKey K) { + JITTargetAddress getStubAddr(StubKey K) { assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 && "Missing stub address"); return RemoteIndirectStubsInfos[K.first].StubBase + K.second * Remote.getIndirectStubSize(); } - TargetAddress getPtrAddr(StubKey K) { + JITTargetAddress getPtrAddr(StubKey K) { assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 && "Missing pointer address"); return RemoteIndirectStubsInfos[K.first].PtrBase + @@ -561,13 +561,13 @@ public: /// Remote compile callback manager. class RCCompileCallbackManager : public JITCompileCallbackManager { public: - RCCompileCallbackManager(TargetAddress ErrorHandlerAddress, + RCCompileCallbackManager(JITTargetAddress ErrorHandlerAddress, OrcRemoteTargetClient &Remote) : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {} private: void grow() override { - TargetAddress BlockAddr = 0; + JITTargetAddress BlockAddr = 0; uint32_t NumTrampolines = 0; if (auto TrampolineInfoOrErr = Remote.emitTrampolineBlock()) std::tie(BlockAddr, NumTrampolines) = *TrampolineInfoOrErr; @@ -597,7 +597,7 @@ public: /// Call the int(void) function at the given address in the target and return /// its result. - Expected<int> callIntVoid(TargetAddress Addr) { + Expected<int> callIntVoid(JITTargetAddress Addr) { DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n"); auto Listen = [&](RPCChannel &C, uint32_t Id) { @@ -608,7 +608,7 @@ public: /// Call the int(int, char*[]) function at the given address in the target and /// return its result. - Expected<int> callMain(TargetAddress Addr, + Expected<int> callMain(JITTargetAddress Addr, const std::vector<std::string> &Args) { DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr) << "\n"); @@ -621,7 +621,7 @@ public: /// Call the void() function at the given address in the target and wait for /// it to finish. - Error callVoidVoid(TargetAddress Addr) { + Error callVoidVoid(JITTargetAddress Addr) { DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr) << "\n"); @@ -655,7 +655,7 @@ public: } Expected<RCCompileCallbackManager &> - enableCompileCallbacks(TargetAddress ErrorHandlerAddress) { + enableCompileCallbacks(JITTargetAddress ErrorHandlerAddress) { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) return std::move(ExistingError); @@ -673,7 +673,7 @@ public: /// Search for symbols in the remote process. Note: This should be used by /// symbol resolvers *after* they've searched the local symbol table in the /// JIT stack. - Expected<TargetAddress> getSymbolAddress(StringRef Name) { + Expected<JITTargetAddress> getSymbolAddress(StringRef Name) { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) return std::move(ExistingError); @@ -698,7 +698,7 @@ private: } } - Error deregisterEHFrames(TargetAddress Addr, uint32_t Size) { + Error deregisterEHFrames(JITTargetAddress Addr, uint32_t Size) { return callST<RegisterEHFrames>(Channel, Addr, Size); } @@ -716,12 +716,12 @@ private: return callST<DestroyIndirectStubsOwner>(Channel, Id); } - Expected<std::tuple<TargetAddress, TargetAddress, uint32_t>> + Expected<std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>> emitIndirectStubs(ResourceIdMgr::ResourceId Id, uint32_t NumStubsRequired) { return callST<EmitIndirectStubs>(Channel, Id, NumStubsRequired); } - Expected<std::tuple<TargetAddress, uint32_t>> emitTrampolineBlock() { + Expected<std::tuple<JITTargetAddress, uint32_t>> emitTrampolineBlock() { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) return std::move(ExistingError); @@ -747,7 +747,7 @@ private: // site below, but that triggers a GCC 4.7 ICE. When we move off // GCC 4.7, tidy this up. auto CompileCallback = - [this](TargetAddress Addr) -> Expected<TargetAddress> { + [this](JITTargetAddress Addr) -> Expected<JITTargetAddress> { return this->CallbackManager->executeCompileCallback(Addr); }; @@ -760,7 +760,7 @@ private: return orcError(OrcErrorCode::UnexpectedRPCCall); } - Expected<std::vector<char>> readMem(char *Dst, TargetAddress Src, + Expected<std::vector<char>> readMem(char *Dst, JITTargetAddress Src, uint64_t Size) { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) @@ -769,12 +769,12 @@ private: return callST<ReadMem>(Channel, Src, Size); } - Error registerEHFrames(TargetAddress &RAddr, uint32_t Size) { + Error registerEHFrames(JITTargetAddress &RAddr, uint32_t Size) { return callST<RegisterEHFrames>(Channel, RAddr, Size); } - Expected<TargetAddress> reserveMem(ResourceIdMgr::ResourceId Id, - uint64_t Size, uint32_t Align) { + Expected<JITTargetAddress> reserveMem(ResourceIdMgr::ResourceId Id, + uint64_t Size, uint32_t Align) { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) @@ -784,11 +784,11 @@ private: } Error setProtections(ResourceIdMgr::ResourceId Id, - TargetAddress RemoteSegAddr, unsigned ProtFlags) { + JITTargetAddress RemoteSegAddr, unsigned ProtFlags) { return callST<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags); } - Error writeMem(TargetAddress Addr, const char *Src, uint64_t Size) { + Error writeMem(JITTargetAddress Addr, const char *Src, uint64_t Size) { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) return std::move(ExistingError); @@ -796,7 +796,7 @@ private: return callST<WriteMem>(Channel, DirectBufferWriter(Src, Addr, Size)); } - Error writePointer(TargetAddress Addr, TargetAddress PtrVal) { + Error writePointer(JITTargetAddress Addr, JITTargetAddress PtrVal) { // Check for an 'out-of-band' error, e.g. from an MM destructor. if (ExistingError) return std::move(ExistingError); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h index 74d851522f7..e951c124b15 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h @@ -16,9 +16,9 @@ #ifndef LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H #define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H -#include "JITSymbol.h" #include "RPCChannel.h" #include "RPCUtils.h" +#include "llvm/ExecutionEngine/JITSymbol.h" namespace llvm { namespace orc { @@ -27,16 +27,16 @@ namespace remote { class DirectBufferWriter { public: DirectBufferWriter() = default; - DirectBufferWriter(const char *Src, TargetAddress Dst, uint64_t Size) + DirectBufferWriter(const char *Src, JITTargetAddress Dst, uint64_t Size) : Src(Src), Dst(Dst), Size(Size) {} const char *getSrc() const { return Src; } - TargetAddress getDst() const { return Dst; } + JITTargetAddress getDst() const { return Dst; } uint64_t getSize() const { return Size; } private: const char *Src; - TargetAddress Dst; + JITTargetAddress Dst; uint64_t Size; }; @@ -49,7 +49,7 @@ inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) { } inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) { - TargetAddress Dst; + JITTargetAddress Dst; if (auto EC = deserialize(C, Dst)) return EC; uint64_t Size; @@ -120,13 +120,14 @@ public: static const char *getJITFuncIdName(JITFuncId Id); - typedef Function<CallIntVoidId, int32_t(TargetAddress Addr)> CallIntVoid; + typedef Function<CallIntVoidId, int32_t(JITTargetAddress Addr)> CallIntVoid; typedef Function<CallMainId, - int32_t(TargetAddress Addr, std::vector<std::string> Args)> + int32_t(JITTargetAddress Addr, + std::vector<std::string> Args)> CallMain; - typedef Function<CallVoidVoidId, void(TargetAddress FnAddr)> CallVoidVoid; + typedef Function<CallVoidVoidId, void(JITTargetAddress FnAddr)> CallVoidVoid; typedef Function<CreateRemoteAllocatorId, void(ResourceIdMgr::ResourceId AllocatorID)> @@ -137,7 +138,7 @@ public: CreateIndirectStubsOwner; typedef Function<DeregisterEHFramesId, - void(TargetAddress Addr, uint32_t Size)> + void(JITTargetAddress Addr, uint32_t Size)> DeregisterEHFrames; typedef Function<DestroyRemoteAllocatorId, @@ -150,7 +151,7 @@ public: /// EmitIndirectStubs result is (StubsBase, PtrsBase, NumStubsEmitted). typedef Function<EmitIndirectStubsId, - std::tuple<TargetAddress, TargetAddress, uint32_t>( + std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>( ResourceIdMgr::ResourceId StubsOwnerID, uint32_t NumStubsRequired)> EmitIndirectStubs; @@ -158,10 +159,11 @@ public: typedef Function<EmitResolverBlockId, void()> EmitResolverBlock; /// EmitTrampolineBlock result is (BlockAddr, NumTrampolines). - typedef Function<EmitTrampolineBlockId, std::tuple<TargetAddress, uint32_t>()> + typedef Function<EmitTrampolineBlockId, + std::tuple<JITTargetAddress, uint32_t>()> EmitTrampolineBlock; - typedef Function<GetSymbolAddressId, TargetAddress(std::string SymbolName)> + typedef Function<GetSymbolAddressId, JITTargetAddress(std::string SymbolName)> GetSymbolAddress; /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize, @@ -171,23 +173,23 @@ public: GetRemoteInfo; typedef Function<ReadMemId, - std::vector<char>(TargetAddress Src, uint64_t Size)> + std::vector<char>(JITTargetAddress Src, uint64_t Size)> ReadMem; - typedef Function<RegisterEHFramesId, void(TargetAddress Addr, uint32_t Size)> + typedef Function<RegisterEHFramesId, void(JITTargetAddress Addr, uint32_t Size)> RegisterEHFrames; typedef Function<ReserveMemId, - TargetAddress(ResourceIdMgr::ResourceId AllocID, - uint64_t Size, uint32_t Align)> + JITTargetAddress(ResourceIdMgr::ResourceId AllocID, + uint64_t Size, uint32_t Align)> ReserveMem; typedef Function<RequestCompileId, - TargetAddress(TargetAddress TrampolineAddr)> + JITTargetAddress(JITTargetAddress TrampolineAddr)> RequestCompile; typedef Function<SetProtectionsId, - void(ResourceIdMgr::ResourceId AllocID, TargetAddress Dst, + void(ResourceIdMgr::ResourceId AllocID, JITTargetAddress Dst, uint32_t ProtFlags)> SetProtections; @@ -195,7 +197,7 @@ public: typedef Function<WriteMemId, void(DirectBufferWriter DB)> WriteMem; - typedef Function<WritePtrId, void(TargetAddress Dst, TargetAddress Val)> + typedef Function<WritePtrId, void(JITTargetAddress Dst, JITTargetAddress Val)> WritePtr; }; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h index bf4299c69b2..48e58f6bbfd 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h @@ -32,7 +32,7 @@ namespace remote { template <typename ChannelT, typename TargetT> class OrcRemoteTargetServer : public OrcRemoteTargetRPCAPI { public: - typedef std::function<TargetAddress(const std::string &Name)> + typedef std::function<JITTargetAddress(const std::string &Name)> SymbolLookupFtor; typedef std::function<void(uint8_t *Addr, uint32_t Size)> @@ -118,7 +118,7 @@ public: llvm_unreachable("Unhandled JIT RPC procedure Id."); } - Expected<TargetAddress> requestCompile(TargetAddress TrampolineAddr) { + Expected<JITTargetAddress> requestCompile(JITTargetAddress TrampolineAddr) { auto Listen = [&](RPCChannel &C, uint32_t Id) { return handleKnownFunction(static_cast<JITFuncId>(Id)); }; @@ -171,16 +171,16 @@ private: static Error doNothing() { return Error::success(); } - static TargetAddress reenter(void *JITTargetAddr, void *TrampolineAddr) { + static JITTargetAddress reenter(void *JITTargetAddr, void *TrampolineAddr) { auto T = static_cast<OrcRemoteTargetServer *>(JITTargetAddr); - auto AddrOrErr = T->requestCompile(static_cast<TargetAddress>( + auto AddrOrErr = T->requestCompile(static_cast<JITTargetAddress>( reinterpret_cast<uintptr_t>(TrampolineAddr))); // FIXME: Allow customizable failure substitution functions. assert(AddrOrErr && "Compile request failed"); return *AddrOrErr; } - Expected<int32_t> handleCallIntVoid(TargetAddress Addr) { + Expected<int32_t> handleCallIntVoid(JITTargetAddress Addr) { typedef int (*IntVoidFnTy)(); IntVoidFnTy Fn = reinterpret_cast<IntVoidFnTy>(static_cast<uintptr_t>(Addr)); @@ -192,7 +192,7 @@ private: return Result; } - Expected<int32_t> handleCallMain(TargetAddress Addr, + Expected<int32_t> handleCallMain(JITTargetAddress Addr, std::vector<std::string> Args) { typedef int (*MainFnTy)(int, const char *[]); @@ -211,7 +211,7 @@ private: return Result; } - Error handleCallVoidVoid(TargetAddress Addr) { + Error handleCallVoidVoid(JITTargetAddress Addr) { typedef void (*VoidVoidFnTy)(); VoidVoidFnTy Fn = reinterpret_cast<VoidVoidFnTy>(static_cast<uintptr_t>(Addr)); @@ -241,7 +241,7 @@ private: return Error::success(); } - Error handleDeregisterEHFrames(TargetAddress TAddr, uint32_t Size) { + Error handleDeregisterEHFrames(JITTargetAddress TAddr, uint32_t Size) { uint8_t *Addr = reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(TAddr)); DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr) << ", Size = " << Size << " bytes\n"); @@ -266,7 +266,7 @@ private: return Error::success(); } - Expected<std::tuple<TargetAddress, TargetAddress, uint32_t>> + Expected<std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>> handleEmitIndirectStubs(ResourceIdMgr::ResourceId Id, uint32_t NumStubsRequired) { DEBUG(dbgs() << " ISMgr " << Id << " request " << NumStubsRequired @@ -281,10 +281,12 @@ private: TargetT::emitIndirectStubsBlock(IS, NumStubsRequired, nullptr)) return std::move(Err); - TargetAddress StubsBase = - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(IS.getStub(0))); - TargetAddress PtrsBase = - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(IS.getPtr(0))); + JITTargetAddress StubsBase = + static_cast<JITTargetAddress>( + reinterpret_cast<uintptr_t>(IS.getStub(0))); + JITTargetAddress PtrsBase = + static_cast<JITTargetAddress>( + reinterpret_cast<uintptr_t>(IS.getPtr(0))); uint32_t NumStubsEmitted = IS.getNumStubs(); auto &BlockList = StubOwnerItr->second; @@ -309,7 +311,7 @@ private: sys::Memory::MF_READ | sys::Memory::MF_EXEC)); } - Expected<std::tuple<TargetAddress, uint32_t>> handleEmitTrampolineBlock() { + Expected<std::tuple<JITTargetAddress, uint32_t>> handleEmitTrampolineBlock() { std::error_code EC; auto TrampolineBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory( @@ -333,13 +335,14 @@ private: TrampolineBlocks.push_back(std::move(TrampolineBlock)); auto TrampolineBaseAddr = - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(TrampolineMem)); + static_cast<JITTargetAddress>( + reinterpret_cast<uintptr_t>(TrampolineMem)); return std::make_tuple(TrampolineBaseAddr, NumTrampolines); } - Expected<TargetAddress> handleGetSymbolAddress(const std::string &Name) { - TargetAddress Addr = SymbolLookup(Name); + Expected<JITTargetAddress> handleGetSymbolAddress(const std::string &Name) { + JITTargetAddress Addr = SymbolLookup(Name); DEBUG(dbgs() << " Symbol '" << Name << "' = " << format("0x%016x", Addr) << "\n"); return Addr; @@ -362,7 +365,7 @@ private: IndirectStubSize); } - Expected<std::vector<char>> handleReadMem(TargetAddress RSrc, uint64_t Size) { + Expected<std::vector<char>> handleReadMem(JITTargetAddress RSrc, uint64_t Size) { char *Src = reinterpret_cast<char *>(static_cast<uintptr_t>(RSrc)); DEBUG(dbgs() << " Reading " << Size << " bytes from " @@ -376,7 +379,7 @@ private: return Buffer; } - Error handleRegisterEHFrames(TargetAddress TAddr, uint32_t Size) { + Error handleRegisterEHFrames(JITTargetAddress TAddr, uint32_t Size) { uint8_t *Addr = reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(TAddr)); DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr) << ", Size = " << Size << " bytes\n"); @@ -384,8 +387,8 @@ private: return Error::success(); } - Expected<TargetAddress> handleReserveMem(ResourceIdMgr::ResourceId Id, - uint64_t Size, uint32_t Align) { + Expected<JITTargetAddress> handleReserveMem(ResourceIdMgr::ResourceId Id, + uint64_t Size, uint32_t Align) { auto I = Allocators.find(Id); if (I == Allocators.end()) return orcError(OrcErrorCode::RemoteAllocatorDoesNotExist); @@ -397,13 +400,14 @@ private: DEBUG(dbgs() << " Allocator " << Id << " reserved " << LocalAllocAddr << " (" << Size << " bytes, alignment " << Align << ")\n"); - TargetAddress AllocAddr = - static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(LocalAllocAddr)); + JITTargetAddress AllocAddr = + static_cast<JITTargetAddress>( + reinterpret_cast<uintptr_t>(LocalAllocAddr)); return AllocAddr; } - Error handleSetProtections(ResourceIdMgr::ResourceId Id, TargetAddress Addr, + Error handleSetProtections(ResourceIdMgr::ResourceId Id, JITTargetAddress Addr, uint32_t Flags) { auto I = Allocators.find(Id); if (I == Allocators.end()) @@ -423,7 +427,7 @@ private: return Error::success(); } - Error handleWritePtr(TargetAddress Addr, TargetAddress PtrVal) { + Error handleWritePtr(JITTargetAddress Addr, JITTargetAddress PtrVal) { DEBUG(dbgs() << " Writing pointer *" << format("0x%016x", Addr) << " = " << format("0x%016x", PtrVal) << "\n"); uintptr_t *Ptr = diff --git a/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h b/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h index adcb063f454..74423b92d80 100644 --- a/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h @@ -54,7 +54,7 @@ public: // FIXME: As the RuntimeDyld fills out, additional routines will be needed // for the varying types of objects to be allocated. class RTDyldMemoryManager : public MCJITMemoryManager, - public RuntimeDyld::SymbolResolver { + public JITSymbolResolver { RTDyldMemoryManager(const RTDyldMemoryManager&) = delete; void operator=(const RTDyldMemoryManager&) = delete; public: @@ -98,9 +98,8 @@ public: /// Clients writing custom RTDyldMemoryManagers are encouraged to override /// this method and return a SymbolInfo with the flags set correctly. This is /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols. - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override { - return RuntimeDyld::SymbolInfo(getSymbolAddress(Name), - JITSymbolFlags::Exported); + JITSymbol findSymbol(const std::string &Name) override { + return JITSymbol(getSymbolAddress(Name), JITSymbolFlags::Exported); } /// Legacy symbol lookup -- DEPRECATED! Please override @@ -121,10 +120,10 @@ public: /// Clients writing custom RTDyldMemoryManagers are encouraged to override /// this method and return a SymbolInfo with the flags set correctly. This is /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols. - RuntimeDyld::SymbolInfo + JITSymbol findSymbolInLogicalDylib(const std::string &Name) override { - return RuntimeDyld::SymbolInfo(getSymbolAddressInLogicalDylib(Name), - JITSymbolFlags::Exported); + return JITSymbol(getSymbolAddressInLogicalDylib(Name), + JITSymbolFlags::Exported); } /// This method returns the address of the specified function. As such it is diff --git a/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h b/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h index bd485de91bd..70df6ca0d8f 100644 --- a/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h +++ b/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h @@ -14,7 +14,7 @@ #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H -#include "JITSymbolFlags.h" +#include "JITSymbol.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/DIContext.h" #include "llvm/Object/ObjectFile.h" @@ -60,18 +60,6 @@ protected: void reassignSectionAddress(unsigned SectionID, uint64_t Addr); public: - /// \brief Information about a named symbol. - class SymbolInfo : public JITSymbolBase { - public: - SymbolInfo(std::nullptr_t) : JITSymbolBase(JITSymbolFlags::None), Address(0) {} - SymbolInfo(uint64_t Address, JITSymbolFlags Flags) - : JITSymbolBase(Flags), Address(Address) {} - explicit operator bool() const { return Address != 0; } - uint64_t getAddress() const { return Address; } - private: - uint64_t Address; - }; - /// \brief Information about the loaded object. class LoadedObjectInfo : public llvm::LoadedObjectInfo { friend class RuntimeDyldImpl; @@ -189,39 +177,8 @@ public: bool FinalizationLocked; }; - /// \brief Symbol resolution. - class SymbolResolver { - public: - virtual ~SymbolResolver() {} - - /// This method returns the address of the specified symbol if it exists - /// within the logical dynamic library represented by this - /// RTDyldMemoryManager. Unlike findSymbol, queries through this - /// interface should return addresses for hidden symbols. - /// - /// This is of particular importance for the Orc JIT APIs, which support lazy - /// compilation by breaking up modules: Each of those broken out modules - /// must be able to resolve hidden symbols provided by the others. Clients - /// writing memory managers for MCJIT can usually ignore this method. - /// - /// This method will be queried by RuntimeDyld when checking for previous - /// definitions of common symbols. - virtual SymbolInfo findSymbolInLogicalDylib(const std::string &Name) = 0; - - /// This method returns the address of the specified function or variable. - /// It is used to resolve symbols during module linking. - /// - /// If the returned symbol's address is equal to ~0ULL then RuntimeDyld will - /// skip all relocations for that symbol, and the client will be responsible - /// for handling them manually. - virtual SymbolInfo findSymbol(const std::string &Name) = 0; - - private: - virtual void anchor(); - }; - /// \brief Construct a RuntimeDyld instance. - RuntimeDyld(MemoryManager &MemMgr, SymbolResolver &Resolver); + RuntimeDyld(MemoryManager &MemMgr, JITSymbolResolver &Resolver); ~RuntimeDyld(); /// Add the referenced object file to the list of objects to be loaded and @@ -235,7 +192,7 @@ public: /// Get the target address and flags for the named symbol. /// This address is the one used for relocation. - SymbolInfo getSymbol(StringRef Name) const; + JITEvaluatedSymbol getSymbol(StringRef Name) const; /// Resolve the relocations for all symbols we currently know about. void resolveRelocations(); @@ -295,7 +252,7 @@ private: // interface. std::unique_ptr<RuntimeDyldImpl> Dyld; MemoryManager &MemMgr; - SymbolResolver &Resolver; + JITSymbolResolver &Resolver; bool ProcessAllSections; RuntimeDyldCheckerImpl *Checker; }; |

