[ExecutionEngine][MCJIT][Orc] Replace RuntimeDyld::SymbolInfo with JITSymbol.

This patch replaces RuntimeDyld::SymbolInfo with JITSymbol: A symbol class
that is capable of lazy materialization (i.e. the symbol definition needn't be
emitted until the address is requested). This can be used to support common
and weak symbols in the JIT (though this is not implemented in this patch).

For consistency, RuntimeDyld::SymbolResolver is renamed to JITSymbolResolver.

For space efficiency a new class, JITEvaluatedSymbol, is introduced that
behaves like the old RuntimeDyld::SymbolInfo - i.e. it is just a pair of an
address and symbol flags. Instances of JITEvaluatedSymbol can be used in
symbol-tables to avoid paying the space cost of the materializer.

llvm-svn: 277386
This commit is contained in:
Lang Hames 2016-08-01 20:49:11 +00:00
parent 317d42c1ea
commit ad4a911fea
63 changed files with 511 additions and 506 deletions

View File

@ -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

View File

@ -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);
},
// ...

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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)) {

View File

@ -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<MyRemote::RCMemoryManager> 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);
}

View File

@ -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)),

View File

@ -137,13 +137,13 @@ protected:
std::unique_ptr<Module> M,
std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MM,
std::shared_ptr<RuntimeDyld::SymbolResolver> SR,
std::shared_ptr<JITSymbolResolver> SR,
std::unique_ptr<TargetMachine> TM);
static ExecutionEngine *(*OrcMCJITReplacementCtor)(
std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MM,
std::shared_ptr<RuntimeDyld::SymbolResolver> SR,
std::shared_ptr<JITSymbolResolver> SR,
std::unique_ptr<TargetMachine> TM);
static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M,
@ -516,7 +516,7 @@ private:
std::string *ErrorStr;
CodeGenOpt::Level OptLevel;
std::shared_ptr<MCJITMemoryManager> MemMgr;
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver;
std::shared_ptr<JITSymbolResolver> Resolver;
TargetOptions Options;
Optional<Reloc::Model> RelocModel;
CodeModel::Model CMModel;
@ -555,7 +555,7 @@ public:
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
setSymbolResolver(std::unique_ptr<JITSymbolResolver> SR);
/// setErrorStr - Set the error string to write to on error. This option
/// defaults to NULL.

View File

@ -0,0 +1,132 @@
//===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Abstraction for target process addresses.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_JITSYMBOL_H
#define LLVM_EXECUTIONENGINE_JITSYMBOL_H
#include "llvm/ExecutionEngine/JITSymbolFlags.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
#include <functional>
namespace llvm {
/// @brief Represents an address in the target process's address space.
typedef uint64_t JITTargetAddress;
/// @brief Represents a symbol that has been evaluated to an address already.
class JITEvaluatedSymbol : public JITSymbolBase {
public:
/// @brief Create a 'null' symbol.
JITEvaluatedSymbol(std::nullptr_t)
: JITSymbolBase(JITSymbolFlags::None), Address(0) {}
/// @brief Create a symbol for the given address and flags.
JITEvaluatedSymbol(JITTargetAddress Address, JITSymbolFlags Flags)
: JITSymbolBase(Flags), Address(Address) {}
/// @brief An evaluated symbol converts to 'true' if its address is non-zero.
explicit operator bool() const { return Address != 0; }
/// @brief Return the address of this symbol.
JITTargetAddress getAddress() const { return Address; }
private:
JITTargetAddress Address;
};
/// @brief Represents a symbol in the JIT.
class JITSymbol : public JITSymbolBase {
public:
typedef std::function<JITTargetAddress()> GetAddressFtor;
/// @brief Create a 'null' symbol that represents failure to find a symbol
/// definition.
JITSymbol(std::nullptr_t)
: JITSymbolBase(JITSymbolFlags::None), CachedAddr(0) {}
/// @brief Create a symbol for a definition with a known address.
JITSymbol(JITTargetAddress Addr, JITSymbolFlags Flags)
: JITSymbolBase(Flags), CachedAddr(Addr) {}
/// @brief Construct a JITSymbol from a JITEvaluatedSymbol.
JITSymbol(JITEvaluatedSymbol Sym)
: JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {}
/// @brief Create a symbol for a definition that doesn't have a known address
/// yet.
/// @param GetAddress A functor to materialize a definition (fixing the
/// address) on demand.
///
/// This constructor allows a JIT layer to provide a reference to a symbol
/// definition without actually materializing the definition up front. The
/// user can materialize the definition at any time by calling the getAddress
/// method.
JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)
: JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {}
/// @brief Returns true if the symbol exists, false otherwise.
explicit operator bool() const { return CachedAddr || GetAddress; }
/// @brief Get the address of the symbol in the target address space. Returns
/// '0' if the symbol does not exist.
JITTargetAddress getAddress() {
if (GetAddress) {
CachedAddr = GetAddress();
assert(CachedAddr && "Symbol could not be materialized.");
GetAddress = nullptr;
}
return CachedAddr;
}
private:
GetAddressFtor GetAddress;
JITTargetAddress CachedAddr;
};
/// \brief Symbol resolution.
class JITSymbolResolver {
public:
virtual ~JITSymbolResolver() {}
/// This method returns the address of the specified symbol if it exists
/// within the logical dynamic library represented by this JITSymbolResolver.
/// Unlike findSymbol, queries through this interface should return addresses
/// for hidden symbols.
///
/// This is of particular importance for the Orc JIT APIs, which support lazy
/// compilation by breaking up modules: Each of those broken out modules
/// must be able to resolve hidden symbols provided by the others. Clients
/// writing memory managers for MCJIT can usually ignore this method.
///
/// This method will be queried by RuntimeDyld when checking for previous
/// definitions of common symbols.
virtual JITSymbol findSymbolInLogicalDylib(const std::string &Name) = 0;
/// This method returns the address of the specified function or variable.
/// It is used to resolve symbols during module linking.
///
/// If the returned symbol's address is equal to ~0ULL then RuntimeDyld will
/// skip all relocations for that symbol, and the client will be responsible
/// for handling them manually.
virtual JITSymbol findSymbol(const std::string &Name) = 0;
private:
virtual void anchor();
};
} // End namespace llvm.
#endif // LLVM_EXECUTIONENGINE_JITSYMBOL_H

View File

