diff --git a/docs/tutorial/BuildingAJIT1.rst b/docs/tutorial/BuildingAJIT1.rst index f30b979579d..80957ee620f 100644 --- a/docs/tutorial/BuildingAJIT1.rst +++ b/docs/tutorial/BuildingAJIT1.rst @@ -190,14 +190,14 @@ available for execution. auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = CompileLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &S) { if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) - return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(SymAddr, JITSymbolFlags::Exported); + return JITSymbol(nullptr); }); // Build a singlton module set to hold our module. @@ -242,28 +242,27 @@ implementation? By using a single symbol resolution scheme we are free to choose whatever makes the most sense for any given use case. Building a symbol resolver is made especially easy by the *createLambdaResolver* -function. This function takes two lambdas [3]_ and returns a -RuntimeDyld::SymbolResolver instance. The first lambda is used as the -implementation of the resolver's findSymbolInLogicalDylib method, which searches -for symbol definitions that should be thought of as being part of the same -"logical" dynamic library as this Module. If you are familiar with static -linking: this means that findSymbolInLogicalDylib should expose symbols with -common linkage and hidden visibility. If all this sounds foreign you can ignore -the details and just remember that this is the first method that the linker will -use to try to find a symbol definition. If the findSymbolInLogicalDylib method -returns a null result then the linker will call the second symbol resolver -method, called findSymbol, which searches for symbols that should be thought of -as external to (but visibile from) the module and its logical dylib. In this -tutorial we will adopt the following simple scheme: All modules added to the JIT -will behave as if they were linked into a single, ever-growing logical dylib. To -implement this our first lambda (the one defining findSymbolInLogicalDylib) will -just search for JIT'd code by calling the CompileLayer's findSymbol method. If -we don't find a symbol in the JIT itself we'll fall back to our second lambda, -which implements findSymbol. This will use the -RTDyldMemoyrManager::getSymbolAddressInProcess method to search for the symbol -within the program itself. If we can't find a symbol definition via either of -these paths the JIT will refuse to accept our module, returning a "symbol not -found" error. +function. This function takes two lambdas [3]_ and returns a JITSymbolResolver +instance. The first lambda is used as the implementation of the resolver's +findSymbolInLogicalDylib method, which searches for symbol definitions that +should be thought of as being part of the same "logical" dynamic library as this +Module. If you are familiar with static linking: this means that +findSymbolInLogicalDylib should expose symbols with common linkage and hidden +visibility. If all this sounds foreign you can ignore the details and just +remember that this is the first method that the linker will use to try to find a +symbol definition. If the findSymbolInLogicalDylib method returns a null result +then the linker will call the second symbol resolver method, called findSymbol, +which searches for symbols that should be thought of as external to (but +visibile from) the module and its logical dylib. In this tutorial we will adopt +the following simple scheme: All modules added to the JIT will behave as if they +were linked into a single, ever-growing logical dylib. To implement this our +first lambda (the one defining findSymbolInLogicalDylib) will just search for +JIT'd code by calling the CompileLayer's findSymbol method. If we don't find a +symbol in the JIT itself we'll fall back to our second lambda, which implements +findSymbol. This will use the RTDyldMemoyrManager::getSymbolAddressInProcess +method to search for the symbol within the program itself. If we can't find a +symbol definition via either of these paths the JIT will refuse to accept our +module, returning a "symbol not found" error. Now that we've built our symbol resolver we're ready to add our module to the JIT. We do this by calling the CompileLayer's addModuleSet method [4]_. Since diff --git a/docs/tutorial/BuildingAJIT2.rst b/docs/tutorial/BuildingAJIT2.rst index 8fa92317f54..839875266a2 100644 --- a/docs/tutorial/BuildingAJIT2.rst +++ b/docs/tutorial/BuildingAJIT2.rst @@ -93,8 +93,8 @@ define below. auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = OptimizeLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, // ... diff --git a/docs/tutorial/BuildingAJIT3.rst b/docs/tutorial/BuildingAJIT3.rst index 216e65c6fa1..fa197c59a6b 100644 --- a/docs/tutorial/BuildingAJIT3.rst +++ b/docs/tutorial/BuildingAJIT3.rst @@ -113,10 +113,11 @@ to create the compile callback needed for each function. Next we have to update our constructor to initialize the new members. To create an appropriate compile callback manager we use the createLocalCompileCallbackManager function, which takes a TargetMachine and a -TargetAddress to call if it receives a request to compile an unknown function. -In our simple JIT this situation is unlikely to come up, so we'll cheat and -just pass '0' here. In a production quality JIT you could give the address of a -function that throws an exception in order to unwind the JIT'd code's stack. +JITTargetAddress to call if it receives a request to compile an unknown +function. In our simple JIT this situation is unlikely to come up, so we'll +cheat and just pass '0' here. In a production quality JIT you could give the +address of a function that throws an exception in order to unwind the JIT'd +code's stack. Now we can construct our CompileOnDemandLayer. Following the pattern from previous layers we start by passing a reference to the next layer down in our diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h index 35c871affec..f750cba5336 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h @@ -16,10 +16,10 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" @@ -62,14 +62,14 @@ public: auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = CompileLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &Name) { if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) - return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(SymAddr, JITSymbolFlags::Exported); + return JITSymbol(nullptr); }); // Build a singlton module set to hold our module. diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h index 30cfed6af95..2b05b117b9a 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h @@ -16,10 +16,10 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" @@ -72,14 +72,14 @@ public: auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = OptimizeLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &Name) { if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) - return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(SymAddr, JITSymbolFlags::Exported); + return JITSymbol(nullptr); }); // Build a singlton module set to hold our module. diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h index 68bdafe9897..58afd9ab158 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h @@ -16,11 +16,11 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" @@ -83,14 +83,14 @@ public: auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = CODLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &Name) { if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) - return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(SymAddr, JITSymbolFlags::Exported); + return JITSymbol(nullptr); }); // Build a singlton module set to hold our module. diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h index d14c2b1805f..3aed48757bf 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h @@ -16,11 +16,11 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" @@ -107,16 +107,16 @@ public: auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = IndirectStubsMgr->findStub(Name, false)) - return Sym.toRuntimeDyldSymbol(); + return Sym; if (auto Sym = OptimizeLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &Name) { if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) - return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(SymAddr, JITSymbolFlags::Exported); + return JITSymbol(nullptr); }); // Build a singlton module set to hold our module. @@ -173,7 +173,7 @@ public: addModule(std::move(M)); auto Sym = findSymbol(SharedFnAST->getName() + "$impl"); assert(Sym && "Couldn't find compiled function?"); - TargetAddress SymAddr = Sym.getAddress(); + JITTargetAddress SymAddr = Sym.getAddress(); if (auto Err = IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()), SymAddr)) { diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h index 24d6dc9b7b8..0ba785eab9b 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h @@ -17,11 +17,11 @@ #include "RemoteJITUtils.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" @@ -123,21 +123,20 @@ public: auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = IndirectStubsMgr->findStub(Name, false)) - return Sym.toRuntimeDyldSymbol(); + return Sym; if (auto Sym = OptimizeLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [&](const std::string &Name) { if (auto AddrOrErr = Remote.getSymbolAddress(Name)) - return RuntimeDyld::SymbolInfo(*AddrOrErr, - JITSymbolFlags::Exported); + return JITSymbol(*AddrOrErr, JITSymbolFlags::Exported); else { logAllUnhandledErrors(AddrOrErr.takeError(), errs(), "Error resolving remote symbol:"); exit(1); } - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }); std::unique_ptr MemMgr; @@ -201,7 +200,7 @@ public: addModule(std::move(M)); auto Sym = findSymbol(SharedFnAST->getName() + "$impl"); assert(Sym && "Couldn't find compiled function?"); - TargetAddress SymAddr = Sym.getAddress(); + JITTargetAddress SymAddr = Sym.getAddress(); if (auto Err = IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()), SymAddr)) { @@ -216,7 +215,7 @@ public: return Error::success(); } - Error executeRemoteExpr(TargetAddress ExprAddr) { + Error executeRemoteExpr(JITTargetAddress ExprAddr) { return Remote.callVoidVoid(ExprAddr); } diff --git a/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/examples/Kaleidoscope/include/KaleidoscopeJIT.h index 2f492b0e17f..553ba2d15bd 100644 --- a/examples/Kaleidoscope/include/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/include/KaleidoscopeJIT.h @@ -17,12 +17,11 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/ExecutionEngine/JITSymbolFlags.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" @@ -60,8 +59,8 @@ public: auto Resolver = createLambdaResolver( [&](const std::string &Name) { if (auto Sym = findMangledSymbol(Name)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &S) { return nullptr; }); auto H = CompileLayer.addModuleSet(singletonSet(std::move(M)), diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h index ab13028b3ae..9bada02d569 100644 --- a/include/llvm/ExecutionEngine/ExecutionEngine.h +++ b/include/llvm/ExecutionEngine/ExecutionEngine.h @@ -137,13 +137,13 @@ protected: std::unique_ptr M, std::string *ErrorStr, std::shared_ptr MM, - std::shared_ptr SR, + std::shared_ptr SR, std::unique_ptr TM); static ExecutionEngine *(*OrcMCJITReplacementCtor)( std::string *ErrorStr, std::shared_ptr MM, - std::shared_ptr SR, + std::shared_ptr SR, std::unique_ptr TM); static ExecutionEngine *(*InterpCtor)(std::unique_ptr M, @@ -516,7 +516,7 @@ private: std::string *ErrorStr; CodeGenOpt::Level OptLevel; std::shared_ptr MemMgr; - std::shared_ptr Resolver; + std::shared_ptr Resolver; TargetOptions Options; Optional RelocModel; CodeModel::Model CMModel; @@ -555,7 +555,7 @@ public: setMemoryManager(std::unique_ptr MM); EngineBuilder& - setSymbolResolver(std::unique_ptr SR); + setSymbolResolver(std::unique_ptr SR); /// setErrorStr - Set the error string to write to on error. This option /// defaults to NULL. diff --git a/include/llvm/ExecutionEngine/JITSymbol.h b/include/llvm/ExecutionEngine/JITSymbol.h new file mode 100644 index 00000000000..135b51f0301 --- /dev/null +++ b/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 +#include + +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 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/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h index 9a6a9de6df4..d3dfbe5f6a6 100644 --- a/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ b/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -120,13 +120,12 @@ private: }; struct LogicalDylibResources { - typedef std::function - SymbolResolverFtor; + typedef std::function SymbolResolverFtor; typedef std::function, - std::unique_ptr)> + std::unique_ptr)> ModuleAdderFtor; LogicalDylibResources() = default; @@ -145,7 +144,7 @@ private: return *this; } - std::unique_ptr ExternalSymbolResolver; + std::unique_ptr ExternalSymbolResolver; std::unique_ptr> MemMgr; ModuleAdderFtor ModuleAdder; }; @@ -196,7 +195,7 @@ public: LDResources.ModuleAdder = [&MemMgrRef](BaseLayerT &B, std::unique_ptr M, - std::unique_ptr R) { + std::unique_ptr R) { std::vector> 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/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h b/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h index c10508cc8a6..21d4f81a124 100644 --- a/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h +++ b/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 @@ -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 - TargetAddress toTargetAddress(PtrTy* P) { - return static_cast(reinterpret_cast(P)); + JITTargetAddress toTargetAddress(PtrTy* P) { + return static_cast(reinterpret_cast(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 CXXRuntimeOverrides; + StringMap CXXRuntimeOverrides; typedef void (*DestructorPtr)(void*); typedef std::pair CXXDestructorDataPair; diff --git a/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h b/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h index 9fa222c340f..634d1480ae4 100644 --- a/include/llvm/ExecutionEngine/Orc/GlobalMappingLayer.h +++ b/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 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 SymbolTable; + std::map SymbolTable; }; } // End namespace orc. diff --git a/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h index e6ce18a42b8..f16dd021ea5 100644 --- a/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h +++ b/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 diff --git a/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h b/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h index 4dabb9a4149..c67297b111b 100644 --- a/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h +++ b/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/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h b/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h index 51172c51e13..bce0e990ef0 100644 --- a/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h +++ b/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 CompileFtor; + typedef std::function 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 TrampolineMapT; + typedef std::map TrampolineMapT; TrampolineMapT ActiveTrampolines; - std::vector AvailableTrampolines; + std::vector 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(CCMgr); return Mgr->executeCompileCallback( - static_cast(reinterpret_cast(TrampolineId))); + static_cast( + reinterpret_cast(TrampolineId))); } void grow() override { @@ -188,7 +189,7 @@ private: for (unsigned I = 0; I < NumTrampolines; ++I) this->AvailableTrampolines.push_back( - static_cast(reinterpret_cast( + static_cast(reinterpret_cast( 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> StubInitsMap; + typedef StringMap> 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 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(reinterpret_cast(StubAddr)); + static_cast(reinterpret_cast(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(reinterpret_cast(PtrAddr)); + static_cast(reinterpret_cast(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 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/include/llvm/ExecutionEngine/Orc/JITSymbol.h b/include/llvm/ExecutionEngine/Orc/JITSymbol.h deleted file mode 100644 index 464417e4e6d..00000000000 --- a/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 -#include - -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 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/include/llvm/ExecutionEngine/Orc/LambdaResolver.h b/include/llvm/ExecutionEngine/Orc/LambdaResolver.h index a42b9d5c29d..cbe2a80edf1 100644 --- a/include/llvm/ExecutionEngine/Orc/LambdaResolver.h +++ b/include/llvm/ExecutionEngine/Orc/LambdaResolver.h @@ -23,7 +23,7 @@ namespace llvm { namespace orc { template -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/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h b/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h index c5fb6b847b3..f992be97b50 100644 --- a/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h +++ b/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/include/llvm/ExecutionEngine/Orc/LogicalDylib.h b/include/llvm/ExecutionEngine/Orc/LogicalDylib.h index 914b112b7b6..af10b357235 100644 --- a/include/llvm/ExecutionEngine/Orc/LogicalDylib.h +++ b/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 #include diff --git a/include/llvm/ExecutionEngine/Orc/NullResolver.h b/include/llvm/ExecutionEngine/Orc/NullResolver.h index 1560c6d86e0..957b94912b3 100644 --- a/include/llvm/ExecutionEngine/Orc/NullResolver.h +++ b/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/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h index a7798d8beb8..1435c86326e 100644 --- a/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/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 #include @@ -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 SymbolTable; + StringMap 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/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h b/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h index 2ffe71c9435..173c106cd3e 100644 --- a/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h +++ b/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/include/llvm/ExecutionEngine/Orc/OrcABISupport.h b/include/llvm/ExecutionEngine/Orc/OrcABISupport.h index 4a8d0b0b801..fa236b0de88 100644 --- a/include/llvm/ExecutionEngine/Orc/OrcABISupport.h +++ b/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/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h index 12705aff9e1..4b31e860912 100644 --- a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h +++ b/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(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 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 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 callIntVoid(TargetAddress Addr) { + Expected 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 callMain(TargetAddress Addr, + Expected callMain(JITTargetAddress Addr, const std::vector &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 - 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 getSymbolAddress(StringRef Name) { + Expected 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(Channel, Addr, Size); } @@ -716,12 +716,12 @@ private: return callST(Channel, Id); } - Expected> + Expected> emitIndirectStubs(ResourceIdMgr::ResourceId Id, uint32_t NumStubsRequired) { return callST(Channel, Id, NumStubsRequired); } - Expected> emitTrampolineBlock() { + Expected> 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 { + [this](JITTargetAddress Addr) -> Expected { return this->CallbackManager->executeCompileCallback(Addr); }; @@ -760,7 +760,7 @@ private: return orcError(OrcErrorCode::UnexpectedRPCCall); } - Expected> readMem(char *Dst, TargetAddress Src, + Expected> 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(Channel, Src, Size); } - Error registerEHFrames(TargetAddress &RAddr, uint32_t Size) { + Error registerEHFrames(JITTargetAddress &RAddr, uint32_t Size) { return callST(Channel, RAddr, Size); } - Expected reserveMem(ResourceIdMgr::ResourceId Id, - uint64_t Size, uint32_t Align) { + Expected 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(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(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/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h index 74d851522f7..e951c124b15 100644 --- a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h +++ b/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 CallIntVoid; + typedef Function CallIntVoid; typedef Function Args)> + int32_t(JITTargetAddress Addr, + std::vector Args)> CallMain; - typedef Function CallVoidVoid; + typedef Function CallVoidVoid; typedef Function @@ -137,7 +138,7 @@ public: CreateIndirectStubsOwner; typedef Function + void(JITTargetAddress Addr, uint32_t Size)> DeregisterEHFrames; typedef Function( + std::tuple( ResourceIdMgr::ResourceId StubsOwnerID, uint32_t NumStubsRequired)> EmitIndirectStubs; @@ -158,10 +159,11 @@ public: typedef Function EmitResolverBlock; /// EmitTrampolineBlock result is (BlockAddr, NumTrampolines). - typedef Function()> + typedef Function()> EmitTrampolineBlock; - typedef Function + typedef Function GetSymbolAddress; /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize, @@ -171,23 +173,23 @@ public: GetRemoteInfo; typedef Function(TargetAddress Src, uint64_t Size)> + std::vector(JITTargetAddress Src, uint64_t Size)> ReadMem; - typedef Function + typedef Function RegisterEHFrames; typedef Function + JITTargetAddress(ResourceIdMgr::ResourceId AllocID, + uint64_t Size, uint32_t Align)> ReserveMem; typedef Function + JITTargetAddress(JITTargetAddress TrampolineAddr)> RequestCompile; typedef Function SetProtections; @@ -195,7 +197,7 @@ public: typedef Function WriteMem; - typedef Function + typedef Function WritePtr; }; diff --git a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h index bf4299c69b2..48e58f6bbfd 100644 --- a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h +++ b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h @@ -32,7 +32,7 @@ namespace remote { template class OrcRemoteTargetServer : public OrcRemoteTargetRPCAPI { public: - typedef std::function + typedef std::function SymbolLookupFtor; typedef std::function @@ -118,7 +118,7 @@ public: llvm_unreachable("Unhandled JIT RPC procedure Id."); } - Expected requestCompile(TargetAddress TrampolineAddr) { + Expected requestCompile(JITTargetAddress TrampolineAddr) { auto Listen = [&](RPCChannel &C, uint32_t Id) { return handleKnownFunction(static_cast(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(JITTargetAddr); - auto AddrOrErr = T->requestCompile(static_cast( + auto AddrOrErr = T->requestCompile(static_cast( reinterpret_cast(TrampolineAddr))); // FIXME: Allow customizable failure substitution functions. assert(AddrOrErr && "Compile request failed"); return *AddrOrErr; } - Expected handleCallIntVoid(TargetAddress Addr) { + Expected handleCallIntVoid(JITTargetAddress Addr) { typedef int (*IntVoidFnTy)(); IntVoidFnTy Fn = reinterpret_cast(static_cast(Addr)); @@ -192,7 +192,7 @@ private: return Result; } - Expected handleCallMain(TargetAddress Addr, + Expected handleCallMain(JITTargetAddress Addr, std::vector 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(static_cast(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(static_cast(TAddr)); DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr) << ", Size = " << Size << " bytes\n"); @@ -266,7 +266,7 @@ private: return Error::success(); } - Expected> + Expected> 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(reinterpret_cast(IS.getStub(0))); - TargetAddress PtrsBase = - static_cast(reinterpret_cast(IS.getPtr(0))); + JITTargetAddress StubsBase = + static_cast( + reinterpret_cast(IS.getStub(0))); + JITTargetAddress PtrsBase = + static_cast( + reinterpret_cast(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> handleEmitTrampolineBlock() { + Expected> 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(reinterpret_cast(TrampolineMem)); + static_cast( + reinterpret_cast(TrampolineMem)); return std::make_tuple(TrampolineBaseAddr, NumTrampolines); } - Expected handleGetSymbolAddress(const std::string &Name) { - TargetAddress Addr = SymbolLookup(Name); + Expected 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> handleReadMem(TargetAddress RSrc, uint64_t Size) { + Expected> handleReadMem(JITTargetAddress RSrc, uint64_t Size) { char *Src = reinterpret_cast(static_cast(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(static_cast(TAddr)); DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr) << ", Size = " << Size << " bytes\n"); @@ -384,8 +387,8 @@ private: return Error::success(); } - Expected handleReserveMem(ResourceIdMgr::ResourceId Id, - uint64_t Size, uint32_t Align) { + Expected 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(reinterpret_cast(LocalAllocAddr)); + JITTargetAddress AllocAddr = + static_cast( + reinterpret_cast(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/include/llvm/ExecutionEngine/RTDyldMemoryManager.h b/include/llvm/ExecutionEngine/RTDyldMemoryManager.h index adcb063f454..74423b92d80 100644 --- a/include/llvm/ExecutionEngine/RTDyldMemoryManager.h +++ b/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/include/llvm/ExecutionEngine/RuntimeDyld.h b/include/llvm/ExecutionEngine/RuntimeDyld.h index bd485de91bd..70df6ca0d8f 100644 --- a/include/llvm/ExecutionEngine/RuntimeDyld.h +++ b/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 Dyld; MemoryManager &MemMgr; - SymbolResolver &Resolver; + JITSymbolResolver &Resolver; bool ProcessAllSections; RuntimeDyldCheckerImpl *Checker; }; diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index a8e68bf49ab..2985f9bae8c 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -48,12 +48,13 @@ STATISTIC(NumGlobals , "Number of global vars initialized"); ExecutionEngine *(*ExecutionEngine::MCJITCtor)( std::unique_ptr M, std::string *ErrorStr, std::shared_ptr MemMgr, - std::shared_ptr Resolver, + + std::shared_ptr Resolver, std::unique_ptr TM) = nullptr; ExecutionEngine *(*ExecutionEngine::OrcMCJITReplacementCtor)( std::string *ErrorStr, std::shared_ptr MemMgr, - std::shared_ptr Resolver, + std::shared_ptr Resolver, std::unique_ptr TM) = nullptr; ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr M, @@ -499,8 +500,8 @@ EngineBuilder::setMemoryManager(std::unique_ptr MM) { } EngineBuilder& -EngineBuilder::setSymbolResolver(std::unique_ptr SR) { - Resolver = std::shared_ptr(std::move(SR)); +EngineBuilder::setSymbolResolver(std::unique_ptr SR) { + Resolver = std::shared_ptr(std::move(SR)); return *this; } diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 7fb328babfe..bb93271f596 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -46,7 +46,7 @@ ExecutionEngine* MCJIT::createJIT(std::unique_ptr M, std::string *ErrorStr, std::shared_ptr MemMgr, - std::shared_ptr Resolver, + std::shared_ptr Resolver, std::unique_ptr TM) { // Try to register the program as a source of symbols to resolve against. // @@ -67,7 +67,7 @@ MCJIT::createJIT(std::unique_ptr M, MCJIT::MCJIT(std::unique_ptr M, std::unique_ptr TM, std::shared_ptr MemMgr, - std::shared_ptr Resolver) + std::shared_ptr Resolver) : ExecutionEngine(TM->createDataLayout(), std::move(M)), TM(std::move(TM)), Ctx(nullptr), MemMgr(std::move(MemMgr)), Resolver(*this, std::move(Resolver)), Dyld(*this->MemMgr, this->Resolver), @@ -276,14 +276,14 @@ void MCJIT::finalizeModule(Module *M) { finalizeLoadedModules(); } -RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) { +JITSymbol MCJIT::findExistingSymbol(const std::string &Name) { SmallString<128> FullName; Mangler::getNameWithPrefix(FullName, Name, getDataLayout()); if (void *Addr = getPointerToGlobalIfAvailable(FullName)) - return RuntimeDyld::SymbolInfo(static_cast( - reinterpret_cast(Addr)), - JITSymbolFlags::Exported); + return JITSymbol(static_cast( + reinterpret_cast(Addr)), + JITSymbolFlags::Exported); return Dyld.getSymbol(FullName); } @@ -316,8 +316,8 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name, return findSymbol(Name, CheckFunctionsOnly).getAddress(); } -RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name, - bool CheckFunctionsOnly) { +JITSymbol MCJIT::findSymbol(const std::string &Name, + bool CheckFunctionsOnly) { MutexGuard locked(lock); // First, check to see if we already have this symbol. @@ -367,7 +367,7 @@ RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name, if (LazyFunctionCreator) { auto Addr = static_cast( reinterpret_cast(LazyFunctionCreator(Name))); - return RuntimeDyld::SymbolInfo(Addr, JITSymbolFlags::Exported); + return JITSymbol(Addr, JITSymbolFlags::Exported); } return nullptr; @@ -644,7 +644,7 @@ void MCJIT::NotifyFreeingObject(const object::ObjectFile& Obj) { L->NotifyFreeingObject(Obj); } -RuntimeDyld::SymbolInfo +JITSymbol LinkingSymbolResolver::findSymbol(const std::string &Name) { auto Result = ParentEngine.findSymbol(Name, false); // If the symbols wasn't found and it begins with an underscore, try again diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.h b/lib/ExecutionEngine/MCJIT/MCJIT.h index e25f76cd57f..4cb9bebde55 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.h +++ b/lib/ExecutionEngine/MCJIT/MCJIT.h @@ -26,23 +26,22 @@ class MCJIT; // functions across modules that it owns. It aggregates the memory manager // that is passed in to the MCJIT constructor and defers most functionality // to that object. -class LinkingSymbolResolver : public RuntimeDyld::SymbolResolver { +class LinkingSymbolResolver : public JITSymbolResolver { public: LinkingSymbolResolver(MCJIT &Parent, - std::shared_ptr Resolver) + std::shared_ptr Resolver) : ParentEngine(Parent), ClientResolver(std::move(Resolver)) {} - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override; + JITSymbol findSymbol(const std::string &Name) override; // MCJIT doesn't support logical dylibs. - RuntimeDyld::SymbolInfo - findSymbolInLogicalDylib(const std::string &Name) override { + JITSymbol findSymbolInLogicalDylib(const std::string &Name) override { return nullptr; } private: MCJIT &ParentEngine; - std::shared_ptr ClientResolver; + std::shared_ptr ClientResolver; }; // About Module states: added->loaded->finalized. @@ -68,7 +67,7 @@ private: class MCJIT : public ExecutionEngine { MCJIT(std::unique_ptr M, std::unique_ptr tm, std::shared_ptr MemMgr, - std::shared_ptr Resolver); + std::shared_ptr Resolver); typedef llvm::SmallPtrSet ModulePtrSet; @@ -305,13 +304,12 @@ public: createJIT(std::unique_ptr M, std::string *ErrorStr, std::shared_ptr MemMgr, - std::shared_ptr Resolver, + std::shared_ptr Resolver, std::unique_ptr TM); // @} - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name, - bool CheckFunctionsOnly); + JITSymbol findSymbol(const std::string &Name, bool CheckFunctionsOnly); // DEPRECATED - Please use findSymbol instead. // This is not directly exposed via the ExecutionEngine API, but it is // used by the LinkingMemoryManager. @@ -330,9 +328,8 @@ protected: const RuntimeDyld::LoadedObjectInfo &L); void NotifyFreeingObject(const object::ObjectFile& Obj); - RuntimeDyld::SymbolInfo findExistingSymbol(const std::string &Name); - Module *findModuleForSymbol(const std::string &Name, - bool CheckFunctionsOnly); + JITSymbol findExistingSymbol(const std::string &Name); + Module *findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly); }; } // end llvm namespace diff --git a/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index 6f7c29feef0..7e2e873f8d3 100644 --- a/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -24,7 +24,7 @@ void IndirectStubsManager::anchor() {} std::unique_ptr createLocalCompileCallbackManager(const Triple &T, - TargetAddress ErrorHandlerAddress) { + JITTargetAddress ErrorHandlerAddress) { switch (T.getArch()) { default: return nullptr; @@ -71,7 +71,7 @@ createLocalIndirectStubsManagerBuilder(const Triple &T) { } } -Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr) { +Constant* createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr) { Constant *AddrIntVal = ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr); Constant *AddrPtrVal = diff --git a/lib/ExecutionEngine/Orc/NullResolver.cpp b/lib/ExecutionEngine/Orc/NullResolver.cpp index 57666a9dada..8f2d6fd6c32 100644 --- a/lib/ExecutionEngine/Orc/NullResolver.cpp +++ b/lib/ExecutionEngine/Orc/NullResolver.cpp @@ -14,12 +14,11 @@ namespace llvm { namespace orc { -RuntimeDyld::SymbolInfo NullResolver::findSymbol(const std::string &Name) { +JITSymbol NullResolver::findSymbol(const std::string &Name) { llvm_unreachable("Unexpected cross-object symbol reference"); } -RuntimeDyld::SymbolInfo -NullResolver::findSymbolInLogicalDylib(const std::string &Name) { +JITSymbol NullResolver::findSymbolInLogicalDylib(const std::string &Name) { llvm_unreachable("Unexpected cross-object symbol reference"); } diff --git a/lib/ExecutionEngine/Orc/OrcCBindingsStack.h b/lib/ExecutionEngine/Orc/OrcCBindingsStack.h index 9ae9b20feb0..a74fae775ac 100644 --- a/lib/ExecutionEngine/Orc/OrcCBindingsStack.h +++ b/lib/ExecutionEngine/Orc/OrcCBindingsStack.h @@ -44,8 +44,8 @@ private: class GenericHandle { public: virtual ~GenericHandle() {} - virtual orc::JITSymbol findSymbolIn(const std::string &Name, - bool ExportedSymbolsOnly) = 0; + virtual JITSymbol findSymbolIn(const std::string &Name, + bool ExportedSymbolsOnly) = 0; virtual void removeModule() = 0; }; @@ -54,8 +54,8 @@ private: GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle) : Layer(Layer), Handle(std::move(Handle)) {} - orc::JITSymbol findSymbolIn(const std::string &Name, - bool ExportedSymbolsOnly) override { + JITSymbol findSymbolIn(const std::string &Name, + bool ExportedSymbolsOnly) override { return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly); } @@ -109,55 +109,56 @@ public: } template - static PtrTy fromTargetAddress(orc::TargetAddress Addr) { + static PtrTy fromTargetAddress(JITTargetAddress Addr) { return reinterpret_cast(static_cast(Addr)); } - orc::TargetAddress + JITTargetAddress createLazyCompileCallback(LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx) { auto CCInfo = CCMgr->getCompileCallback(); - CCInfo.setCompileAction([=]() -> orc::TargetAddress { + CCInfo.setCompileAction([=]() -> JITTargetAddress { return Callback(wrap(this), CallbackCtx); }); return CCInfo.getAddress(); } LLVMOrcErrorCode createIndirectStub(StringRef StubName, - orc::TargetAddress Addr) { + JITTargetAddress Addr) { return mapError( IndirectStubsMgr->createStub(StubName, Addr, JITSymbolFlags::Exported)); } LLVMOrcErrorCode setIndirectStubPointer(StringRef Name, - orc::TargetAddress Addr) { + JITTargetAddress Addr) { return mapError(IndirectStubsMgr->updatePointer(Name, Addr)); } - std::unique_ptr + std::unique_ptr createResolver(LLVMOrcSymbolResolverFn ExternalResolver, void *ExternalResolverCtx) { return orc::createLambdaResolver( - [this, ExternalResolver, ExternalResolverCtx](const std::string &Name) { + [this, ExternalResolver, ExternalResolverCtx](const std::string &Name) + -> JITSymbol { // Search order: // 1. JIT'd symbols. // 2. Runtime overrides. // 3. External resolver (if present). if (auto Sym = CODLayer.findSymbol(Name, true)) - return Sym.toRuntimeDyldSymbol(); + return Sym; if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name)) return Sym; if (ExternalResolver) - return RuntimeDyld::SymbolInfo( + return JITSymbol( ExternalResolver(Name.c_str(), ExternalResolverCtx), llvm::JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }, [](const std::string &Name) { - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }); } @@ -222,14 +223,14 @@ public: FreeHandleIndexes.push_back(H); } - orc::JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { + JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { if (auto Sym = IndirectStubsMgr->findStub(Name, ExportedSymbolsOnly)) return Sym; return CODLayer.findSymbol(mangle(Name), ExportedSymbolsOnly); } - orc::JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, - bool ExportedSymbolsOnly) { + JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, + bool ExportedSymbolsOnly) { return GenericHandles[H]->findSymbolIn(Name, ExportedSymbolsOnly); } diff --git a/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h b/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h index d1083072c98..805852b4887 100644 --- a/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h +++ b/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h @@ -111,16 +111,15 @@ class OrcMCJITReplacement : public ExecutionEngine { std::shared_ptr ClientMM; }; - class LinkingResolver : public RuntimeDyld::SymbolResolver { + class LinkingResolver : public JITSymbolResolver { public: LinkingResolver(OrcMCJITReplacement &M) : M(M) {} - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override { + JITSymbol findSymbol(const std::string &Name) override { return M.findMangledSymbol(Name); } - RuntimeDyld::SymbolInfo - findSymbolInLogicalDylib(const std::string &Name) override { + JITSymbol findSymbolInLogicalDylib(const std::string &Name) override { return M.ClientResolver->findSymbol(Name); } @@ -133,7 +132,7 @@ private: static ExecutionEngine * createOrcMCJITReplacement(std::string *ErrorMsg, std::shared_ptr MemMgr, - std::shared_ptr Resolver, + std::shared_ptr Resolver, std::unique_ptr TM) { return new OrcMCJITReplacement(std::move(MemMgr), std::move(Resolver), std::move(TM)); @@ -146,7 +145,7 @@ public: OrcMCJITReplacement( std::shared_ptr MemMgr, - std::shared_ptr ClientResolver, + std::shared_ptr ClientResolver, std::unique_ptr TM) : ExecutionEngine(TM->createDataLayout()), TM(std::move(TM)), MemMgr(*this, std::move(MemMgr)), Resolver(*this), @@ -193,7 +192,7 @@ public: return findSymbol(Name).getAddress(); } - RuntimeDyld::SymbolInfo findSymbol(StringRef Name) { + JITSymbol findSymbol(StringRef Name) { return findMangledSymbol(Mangle(Name)); } @@ -243,13 +242,13 @@ public: private: - RuntimeDyld::SymbolInfo findMangledSymbol(StringRef Name) { + JITSymbol findMangledSymbol(StringRef Name) { if (auto Sym = LazyEmitLayer.findSymbol(Name, false)) - return Sym.toRuntimeDyldSymbol(); + return Sym; if (auto Sym = ClientResolver->findSymbol(Name)) return Sym; if (auto Sym = scanArchives(Name)) - return Sym.toRuntimeDyldSymbol(); + return Sym; return nullptr; } @@ -346,7 +345,7 @@ private: std::unique_ptr TM; MCJITReplacementMemMgr MemMgr; LinkingResolver Resolver; - std::shared_ptr ClientResolver; + std::shared_ptr ClientResolver; Mangler Mang; NotifyObjectLoadedT NotifyObjectLoaded; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 1dfbe31f271..1e0903349ef 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -974,10 +974,10 @@ uint64_t RuntimeDyld::LoadedObjectInfo::getSectionLoadAddress( } void RuntimeDyld::MemoryManager::anchor() {} -void RuntimeDyld::SymbolResolver::anchor() {} +void JITSymbolResolver::anchor() {} RuntimeDyld::RuntimeDyld(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : MemMgr(MemMgr), Resolver(Resolver) { // FIXME: There's a potential issue lurking here if a single instance of // RuntimeDyld is used to load multiple objects. The current implementation @@ -994,8 +994,8 @@ RuntimeDyld::~RuntimeDyld() {} static std::unique_ptr createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver, - bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker) { + JITSymbolResolver &Resolver, bool ProcessAllSections, + RuntimeDyldCheckerImpl *Checker) { std::unique_ptr Dyld = RuntimeDyldCOFF::create(Arch, MM, Resolver); Dyld->setProcessAllSections(ProcessAllSections); @@ -1005,8 +1005,8 @@ createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, static std::unique_ptr createRuntimeDyldELF(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver, - bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker) { + JITSymbolResolver &Resolver, bool ProcessAllSections, + RuntimeDyldCheckerImpl *Checker) { std::unique_ptr Dyld(new RuntimeDyldELF(MM, Resolver)); Dyld->setProcessAllSections(ProcessAllSections); Dyld->setRuntimeDyldChecker(Checker); @@ -1015,7 +1015,7 @@ createRuntimeDyldELF(RuntimeDyld::MemoryManager &MM, static std::unique_ptr createRuntimeDyldMachO(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver, + JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker) { std::unique_ptr Dyld = @@ -1056,7 +1056,7 @@ void *RuntimeDyld::getSymbolLocalAddress(StringRef Name) const { return Dyld->getSymbolLocalAddress(Name); } -RuntimeDyld::SymbolInfo RuntimeDyld::getSymbol(StringRef Name) const { +JITEvaluatedSymbol RuntimeDyld::getSymbol(StringRef Name) const { if (!Dyld) return nullptr; return Dyld->getSymbol(Name); diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp index 24bd9a002c2..1bd28ef37ed 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp @@ -44,7 +44,7 @@ namespace llvm { std::unique_ptr llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) { + JITSymbolResolver &Resolver) { switch (Arch) { default: llvm_unreachable("Unsupported target for RuntimeDyldCOFF."); case Triple::x86: diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h index 03a91f6cf69..729a358fa0e 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h @@ -33,11 +33,11 @@ public: static std::unique_ptr create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver); + JITSymbolResolver &Resolver); protected: RuntimeDyldCOFF(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldImpl(MemMgr, Resolver) {} uint64_t getSymbolOffset(const SymbolRef &Sym); }; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 9cbdb13a357..0f0ef993bc4 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -184,7 +184,7 @@ LoadedELFObjectInfo::getObjectForDebug(const ObjectFile &Obj) const { namespace llvm { RuntimeDyldELF::RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldImpl(MemMgr, Resolver), GOTSectionID(0), CurrentGOTIndex(0) {} RuntimeDyldELF::~RuntimeDyldELF() {} diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h index 82931b9f45a..74e48b1b137 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h @@ -159,7 +159,7 @@ class RuntimeDyldELF : public RuntimeDyldImpl { public: RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver); + JITSymbolResolver &Resolver); ~RuntimeDyldELF() override; std::unique_ptr diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h index 76bd3fc295b..af2c9e8a4eb 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h @@ -227,7 +227,7 @@ protected: RuntimeDyld::MemoryManager &MemMgr; // The symbol resolver to use for external symbols. - RuntimeDyld::SymbolResolver &Resolver; + JITSymbolResolver &Resolver; // Attached RuntimeDyldChecker instance. Null if no instance attached. RuntimeDyldCheckerImpl *Checker; @@ -420,7 +420,7 @@ protected: public: RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : MemMgr(MemMgr), Resolver(Resolver), Checker(nullptr), ProcessAllSections(false), HasError(false) { } @@ -451,7 +451,7 @@ public: return getSectionAddress(SymInfo.getSectionID()) + SymInfo.getOffset(); } - RuntimeDyld::SymbolInfo getSymbol(StringRef Name) const { + JITEvaluatedSymbol getSymbol(StringRef Name) const { // FIXME: Just look up as a function for now. Overly simple of course. // Work in progress. RTDyldSymbolTable::const_iterator pos = GlobalSymbolTable.find(Name); @@ -462,7 +462,7 @@ public: if (SymEntry.getSectionID() != AbsoluteSymbolSection) SectionAddr = getSectionLoadAddress(SymEntry.getSectionID()); uint64_t TargetAddr = SectionAddr + SymEntry.getOffset(); - return RuntimeDyld::SymbolInfo(TargetAddr, SymEntry.getFlags()); + return JITEvaluatedSymbol(TargetAddr, SymEntry.getFlags()); } void resolveRelocations(); diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index fd109aea91d..00541e8c06f 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -343,7 +343,7 @@ void RuntimeDyldMachOCRTPBase::registerEHFrames() { std::unique_ptr RuntimeDyldMachO::create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) { + JITSymbolResolver &Resolver) { switch (Arch) { default: llvm_unreachable("Unsupported target for RuntimeDyldMachO."); diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h index 30f3bb3bf07..67a5020fc4f 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h @@ -50,7 +50,7 @@ protected: SmallVector UnregisteredEHFrameSections; RuntimeDyldMachO(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldImpl(MemMgr, Resolver) {} /// This convenience method uses memcpy to extract a contiguous addend (the @@ -124,7 +124,7 @@ public: static std::unique_ptr create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver); + JITSymbolResolver &Resolver); std::unique_ptr loadObject(const object::ObjectFile &O) override; @@ -152,7 +152,7 @@ private: public: RuntimeDyldMachOCRTPBase(RuntimeDyld::MemoryManager &MemMgr, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldMachO(MemMgr, Resolver) {} Error finalizeLoad(const ObjectFile &Obj, diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h index 44fda87e0f9..0398413e153 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h @@ -25,7 +25,7 @@ namespace llvm { class RuntimeDyldCOFFI386 : public RuntimeDyldCOFF { public: RuntimeDyldCOFFI386(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldCOFF(MM, Resolver) {} unsigned getMaxStubSize() override { diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h index ff7d1d43925..91fdd936d7d 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h @@ -25,7 +25,7 @@ namespace llvm { class RuntimeDyldCOFFThumb : public RuntimeDyldCOFF { public: RuntimeDyldCOFFThumb(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldCOFF(MM, Resolver) {} unsigned getMaxStubSize() override { diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h index df8681da24d..109beb36f1e 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h @@ -33,7 +33,7 @@ private: public: RuntimeDyldCOFFX86_64(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldCOFF(MM, Resolver) {} unsigned getMaxStubSize() override { diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h index 63598f19707..cf8309319d6 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h @@ -24,7 +24,7 @@ public: typedef uint64_t TargetPtrT; RuntimeDyldMachOAArch64(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldMachOCRTPBase(MM, Resolver) {} unsigned getMaxStubSize() override { return 8; } diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h index 0abf9daba50..adca0eeb08b 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h @@ -27,7 +27,7 @@ public: typedef uint32_t TargetPtrT; RuntimeDyldMachOARM(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldMachOCRTPBase(MM, Resolver) {} unsigned getMaxStubSize() override { return 8; } diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h index 2c79b3f7c81..c42f1751a18 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h @@ -24,7 +24,7 @@ public: typedef uint32_t TargetPtrT; RuntimeDyldMachOI386(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldMachOCRTPBase(MM, Resolver) {} unsigned getMaxStubSize() override { return 0; } diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h index bc482298324..32fd3efddd0 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h @@ -24,7 +24,7 @@ public: typedef uint64_t TargetPtrT; RuntimeDyldMachOX86_64(RuntimeDyld::MemoryManager &MM, - RuntimeDyld::SymbolResolver &Resolver) + JITSymbolResolver &Resolver) : RuntimeDyldMachOCRTPBase(MM, Resolver) {} unsigned getMaxStubSize() override { return 8; } diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp index b13e7696627..552f5791a10 100644 --- a/tools/lli/OrcLazyJIT.cpp +++ b/tools/lli/OrcLazyJIT.cpp @@ -101,7 +101,7 @@ CodeGenOpt::Level getOptLevel(); template -static PtrTy fromTargetAddress(orc::TargetAddress Addr) { +static PtrTy fromTargetAddress(JITTargetAddress Addr) { return reinterpret_cast(static_cast(Addr)); } diff --git a/tools/lli/OrcLazyJIT.h b/tools/lli/OrcLazyJIT.h index 733bdd8c04d..72f35ad6ab6 100644 --- a/tools/lli/OrcLazyJIT.h +++ b/tools/lli/OrcLazyJIT.h @@ -81,20 +81,20 @@ public: // 3) Search the host process (LLI)'s symbol table. auto Resolver = orc::createLambdaResolver( - [this](const std::string &Name) { + [this](const std::string &Name) -> JITSymbol { if (auto Sym = CODLayer.findSymbol(Name, true)) - return Sym.toRuntimeDyldSymbol(); + return Sym; if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name)) return Sym; if (auto Addr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) - return RuntimeDyld::SymbolInfo(Addr, JITSymbolFlags::Exported); + return JITSymbol(Addr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }, [](const std::string &Name) { - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); } ); @@ -115,11 +115,11 @@ public: return H; } - orc::JITSymbol findSymbol(const std::string &Name) { + JITSymbol findSymbol(const std::string &Name) { return CODLayer.findSymbol(mangle(Name), true); } - orc::JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) { + JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) { return CODLayer.findSymbolIn(H, mangle(Name), true); } diff --git a/tools/lli/RemoteJITUtils.h b/tools/lli/RemoteJITUtils.h index 15068d2faf6..0c4306ad5cb 100644 --- a/tools/lli/RemoteJITUtils.h +++ b/tools/lli/RemoteJITUtils.h @@ -83,7 +83,7 @@ public: this->MemMgr = std::move(MemMgr); } - void setResolver(std::unique_ptr Resolver) { + void setResolver(std::unique_ptr Resolver) { this->Resolver = std::move(Resolver); } @@ -134,18 +134,18 @@ public: // Don't hide the sibling notifyObjectLoaded from RTDyldMemoryManager. using RTDyldMemoryManager::notifyObjectLoaded; - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override { + JITSymbol findSymbol(const std::string &Name) override { return Resolver->findSymbol(Name); } - RuntimeDyld::SymbolInfo + JITSymbol findSymbolInLogicalDylib(const std::string &Name) override { return Resolver->findSymbolInLogicalDylib(Name); } private: std::unique_ptr MemMgr; - std::unique_ptr Resolver; + std::unique_ptr Resolver; }; } diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 92de5da4721..be22cc927c2 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -669,15 +669,15 @@ int main(int argc, char **argv, char * const *envp) { [](const std::string &Name) { return nullptr; }, [&](const std::string &Name) { if (auto Addr = ExitOnErr(R.getSymbolAddress(Name))) - return RuntimeDyld::SymbolInfo(Addr, JITSymbolFlags::Exported); - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(Addr, JITSymbolFlags::Exported); + return JITSymbol(nullptr); } )); // Grab the target address of the JIT'd main function on the remote and call // it. // FIXME: argv and envp handling. - orc::TargetAddress Entry = EE->getFunctionAddress(EntryFn->getName().str()); + JITTargetAddress Entry = EE->getFunctionAddress(EntryFn->getName().str()); EE->finalizeObject(); DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x" << format("%llx", Entry) << "\n"); diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index b1460e35de8..f1b0e6d63c0 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -165,11 +165,11 @@ public: DummyExterns[Name] = Addr; } - RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override { + JITSymbol findSymbol(const std::string &Name) override { auto I = DummyExterns.find(Name); if (I != DummyExterns.end()) - return RuntimeDyld::SymbolInfo(I->second, JITSymbolFlags::Exported); + return JITSymbol(I->second, JITSymbolFlags::Exported); return RTDyldMemoryManager::findSymbol(Name); } diff --git a/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp b/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp index 8140a1ff249..ab04c14b095 100644 --- a/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp @@ -26,7 +26,7 @@ public: class DummyStubsManager : public orc::IndirectStubsManager { public: - Error createStub(StringRef StubName, TargetAddress InitAddr, + Error createStub(StringRef StubName, JITTargetAddress InitAddr, JITSymbolFlags Flags) override { llvm_unreachable("Not implemented"); } @@ -43,7 +43,7 @@ public: llvm_unreachable("Not implemented"); } - Error updatePointer(StringRef Name, TargetAddress NewAddr) override { + Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override { llvm_unreachable("Not implemented"); } }; diff --git a/unittests/ExecutionEngine/Orc/GlobalMappingLayerTest.cpp b/unittests/ExecutionEngine/Orc/GlobalMappingLayerTest.cpp index 054fc16cabd..25b6c891c62 100644 --- a/unittests/ExecutionEngine/Orc/GlobalMappingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/GlobalMappingLayerTest.cpp @@ -21,7 +21,7 @@ struct MockBaseLayer { JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { if (Name == "bar") - return llvm::orc::JITSymbol(0x4567, JITSymbolFlags::Exported); + return llvm::JITSymbol(0x4567, JITSymbolFlags::Exported); return nullptr; } @@ -37,13 +37,13 @@ TEST(GlobalMappingLayerTest, Empty) { // Test fall-through for symbol in base layer. auto BarSym = L.findSymbol("bar", true); - EXPECT_EQ(BarSym.getAddress(), static_cast(0x4567)) + EXPECT_EQ(BarSym.getAddress(), static_cast(0x4567)) << "Symbol lookup fall-through failed."; // Test setup of a global mapping. L.setGlobalMapping("foo", 0x0123); auto FooSym2 = L.findSymbol("foo", true); - EXPECT_EQ(FooSym2.getAddress(), static_cast(0x0123)) + EXPECT_EQ(FooSym2.getAddress(), static_cast(0x0123)) << "Symbol mapping setup failed."; // Test removal of a global mapping. diff --git a/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp b/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp index a495766db91..3362f490a38 100644 --- a/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" #include "gtest/gtest.h" @@ -17,7 +18,7 @@ struct MockBaseLayer { ModuleSetHandleT addModuleSet( std::list>, std::unique_ptr MemMgr, - std::unique_ptr Resolver) { + std::unique_ptr Resolver) { EXPECT_FALSE(MemMgr); return 42; } diff --git a/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp b/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp index 87928347d88..44b44f60415 100644 --- a/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp @@ -90,10 +90,10 @@ TEST(ObjectLinkingLayerTest, TestSetProcessAllSections) { auto Resolver = createLambdaResolver( [](const std::string &Name) { - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }, [](const std::string &Name) { - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }); { @@ -165,11 +165,11 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) { createLambdaResolver( [&](const std::string &Name) { if (auto Sym = ObjLayer.findSymbol(Name, true)) - return Sym.toRuntimeDyldSymbol(); - return RuntimeDyld::SymbolInfo(nullptr); + return Sym; + return JITSymbol(nullptr); }, [](const std::string &Name) { - return RuntimeDyld::SymbolInfo(nullptr); + return JITSymbol(nullptr); }); SectionMemoryManagerWrapper SMMW; diff --git a/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp b/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp index e1b1f2f9278..63b85dc82ca 100644 --- a/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp @@ -95,31 +95,32 @@ public: resetExpectations(); } - JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { + llvm::JITSymbol findSymbol(const std::string &Name, + bool ExportedSymbolsOnly) { EXPECT_EQ(MockName, Name) << "Name should pass through"; EXPECT_EQ(MockBool, ExportedSymbolsOnly) << "Flag should pass through"; LastCalled = "findSymbol"; - MockSymbol = JITSymbol(122, llvm::JITSymbolFlags::None); + MockSymbol = llvm::JITSymbol(122, llvm::JITSymbolFlags::None); return MockSymbol; } void expectFindSymbol(const std::string &Name, bool ExportedSymbolsOnly) { MockName = Name; MockBool = ExportedSymbolsOnly; } - void verifyFindSymbol(llvm::orc::JITSymbol Returned) { + void verifyFindSymbol(llvm::JITSymbol Returned) { EXPECT_EQ("findSymbol", LastCalled); EXPECT_EQ(MockSymbol.getAddress(), Returned.getAddress()) << "Return should pass through"; resetExpectations(); } - JITSymbol findSymbolIn(ObjSetHandleT H, const std::string &Name, - bool ExportedSymbolsOnly) { + llvm::JITSymbol findSymbolIn(ObjSetHandleT H, const std::string &Name, + bool ExportedSymbolsOnly) { EXPECT_EQ(MockObjSetHandle, H) << "Handle should pass through"; EXPECT_EQ(MockName, Name) << "Name should pass through"; EXPECT_EQ(MockBool, ExportedSymbolsOnly) << "Flag should pass through"; LastCalled = "findSymbolIn"; - MockSymbol = JITSymbol(122, llvm::JITSymbolFlags::None); + MockSymbol = llvm::JITSymbol(122, llvm::JITSymbolFlags::None); return MockSymbol; } void expectFindSymbolIn(ObjSetHandleT H, const std::string &Name, @@ -128,7 +129,7 @@ public: MockName = Name; MockBool = ExportedSymbolsOnly; } - void verifyFindSymbolIn(llvm::orc::JITSymbol Returned) { + void verifyFindSymbolIn(llvm::JITSymbol Returned) { EXPECT_EQ("findSymbolIn", LastCalled); EXPECT_EQ(MockSymbol.getAddress(), Returned.getAddress()) << "Return should pass through"; @@ -146,14 +147,14 @@ public: } void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress, - TargetAddress TargetAddr) { + llvm::JITTargetAddress TargetAddr) { EXPECT_EQ(MockObjSetHandle, H); EXPECT_EQ(MockLocalAddress, LocalAddress); EXPECT_EQ(MockTargetAddress, TargetAddr); LastCalled = "mapSectionAddress"; } void expectMapSectionAddress(ObjSetHandleT H, const void *LocalAddress, - TargetAddress TargetAddr) { + llvm::JITTargetAddress TargetAddr) { MockObjSetHandle = H; MockLocalAddress = LocalAddress; MockTargetAddress = TargetAddr; @@ -172,9 +173,9 @@ private: ObjSetHandleT MockObjSetHandle; std::string MockName; bool MockBool; - JITSymbol MockSymbol; + llvm::JITSymbol MockSymbol; const void *MockLocalAddress; - TargetAddress MockTargetAddress; + llvm::JITTargetAddress MockTargetAddress; MockMemoryBufferSet MockBufferSet; // Clear remembered parameters between calls @@ -185,7 +186,7 @@ private: MockObjects.clear(); MockObjSetHandle = 0; MockName = "bogus"; - MockSymbol = JITSymbol(nullptr); + MockSymbol = llvm::JITSymbol(nullptr); MockLocalAddress = nullptr; MockTargetAddress = 0; MockBufferSet = 0; @@ -245,7 +246,7 @@ TEST(ObjectTransformLayerTest, Main) { std::string Name = "foo"; bool ExportedOnly = true; M.expectFindSymbol(Name, ExportedOnly); - JITSymbol Symbol = T2.findSymbol(Name, ExportedOnly); + llvm::JITSymbol Symbol = T2.findSymbol(Name, ExportedOnly); M.verifyFindSymbol(Symbol); // Test findSymbolIn @@ -262,7 +263,7 @@ TEST(ObjectTransformLayerTest, Main) { // Test mapSectionAddress char Buffer[24]; - TargetAddress MockAddress = 255; + llvm::JITTargetAddress MockAddress = 255; M.expectMapSectionAddress(H, Buffer, MockAddress); T1.mapSectionAddress(H, Buffer, MockAddress); M.verifyMapSectionAddress(); diff --git a/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/unittests/ExecutionEngine/Orc/OrcTestCommon.h index fe3da88dc9d..f3972a3084e 100644 --- a/unittests/ExecutionEngine/Orc/OrcTestCommon.h +++ b/unittests/ExecutionEngine/Orc/OrcTestCommon.h @@ -22,7 +22,7 @@ #include "llvm/IR/TypeBuilder.h" #include "llvm/Object/ObjectFile.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/ExecutionEngine/Orc/JITSymbol.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/Support/TargetSelect.h" #include @@ -124,11 +124,11 @@ public: RemoveModuleSet(H); } - orc::JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { + JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { return FindSymbol(Name, ExportedSymbolsOnly); } - orc::JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name, + JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name, bool ExportedSymbolsOnly) { return FindSymbolIn(H, Name, ExportedSymbolsOnly); }