2010-11-18 00:06:43 +08:00
|
|
|
//===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-11-18 00:06:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
|
|
|
|
#define LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
|
2010-11-18 00:06:43 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-11-07 02:51:59 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2010-11-18 00:06:43 +08:00
|
|
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
2013-04-26 05:02:36 +08:00
|
|
|
#include "llvm/ExecutionEngine/ObjectCache.h"
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
2011-03-22 09:06:42 +08:00
|
|
|
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
2013-10-24 08:19:14 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2018-04-16 11:44:03 +08:00
|
|
|
#include "llvm/Support/SmallVectorMemoryBuffer.h"
|
2010-11-18 00:06:43 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2013-10-01 09:47:35 +08:00
|
|
|
class MCJIT;
|
|
|
|
|
|
|
|
// This is a helper class that the MCJIT execution engine uses for linking
|
|
|
|
// 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.
|
2018-01-20 06:24:13 +08:00
|
|
|
class LinkingSymbolResolver : public LegacyJITSymbolResolver {
|
2013-10-01 09:47:35 +08:00
|
|
|
public:
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
LinkingSymbolResolver(MCJIT &Parent,
|
2018-01-20 06:24:13 +08:00
|
|
|
std::shared_ptr<LegacyJITSymbolResolver> Resolver)
|
|
|
|
: ParentEngine(Parent), ClientResolver(std::move(Resolver)) {}
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findSymbol(const std::string &Name) override;
|
2013-10-01 09:47:35 +08:00
|
|
|
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
// MCJIT doesn't support logical dylibs.
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findSymbolInLogicalDylib(const std::string &Name) override {
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
return nullptr;
|
2013-10-01 09:47:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
MCJIT &ParentEngine;
|
2018-01-20 06:24:13 +08:00
|
|
|
std::shared_ptr<LegacyJITSymbolResolver> ClientResolver;
|
Add missing vtable anchors
Summary: This patch adds anchor() for MemoryBuffer, raw_fd_ostream, RTDyldMemoryManager, SectionMemoryManager, etc.
Reviewers: jlebar, eli.friedman, dblaikie
Reviewed By: dblaikie
Subscribers: mehdi_amini, mgorny, dblaikie, weimingz, llvm-commits
Differential Revision: https://reviews.llvm.org/D45244
llvm-svn: 329861
2018-04-12 07:09:20 +08:00
|
|
|
void anchor() override;
|
2013-10-01 09:47:35 +08:00
|
|
|
};
|
2012-10-03 05:18:39 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
// About Module states: added->loaded->finalized.
|
2013-10-19 17:03:20 +08:00
|
|
|
//
|
|
|
|
// The purpose of the "added" state is having modules in standby. (added=known
|
|
|
|
// but not compiled). The idea is that you can add a module to provide function
|
|
|
|
// definitions but if nothing in that module is referenced by a module in which
|
2013-10-24 18:04:47 +08:00
|
|
|
// a function is executed (note the wording here because it's not exactly the
|
2013-10-19 17:03:20 +08:00
|
|
|
// ideal case) then the module never gets compiled. This is sort of lazy
|
|
|
|
// compilation.
|
|
|
|
//
|
|
|
|
// The purpose of the "loaded" state (loaded=compiled and required sections
|
|
|
|
// copied into local memory but not yet ready for execution) is to have an
|
|
|
|
// intermediate state wherein clients can remap the addresses of sections, using
|
|
|
|
// MCJIT::mapSectionAddress, (in preparation for later copying to a new location
|
|
|
|
// or an external process) before relocations and page permissions are applied.
|
|
|
|
//
|
|
|
|
// It might not be obvious at first glance, but the "remote-mcjit" case in the
|
|
|
|
// lli tool does this. In that case, the intermediate action is taken by the
|
|
|
|
// RemoteMemoryManager in response to the notifyObjectLoaded function being
|
|
|
|
// called.
|
|
|
|
|
2010-11-18 00:06:43 +08:00
|
|
|
class MCJIT : public ExecutionEngine {
|
2014-09-03 06:41:07 +08:00
|
|
|
MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> tm,
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
std::shared_ptr<MCJITMemoryManager> MemMgr,
|
2018-01-20 06:24:13 +08:00
|
|
|
std::shared_ptr<LegacyJITSymbolResolver> Resolver);
|
2011-03-19 06:48:41 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
typedef llvm::SmallPtrSet<Module *, 4> ModulePtrSet;
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
class OwningModuleContainer {
|
2013-10-01 09:47:35 +08:00
|
|
|
public:
|
2013-10-24 08:19:14 +08:00
|
|
|
OwningModuleContainer() {
|
|
|
|
}
|
|
|
|
~OwningModuleContainer() {
|
|
|
|
freeModulePtrSet(AddedModules);
|
|
|
|
freeModulePtrSet(LoadedModules);
|
|
|
|
freeModulePtrSet(FinalizedModules);
|
|
|
|
}
|
|
|
|
|
|
|
|
ModulePtrSet::iterator begin_added() { return AddedModules.begin(); }
|
|
|
|
ModulePtrSet::iterator end_added() { return AddedModules.end(); }
|
2014-09-06 07:38:35 +08:00
|
|
|
iterator_range<ModulePtrSet::iterator> added() {
|
2015-12-06 13:08:07 +08:00
|
|
|
return make_range(begin_added(), end_added());
|
2014-09-06 07:38:35 +08:00
|
|
|
}
|
2013-10-24 08:19:14 +08:00
|
|
|
|
|
|
|
ModulePtrSet::iterator begin_loaded() { return LoadedModules.begin(); }
|
|
|
|
ModulePtrSet::iterator end_loaded() { return LoadedModules.end(); }
|
|
|
|
|
|
|
|
ModulePtrSet::iterator begin_finalized() { return FinalizedModules.begin(); }
|
|
|
|
ModulePtrSet::iterator end_finalized() { return FinalizedModules.end(); }
|
|
|
|
|
2014-08-19 12:04:25 +08:00
|
|
|
void addModule(std::unique_ptr<Module> M) {
|
|
|
|
AddedModules.insert(M.release());
|
2013-10-24 08:19:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool removeModule(Module *M) {
|
|
|
|
return AddedModules.erase(M) || LoadedModules.erase(M) ||
|
|
|
|
FinalizedModules.erase(M);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasModuleBeenAddedButNotLoaded(Module *M) {
|
|
|
|
return AddedModules.count(M) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasModuleBeenLoaded(Module *M) {
|
|
|
|
// If the module is in either the "loaded" or "finalized" sections it
|
|
|
|
// has been loaded.
|
|
|
|
return (LoadedModules.count(M) != 0 ) || (FinalizedModules.count(M) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasModuleBeenFinalized(Module *M) {
|
|
|
|
return FinalizedModules.count(M) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ownsModule(Module* M) {
|
|
|
|
return (AddedModules.count(M) != 0) || (LoadedModules.count(M) != 0) ||
|
|
|
|
(FinalizedModules.count(M) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void markModuleAsLoaded(Module *M) {
|
|
|
|
// This checks against logic errors in the MCJIT implementation.
|
|
|
|
// This function should never be called with either a Module that MCJIT
|
|
|
|
// does not own or a Module that has already been loaded and/or finalized.
|
|
|
|
assert(AddedModules.count(M) &&
|
|
|
|
"markModuleAsLoaded: Module not found in AddedModules");
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
// Remove the module from the "Added" set.
|
|
|
|
AddedModules.erase(M);
|
|
|
|
|
|
|
|
// Add the Module to the "Loaded" set.
|
|
|
|
LoadedModules.insert(M);
|
|
|
|
}
|
|
|
|
|
|
|
|
void markModuleAsFinalized(Module *M) {
|
|
|
|
// This checks against logic errors in the MCJIT implementation.
|
|
|
|
// This function should never be called with either a Module that MCJIT
|
|
|
|
// does not own, a Module that has not been loaded or a Module that has
|
|
|
|
// already been finalized.
|
|
|
|
assert(LoadedModules.count(M) &&
|
|
|
|
"markModuleAsFinalized: Module not found in LoadedModules");
|
|
|
|
|
|
|
|
// Remove the module from the "Loaded" section of the list.
|
|
|
|
LoadedModules.erase(M);
|
|
|
|
|
|
|
|
// Add the Module to the "Finalized" section of the list by inserting it
|
|
|
|
// before the 'end' iterator.
|
|
|
|
FinalizedModules.insert(M);
|
|
|
|
}
|
|
|
|
|
|
|
|
void markAllLoadedModulesAsFinalized() {
|
|
|
|
for (ModulePtrSet::iterator I = LoadedModules.begin(),
|
|
|
|
E = LoadedModules.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Module *M = *I;
|
|
|
|
FinalizedModules.insert(M);
|
|
|
|
}
|
|
|
|
LoadedModules.clear();
|
|
|
|
}
|
2013-10-01 09:47:35 +08:00
|
|
|
|
|
|
|
private:
|
2013-10-24 08:19:14 +08:00
|
|
|
ModulePtrSet AddedModules;
|
|
|
|
ModulePtrSet LoadedModules;
|
|
|
|
ModulePtrSet FinalizedModules;
|
|
|
|
|
|
|
|
void freeModulePtrSet(ModulePtrSet& MPS) {
|
|
|
|
// Go through the module set and delete everything.
|
|
|
|
for (ModulePtrSet::iterator I = MPS.begin(), E = MPS.end(); I != E; ++I) {
|
|
|
|
Module *M = *I;
|
|
|
|
delete M;
|
|
|
|
}
|
|
|
|
MPS.clear();
|
|
|
|
}
|
2013-10-01 09:47:35 +08:00
|
|
|
};
|
|
|
|
|
2014-09-03 06:41:07 +08:00
|
|
|
std::unique_ptr<TargetMachine> TM;
|
2011-03-19 06:48:41 +08:00
|
|
|
MCContext *Ctx;
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
std::shared_ptr<MCJITMemoryManager> MemMgr;
|
|
|
|
LinkingSymbolResolver Resolver;
|
2012-08-08 02:33:00 +08:00
|
|
|
RuntimeDyld Dyld;
|
2014-09-03 06:28:02 +08:00
|
|
|
std::vector<JITEventListener*> EventListeners;
|
2011-03-19 06:48:41 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
OwningModuleContainer OwnedModules;
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2014-08-20 02:44:46 +08:00
|
|
|
SmallVector<object::OwningBinary<object::Archive>, 2> Archives;
|
2014-08-27 05:04:04 +08:00
|
|
|
SmallVector<std::unique_ptr<MemoryBuffer>, 2> Buffers;
|
2014-01-08 12:09:09 +08:00
|
|
|
|
2014-11-27 00:54:40 +08:00
|
|
|
SmallVector<std::unique_ptr<object::ObjectFile>, 2> LoadedObjects;
|
2011-03-19 06:48:41 +08:00
|
|
|
|
2013-04-26 05:02:36 +08:00
|
|
|
// An optional ObjectCache to be notified of compiled objects and used to
|
|
|
|
// perform lookup of pre-compiled code to avoid re-compilation.
|
|
|
|
ObjectCache *ObjCache;
|
|
|
|
|
2016-10-01 14:22:04 +08:00
|
|
|
Function *FindFunctionNamedInModulePtrSet(StringRef FnName,
|
2013-10-24 08:19:14 +08:00
|
|
|
ModulePtrSet::iterator I,
|
|
|
|
ModulePtrSet::iterator E);
|
|
|
|
|
2016-10-01 14:22:04 +08:00
|
|
|
GlobalVariable *FindGlobalVariableNamedInModulePtrSet(StringRef Name,
|
2015-06-20 08:55:58 +08:00
|
|
|
bool AllowInternal,
|
|
|
|
ModulePtrSet::iterator I,
|
|
|
|
ModulePtrSet::iterator E);
|
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
void runStaticConstructorsDestructorsInModulePtrSet(bool isDtors,
|
|
|
|
ModulePtrSet::iterator I,
|
|
|
|
ModulePtrSet::iterator E);
|
|
|
|
|
2010-11-18 00:06:43 +08:00
|
|
|
public:
|
2015-04-11 10:11:45 +08:00
|
|
|
~MCJIT() override;
|
2010-11-18 00:06:43 +08:00
|
|
|
|
|
|
|
/// @name ExecutionEngine interface implementation
|
|
|
|
/// @{
|
2014-08-19 12:04:25 +08:00
|
|
|
void addModule(std::unique_ptr<Module> M) override;
|
2014-04-30 05:52:46 +08:00
|
|
|
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override;
|
2014-08-27 05:04:04 +08:00
|
|
|
void addObjectFile(object::OwningBinary<object::ObjectFile> O) override;
|
2014-08-20 02:44:46 +08:00
|
|
|
void addArchive(object::OwningBinary<object::Archive> O) override;
|
2014-03-08 15:51:20 +08:00
|
|
|
bool removeModule(Module *M) override;
|
2013-10-24 08:19:14 +08:00
|
|
|
|
2015-06-20 08:55:58 +08:00
|
|
|
/// FindFunctionNamed - Search all of the active modules to find the function that
|
2013-10-24 08:19:14 +08:00
|
|
|
/// defines FnName. This is very slow operation and shouldn't be used for
|
|
|
|
/// general code.
|
2016-10-01 14:22:04 +08:00
|
|
|
Function *FindFunctionNamed(StringRef FnName) override;
|
2015-06-20 08:55:58 +08:00
|
|
|
|
2015-09-11 00:49:58 +08:00
|
|
|
/// FindGlobalVariableNamed - Search all of the active modules to find the
|
|
|
|
/// global variable that defines Name. This is very slow operation and
|
|
|
|
/// shouldn't be used for general code.
|
2016-10-01 14:22:04 +08:00
|
|
|
GlobalVariable *FindGlobalVariableNamed(StringRef Name,
|
2015-09-11 00:49:58 +08:00
|
|
|
bool AllowInternal = false) override;
|
2010-11-18 00:06:43 +08:00
|
|
|
|
2013-04-26 05:02:36 +08:00
|
|
|
/// Sets the object manager that MCJIT should use to avoid compilation.
|
2014-03-08 15:51:20 +08:00
|
|
|
void setObjectCache(ObjectCache *manager) override;
|
2013-04-26 05:02:36 +08:00
|
|
|
|
2014-03-21 05:06:46 +08:00
|
|
|
void setProcessAllSections(bool ProcessAllSections) override {
|
|
|
|
Dyld.setProcessAllSections(ProcessAllSections);
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
void generateCodeForModule(Module *M) override;
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2013-05-17 18:01:46 +08:00
|
|
|
/// finalizeObject - ensure the module is fully processed and is usable.
|
|
|
|
///
|
|
|
|
/// It is the user-level function for completing the process of making the
|
|
|
|
/// object usable for execution. It should be called after sections within an
|
|
|
|
/// object have been relocated using mapSectionAddress. When this method is
|
|
|
|
/// called the MCJIT execution engine will reapply relocations for a loaded
|
|
|
|
/// object.
|
2013-10-19 17:03:20 +08:00
|
|
|
/// Is it OK to finalize a set of modules, add modules and finalize again.
|
2013-10-22 07:27:02 +08:00
|
|
|
// FIXME: Do we really need both of these?
|
2014-03-08 15:51:20 +08:00
|
|
|
void finalizeObject() override;
|
2013-10-01 09:47:35 +08:00
|
|
|
virtual void finalizeModule(Module *);
|
|
|
|
void finalizeLoadedModules();
|
2012-11-06 04:57:16 +08:00
|
|
|
|
2013-10-24 08:19:14 +08:00
|
|
|
/// runStaticConstructorsDestructors - This method is used to execute all of
|
|
|
|
/// the static constructors or destructors for a program.
|
|
|
|
///
|
|
|
|
/// \param isDtors - Run the destructors instead of constructors.
|
2014-03-08 15:51:20 +08:00
|
|
|
void runStaticConstructorsDestructors(bool isDtors) override;
|
2013-10-24 08:19:14 +08:00
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
void *getPointerToFunction(Function *F) override;
|
2010-11-18 00:06:43 +08:00
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
GenericValue runFunction(Function *F,
|
2015-06-14 03:50:29 +08:00
|
|
|
ArrayRef<GenericValue> ArgValues) override;
|
2010-11-18 00:06:43 +08:00
|
|
|
|
2011-03-23 02:05:27 +08:00
|
|
|
/// getPointerToNamedFunction - This method returns the address of the
|
|
|
|
/// specified function by using the dlsym function call. As such it is only
|
|
|
|
/// useful for resolving library symbols, not code generated symbols.
|
|
|
|
///
|
|
|
|
/// If AbortOnFailure is false and no function with the given name is
|
|
|
|
/// found, this function silently returns a null pointer. Otherwise,
|
|
|
|
/// it prints a message to stderr and aborts.
|
|
|
|
///
|
2014-09-16 01:50:22 +08:00
|
|
|
void *getPointerToNamedFunction(StringRef Name,
|
2014-03-08 15:51:20 +08:00
|
|
|
bool AbortOnFailure = true) override;
|
2012-03-29 05:46:36 +08:00
|
|
|
|
2012-01-17 07:50:55 +08:00
|
|
|
/// mapSectionAddress - map a section to its target address space value.
|
|
|
|
/// Map the address of a JIT section as returned from the memory manager
|
|
|
|
/// to the address in the target process as the running code will see it.
|
|
|
|
/// This is the address which will be used for relocation resolution.
|
2014-03-08 15:51:20 +08:00
|
|
|
void mapSectionAddress(const void *LocalAddress,
|
|
|
|
uint64_t TargetAddress) override {
|
2012-01-17 07:50:55 +08:00
|
|
|
Dyld.mapSectionAddress(LocalAddress, TargetAddress);
|
|
|
|
}
|
2014-03-08 15:51:20 +08:00
|
|
|
void RegisterJITEventListener(JITEventListener *L) override;
|
|
|
|
void UnregisterJITEventListener(JITEventListener *L) override;
|
2012-11-07 02:51:59 +08:00
|
|
|
|
2013-10-01 09:47:35 +08:00
|
|
|
// If successful, these function will implicitly finalize all loaded objects.
|
|
|
|
// To get a function address within MCJIT without causing a finalize, use
|
|
|
|
// getSymbolAddress.
|
2014-03-08 15:51:20 +08:00
|
|
|
uint64_t getGlobalValueAddress(const std::string &Name) override;
|
|
|
|
uint64_t getFunctionAddress(const std::string &Name) override;
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2014-09-03 06:41:07 +08:00
|
|
|
TargetMachine *getTargetMachine() override { return TM.get(); }
|
2014-01-24 03:23:28 +08:00
|
|
|
|
2010-11-18 00:06:43 +08:00
|
|
|
/// @}
|
|
|
|
/// @name (Private) Registration Interfaces
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
static void Register() {
|
|
|
|
MCJITCtor = createJIT;
|
|
|
|
}
|
|
|
|
|
2018-01-20 06:24:13 +08:00
|
|
|
static ExecutionEngine *
|
|
|
|
createJIT(std::unique_ptr<Module> M, std::string *ErrorStr,
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
std::shared_ptr<MCJITMemoryManager> MemMgr,
|
2018-01-20 06:24:13 +08:00
|
|
|
std::shared_ptr<LegacyJITSymbolResolver> Resolver,
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
std::unique_ptr<TargetMachine> TM);
|
2010-11-18 00:06:43 +08:00
|
|
|
|
|
|
|
// @}
|
2012-08-08 02:33:00 +08:00
|
|
|
|
2016-09-13 01:19:24 +08:00
|
|
|
// Takes a mangled name and returns the corresponding JITSymbol (if a
|
|
|
|
// definition of that mangled name has been added to the JIT).
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findSymbol(const std::string &Name, bool CheckFunctionsOnly);
|
2016-09-13 01:19:24 +08:00
|
|
|
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
// DEPRECATED - Please use findSymbol instead.
|
2016-09-13 01:19:24 +08:00
|
|
|
//
|
2013-10-01 09:47:35 +08:00
|
|
|
// This is not directly exposed via the ExecutionEngine API, but it is
|
|
|
|
// used by the LinkingMemoryManager.
|
2016-09-13 01:19:24 +08:00
|
|
|
//
|
|
|
|
// getSymbolAddress takes an unmangled name and returns the corresponding
|
|
|
|
// JITSymbol if a definition of the name has been added to the JIT.
|
2013-10-01 09:47:35 +08:00
|
|
|
uint64_t getSymbolAddress(const std::string &Name,
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
bool CheckFunctionsOnly);
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2012-08-08 02:33:00 +08:00
|
|
|
protected:
|
|
|
|
/// emitObject -- Generate a JITed object in memory from the specified module
|
|
|
|
/// Currently, MCJIT only supports a single module and the module passed to
|
|
|
|
/// this function call is expected to be the contained module. The module
|
2013-12-07 19:21:42 +08:00
|
|
|
/// is passed as a parameter here to prepare for multiple module support in
|
2012-08-08 02:33:00 +08:00
|
|
|
/// the future.
|
2014-11-27 00:54:40 +08:00
|
|
|
std::unique_ptr<MemoryBuffer> emitObject(Module *M);
|
2013-04-26 05:02:36 +08:00
|
|
|
|
2018-12-04 08:55:15 +08:00
|
|
|
void notifyObjectLoaded(const object::ObjectFile &Obj,
|
|
|
|
const RuntimeDyld::LoadedObjectInfo &L);
|
|
|
|
void notifyFreeingObject(const object::ObjectFile &Obj);
|
2013-10-01 09:47:35 +08:00
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findExistingSymbol(const std::string &Name);
|
|
|
|
Module *findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly);
|
2010-11-18 00:06:43 +08:00
|
|
|
};
|
|
|
|
|
2015-09-11 00:49:58 +08:00
|
|
|
} // end llvm namespace
|
2010-11-18 00:06:43 +08:00
|
|
|
|
2015-09-11 00:49:58 +08:00
|
|
|
#endif // LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
|