@ -120,13 +120,12 @@ private:
};
struct LogicalDylibResources {
typedef std::function<RuntimeDyld::SymbolInfo(const std::string&)>
SymbolResolverFtor;
typedef std::function<JITSymbol(const std::string&)> SymbolResolverFtor;
typedef std::function<typename BaseLayerT::ModuleSetHandleT(
BaseLayerT&,
std::unique_ptr<Module>,
std::unique_ptr<RuntimeDyld::SymbolResolver>)>
std::unique_ptr<JITSymbolResolver>)>
ModuleAdderFtor;
LogicalDylibResources() = default;
@ -145,7 +144,7 @@ private:
return *this;
}
std::unique_ptr<RuntimeDyld::SymbolResolver> ExternalSymbolResolver;
std::unique_ptr<JITSymbolResolver> ExternalSymbolResolver;
std::unique_ptr<ResourceOwner<RuntimeDyld::MemoryManager>> MemMgr;
ModuleAdderFtor ModuleAdder;
};
@ -196,7 +195,7 @@ public:
LDResources.ModuleAdder =
[&MemMgrRef](BaseLayerT &B, std::unique_ptr<Module> M,
std::unique_ptr<RuntimeDyld::SymbolResolver> R) {
std::unique_ptr<JITSymbolResolver> R) {
std::vector<std::unique_ptr<Module>> Ms;
Ms.push_back(std::move(M));
return B.addModuleSet(std::move(Ms), &MemMgrRef, std::move(R));
@ -245,7 +244,7 @@ public:
// callbacks, uncompiled IR, and no-longer-needed/reachable function
// implementations).
// FIXME: Return Error once the JIT APIs are Errorized.
bool updatePointer(std::string FuncName, TargetAddress FnBodyAddr) {
bool updatePointer(std::string FuncName, JITTargetAddress FnBodyAddr) {
//Find out which logical dylib contains our symbol
auto LDI = LogicalDylibs.begin();
for (auto LDE = LogicalDylibs.end(); LDI != LDE; ++LDI) {
@ -386,7 +385,7 @@ private:
[&LD, LMH](const std::string &Name) {
auto &LMResources = LD.getLogicalModuleResources(LMH);
if (auto Sym = LMResources.StubsMgr->findStub(Name, false))
return Sym.toRuntimeDyldSymbol();
return Sym;
auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver;
return LDResolver->findSymbolInLogicalDylib(Name);
},
@ -409,9 +408,9 @@ private:
return MangledName;
}
TargetAddress extractAndCompile(CODLogicalDylib &LD,
LogicalModuleHandle LMH,
Function &F) {
JITTargetAddress extractAndCompile(CODLogicalDylib &LD,
LogicalModuleHandle LMH,
Function &F) {
auto &LMResources = LD.getLogicalModuleResources(LMH);
Module &SrcM = LMResources.SourceModule->getResource();
@ -425,13 +424,13 @@ private:
auto Part = Partition(F);
auto PartH = emitPartition(LD, LMH, Part);
TargetAddress CalledAddr = 0;
JITTargetAddress CalledAddr = 0;
for (auto *SubF : Part) {
std::string FnName = mangle(SubF->getName(), SrcM.getDataLayout());
auto FnBodySym = BaseLayer.findSymbolIn(PartH, FnName, false);
assert(FnBodySym && "Couldn't find function body.");
TargetAddress FnBodyAddr = FnBodySym.getAddress();
JITTargetAddress FnBodyAddr = FnBodySym.getAddress();
// If this is the function we're calling record the address so we can
// return it from this function.
@ -513,7 +512,7 @@ private:
auto Resolver = createLambdaResolver(
[this, &LD, LMH](const std::string &Name) {
if (auto Sym = LD.findSymbolInternally(LMH, Name))
return Sym.toRuntimeDyldSymbol();
return Sym;
auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver;
return LDResolver->findSymbolInLogicalDylib(Name);
},

View File

@ -14,9 +14,9 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
#define LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
#include "JITSymbol.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include <vector>
@ -144,10 +144,10 @@ public:
}
/// Search overrided symbols.
RuntimeDyld::SymbolInfo searchOverrides(const std::string &Name) {
JITEvaluatedSymbol searchOverrides(const std::string &Name) {
auto I = CXXRuntimeOverrides.find(Name);
if (I != CXXRuntimeOverrides.end())
return RuntimeDyld::SymbolInfo(I->second, JITSymbolFlags::Exported);
return JITEvaluatedSymbol(I->second, JITSymbolFlags::Exported);
return nullptr;
}
@ -158,15 +158,15 @@ public:
private:
template <typename PtrTy>
TargetAddress toTargetAddress(PtrTy* P) {
return static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(P));
JITTargetAddress toTargetAddress(PtrTy* P) {
return static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(P));
}
void addOverride(const std::string &Name, TargetAddress Addr) {
void addOverride(const std::string &Name, JITTargetAddress Addr) {
CXXRuntimeOverrides.insert(std::make_pair(Name, Addr));
}
StringMap<TargetAddress> CXXRuntimeOverrides;
StringMap<JITTargetAddress> CXXRuntimeOverrides;
typedef void (*DestructorPtr)(void*);
typedef std::pair<DestructorPtr, void*> CXXDestructorDataPair;

View File

@ -15,7 +15,7 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H
#define LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H
#include "JITSymbol.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include <map>
namespace llvm {
@ -52,7 +52,7 @@ public:
void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeModuleSet(H); }
/// @brief Manually set the address to return for the given symbol.
void setGlobalMapping(const std::string &Name, TargetAddress Addr) {
void setGlobalMapping(const std::string &Name, JITTargetAddress Addr) {
SymbolTable[Name] = Addr;
}
@ -99,7 +99,7 @@ public:
private:
BaseLayerT &BaseLayer;
std::map<std::string, TargetAddress> SymbolTable;
std::map<std::string, JITTargetAddress> SymbolTable;
};
} // End namespace orc.

View File

@ -14,9 +14,8 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
#define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
#include "JITSymbol.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/Object/ObjectFile.h"
#include <memory>

View File

@ -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 {

View File

@ -14,8 +14,8 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
#define LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
#include "JITSymbol.h"
#include "LambdaResolver.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Mangler.h"
@ -29,37 +29,37 @@ namespace orc {
/// @brief Target-independent base class for compile callback management.
class JITCompileCallbackManager {
public:
typedef std::function<TargetAddress()> CompileFtor;
typedef std::function<JITTargetAddress()> CompileFtor;
/// @brief Handle to a newly created compile callback. Can be used to get an
/// IR constant representing the address of the trampoline, and to set
/// the compile action for the callback.
class CompileCallbackInfo {
public:
CompileCallbackInfo(TargetAddress Addr, CompileFtor &Compile)
CompileCallbackInfo(JITTargetAddress Addr, CompileFtor &Compile)
: Addr(Addr), Compile(Compile) {}
TargetAddress getAddress() const { return Addr; }
JITTargetAddress getAddress() const { return Addr; }
void setCompileAction(CompileFtor Compile) {
this->Compile = std::move(Compile);
}
private:
TargetAddress Addr;
JITTargetAddress Addr;
CompileFtor &Compile;
};
/// @brief Construct a JITCompileCallbackManager.
/// @param ErrorHandlerAddress The address of an error handler in the target
/// process to be used if a compile callback fails.
JITCompileCallbackManager(TargetAddress ErrorHandlerAddress)
JITCompileCallbackManager(JITTargetAddress ErrorHandlerAddress)
: ErrorHandlerAddress(ErrorHandlerAddress) {}
virtual ~JITCompileCallbackManager() {}
/// @brief Execute the callback for the given trampoline id. Called by the JIT
/// to compile functions on demand.
TargetAddress executeCompileCallback(TargetAddress TrampolineAddr) {
JITTargetAddress executeCompileCallback(JITTargetAddress TrampolineAddr) {
auto I = ActiveTrampolines.find(TrampolineAddr);
// FIXME: Also raise an error in the Orc error-handler when we finally have
// one.
@ -86,13 +86,13 @@ public:
/// @brief Reserve a compile callback.
CompileCallbackInfo getCompileCallback() {
TargetAddress TrampolineAddr = getAvailableTrampolineAddr();
JITTargetAddress TrampolineAddr = getAvailableTrampolineAddr();
auto &Compile = this->ActiveTrampolines[TrampolineAddr];
return CompileCallbackInfo(TrampolineAddr, Compile);
}
/// @brief Get a CompileCallbackInfo for an existing callback.
CompileCallbackInfo getCompileCallbackInfo(TargetAddress TrampolineAddr) {
CompileCallbackInfo getCompileCallbackInfo(JITTargetAddress TrampolineAddr) {
auto I = ActiveTrampolines.find(TrampolineAddr);
assert(I != ActiveTrampolines.end() && "Not an active trampoline.");
return CompileCallbackInfo(I->first, I->second);
@ -103,7 +103,7 @@ public:
/// Note: Callbacks are auto-released after they execute. This method should
/// only be called to manually release a callback that is not going to
/// execute.
void releaseCompileCallback(TargetAddress TrampolineAddr) {
void releaseCompileCallback(JITTargetAddress TrampolineAddr) {
auto I = ActiveTrampolines.find(TrampolineAddr);
assert(I != ActiveTrampolines.end() && "Not an active trampoline.");
ActiveTrampolines.erase(I);
@ -111,19 +111,19 @@ public:
}
protected:
TargetAddress ErrorHandlerAddress;
JITTargetAddress ErrorHandlerAddress;
typedef std::map<TargetAddress, CompileFtor> TrampolineMapT;
typedef std::map<JITTargetAddress, CompileFtor> TrampolineMapT;
TrampolineMapT ActiveTrampolines;
std::vector<TargetAddress> AvailableTrampolines;
std::vector<JITTargetAddress> AvailableTrampolines;
private:
TargetAddress getAvailableTrampolineAddr() {
JITTargetAddress getAvailableTrampolineAddr() {
if (this->AvailableTrampolines.empty())
grow();
assert(!this->AvailableTrampolines.empty() &&
"Failed to grow available trampolines.");
TargetAddress TrampolineAddr = this->AvailableTrampolines.back();
JITTargetAddress TrampolineAddr = this->AvailableTrampolines.back();
this->AvailableTrampolines.pop_back();
return TrampolineAddr;
}
@ -141,7 +141,7 @@ public:
/// @brief Construct a InProcessJITCompileCallbackManager.
/// @param ErrorHandlerAddress The address of an error handler in the target
/// process to be used if a compile callback fails.
LocalJITCompileCallbackManager(TargetAddress ErrorHandlerAddress)
LocalJITCompileCallbackManager(JITTargetAddress ErrorHandlerAddress)
: JITCompileCallbackManager(ErrorHandlerAddress) {
/// Set up the resolver block.
@ -161,11 +161,12 @@ public:
}
private:
static TargetAddress reenter(void *CCMgr, void *TrampolineId) {
static JITTargetAddress reenter(void *CCMgr, void *TrampolineId) {
JITCompileCallbackManager *Mgr =
static_cast<JITCompileCallbackManager *>(CCMgr);
return Mgr->executeCompileCallback(
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(TrampolineId)));
static_cast<JITTargetAddress>(
reinterpret_cast<uintptr_t>(TrampolineId)));
}
void grow() override {
@ -188,7 +189,7 @@ private:
for (unsigned I = 0; I < NumTrampolines; ++I)
this->AvailableTrampolines.push_back(
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(
TrampolineMem + (I * TargetT::TrampolineSize))));
EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(),
@ -207,12 +208,12 @@ private:
class IndirectStubsManager {
public:
/// @brief Map type for initializing the manager. See init.
typedef StringMap<std::pair<TargetAddress, JITSymbolFlags>> StubInitsMap;
typedef StringMap<std::pair<JITTargetAddress, JITSymbolFlags>> StubInitsMap;
virtual ~IndirectStubsManager() {}
/// @brief Create a single stub with the given name, target address and flags.
virtual Error createStub(StringRef StubName, TargetAddress StubAddr,
virtual Error createStub(StringRef StubName, JITTargetAddress StubAddr,
JITSymbolFlags StubFlags) = 0;
/// @brief Create StubInits.size() stubs with the given names, target
@ -228,7 +229,7 @@ public:
virtual JITSymbol findPointer(StringRef Name) = 0;
/// @brief Change the value of the implementation pointer for the stub.
virtual Error updatePointer(StringRef Name, TargetAddress NewAddr) = 0;
virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr) = 0;
private:
virtual void anchor();
@ -239,7 +240,7 @@ private:
template <typename TargetT>
class LocalIndirectStubsManager : public IndirectStubsManager {
public:
Error createStub(StringRef StubName, TargetAddress StubAddr,
Error createStub(StringRef StubName, JITTargetAddress StubAddr,
JITSymbolFlags StubFlags) override {
if (auto Err = reserveStubs(1))
return Err;
@ -268,7 +269,7 @@ public:
void *StubAddr = IndirectStubsInfos[Key.first].getStub(Key.second);
assert(StubAddr && "Missing stub address");
auto StubTargetAddr =
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(StubAddr));
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(StubAddr));
auto StubSymbol = JITSymbol(StubTargetAddr, I->second.second);
if (ExportedStubsOnly && !StubSymbol.isExported())
return nullptr;
@ -283,11 +284,11 @@ public:
void *PtrAddr = IndirectStubsInfos[Key.first].getPtr(Key.second);
assert(PtrAddr && "Missing pointer address");
auto PtrTargetAddr =
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr));
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr));
return JITSymbol(PtrTargetAddr, I->second.second);
}
Error updatePointer(StringRef Name, TargetAddress NewAddr) override {
Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {
auto I = StubIndexes.find(Name);
assert(I != StubIndexes.end() && "No stub pointer for symbol");
auto Key = I->second.first;
@ -313,7 +314,7 @@ private:
return Error::success();
}
void createStubInternal(StringRef StubName, TargetAddress InitAddr,
void createStubInternal(StringRef StubName, JITTargetAddress InitAddr,
JITSymbolFlags StubFlags) {
auto Key = FreeStubs.back();
FreeStubs.pop_back();
@ -335,7 +336,7 @@ private:
/// manager if a compile callback fails.
std::unique_ptr<JITCompileCallbackManager>
createLocalCompileCallbackManager(const Triple &T,
TargetAddress ErrorHandlerAddress);
JITTargetAddress ErrorHandlerAddress);
/// @brief Create a local indriect stubs manager builder.
///
@ -348,7 +349,7 @@ createLocalIndirectStubsManagerBuilder(const Triple &T);
///
/// Usage example: Turn a trampoline address into a function pointer constant
/// for use in a stub.
Constant *createIRTypedAddress(FunctionType &FT, TargetAddress Addr);
Constant *createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr);
/// @brief Create a function pointer with the given type, name, and initializer
/// in the given Module.

View File

@ -1,87 +0,0 @@
//===----------- JITSymbol.h - JIT symbol abstraction -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Abstraction for target process addresses.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
#define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
#include "llvm/ExecutionEngine/JITSymbolFlags.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
#include <functional>
namespace llvm {
namespace orc {
/// @brief Represents an address in the target process's address space.
typedef uint64_t TargetAddress;
/// @brief Represents a symbol in the JIT.
class JITSymbol : public JITSymbolBase {
public:
typedef std::function<TargetAddress()> GetAddressFtor;
/// @brief Create a 'null' symbol that represents failure to find a symbol
/// definition.
JITSymbol(std::nullptr_t)
: JITSymbolBase(JITSymbolFlags::None), CachedAddr(0) {}
/// @brief Create a symbol for a definition with a known address.
JITSymbol(TargetAddress Addr, JITSymbolFlags Flags)
: JITSymbolBase(Flags), CachedAddr(Addr) {}
/// @brief Create a symbol for a definition that doesn't have a known address
/// yet.
/// @param GetAddress A functor to materialize a definition (fixing the
/// address) on demand.
///
/// This constructor allows a JIT layer to provide a reference to a symbol
/// definition without actually materializing the definition up front. The
/// user can materialize the definition at any time by calling the getAddress
/// method.
JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)
: JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {}
/// @brief Create a JITSymbol from a RuntimeDyld::SymbolInfo.
JITSymbol(const RuntimeDyld::SymbolInfo &Sym)
: JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {}
/// @brief Returns true if the symbol exists, false otherwise.
explicit operator bool() const { return CachedAddr || GetAddress; }
/// @brief Get the address of the symbol in the target address space. Returns
/// '0' if the symbol does not exist.
TargetAddress getAddress() {
if (GetAddress) {
CachedAddr = GetAddress();
assert(CachedAddr && "Symbol could not be materialized.");
GetAddress = nullptr;
}
return CachedAddr;
}
/// @brief Convert this JITSymbol to a RuntimeDyld::SymbolInfo.
RuntimeDyld::SymbolInfo toRuntimeDyldSymbol() {
return RuntimeDyld::SymbolInfo(getAddress(), getFlags());
}
private:
GetAddressFtor GetAddress;
TargetAddress CachedAddr;
};
} // End namespace orc.
} // End namespace llvm.
#endif // LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H

View File

@ -23,7 +23,7 @@ namespace llvm {
namespace orc {
template <typename DylibLookupFtorT, typename ExternalLookupFtorT>
class LambdaResolver : public RuntimeDyld::SymbolResolver {
class LambdaResolver : public JITSymbolResolver {
public:
LambdaResolver(DylibLookupFtorT DylibLookupFtor,
@ -31,12 +31,11 @@ public:
: DylibLookupFtor(DylibLookupFtor),
ExternalLookupFtor(ExternalLookupFtor) {}
RuntimeDyld::SymbolInfo
findSymbolInLogicalDylib(const std::string &Name) final {
JITSymbol findSymbolInLogicalDylib(const std::string &Name) final {
return DylibLookupFtor(Name);
}
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) final {
JITSymbol findSymbol(const std::string &Name) final {
return ExternalLookupFtor(Name);
}

View File

@ -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) {

View File

@ -14,7 +14,7 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
#define LLVM_EXECUTIONENGINE_ORC_LOGICALDYLIB_H
#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include <string>
#include <vector>

View File

@ -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.

View File

@ -14,9 +14,9 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
#define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
#include "JITSymbol.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include <list>
#include <memory>
@ -46,7 +46,7 @@ protected:
getSymbolMaterializer(std::string Name) = 0;
virtual void mapSectionAddress(const void *LocalAddress,
TargetAddress TargetAddr) const = 0;
JITTargetAddress TargetAddr) const = 0;
JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly) {
auto SymEntry = SymbolTable.find(Name);
@ -60,7 +60,7 @@ protected:
return JITSymbol(SymEntry->second);
}
protected:
StringMap<RuntimeDyld::SymbolInfo> SymbolTable;
StringMap<JITEvaluatedSymbol> SymbolTable;
bool Finalized = false;
};
@ -144,7 +144,7 @@ private:
}
void mapSectionAddress(const void *LocalAddress,
TargetAddress TargetAddr) const override {
JITTargetAddress TargetAddr) const override {
assert(PFC && "mapSectionAddress called on finalized LinkedObjectSet");
assert(PFC->RTDyld && "mapSectionAddress called on raw LinkedObjectSet");
PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
@ -165,7 +165,7 @@ private:
}
auto Flags = JITSymbol::flagsFromObjectSymbol(Symbol);
SymbolTable.insert(
std::make_pair(*SymbolName, RuntimeDyld::SymbolInfo(0, Flags)));
std::make_pair(*SymbolName, JITEvaluatedSymbol(0, Flags)));
}
}
@ -322,7 +322,7 @@ public:
/// @brief Map section addresses for the objects associated with the handle H.
void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress,
TargetAddress TargetAddr) {
JITTargetAddress TargetAddr) {
(*H)->mapSectionAddress(LocalAddress, TargetAddr);
}

View File

@ -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);
}

View File

@ -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.

View File

@ -185,7 +185,7 @@ public:
DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
for (auto &ObjAllocs : Unmapped) {
{
TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
JITTargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
for (auto &Alloc : ObjAllocs.CodeAllocs) {
NextCodeAddr = alignTo(NextCodeAddr, Alloc.getAlign());
Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr);
@ -197,7 +197,7 @@ public:
}
}
{
TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
JITTargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
for (auto &Alloc : ObjAllocs.RODataAllocs) {
NextRODataAddr = alignTo(NextRODataAddr, Alloc.getAlign());
Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr);
@ -210,7 +210,7 @@ public:
}
}
{
TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
JITTargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
for (auto &Alloc : ObjAllocs.RWDataAllocs) {
NextRWDataAddr = alignTo(NextRWDataAddr, Alloc.getAlign());
Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr);
@ -389,17 +389,17 @@ public:
return reinterpret_cast<char *>(LocalAddr);
}
void setRemoteAddress(TargetAddress RemoteAddr) {
void setRemoteAddress(JITTargetAddress RemoteAddr) {
this->RemoteAddr = RemoteAddr;
}
TargetAddress getRemoteAddress() const { return RemoteAddr; }
JITTargetAddress getRemoteAddress() const { return RemoteAddr; }
private:
uint64_t Size;
unsigned Align;
std::unique_ptr<char[]> Contents;
TargetAddress RemoteAddr = 0;
JITTargetAddress RemoteAddr = 0;
};
struct ObjectAllocs {
@ -423,9 +423,9 @@ public:
return *this;
}
TargetAddress RemoteCodeAddr = 0;
TargetAddress RemoteRODataAddr = 0;
TargetAddress RemoteRWDataAddr = 0;
JITTargetAddress RemoteCodeAddr = 0;
JITTargetAddress RemoteRODataAddr = 0;
JITTargetAddress RemoteRWDataAddr = 0;
std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
};
@ -450,7 +450,7 @@ public:
}
}
Error createStub(StringRef StubName, TargetAddress StubAddr,
Error createStub(StringRef StubName, JITTargetAddress StubAddr,
JITSymbolFlags StubFlags) override {
if (auto Err = reserveStubs(1))
return Err;
@ -491,7 +491,7 @@ public:
return JITSymbol(getPtrAddr(Key), Flags);
}
Error updatePointer(StringRef Name, TargetAddress NewAddr) override {
Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {
auto I = StubIndexes.find(Name);
assert(I != StubIndexes.end() && "No stub pointer for symbol");
auto Key = I->second.first;
@ -500,8 +500,8 @@ public:
private:
struct RemoteIndirectStubsInfo {
TargetAddress StubBase;
TargetAddress PtrBase;
JITTargetAddress StubBase;
JITTargetAddress PtrBase;
unsigned NumStubs;
};
@ -517,8 +517,8 @@ public:
return Error::success();
unsigned NewStubsRequired = NumStubs - FreeStubs.size();
TargetAddress StubBase;
TargetAddress PtrBase;
JITTargetAddress StubBase;
JITTargetAddress PtrBase;
unsigned NumStubsEmitted;
if (auto StubInfoOrErr = Remote.emitIndirectStubs(Id, NewStubsRequired))
@ -535,7 +535,7 @@ public:
return Error::success();
}
Error createStubInternal(StringRef StubName, TargetAddress InitAddr,
Error createStubInternal(StringRef StubName, JITTargetAddress InitAddr,
JITSymbolFlags StubFlags) {
auto Key = FreeStubs.back();
FreeStubs.pop_back();
@ -543,14 +543,14 @@ public:
return Remote.writePointer(getPtrAddr(Key), InitAddr);
}
TargetAddress getStubAddr(StubKey K) {
JITTargetAddress getStubAddr(StubKey K) {
assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
"Missing stub address");
return RemoteIndirectStubsInfos[K.first].StubBase +
K.second * Remote.getIndirectStubSize();
}
TargetAddress getPtrAddr(StubKey K) {
JITTargetAddress getPtrAddr(StubKey K) {
assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
"Missing pointer address");
return RemoteIndirectStubsInfos[K.first].PtrBase +
@ -561,13 +561,13 @@ public:
/// Remote compile callback manager.
class RCCompileCallbackManager : public JITCompileCallbackManager {
public:
RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
RCCompileCallbackManager(JITTargetAddress ErrorHandlerAddress,
OrcRemoteTargetClient &Remote)
: JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {}
private:
void grow() override {
TargetAddress BlockAddr = 0;
JITTargetAddress BlockAddr = 0;
uint32_t NumTrampolines = 0;
if (auto TrampolineInfoOrErr = Remote.emitTrampolineBlock())
std::tie(BlockAddr, NumTrampolines) = *TrampolineInfoOrErr;
@ -597,7 +597,7 @@ public:
/// Call the int(void) function at the given address in the target and return
/// its result.
Expected<int> callIntVoid(TargetAddress Addr) {
Expected<int> callIntVoid(JITTargetAddress Addr) {
DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
auto Listen = [&](RPCChannel &C, uint32_t Id) {
@ -608,7 +608,7 @@ public:
/// Call the int(int, char*[]) function at the given address in the target and
/// return its result.
Expected<int> callMain(TargetAddress Addr,
Expected<int> callMain(JITTargetAddress Addr,
const std::vector<std::string> &Args) {
DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
<< "\n");
@ -621,7 +621,7 @@ public:
/// Call the void() function at the given address in the target and wait for
/// it to finish.
Error callVoidVoid(TargetAddress Addr) {
Error callVoidVoid(JITTargetAddress Addr) {
DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
<< "\n");
@ -655,7 +655,7 @@ public:
}
Expected<RCCompileCallbackManager &>
enableCompileCallbacks(TargetAddress ErrorHandlerAddress) {
enableCompileCallbacks(JITTargetAddress ErrorHandlerAddress) {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
return std::move(ExistingError);
@ -673,7 +673,7 @@ public:
/// Search for symbols in the remote process. Note: This should be used by
/// symbol resolvers *after* they've searched the local symbol table in the
/// JIT stack.
Expected<TargetAddress> getSymbolAddress(StringRef Name) {
Expected<JITTargetAddress> getSymbolAddress(StringRef Name) {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
return std::move(ExistingError);
@ -698,7 +698,7 @@ private:
}
}
Error deregisterEHFrames(TargetAddress Addr, uint32_t Size) {
Error deregisterEHFrames(JITTargetAddress Addr, uint32_t Size) {
return callST<RegisterEHFrames>(Channel, Addr, Size);
}
@ -716,12 +716,12 @@ private:
return callST<DestroyIndirectStubsOwner>(Channel, Id);
}
Expected<std::tuple<TargetAddress, TargetAddress, uint32_t>>
Expected<std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>>
emitIndirectStubs(ResourceIdMgr::ResourceId Id, uint32_t NumStubsRequired) {
return callST<EmitIndirectStubs>(Channel, Id, NumStubsRequired);
}
Expected<std::tuple<TargetAddress, uint32_t>> emitTrampolineBlock() {
Expected<std::tuple<JITTargetAddress, uint32_t>> emitTrampolineBlock() {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
return std::move(ExistingError);
@ -747,7 +747,7 @@ private:
// site below, but that triggers a GCC 4.7 ICE. When we move off
// GCC 4.7, tidy this up.
auto CompileCallback =
[this](TargetAddress Addr) -> Expected<TargetAddress> {
[this](JITTargetAddress Addr) -> Expected<JITTargetAddress> {
return this->CallbackManager->executeCompileCallback(Addr);
};
@ -760,7 +760,7 @@ private:
return orcError(OrcErrorCode::UnexpectedRPCCall);
}
Expected<std::vector<char>> readMem(char *Dst, TargetAddress Src,
Expected<std::vector<char>> readMem(char *Dst, JITTargetAddress Src,
uint64_t Size) {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
@ -769,12 +769,12 @@ private:
return callST<ReadMem>(Channel, Src, Size);
}
Error registerEHFrames(TargetAddress &RAddr, uint32_t Size) {
Error registerEHFrames(JITTargetAddress &RAddr, uint32_t Size) {
return callST<RegisterEHFrames>(Channel, RAddr, Size);
}
Expected<TargetAddress> reserveMem(ResourceIdMgr::ResourceId Id,
uint64_t Size, uint32_t Align) {
Expected<JITTargetAddress> reserveMem(ResourceIdMgr::ResourceId Id,
uint64_t Size, uint32_t Align) {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
@ -784,11 +784,11 @@ private:
}
Error setProtections(ResourceIdMgr::ResourceId Id,
TargetAddress RemoteSegAddr, unsigned ProtFlags) {
JITTargetAddress RemoteSegAddr, unsigned ProtFlags) {
return callST<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
}
Error writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
Error writeMem(JITTargetAddress Addr, const char *Src, uint64_t Size) {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
return std::move(ExistingError);
@ -796,7 +796,7 @@ private:
return callST<WriteMem>(Channel, DirectBufferWriter(Src, Addr, Size));
}
Error writePointer(TargetAddress Addr, TargetAddress PtrVal) {
Error writePointer(JITTargetAddress Addr, JITTargetAddress PtrVal) {
// Check for an 'out-of-band' error, e.g. from an MM destructor.
if (ExistingError)
return std::move(ExistingError);

View File

@ -16,9 +16,9 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H
#define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETRPCAPI_H
#include "JITSymbol.h"
#include "RPCChannel.h"
#include "RPCUtils.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
namespace llvm {
namespace orc {
@ -27,16 +27,16 @@ namespace remote {
class DirectBufferWriter {
public:
DirectBufferWriter() = default;
DirectBufferWriter(const char *Src, TargetAddress Dst, uint64_t Size)
DirectBufferWriter(const char *Src, JITTargetAddress Dst, uint64_t Size)
: Src(Src), Dst(Dst), Size(Size) {}
const char *getSrc() const { return Src; }
TargetAddress getDst() const { return Dst; }
JITTargetAddress getDst() const { return Dst; }
uint64_t getSize() const { return Size; }
private:
const char *Src;
TargetAddress Dst;
JITTargetAddress Dst;
uint64_t Size;
};
@ -49,7 +49,7 @@ inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) {
}
inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) {
TargetAddress Dst;
JITTargetAddress Dst;
if (auto EC = deserialize(C, Dst))
return EC;
uint64_t Size;
@ -120,13 +120,14 @@ public:
static const char *getJITFuncIdName(JITFuncId Id);
typedef Function<CallIntVoidId, int32_t(TargetAddress Addr)> CallIntVoid;
typedef Function<CallIntVoidId, int32_t(JITTargetAddress Addr)> CallIntVoid;
typedef Function<CallMainId,
int32_t(TargetAddress Addr, std::vector<std::string> Args)>
int32_t(JITTargetAddress Addr,
std::vector<std::string> Args)>
CallMain;
typedef Function<CallVoidVoidId, void(TargetAddress FnAddr)> CallVoidVoid;
typedef Function<CallVoidVoidId, void(JITTargetAddress FnAddr)> CallVoidVoid;
typedef Function<CreateRemoteAllocatorId,
void(ResourceIdMgr::ResourceId AllocatorID)>
@ -137,7 +138,7 @@ public:
CreateIndirectStubsOwner;
typedef Function<DeregisterEHFramesId,
void(TargetAddress Addr, uint32_t Size)>
void(JITTargetAddress Addr, uint32_t Size)>
DeregisterEHFrames;
typedef Function<DestroyRemoteAllocatorId,
@ -150,7 +151,7 @@ public:
/// EmitIndirectStubs result is (StubsBase, PtrsBase, NumStubsEmitted).
typedef Function<EmitIndirectStubsId,
std::tuple<TargetAddress, TargetAddress, uint32_t>(
std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>(
ResourceIdMgr::ResourceId StubsOwnerID,
uint32_t NumStubsRequired)>
EmitIndirectStubs;
@ -158,10 +159,11 @@ public:
typedef Function<EmitResolverBlockId, void()> EmitResolverBlock;
/// EmitTrampolineBlock result is (BlockAddr, NumTrampolines).
typedef Function<EmitTrampolineBlockId, std::tuple<TargetAddress, uint32_t>()>
typedef Function<EmitTrampolineBlockId,
std::tuple<JITTargetAddress, uint32_t>()>
EmitTrampolineBlock;
typedef Function<GetSymbolAddressId, TargetAddress(std::string SymbolName)>
typedef Function<GetSymbolAddressId, JITTargetAddress(std::string SymbolName)>
GetSymbolAddress;
/// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize,
@ -171,23 +173,23 @@ public:
GetRemoteInfo;
typedef Function<ReadMemId,
std::vector<char>(TargetAddress Src, uint64_t Size)>
std::vector<char>(JITTargetAddress Src, uint64_t Size)>
ReadMem;
typedef Function<RegisterEHFramesId, void(TargetAddress Addr, uint32_t Size)>
typedef Function<RegisterEHFramesId, void(JITTargetAddress Addr, uint32_t Size)>
RegisterEHFrames;
typedef Function<ReserveMemId,
TargetAddress(ResourceIdMgr::ResourceId AllocID,
uint64_t Size, uint32_t Align)>
JITTargetAddress(ResourceIdMgr::ResourceId AllocID,
uint64_t Size, uint32_t Align)>
ReserveMem;
typedef Function<RequestCompileId,
TargetAddress(TargetAddress TrampolineAddr)>
JITTargetAddress(JITTargetAddress TrampolineAddr)>
RequestCompile;
typedef Function<SetProtectionsId,
void(ResourceIdMgr::ResourceId AllocID, TargetAddress Dst,
void(ResourceIdMgr::ResourceId AllocID, JITTargetAddress Dst,
uint32_t ProtFlags)>
SetProtections;
@ -195,7 +197,7 @@ public:
typedef Function<WriteMemId, void(DirectBufferWriter DB)> WriteMem;
typedef Function<WritePtrId, void(TargetAddress Dst, TargetAddress Val)>
typedef Function<WritePtrId, void(JITTargetAddress Dst, JITTargetAddress Val)>
WritePtr;
};

View File

@ -32,7 +32,7 @@ namespace remote {
template <typename ChannelT, typename TargetT>
class OrcRemoteTargetServer : public OrcRemoteTargetRPCAPI {
public:
typedef std::function<TargetAddress(const std::string &Name)>
typedef std::function<JITTargetAddress(const std::string &Name)>
SymbolLookupFtor;
typedef std::function<void(uint8_t *Addr, uint32_t Size)>
@ -118,7 +118,7 @@ public:
llvm_unreachable("Unhandled JIT RPC procedure Id.");
}
Expected<TargetAddress> requestCompile(TargetAddress TrampolineAddr) {
Expected<JITTargetAddress> requestCompile(JITTargetAddress TrampolineAddr) {
auto Listen = [&](RPCChannel &C, uint32_t Id) {
return handleKnownFunction(static_cast<JITFuncId>(Id));
};
@ -171,16 +171,16 @@ private:
static Error doNothing() { return Error::success(); }
static TargetAddress reenter(void *JITTargetAddr, void *TrampolineAddr) {
static JITTargetAddress reenter(void *JITTargetAddr, void *TrampolineAddr) {
auto T = static_cast<OrcRemoteTargetServer *>(JITTargetAddr);
auto AddrOrErr = T->requestCompile(static_cast<TargetAddress>(
auto AddrOrErr = T->requestCompile(static_cast<JITTargetAddress>(
reinterpret_cast<uintptr_t>(TrampolineAddr)));
// FIXME: Allow customizable failure substitution functions.
assert(AddrOrErr && "Compile request failed");
return *AddrOrErr;
}
Expected<int32_t> handleCallIntVoid(TargetAddress Addr) {
Expected<int32_t> handleCallIntVoid(JITTargetAddress Addr) {
typedef int (*IntVoidFnTy)();
IntVoidFnTy Fn =
reinterpret_cast<IntVoidFnTy>(static_cast<uintptr_t>(Addr));
@ -192,7 +192,7 @@ private:
return Result;
}
Expected<int32_t> handleCallMain(TargetAddress Addr,
Expected<int32_t> handleCallMain(JITTargetAddress Addr,
std::vector<std::string> Args) {
typedef int (*MainFnTy)(int, const char *[]);
@ -211,7 +211,7 @@ private:
return Result;
}
Error handleCallVoidVoid(TargetAddress Addr) {
Error handleCallVoidVoid(JITTargetAddress Addr) {
typedef void (*VoidVoidFnTy)();
VoidVoidFnTy Fn =
reinterpret_cast<VoidVoidFnTy>(static_cast<uintptr_t>(Addr));
@ -241,7 +241,7 @@ private:
return Error::success();
}
Error handleDeregisterEHFrames(TargetAddress TAddr, uint32_t Size) {
Error handleDeregisterEHFrames(JITTargetAddress TAddr, uint32_t Size) {
uint8_t *Addr = reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(TAddr));
DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr)
<< ", Size = " << Size << " bytes\n");
@ -266,7 +266,7 @@ private:
return Error::success();
}
Expected<std::tuple<TargetAddress, TargetAddress, uint32_t>>
Expected<std::tuple<JITTargetAddress, JITTargetAddress, uint32_t>>
handleEmitIndirectStubs(ResourceIdMgr::ResourceId Id,
uint32_t NumStubsRequired) {
DEBUG(dbgs() << " ISMgr " << Id << " request " << NumStubsRequired
@ -281,10 +281,12 @@ private:
TargetT::emitIndirectStubsBlock(IS, NumStubsRequired, nullptr))
return std::move(Err);
TargetAddress StubsBase =
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(IS.getStub(0)));
TargetAddress PtrsBase =
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(IS.getPtr(0)));
JITTargetAddress StubsBase =
static_cast<JITTargetAddress>(
reinterpret_cast<uintptr_t>(IS.getStub(0)));
JITTargetAddress PtrsBase =
static_cast<JITTargetAddress>(
reinterpret_cast<uintptr_t>(IS.getPtr(0)));
uint32_t NumStubsEmitted = IS.getNumStubs();
auto &BlockList = StubOwnerItr->second;
@ -309,7 +311,7 @@ private:
sys::Memory::MF_READ | sys::Memory::MF_EXEC));
}
Expected<std::tuple<TargetAddress, uint32_t>> handleEmitTrampolineBlock() {
Expected<std::tuple<JITTargetAddress, uint32_t>> handleEmitTrampolineBlock() {
std::error_code EC;
auto TrampolineBlock =
sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
@ -333,13 +335,14 @@ private:
TrampolineBlocks.push_back(std::move(TrampolineBlock));
auto TrampolineBaseAddr =
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(TrampolineMem));
static_cast<JITTargetAddress>(
reinterpret_cast<uintptr_t>(TrampolineMem));
return std::make_tuple(TrampolineBaseAddr, NumTrampolines);
}
Expected<TargetAddress> handleGetSymbolAddress(const std::string &Name) {
TargetAddress Addr = SymbolLookup(Name);
Expected<JITTargetAddress> handleGetSymbolAddress(const std::string &Name) {
JITTargetAddress Addr = SymbolLookup(Name);
DEBUG(dbgs() << " Symbol '" << Name << "' = " << format("0x%016x", Addr)
<< "\n");
return Addr;
@ -362,7 +365,7 @@ private:
IndirectStubSize);
}
Expected<std::vector<char>> handleReadMem(TargetAddress RSrc, uint64_t Size) {
Expected<std::vector<char>> handleReadMem(JITTargetAddress RSrc, uint64_t Size) {
char *Src = reinterpret_cast<char *>(static_cast<uintptr_t>(RSrc));
DEBUG(dbgs() << " Reading " << Size << " bytes from "
@ -376,7 +379,7 @@ private:
return Buffer;
}
Error handleRegisterEHFrames(TargetAddress TAddr, uint32_t Size) {
Error handleRegisterEHFrames(JITTargetAddress TAddr, uint32_t Size) {
uint8_t *Addr = reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(TAddr));
DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr)
<< ", Size = " << Size << " bytes\n");
@ -384,8 +387,8 @@ private:
return Error::success();
}
Expected<TargetAddress> handleReserveMem(ResourceIdMgr::ResourceId Id,
uint64_t Size, uint32_t Align) {
Expected<JITTargetAddress> handleReserveMem(ResourceIdMgr::ResourceId Id,
uint64_t Size, uint32_t Align) {
auto I = Allocators.find(Id);
if (I == Allocators.end())
return orcError(OrcErrorCode::RemoteAllocatorDoesNotExist);
@ -397,13 +400,14 @@ private:
DEBUG(dbgs() << " Allocator " << Id << " reserved " << LocalAllocAddr
<< " (" << Size << " bytes, alignment " << Align << ")\n");
TargetAddress AllocAddr =
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(LocalAllocAddr));
JITTargetAddress AllocAddr =
static_cast<JITTargetAddress>(
reinterpret_cast<uintptr_t>(LocalAllocAddr));
return AllocAddr;
}
Error handleSetProtections(ResourceIdMgr::ResourceId Id, TargetAddress Addr,
Error handleSetProtections(ResourceIdMgr::ResourceId Id, JITTargetAddress Addr,
uint32_t Flags) {
auto I = Allocators.find(Id);
if (I == Allocators.end())
@ -423,7 +427,7 @@ private:
return Error::success();
}
Error handleWritePtr(TargetAddress Addr, TargetAddress PtrVal) {
Error handleWritePtr(JITTargetAddress Addr, JITTargetAddress PtrVal) {
DEBUG(dbgs() << " Writing pointer *" << format("0x%016x", Addr) << " = "
<< format("0x%016x", PtrVal) << "\n");
uintptr_t *Ptr =

View File

@ -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

View File

@ -14,7 +14,7 @@
#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
#define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
#include "JITSymbolFlags.h"
#include "JITSymbol.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/Object/ObjectFile.h"
@ -60,18 +60,6 @@ protected:
void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
public:
/// \brief Information about a named symbol.
class SymbolInfo : public JITSymbolBase {
public:
SymbolInfo(std::nullptr_t) : JITSymbolBase(JITSymbolFlags::None), Address(0) {}
SymbolInfo(uint64_t Address, JITSymbolFlags Flags)
: JITSymbolBase(Flags), Address(Address) {}
explicit operator bool() const { return Address != 0; }
uint64_t getAddress() const { return Address; }
private:
uint64_t Address;
};
/// \brief Information about the loaded object.
class LoadedObjectInfo : public llvm::LoadedObjectInfo {
friend class RuntimeDyldImpl;
@ -189,39 +177,8 @@ public:
bool FinalizationLocked;
};
/// \brief Symbol resolution.
class SymbolResolver {
public:
virtual ~SymbolResolver() {}
/// This method returns the address of the specified symbol if it exists
/// within the logical dynamic library represented by this
/// RTDyldMemoryManager. Unlike findSymbol, queries through this
/// interface should return addresses for hidden symbols.
///
/// This is of particular importance for the Orc JIT APIs, which support lazy
/// compilation by breaking up modules: Each of those broken out modules
/// must be able to resolve hidden symbols provided by the others. Clients
/// writing memory managers for MCJIT can usually ignore this method.
///
/// This method will be queried by RuntimeDyld when checking for previous
/// definitions of common symbols.
virtual SymbolInfo findSymbolInLogicalDylib(const std::string &Name) = 0;
/// This method returns the address of the specified function or variable.
/// It is used to resolve symbols during module linking.
///
/// If the returned symbol's address is equal to ~0ULL then RuntimeDyld will
/// skip all relocations for that symbol, and the client will be responsible
/// for handling them manually.
virtual SymbolInfo findSymbol(const std::string &Name) = 0;
private:
virtual void anchor();
};
/// \brief Construct a RuntimeDyld instance.
RuntimeDyld(MemoryManager &MemMgr, SymbolResolver &Resolver);
RuntimeDyld(MemoryManager &MemMgr, JITSymbolResolver &Resolver);
~RuntimeDyld();
/// Add the referenced object file to the list of objects to be loaded and
@ -235,7 +192,7 @@ public:
/// Get the target address and flags for the named symbol.
/// This address is the one used for relocation.
SymbolInfo getSymbol(StringRef Name) const;
JITEvaluatedSymbol getSymbol(StringRef Name) const;
/// Resolve the relocations for all symbols we currently know about.
void resolveRelocations();
@ -295,7 +252,7 @@ private:
// interface.
std::unique_ptr<RuntimeDyldImpl> Dyld;
MemoryManager &MemMgr;
SymbolResolver &Resolver;
JITSymbolResolver &Resolver;
bool ProcessAllSections;
RuntimeDyldCheckerImpl *Checker;
};

View File

@ -48,12 +48,13 @@ STATISTIC(NumGlobals , "Number of global vars initialized");
ExecutionEngine *(*ExecutionEngine::MCJITCtor)(
std::unique_ptr<Module> M, std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver,
std::shared_ptr<JITSymbolResolver> Resolver,
std::unique_ptr<TargetMachine> TM) = nullptr;
ExecutionEngine *(*ExecutionEngine::OrcMCJITReplacementCtor)(
std::string *ErrorStr, std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver,
std::shared_ptr<JITSymbolResolver> Resolver,
std::unique_ptr<TargetMachine> TM) = nullptr;
ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
@ -499,8 +500,8 @@ EngineBuilder::setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM) {
}
EngineBuilder&
EngineBuilder::setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR) {
Resolver = std::shared_ptr<RuntimeDyld::SymbolResolver>(std::move(SR));
EngineBuilder::setSymbolResolver(std::unique_ptr<JITSymbolResolver> SR) {
Resolver = std::shared_ptr<JITSymbolResolver>(std::move(SR));
return *this;
}

View File

@ -46,7 +46,7 @@ ExecutionEngine*
MCJIT::createJIT(std::unique_ptr<Module> M,
std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver,
std::shared_ptr<JITSymbolResolver> Resolver,
std::unique_ptr<TargetMachine> TM) {
// Try to register the program as a source of symbols to resolve against.
//
@ -67,7 +67,7 @@ MCJIT::createJIT(std::unique_ptr<Module> M,
MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> TM,
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver)
std::shared_ptr<JITSymbolResolver> 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<uint64_t>(
reinterpret_cast<uintptr_t>(Addr)),
JITSymbolFlags::Exported);
return JITSymbol(static_cast<uint64_t>(
reinterpret_cast<uintptr_t>(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<uint64_t>(
reinterpret_cast<uintptr_t>(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

View File

@ -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<RuntimeDyld::SymbolResolver> Resolver)
std::shared_ptr<JITSymbolResolver> 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<RuntimeDyld::SymbolResolver> ClientResolver;
std::shared_ptr<JITSymbolResolver> ClientResolver;
};
// About Module states: added->loaded->finalized.
@ -68,7 +67,7 @@ private:
class MCJIT : public ExecutionEngine {
MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> tm,
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver);
std::shared_ptr<JITSymbolResolver> Resolver);
typedef llvm::SmallPtrSet<Module *, 4> ModulePtrSet;
@ -305,13 +304,12 @@ public:
createJIT(std::unique_ptr<Module> M,
std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver,
std::shared_ptr<JITSymbolResolver> Resolver,
std::unique_ptr<TargetMachine> 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

View File

@ -24,7 +24,7 @@ void IndirectStubsManager::anchor() {}
std::unique_ptr<JITCompileCallbackManager>
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 =

View File

@ -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");
}

View File

@ -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 <typename PtrTy>
static PtrTy fromTargetAddress(orc::TargetAddress Addr) {
static PtrTy fromTargetAddress(JITTargetAddress Addr) {
return reinterpret_cast<PtrTy>(static_cast<uintptr_t>(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<RuntimeDyld::SymbolResolver>
std::unique_ptr<JITSymbolResolver>
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);
}

View File

@ -111,16 +111,15 @@ class OrcMCJITReplacement : public ExecutionEngine {
std::shared_ptr<MCJITMemoryManager> 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<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver,
std::shared_ptr<JITSymbolResolver> Resolver,
std::unique_ptr<TargetMachine> TM) {
return new OrcMCJITReplacement(std::move(MemMgr), std::move(Resolver),
std::move(TM));
@ -146,7 +145,7 @@ public:
OrcMCJITReplacement(
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<RuntimeDyld::SymbolResolver> ClientResolver,
std::shared_ptr<JITSymbolResolver> ClientResolver,
std::unique_ptr<TargetMachine> 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<TargetMachine> TM;
MCJITReplacementMemMgr MemMgr;
LinkingResolver Resolver;
std::shared_ptr<RuntimeDyld::SymbolResolver> ClientResolver;
std::shared_ptr<JITSymbolResolver> ClientResolver;
Mangler Mang;
NotifyObjectLoadedT NotifyObjectLoaded;

View File

@ -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<RuntimeDyldCOFF>
createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM,
RuntimeDyld::SymbolResolver &Resolver,
bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker) {
JITSymbolResolver &Resolver, bool ProcessAllSections,
RuntimeDyldCheckerImpl *Checker) {
std::unique_ptr<RuntimeDyldCOFF> Dyld =
RuntimeDyldCOFF::create(Arch, MM, Resolver);
Dyld->setProcessAllSections(ProcessAllSections);
@ -1005,8 +1005,8 @@ createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM,
static std::unique_ptr<RuntimeDyldELF>
createRuntimeDyldELF(RuntimeDyld::MemoryManager &MM,
RuntimeDyld::SymbolResolver &Resolver,
bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker) {
JITSymbolResolver &Resolver, bool ProcessAllSections,
RuntimeDyldCheckerImpl *Checker) {
std::unique_ptr<RuntimeDyldELF> Dyld(new RuntimeDyldELF(MM, Resolver));
Dyld->setProcessAllSections(ProcessAllSections);
Dyld->setRuntimeDyldChecker(Checker);
@ -1015,7 +1015,7 @@ createRuntimeDyldELF(RuntimeDyld::MemoryManager &MM,
static std::unique_ptr<RuntimeDyldMachO>
createRuntimeDyldMachO(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM,
RuntimeDyld::SymbolResolver &Resolver,
JITSymbolResolver &Resolver,
bool ProcessAllSections,
RuntimeDyldCheckerImpl *Checker) {
std::unique_ptr<RuntimeDyldMachO> 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);

View File

@ -44,7 +44,7 @@ namespace llvm {
std::unique_ptr<RuntimeDyldCOFF>
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:

View File

@ -33,11 +33,11 @@ public:
static std::unique_ptr<RuntimeDyldCOFF>
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);
};

View File

@ -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() {}

View File

@ -159,7 +159,7 @@ class RuntimeDyldELF : public RuntimeDyldImpl {
public:
RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr,
RuntimeDyld::SymbolResolver &Resolver);
JITSymbolResolver &Resolver);
~RuntimeDyldELF() override;
std::unique_ptr<RuntimeDyld::LoadedObjectInfo>

View File

@ -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();

View File

@ -343,7 +343,7 @@ void RuntimeDyldMachOCRTPBase<Impl>::registerEHFrames() {
std::unique_ptr<RuntimeDyldMachO>
RuntimeDyldMachO::create(Triple::ArchType Arch,
RuntimeDyld::MemoryManager &MemMgr,
RuntimeDyld::SymbolResolver &Resolver) {
JITSymbolResolver &Resolver) {
switch (Arch) {
default:
llvm_unreachable("Unsupported target for RuntimeDyldMachO.");

View File

@ -50,7 +50,7 @@ protected:
SmallVector<EHFrameRelatedSections, 2> 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<RuntimeDyldMachO>
create(Triple::ArchType Arch,
RuntimeDyld::MemoryManager &MemMgr,
RuntimeDyld::SymbolResolver &Resolver);
JITSymbolResolver &Resolver);
std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
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,

View File

@ -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 {

View File

@ -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 {

View File

@ -33,7 +33,7 @@ private:
public:
RuntimeDyldCOFFX86_64(RuntimeDyld::MemoryManager &MM,
RuntimeDyld::SymbolResolver &Resolver)
JITSymbolResolver &Resolver)
: RuntimeDyldCOFF(MM, Resolver) {}
unsigned getMaxStubSize() override {

View File

@ -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; }

View File

@ -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; }

View File

@ -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; }

View File

@ -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; }

View File

@ -101,7 +101,7 @@ CodeGenOpt::Level getOptLevel();
template <typename PtrTy>
static PtrTy fromTargetAddress(orc::TargetAddress Addr) {
static PtrTy fromTargetAddress(JITTargetAddress Addr) {
return reinterpret_cast<PtrTy>(static_cast<uintptr_t>(Addr));
}

View File

@ -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);
}

View File

@ -83,7 +83,7 @@ public:
this->MemMgr = std::move(MemMgr);
}
void setResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> Resolver) {
void setResolver(std::unique_ptr<JITSymbolResolver> 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<RuntimeDyld::MemoryManager> MemMgr;
std::unique_ptr<RuntimeDyld::SymbolResolver> Resolver;
std::unique_ptr<JITSymbolResolver> Resolver;
};
}

View File

@ -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");

View File

@ -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);
}

View File

@ -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");
}
};

View File

@ -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<TargetAddress>(0x4567))
EXPECT_EQ(BarSym.getAddress(), static_cast<JITTargetAddress>(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<TargetAddress>(0x0123))
EXPECT_EQ(FooSym2.getAddress(), static_cast<JITTargetAddress>(0x0123))
<< "Symbol mapping setup failed.";
// Test removal of a global mapping.

View File

@ -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<llvm::Module>>,
std::unique_ptr<llvm::RuntimeDyld::MemoryManager> MemMgr,
std::unique_ptr<llvm::RuntimeDyld::SymbolResolver> Resolver) {
std::unique_ptr<llvm::JITSymbolResolver> Resolver) {
EXPECT_FALSE(MemMgr);
return 42;
}

View File

@ -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;

View File

@ -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();

View File

@ -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 <memory>
@ -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);
}