aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/ExecutionEngine/Orc')
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp1
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp76
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp2
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp7
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp11
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp88
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp3
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp6
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp8
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp2
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp16
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp1
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp56
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Layer.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp433
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp152
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp11
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp14
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp171
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp252
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Speculation.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp2
27 files changed, 966 insertions, 374 deletions
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
index f34247005258..fad7428e1f90 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
@@ -12,6 +12,7 @@
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp
index e5cb8103919a..dd80630a33c1 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -62,7 +62,7 @@ void ResourceTracker::makeDefunct() {
JDAndFlag.store(Val);
}
-ResourceManager::~ResourceManager() {}
+ResourceManager::~ResourceManager() = default;
ResourceTrackerDefunct::ResourceTrackerDefunct(ResourceTrackerSP RT)
: RT(std::move(RT)) {}
@@ -76,9 +76,21 @@ void ResourceTrackerDefunct::log(raw_ostream &OS) const {
}
FailedToMaterialize::FailedToMaterialize(
+ std::shared_ptr<SymbolStringPool> SSP,
std::shared_ptr<SymbolDependenceMap> Symbols)
- : Symbols(std::move(Symbols)) {
+ : SSP(std::move(SSP)), Symbols(std::move(Symbols)) {
+ assert(this->SSP && "String pool cannot be null");
assert(!this->Symbols->empty() && "Can not fail to resolve an empty set");
+
+ // FIXME: Use a new dep-map type for FailedToMaterialize errors so that we
+ // don't have to manually retain/release.
+ for (auto &KV : *this->Symbols)
+ KV.first->Retain();
+}
+
+FailedToMaterialize::~FailedToMaterialize() {
+ for (auto &KV : *Symbols)
+ KV.first->Release();
}
std::error_code FailedToMaterialize::convertToErrorCode() const {
@@ -251,9 +263,21 @@ StringRef AbsoluteSymbolsMaterializationUnit::getName() const {
void AbsoluteSymbolsMaterializationUnit::materialize(
std::unique_ptr<MaterializationResponsibility> R) {
- // No dependencies, so these calls can't fail.
- cantFail(R->notifyResolved(Symbols));
- cantFail(R->notifyEmitted());
+ // Even though these are just absolute symbols we need to check for failure
+ // to resolve/emit: the tracker for these symbols may have been removed while
+ // the materialization was in flight (e.g. due to a failure in some action
+ // triggered by the queries attached to the resolution/emission of these
+ // symbols).
+ if (auto Err = R->notifyResolved(Symbols)) {
+ R->getExecutionSession().reportError(std::move(Err));
+ R->failMaterialization();
+ return;
+ }
+ if (auto Err = R->notifyEmitted()) {
+ R->getExecutionSession().reportError(std::move(Err));
+ R->failMaterialization();
+ return;
+ }
}
void AbsoluteSymbolsMaterializationUnit::discard(const JITDylib &JD,
@@ -485,13 +509,16 @@ Expected<SymbolAliasMap> buildSimpleReexportsAliasMap(JITDylib &SourceJD,
class InProgressLookupState {
public:
+ // FIXME: Reduce the number of SymbolStringPtrs here. See
+ // https://github.com/llvm/llvm-project/issues/55576.
+
InProgressLookupState(LookupKind K, JITDylibSearchOrder SearchOrder,
SymbolLookupSet LookupSet, SymbolState RequiredState)
: K(K), SearchOrder(std::move(SearchOrder)),
LookupSet(std::move(LookupSet)), RequiredState(RequiredState) {
DefGeneratorCandidates = this->LookupSet;
}
- virtual ~InProgressLookupState() {}
+ virtual ~InProgressLookupState() = default;
virtual void complete(std::unique_ptr<InProgressLookupState> IPLS) = 0;
virtual void fail(Error Err) = 0;
@@ -609,7 +636,7 @@ void LookupState::continueLookup(Error Err) {
ES.OL_applyQueryPhase1(std::move(IPLS), std::move(Err));
}
-DefinitionGenerator::~DefinitionGenerator() {}
+DefinitionGenerator::~DefinitionGenerator() = default;
JITDylib::~JITDylib() {
LLVM_DEBUG(dbgs() << "Destroying JITDylib " << getName() << "\n");
@@ -959,6 +986,7 @@ Error JITDylib::resolve(MaterializationResponsibility &MR,
auto FailedSymbolsDepMap = std::make_shared<SymbolDependenceMap>();
(*FailedSymbolsDepMap)[this] = std::move(SymbolsInErrorState);
return make_error<FailedToMaterialize>(
+ getExecutionSession().getSymbolStringPool(),
std::move(FailedSymbolsDepMap));
}
@@ -1036,6 +1064,7 @@ Error JITDylib::emit(MaterializationResponsibility &MR,
auto FailedSymbolsDepMap = std::make_shared<SymbolDependenceMap>();
(*FailedSymbolsDepMap)[this] = std::move(SymbolsInErrorState);
return make_error<FailedToMaterialize>(
+ getExecutionSession().getSymbolStringPool(),
std::move(FailedSymbolsDepMap));
}
@@ -1411,12 +1440,11 @@ void JITDylib::dump(raw_ostream &OS) {
for (auto &KV : Symbols) {
OS << " \"" << *KV.first << "\": ";
if (auto Addr = KV.second.getAddress())
- OS << format("0x%016" PRIx64, Addr) << ", " << KV.second.getFlags()
- << " ";
+ OS << format("0x%016" PRIx64, Addr);
else
OS << "<not resolved> ";
- OS << KV.second.getFlags() << " " << KV.second.getState();
+ OS << " " << KV.second.getFlags() << " " << KV.second.getState();
if (KV.second.hasMaterializerAttached()) {
OS << " (Materializer ";
@@ -1751,7 +1779,7 @@ void JITDylib::transferEmittedNodeDependencies(
}
}
-Platform::~Platform() {}
+Platform::~Platform() = default;
Expected<DenseMap<JITDylib *, SymbolMap>> Platform::lookupInitSymbols(
ExecutionSession &ES,
@@ -1858,6 +1886,12 @@ ExecutionSession::ExecutionSession(std::unique_ptr<ExecutorProcessControl> EPC)
this->EPC->ES = this;
}
+ExecutionSession::~ExecutionSession() {
+ // You must call endSession prior to destroying the session.
+ assert(!SessionOpen &&
+ "Session still open. Did you forget to call endSession?");
+}
+
Error ExecutionSession::endSession() {
LLVM_DEBUG(dbgs() << "Ending ExecutionSession " << this << "\n");
@@ -1869,7 +1903,7 @@ Error ExecutionSession::endSession() {
// TODO: notifiy platform? run static deinits?
Error Err = Error::success();
- for (auto &JD : JITDylibsToClose)
+ for (auto &JD : reverse(JITDylibsToClose))
Err = joinErrors(std::move(Err), JD->clear());
Err = joinErrors(std::move(Err), EPC->disconnect());
@@ -1987,9 +2021,8 @@ JITDylib::getDFSLinkOrder(ArrayRef<JITDylibSP> JDs) {
for (auto &KV : llvm::reverse(Result.back()->LinkOrder)) {
auto &JD = *KV.first;
- if (Visited.count(&JD))
+ if (!Visited.insert(&JD).second)
continue;
- Visited.insert(&JD);
WorkStack.push_back(&JD);
}
}
@@ -2071,7 +2104,7 @@ void ExecutionSession::lookup(
Expected<SymbolMap>
ExecutionSession::lookup(const JITDylibSearchOrder &SearchOrder,
- const SymbolLookupSet &Symbols, LookupKind K,
+ SymbolLookupSet Symbols, LookupKind K,
SymbolState RequiredState,
RegisterDependenciesFunction RegisterDependencies) {
#if LLVM_ENABLE_THREADS
@@ -2103,7 +2136,7 @@ ExecutionSession::lookup(const JITDylibSearchOrder &SearchOrder,
#endif
// Perform the asynchronous lookup.
- lookup(K, SearchOrder, Symbols, RequiredState, NotifyComplete,
+ lookup(K, SearchOrder, std::move(Symbols), RequiredState, NotifyComplete,
RegisterDependencies);
#if LLVM_ENABLE_THREADS
@@ -2257,7 +2290,8 @@ Error ExecutionSession::removeResourceTracker(ResourceTracker &RT) {
joinErrors(std::move(Err), L->handleRemoveResources(RT.getKeyUnsafe()));
for (auto &Q : QueriesToFail)
- Q->handleFailed(make_error<FailedToMaterialize>(FailedSymbols));
+ Q->handleFailed(
+ make_error<FailedToMaterialize>(getSymbolStringPool(), FailedSymbols));
return Err;
}
@@ -2337,7 +2371,8 @@ Error ExecutionSession::IL_updateCandidatesFor(
if (SymI->second.getFlags().hasError()) {
auto FailedSymbolsMap = std::make_shared<SymbolDependenceMap>();
(*FailedSymbolsMap)[&JD] = {Name};
- return make_error<FailedToMaterialize>(std::move(FailedSymbolsMap));
+ return make_error<FailedToMaterialize>(getSymbolStringPool(),
+ std::move(FailedSymbolsMap));
}
// Otherwise this is a match. Remove it from the candidate set.
@@ -2611,7 +2646,7 @@ void ExecutionSession::OL_completeLookup(
auto FailedSymbolsMap = std::make_shared<SymbolDependenceMap>();
(*FailedSymbolsMap)[&JD] = {Name};
return make_error<FailedToMaterialize>(
- std::move(FailedSymbolsMap));
+ getSymbolStringPool(), std::move(FailedSymbolsMap));
}
// Otherwise this is a match.
@@ -2947,7 +2982,8 @@ void ExecutionSession::OL_notifyFailed(MaterializationResponsibility &MR) {
});
for (auto &Q : FailedQueries)
- Q->handleFailed(make_error<FailedToMaterialize>(FailedSymbols));
+ Q->handleFailed(
+ make_error<FailedToMaterialize>(getSymbolStringPool(), FailedSymbols));
}
Error ExecutionSession::OL_replace(MaterializationResponsibility &MR,
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
index 4ff6b7fd54df..1e68ea1225e6 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
@@ -42,7 +42,7 @@ class DebugObjectSection {
public:
virtual void setTargetMemoryRange(SectionRange Range) = 0;
virtual void dump(raw_ostream &OS, StringRef Name) {}
- virtual ~DebugObjectSection() {}
+ virtual ~DebugObjectSection() = default;
};
template <typename ELFT>
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp
index 5b386a458f1f..028bd245fb55 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp
@@ -297,6 +297,13 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S) {
llvm_unreachable("Invalid state");
}
+raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP) {
+ std::lock_guard<std::mutex> Lock(SSP.PoolMutex);
+ for (auto &KV : SSP.Pool)
+ OS << KV.first() << ": " << KV.second << "\n";
+ return OS;
+}
+
DumpObjects::DumpObjects(std::string DumpDir, std::string IdentifierOverride)
: DumpDir(std::move(DumpDir)),
IdentifierOverride(std::move(IdentifierOverride)) {
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp
index 6916ee4a827f..3c44fe81b4a9 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp
@@ -48,7 +48,7 @@ public:
MachODebugObjectSynthesizerBase(LinkGraph &G, ExecutorAddr RegisterActionAddr)
: G(G), RegisterActionAddr(RegisterActionAddr) {}
- virtual ~MachODebugObjectSynthesizerBase() {}
+ virtual ~MachODebugObjectSynthesizerBase() = default;
Error preserveDebugSections() {
if (G.findSectionByName(SynthDebugSectionName)) {
@@ -349,10 +349,11 @@ public:
}
SectionRange R(MachOContainerBlock->getSection());
- G.allocActions().push_back({cantFail(shared::WrapperFunctionCall::Create<
- SPSArgList<SPSExecutorAddrRange>>(
- RegisterActionAddr, R.getRange())),
- {}});
+ G.allocActions().push_back(
+ {cantFail(shared::WrapperFunctionCall::Create<
+ shared::SPSArgList<shared::SPSExecutorAddrRange>>(
+ RegisterActionAddr, R.getRange())),
+ {}});
return Error::success();
}
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
index d02760703f06..e476c549412a 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
@@ -10,6 +10,7 @@
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/ExecutionEngine/JITLink/ELF_x86_64.h"
+#include "llvm/ExecutionEngine/JITLink/aarch64.h"
#include "llvm/ExecutionEngine/JITLink/x86_64.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -47,6 +48,11 @@ public:
Endianness = support::endianness::little;
EdgeKind = jitlink::x86_64::Pointer64;
break;
+ case Triple::aarch64:
+ PointerSize = 8;
+ Endianness = support::endianness::little;
+ EdgeKind = jitlink::aarch64::Pointer64;
+ break;
default:
llvm_unreachable("Unrecognized architecture");
}
@@ -95,8 +101,6 @@ StringRef InitArrayFuncSectionName = ".init_array";
StringRef ThreadBSSSectionName = ".tbss";
StringRef ThreadDataSectionName = ".tdata";
-StringRef InitSectionNames[] = {InitArrayFuncSectionName};
-
} // end anonymous namespace
namespace llvm {
@@ -117,8 +121,12 @@ ELFNixPlatform::Create(ExecutionSession &ES,
inconvertibleErrorCode());
// Create default aliases if the caller didn't supply any.
- if (!RuntimeAliases)
- RuntimeAliases = standardPlatformAliases(ES);
+ if (!RuntimeAliases) {
+ auto StandardRuntimeAliases = standardPlatformAliases(ES, PlatformJD);
+ if (!StandardRuntimeAliases)
+ return StandardRuntimeAliases.takeError();
+ RuntimeAliases = std::move(*StandardRuntimeAliases);
+ }
// Define the aliases.
if (auto Err = PlatformJD.define(symbolAliases(std::move(*RuntimeAliases))))
@@ -189,10 +197,53 @@ static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases,
}
}
-SymbolAliasMap ELFNixPlatform::standardPlatformAliases(ExecutionSession &ES) {
+Expected<SymbolAliasMap>
+ELFNixPlatform::standardPlatformAliases(ExecutionSession &ES,
+ JITDylib &PlatformJD) {
SymbolAliasMap Aliases;
addAliases(ES, Aliases, requiredCXXAliases());
addAliases(ES, Aliases, standardRuntimeUtilityAliases());
+
+ // Determine whether or not the libunwind extended-API function for
+ // dynamically registering an entire .eh_frame section is available.
+ // If it is not, we assume that libgcc_s is being used, and alias to
+ // its __register_frame with the same functionality.
+ auto RTRegisterFrame = ES.intern("__orc_rt_register_eh_frame_section");
+ auto LibUnwindRegisterFrame = ES.intern("__unw_add_dynamic_eh_frame_section");
+ auto RTDeregisterFrame = ES.intern("__orc_rt_deregister_eh_frame_section");
+ auto LibUnwindDeregisterFrame =
+ ES.intern("__unw_remove_dynamic_eh_frame_section");
+ auto SM = ES.lookup(makeJITDylibSearchOrder(&PlatformJD),
+ SymbolLookupSet()
+ .add(LibUnwindRegisterFrame,
+ SymbolLookupFlags::WeaklyReferencedSymbol)
+ .add(LibUnwindDeregisterFrame,
+ SymbolLookupFlags::WeaklyReferencedSymbol));
+ if (!SM) { // Weak-ref means no "missing symbol" errors, so this must be
+ // something more serious that we should report.
+ return SM.takeError();
+ } else if (SM->size() == 2) {
+ LLVM_DEBUG({
+ dbgs() << "Using libunwind " << LibUnwindRegisterFrame
+ << " for unwind info registration\n";
+ });
+ Aliases[std::move(RTRegisterFrame)] = {LibUnwindRegisterFrame,
+ JITSymbolFlags::Exported};
+ Aliases[std::move(RTDeregisterFrame)] = {LibUnwindDeregisterFrame,
+ JITSymbolFlags::Exported};
+ } else {
+ // Since LLVM libunwind is not present, we assume that unwinding
+ // is provided by libgcc
+ LLVM_DEBUG({
+ dbgs() << "Using libgcc __register_frame"
+ << " for unwind info registration\n";
+ });
+ Aliases[std::move(RTRegisterFrame)] = {ES.intern("__register_frame"),
+ JITSymbolFlags::Exported};
+ Aliases[std::move(RTDeregisterFrame)] = {ES.intern("__deregister_frame"),
+ JITSymbolFlags::Exported};
+ }
+
return Aliases;
}
@@ -210,6 +261,10 @@ ELFNixPlatform::standardRuntimeUtilityAliases() {
static const std::pair<const char *, const char *>
StandardRuntimeUtilityAliases[] = {
{"__orc_rt_run_program", "__orc_rt_elfnix_run_program"},
+ {"__orc_rt_jit_dlerror", "__orc_rt_elfnix_jit_dlerror"},
+ {"__orc_rt_jit_dlopen", "__orc_rt_elfnix_jit_dlopen"},
+ {"__orc_rt_jit_dlclose", "__orc_rt_elfnix_jit_dlclose"},
+ {"__orc_rt_jit_dlsym", "__orc_rt_elfnix_jit_dlsym"},
{"__orc_rt_log_error", "__orc_rt_log_error_to_stderr"}};
return ArrayRef<std::pair<const char *, const char *>>(
@@ -217,16 +272,16 @@ ELFNixPlatform::standardRuntimeUtilityAliases() {
}
bool ELFNixPlatform::isInitializerSection(StringRef SecName) {
- for (auto &Name : InitSectionNames) {
- if (Name.equals(SecName))
- return true;
- }
+ if (SecName.consume_front(InitArrayFuncSectionName) &&
+ (SecName.empty() || SecName[0] == '.'))
+ return true;
return false;
}
bool ELFNixPlatform::supportedTarget(const Triple &TT) {
switch (TT.getArch()) {
case Triple::x86_64:
+ case Triple::aarch64:
return true;
default:
return false;
@@ -723,16 +778,15 @@ Error ELFNixPlatform::ELFNixPlatformPlugin::preserveInitSections(
jitlink::LinkGraph &G, MaterializationResponsibility &MR) {
JITLinkSymbolSet InitSectionSymbols;
- for (auto &InitSectionName : InitSectionNames) {
+ for (auto &InitSection : G.sections()) {
// Skip non-init sections.
- auto *InitSection = G.findSectionByName(InitSectionName);
- if (!InitSection)
+ if (!isInitializerSection(InitSection.getName()))
continue;
// Make a pass over live symbols in the section: those blocks are already
// preserved.
DenseSet<jitlink::Block *> AlreadyLiveBlocks;
- for (auto &Sym : InitSection->symbols()) {
+ for (auto &Sym : InitSection.symbols()) {
auto &B = Sym->getBlock();
if (Sym->isLive() && Sym->getOffset() == 0 &&
Sym->getSize() == B.getSize() && !AlreadyLiveBlocks.count(&B)) {
@@ -742,7 +796,7 @@ Error ELFNixPlatform::ELFNixPlatformPlugin::preserveInitSections(
}
// Add anonymous symbols to preserve any not-already-preserved blocks.
- for (auto *B : InitSection->blocks())
+ for (auto *B : InitSection.blocks())
if (!AlreadyLiveBlocks.count(B))
InitSectionSymbols.insert(
&G.addAnonymousSymbol(*B, 0, B->getSize(), false, true));
@@ -763,9 +817,9 @@ Error ELFNixPlatform::ELFNixPlatformPlugin::registerInitSections(
LLVM_DEBUG({ dbgs() << "ELFNixPlatform::registerInitSections\n"; });
- for (auto InitSectionName : InitSectionNames) {
- if (auto *Sec = G.findSectionByName(InitSectionName)) {
- InitSections.push_back(Sec);
+ for (auto &Sec : G.sections()) {
+ if (isInitializerSection(Sec.getName())) {
+ InitSections.push_back(&Sec);
}
}
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp
index f3fe0555fa75..c591acdd646b 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp
@@ -45,7 +45,8 @@ createJITLoaderGDBRegistrar(ExecutionSession &ES) {
Error EPCDebugObjectRegistrar::registerDebugObject(
ExecutorAddrRange TargetMem) {
- return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(RegisterFn, TargetMem);
+ return ES.callSPSWrapper<void(shared::SPSExecutorAddrRange)>(RegisterFn,
+ TargetMem);
}
} // namespace orc
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp
index 249f02f36bae..48aaab96e71f 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp
@@ -88,7 +88,6 @@ EPCTrampolinePool::EPCTrampolinePool(EPCIndirectionUtils &EPCIU)
}
Error EPCTrampolinePool::deallocatePool() {
- Error Err = Error::success();
std::promise<MSVCPError> DeallocResultP;
auto DeallocResultF = DeallocResultP.get_future();
@@ -234,7 +233,7 @@ Error EPCIndirectStubsManager::updatePointer(StringRef Name,
namespace llvm {
namespace orc {
-EPCIndirectionUtils::ABISupport::~ABISupport() {}
+EPCIndirectionUtils::ABISupport::~ABISupport() = default;
Expected<std::unique_ptr<EPCIndirectionUtils>>
EPCIndirectionUtils::Create(ExecutorProcessControl &EPC) {
@@ -261,6 +260,9 @@ EPCIndirectionUtils::Create(ExecutorProcessControl &EPC) {
case Triple::mips64el:
return CreateWithABI<OrcMips64>(EPC);
+ case Triple::riscv64:
+ return CreateWithABI<OrcRiscv64>(EPC);
+
case Triple::x86_64:
if (TT.getOS() == Triple::OSType::Win32)
return CreateWithABI<OrcX86_64_Win32>(EPC);
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
index ae2d47fb8c5e..95cf89ec3f8b 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
@@ -62,7 +62,7 @@ CtorDtorIterator::Element CtorDtorIterator::operator*() const {
break;
} else if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(FuncC)) {
if (CE->isCast())
- FuncC = dyn_cast_or_null<ConstantExpr>(CE->getOperand(0));
+ FuncC = CE->getOperand(0);
else
break;
} else {
@@ -273,10 +273,10 @@ Expected<std::unique_ptr<StaticLibraryDefinitionGenerator>>
StaticLibraryDefinitionGenerator::Load(
ObjectLayer &L, const char *FileName,
GetObjectFileInterface GetObjFileInterface) {
- auto ArchiveBuffer = errorOrToExpected(MemoryBuffer::getFile(FileName));
+ auto ArchiveBuffer = MemoryBuffer::getFile(FileName);
if (!ArchiveBuffer)
- return ArchiveBuffer.takeError();
+ return createFileError(FileName, ArchiveBuffer.getError());
return Create(L, std::move(*ArchiveBuffer), std::move(GetObjFileInterface));
}
@@ -288,7 +288,7 @@ StaticLibraryDefinitionGenerator::Load(
auto B = object::createBinary(FileName);
if (!B)
- return B.takeError();
+ return createFileError(FileName, B.takeError());
// If this is a regular archive then create an instance from it.
if (isa<object::Archive>(B->getBinary()))
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
index 2eb835551adb..412b9f95ea62 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
@@ -19,9 +19,9 @@
namespace llvm {
namespace orc {
-ExecutorProcessControl::MemoryAccess::~MemoryAccess() {}
+ExecutorProcessControl::MemoryAccess::~MemoryAccess() = default;
-ExecutorProcessControl::~ExecutorProcessControl() {}
+ExecutorProcessControl::~ExecutorProcessControl() = default;
SelfExecutorProcessControl::SelfExecutorProcessControl(
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
index aadc437c80c4..69aba1fff59a 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
@@ -11,7 +11,7 @@
namespace llvm {
namespace orc {
-IRCompileLayer::IRCompiler::~IRCompiler() {}
+IRCompileLayer::IRCompiler::~IRCompiler() = default;
IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
std::unique_ptr<IRCompiler> Compile)
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
index 7a71d2f781d7..38cab526704f 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
@@ -59,7 +59,7 @@ private:
namespace llvm {
namespace orc {
-TrampolinePool::~TrampolinePool() {}
+TrampolinePool::~TrampolinePool() = default;
void IndirectStubsManager::anchor() {}
Expected<JITTargetAddress>
@@ -152,6 +152,11 @@ createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES,
return CCMgrT::Create(ES, ErrorHandlerAddress);
}
+ case Triple::riscv64: {
+ typedef orc::LocalJITCompileCallbackManager<orc::OrcRiscv64> CCMgrT;
+ return CCMgrT::Create(ES, ErrorHandlerAddress);
+ }
+
case Triple::x86_64: {
if (T.getOS() == Triple::OSType::Win32) {
typedef orc::LocalJITCompileCallbackManager<orc::OrcX86_64_Win32> CCMgrT;
@@ -206,6 +211,12 @@ createLocalIndirectStubsManagerBuilder(const Triple &T) {
orc::LocalIndirectStubsManager<orc::OrcMips64>>();
};
+ case Triple::riscv64:
+ return []() {
+ return std::make_unique<
+ orc::LocalIndirectStubsManager<orc::OrcRiscv64>>();
+ };
+
case Triple::x86_64:
if (T.getOS() == Triple::OSType::Win32) {
return [](){
@@ -431,8 +442,7 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym,
auto RelocOffInInstr =
MIA.getMemoryOperandRelocationOffset(Instr, InstrSize);
- if (!RelocOffInInstr.hasValue() ||
- InstrSize - RelocOffInInstr.getValue() != 4) {
+ if (!RelocOffInInstr || InstrSize - *RelocOffInInstr != 4) {
LLVM_DEBUG(dbgs() << "Skipping unknown self-relocation at "
<< InstrStart);
continue;
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
index 0fbf79b8a56d..c60f4b3b263c 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
@@ -19,6 +19,7 @@ JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
: TT(std::move(TT)) {
Options.EmulatedTLS = true;
Options.ExplicitEmulatedTLS = true;
+ Options.UseInitArray = true;
}
Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() {
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 91949c9d7eeb..6d67e6d87b56 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -143,7 +143,7 @@ public:
JITEvaluatedSymbol(pointerToJITTargetAddress(this),
JITSymbolFlags::Exported);
StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
+ JITEvaluatedSymbol(pointerToJITTargetAddress(registerCxaAtExitHelper),
JITSymbolFlags());
cantFail(
@@ -162,6 +162,9 @@ public:
PerJDInterposes[J.mangleAndIntern("__lljit.run_atexits_helper")] =
JITEvaluatedSymbol(pointerToJITTargetAddress(runAtExitsHelper),
JITSymbolFlags());
+ PerJDInterposes[J.mangleAndIntern("__lljit.atexit_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
+ JITSymbolFlags());
cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
auto Ctx = std::make_unique<LLVMContext>();
@@ -190,6 +193,14 @@ public:
GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
{PlatformInstanceDecl, DSOHandle});
+ auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
+ auto *AtExitCallbackTy = FunctionType::get(VoidTy, {}, false);
+ auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
+ addHelperAndWrapper(*M, "atexit",
+ FunctionType::get(IntTy, {AtExitCallbackPtrTy}, false),
+ GlobalValue::HiddenVisibility, "__lljit.atexit_helper",
+ {PlatformInstanceDecl, DSOHandle});
+
return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
}
@@ -413,16 +424,25 @@ private:
.takeError();
}
- static void registerAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
- void *DSOHandle) {
+ static void registerCxaAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
+ void *DSOHandle) {
LLVM_DEBUG({
- dbgs() << "Registering atexit function " << (void *)F << " for JD "
+ dbgs() << "Registering cxa atexit function " << (void *)F << " for JD "
<< (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
});
static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
F, Ctx, DSOHandle);
}
+ static void registerAtExitHelper(void *Self, void *DSOHandle, void (*F)()) {
+ LLVM_DEBUG({
+ dbgs() << "Registering atexit function " << (void *)F << " for JD "
+ << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
+ });
+ static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
+ reinterpret_cast<void (*)(void *)>(F), nullptr, DSOHandle);
+ }
+
static void runAtExitsHelper(void *Self, void *DSOHandle) {
LLVM_DEBUG({
dbgs() << "Running atexit functions for JD "
@@ -450,12 +470,12 @@ private:
auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
auto *VoidTy = Type::getVoidTy(*Ctx);
auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
- auto *AtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
- auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
+ auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
+ auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
addHelperAndWrapper(
*M, "__cxa_atexit",
- FunctionType::get(IntTy, {AtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
+ FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
false),
GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
{PlatformInstanceDecl});
@@ -521,11 +541,7 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
for (auto E : COrDtors)
InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
- llvm::sort(InitsOrDeInits,
- [](const std::pair<Function *, unsigned> &LHS,
- const std::pair<Function *, unsigned> &RHS) {
- return LHS.first < RHS.first;
- });
+ llvm::sort(InitsOrDeInits, llvm::less_second());
auto *InitOrDeInitFuncEntryBlock =
BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc);
@@ -589,7 +605,7 @@ void LLJIT::PlatformSupport::setInitTransform(
J.InitHelperTransformLayer->setTransform(std::move(T));
}
-LLJIT::PlatformSupport::~PlatformSupport() {}
+LLJIT::PlatformSupport::~PlatformSupport() = default;
Error LLJITBuilderState::prepareForConstruction() {
@@ -701,10 +717,14 @@ Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
return addObjectFile(JD.getDefaultResourceTracker(), std::move(Obj));
}
-Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
- SymbolStringPtr Name) {
- return ES->lookup(
- makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols), Name);
+Expected<ExecutorAddr> LLJIT::lookupLinkerMangled(JITDylib &JD,
+ SymbolStringPtr Name) {
+ if (auto Sym = ES->lookup(
+ makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
+ Name))
+ return ExecutorAddr(Sym->getAddress());
+ else
+ return Sym.takeError();
}
Expected<std::unique_ptr<ObjectLayer>>
@@ -897,7 +917,7 @@ LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
LCTMgr = std::move(S.LCTMgr);
else {
if (auto LCTMgrOrErr = createLocalLazyCallThroughManager(
- S.TT, *ES, S.LazyCompileFailureAddr))
+ S.TT, *ES, S.LazyCompileFailureAddr.getValue()))
LCTMgr = std::move(*LCTMgrOrErr);
else {
Err = LCTMgrOrErr.takeError();
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Layer.cpp
index adb8861793b1..4a50f2d7a153 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Layer.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Layer.cpp
@@ -19,7 +19,7 @@
namespace llvm {
namespace orc {
-IRLayer::~IRLayer() {}
+IRLayer::~IRLayer() = default;
Error IRLayer::add(ResourceTrackerSP RT, ThreadSafeModule TSM) {
assert(RT && "RT can not be null");
@@ -158,7 +158,7 @@ char ObjectLayer::ID;
ObjectLayer::ObjectLayer(ExecutionSession &ES) : ES(ES) {}
-ObjectLayer::~ObjectLayer() {}
+ObjectLayer::~ObjectLayer() = default;
Error ObjectLayer::add(ResourceTrackerSP RT, std::unique_ptr<MemoryBuffer> O,
MaterializationUnit::Interface I) {
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
index 66453e6a632f..20b655bdf4b1 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
@@ -131,6 +131,10 @@ createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES,
case Triple::mips64el:
return LocalLazyCallThroughManager::Create<OrcMips64>(ES, ErrorHandlerAddr);
+ case Triple::riscv64:
+ return LocalLazyCallThroughManager::Create<OrcRiscv64>(ES,
+ ErrorHandlerAddr);
+
case Triple::x86_64:
if (T.getOS() == Triple::OSType::Win32)
return LocalLazyCallThroughManager::Create<OrcX86_64_Win32>(
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
index 44cb78c773c9..3452267e4df4 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
@@ -24,7 +24,7 @@ void lookupAndRecordAddrs(
Symbols.add(KV.first, LookupFlags);
ES.lookup(
- K, SearchOrder, Symbols, SymbolState::Ready,
+ K, SearchOrder, std::move(Symbols), SymbolState::Ready,
[Pairs = std::move(Pairs),
OnRec = std::move(OnRecorded)](Expected<SymbolMap> Result) mutable {
if (!Result)
@@ -47,7 +47,7 @@ Error lookupAndRecordAddrs(
std::promise<MSVCPError> ResultP;
auto ResultF = ResultP.get_future();
lookupAndRecordAddrs([&](Error Err) { ResultP.set_value(std::move(Err)); },
- ES, K, SearchOrder, Pairs, LookupFlags);
+ ES, K, SearchOrder, std::move(Pairs), LookupFlags);
return ResultF.get();
}
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index a364719855b4..d5274b06a76f 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -22,6 +22,39 @@ using namespace llvm;
using namespace llvm::orc;
using namespace llvm::orc::shared;
+namespace llvm {
+namespace orc {
+namespace shared {
+
+using SPSMachOJITDylibDepInfo = SPSTuple<bool, SPSSequence<SPSExecutorAddr>>;
+using SPSMachOJITDylibDepInfoMap =
+ SPSSequence<SPSTuple<SPSExecutorAddr, SPSMachOJITDylibDepInfo>>;
+
+template <>
+class SPSSerializationTraits<SPSMachOJITDylibDepInfo,
+ MachOPlatform::MachOJITDylibDepInfo> {
+public:
+ static size_t size(const MachOPlatform::MachOJITDylibDepInfo &DDI) {
+ return SPSMachOJITDylibDepInfo::AsArgList::size(DDI.Sealed, DDI.DepHeaders);
+ }
+
+ static bool serialize(SPSOutputBuffer &OB,
+ const MachOPlatform::MachOJITDylibDepInfo &DDI) {
+ return SPSMachOJITDylibDepInfo::AsArgList::serialize(OB, DDI.Sealed,
+ DDI.DepHeaders);
+ }
+
+ static bool deserialize(SPSInputBuffer &IB,
+ MachOPlatform::MachOJITDylibDepInfo &DDI) {
+ return SPSMachOJITDylibDepInfo::AsArgList::deserialize(IB, DDI.Sealed,
+ DDI.DepHeaders);
+ }
+};
+
+} // namespace shared
+} // namespace orc
+} // namespace llvm
+
namespace {
class MachOHeaderMaterializationUnit : public MaterializationUnit {
@@ -199,11 +232,25 @@ MachOPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
}
Error MachOPlatform::setupJITDylib(JITDylib &JD) {
- return JD.define(std::make_unique<MachOHeaderMaterializationUnit>(
- *this, MachOHeaderStartSymbol));
+ if (auto Err = JD.define(std::make_unique<MachOHeaderMaterializationUnit>(
+ *this, MachOHeaderStartSymbol)))
+ return Err;
+
+ return ES.lookup({&JD}, MachOHeaderStartSymbol).takeError();
}
-Error MachOPlatform::teardownJITDylib(JITDylib &JD) { return Error::success(); }
+Error MachOPlatform::teardownJITDylib(JITDylib &JD) {
+ std::lock_guard<std::mutex> Lock(PlatformMutex);
+ auto I = JITDylibToHeaderAddr.find(&JD);
+ if (I != JITDylibToHeaderAddr.end()) {
+ assert(HeaderAddrToJITDylib.count(I->second) &&
+ "HeaderAddrToJITDylib missing entry");
+ HeaderAddrToJITDylib.erase(I->second);
+ JITDylibToHeaderAddr.erase(I);
+ }
+ JITDylibToPThreadKey.erase(&JD);
+ return Error::success();
+}
Error MachOPlatform::notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) {
@@ -255,6 +302,10 @@ MachOPlatform::standardRuntimeUtilityAliases() {
static const std::pair<const char *, const char *>
StandardRuntimeUtilityAliases[] = {
{"___orc_rt_run_program", "___orc_rt_macho_run_program"},
+ {"___orc_rt_jit_dlerror", "___orc_rt_macho_jit_dlerror"},
+ {"___orc_rt_jit_dlopen", "___orc_rt_macho_jit_dlopen"},
+ {"___orc_rt_jit_dlclose", "___orc_rt_macho_jit_dlclose"},
+ {"___orc_rt_jit_dlsym", "___orc_rt_macho_jit_dlsym"},
{"___orc_rt_log_error", "___orc_rt_log_error_to_stderr"}};
return ArrayRef<std::pair<const char *, const char *>>(
@@ -305,16 +356,6 @@ MachOPlatform::MachOPlatform(
State = BootstrapPhase2;
- // PlatformJD hasn't been 'set-up' by the platform yet (since we're creating
- // the platform now), so set it up.
- if (auto E2 = setupJITDylib(PlatformJD)) {
- Err = std::move(E2);
- return;
- }
-
- RegisteredInitSymbols[&PlatformJD].add(
- MachOHeaderStartSymbol, SymbolLookupFlags::WeaklyReferencedSymbol);
-
// Associate wrapper function tags with JIT-side function implementations.
if (auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
Err = std::move(E2);
@@ -329,23 +370,24 @@ MachOPlatform::MachOPlatform(
return;
}
+ // PlatformJD hasn't been set up by the platform yet (since we're creating
+ // the platform now), so set it up.
+ if (auto E2 = setupJITDylib(PlatformJD)) {
+ Err = std::move(E2);
+ return;
+ }
+
State = Initialized;
}
Error MachOPlatform::associateRuntimeSupportFunctions(JITDylib &PlatformJD) {
ExecutionSession::JITDispatchHandlerAssociationMap WFs;
- using GetInitializersSPSSig =
- SPSExpected<SPSMachOJITDylibInitializerSequence>(SPSString);
- WFs[ES.intern("___orc_rt_macho_get_initializers_tag")] =
- ES.wrapAsyncWithSPS<GetInitializersSPSSig>(
- this, &MachOPlatform::rt_getInitializers);
-
- using GetDeinitializersSPSSig =
- SPSExpected<SPSMachOJITDylibDeinitializerSequence>(SPSExecutorAddr);
- WFs[ES.intern("___orc_rt_macho_get_deinitializers_tag")] =
- ES.wrapAsyncWithSPS<GetDeinitializersSPSSig>(
- this, &MachOPlatform::rt_getDeinitializers);
+ using PushInitializersSPSSig =
+ SPSExpected<SPSMachOJITDylibDepInfoMap>(SPSExecutorAddr);
+ WFs[ES.intern("___orc_rt_macho_push_initializers_tag")] =
+ ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
+ this, &MachOPlatform::rt_pushInitializers);
using LookupSymbolSPSSig =
SPSExpected<SPSExecutorAddr>(SPSExecutorAddr, SPSString);
@@ -356,53 +398,83 @@ Error MachOPlatform::associateRuntimeSupportFunctions(JITDylib &PlatformJD) {
return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
}
-void MachOPlatform::getInitializersBuildSequencePhase(
- SendInitializerSequenceFn SendResult, JITDylib &JD,
- std::vector<JITDylibSP> DFSLinkOrder) {
- MachOJITDylibInitializerSequence FullInitSeq;
- {
- std::lock_guard<std::mutex> Lock(PlatformMutex);
- for (auto &InitJD : reverse(DFSLinkOrder)) {
- LLVM_DEBUG({
- dbgs() << "MachOPlatform: Appending inits for \"" << InitJD->getName()
- << "\" to sequence\n";
- });
- auto ISItr = InitSeqs.find(InitJD.get());
- if (ISItr != InitSeqs.end()) {
- FullInitSeq.emplace_back(std::move(ISItr->second));
- InitSeqs.erase(ISItr);
- }
- }
- }
-
- SendResult(std::move(FullInitSeq));
-}
-
-void MachOPlatform::getInitializersLookupPhase(
- SendInitializerSequenceFn SendResult, JITDylib &JD) {
-
- auto DFSLinkOrder = JD.getDFSLinkOrder();
- if (!DFSLinkOrder) {
- SendResult(DFSLinkOrder.takeError());
- return;
- }
-
+void MachOPlatform::pushInitializersLoop(
+ PushInitializersSendResultFn SendResult, JITDylibSP JD) {
DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
+ DenseMap<JITDylib *, SmallVector<JITDylib *>> JDDepMap;
+ SmallVector<JITDylib *, 16> Worklist({JD.get()});
+
ES.runSessionLocked([&]() {
- for (auto &InitJD : *DFSLinkOrder) {
- auto RISItr = RegisteredInitSymbols.find(InitJD.get());
+ while (!Worklist.empty()) {
+ // FIXME: Check for defunct dylibs.
+
+ auto DepJD = Worklist.back();
+ Worklist.pop_back();
+
+ // If we've already visited this JITDylib on this iteration then continue.
+ if (JDDepMap.count(DepJD))
+ continue;
+
+ // Add dep info.
+ auto &DM = JDDepMap[DepJD];
+ DepJD->withLinkOrderDo([&](const JITDylibSearchOrder &O) {
+ for (auto &KV : O) {
+ if (KV.first == DepJD)
+ continue;
+ DM.push_back(KV.first);
+ Worklist.push_back(KV.first);
+ }
+ });
+
+ // Add any registered init symbols.
+ auto RISItr = RegisteredInitSymbols.find(DepJD);
if (RISItr != RegisteredInitSymbols.end()) {
- NewInitSymbols[InitJD.get()] = std::move(RISItr->second);
+ NewInitSymbols[DepJD] = std::move(RISItr->second);
RegisteredInitSymbols.erase(RISItr);
}
}
});
- // If there are no further init symbols to look up then move on to the next
- // phase.
+ // If there are no further init symbols to look up then send the link order
+ // (as a list of header addresses) to the caller.
if (NewInitSymbols.empty()) {
- getInitializersBuildSequencePhase(std::move(SendResult), JD,
- std::move(*DFSLinkOrder));
+
+ // To make the list intelligible to the runtime we need to convert all
+ // JITDylib pointers to their header addresses.
+ DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
+ HeaderAddrs.reserve(JDDepMap.size());
+ {
+ std::lock_guard<std::mutex> Lock(PlatformMutex);
+ for (auto &KV : JDDepMap) {
+ auto I = JITDylibToHeaderAddr.find(KV.first);
+ if (I == JITDylibToHeaderAddr.end()) {
+ // The header address should have been materialized by the previous
+ // round, but we need to handle the pathalogical case where someone
+ // removes the symbol on another thread while we're running.
+ SendResult(
+ make_error<StringError>("JITDylib " + KV.first->getName() +
+ " has no registered header address",
+ inconvertibleErrorCode()));
+ return;
+ }
+ HeaderAddrs[KV.first] = I->second;
+ }
+ }
+
+ // Build the dep info map to return.
+ MachOJITDylibDepInfoMap DIM;
+ DIM.reserve(JDDepMap.size());
+ for (auto &KV : JDDepMap) {
+ assert(HeaderAddrs.count(KV.first) && "Missing header addr");
+ auto H = HeaderAddrs[KV.first];
+ MachOJITDylibDepInfo DepInfo;
+ for (auto &Dep : KV.second) {
+ assert(HeaderAddrs.count(Dep) && "Missing header addr");
+ DepInfo.DepHeaders.push_back(HeaderAddrs[Dep]);
+ }
+ DIM.push_back(std::make_pair(H, std::move(DepInfo)));
+ }
+ SendResult(DIM);
return;
}
@@ -412,58 +484,38 @@ void MachOPlatform::getInitializersLookupPhase(
if (Err)
SendResult(std::move(Err));
else
- getInitializersLookupPhase(std::move(SendResult), JD);
+ pushInitializersLoop(std::move(SendResult), JD);
},
ES, std::move(NewInitSymbols));
}
-void MachOPlatform::rt_getInitializers(SendInitializerSequenceFn SendResult,
- StringRef JDName) {
- LLVM_DEBUG({
- dbgs() << "MachOPlatform::rt_getInitializers(\"" << JDName << "\")\n";
- });
-
- JITDylib *JD = ES.getJITDylibByName(JDName);
- if (!JD) {
- LLVM_DEBUG({
- dbgs() << " No such JITDylib \"" << JDName << "\". Sending error.\n";
- });
- SendResult(make_error<StringError>("No JITDylib named " + JDName,
- inconvertibleErrorCode()));
- return;
- }
-
- getInitializersLookupPhase(std::move(SendResult), *JD);
-}
-
-void MachOPlatform::rt_getDeinitializers(SendDeinitializerSequenceFn SendResult,
- ExecutorAddr Handle) {
- LLVM_DEBUG({
- dbgs() << "MachOPlatform::rt_getDeinitializers(\""
- << formatv("{0:x}", Handle.getValue()) << "\")\n";
- });
-
- JITDylib *JD = nullptr;
-
+void MachOPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
+ ExecutorAddr JDHeaderAddr) {
+ JITDylibSP JD;
{
std::lock_guard<std::mutex> Lock(PlatformMutex);
- auto I = HeaderAddrToJITDylib.find(Handle);
+ auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
if (I != HeaderAddrToJITDylib.end())
JD = I->second;
}
+ LLVM_DEBUG({
+ dbgs() << "MachOPlatform::rt_pushInitializers(" << JDHeaderAddr << ") ";
+ if (JD)
+ dbgs() << "pushing initializers for " << JD->getName() << "\n";
+ else
+ dbgs() << "No JITDylib for header address.\n";
+ });
+
if (!JD) {
- LLVM_DEBUG({
- dbgs() << " No JITDylib for handle "
- << formatv("{0:x}", Handle.getValue()) << "\n";
- });
- SendResult(make_error<StringError>("No JITDylib associated with handle " +
- formatv("{0:x}", Handle.getValue()),
- inconvertibleErrorCode()));
+ SendResult(
+ make_error<StringError>("No JITDylib with header addr " +
+ formatv("{0:x}", JDHeaderAddr.getValue()),
+ inconvertibleErrorCode()));
return;
}
- SendResult(MachOJITDylibDeinitializerSequence());
+ pushInitializersLoop(std::move(SendResult), JD);
}
void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
@@ -526,10 +578,14 @@ Error MachOPlatform::bootstrapMachORuntime(JITDylib &PlatformJD) {
&orc_rt_macho_platform_bootstrap},
{ES.intern("___orc_rt_macho_platform_shutdown"),
&orc_rt_macho_platform_shutdown},
- {ES.intern("___orc_rt_macho_register_thread_data_section"),
- &orc_rt_macho_register_thread_data_section},
- {ES.intern("___orc_rt_macho_deregister_thread_data_section"),
- &orc_rt_macho_deregister_thread_data_section},
+ {ES.intern("___orc_rt_macho_register_jitdylib"),
+ &orc_rt_macho_register_jitdylib},
+ {ES.intern("___orc_rt_macho_deregister_jitdylib"),
+ &orc_rt_macho_deregister_jitdylib},
+ {ES.intern("___orc_rt_macho_register_object_platform_sections"),
+ &orc_rt_macho_register_object_platform_sections},
+ {ES.intern("___orc_rt_macho_deregister_object_platform_sections"),
+ &orc_rt_macho_deregister_object_platform_sections},
{ES.intern("___orc_rt_macho_create_pthread_key"),
&orc_rt_macho_create_pthread_key}}))
return Err;
@@ -537,45 +593,6 @@ Error MachOPlatform::bootstrapMachORuntime(JITDylib &PlatformJD) {
return ES.callSPSWrapper<void()>(orc_rt_macho_platform_bootstrap);
}
-Error MachOPlatform::registerInitInfo(
- JITDylib &JD, ExecutorAddr ObjCImageInfoAddr,
- ArrayRef<jitlink::Section *> InitSections) {
-
- std::unique_lock<std::mutex> Lock(PlatformMutex);
-
- MachOJITDylibInitializers *InitSeq = nullptr;
- {
- auto I = InitSeqs.find(&JD);
- if (I == InitSeqs.end()) {
- // If there's no init sequence entry yet then we need to look up the
- // header symbol to force creation of one.
- Lock.unlock();
-
- auto SearchOrder =
- JD.withLinkOrderDo([](const JITDylibSearchOrder &SO) { return SO; });
- if (auto Err = ES.lookup(SearchOrder, MachOHeaderStartSymbol).takeError())
- return Err;
-
- Lock.lock();
- I = InitSeqs.find(&JD);
- assert(I != InitSeqs.end() &&
- "Entry missing after header symbol lookup?");
- }
- InitSeq = &I->second;
- }
-
- InitSeq->ObjCImageInfoAddress = ObjCImageInfoAddr;
-
- for (auto *Sec : InitSections) {
- // FIXME: Avoid copy here.
- jitlink::SectionRange R(*Sec);
- InitSeq->InitSections[Sec->getName()].push_back(
- {ExecutorAddr(R.getStart()), ExecutorAddr(R.getEnd())});
- }
-
- return Error::success();
-}
-
Expected<uint64_t> MachOPlatform::createPThreadKey() {
if (!orc_rt_macho_create_pthread_key)
return make_error<StringError>(
@@ -617,11 +634,6 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
return Err;
return processObjCImageInfo(G, MR);
});
-
- Config.PostFixupPasses.push_back(
- [this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
- return registerInitSections(G, JD);
- });
}
// --- Add passes for eh-frame and TLV support ---
@@ -639,10 +651,12 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
return fixTLVSectionsAndEdges(G, JD);
});
- // Add a pass to register the final addresses of the eh-frame and TLV sections
- // with the runtime.
- Config.PostFixupPasses.push_back(
- [this](jitlink::LinkGraph &G) { return registerEHAndTLVSections(G); });
+ // Add a pass to register the final addresses of any special sections in the
+ // object with the runtime.
+ Config.PostAllocationPasses.push_back(
+ [this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
+ return registerObjectPlatformSections(G, JD);
+ });
}
ObjectLinkingLayer::Plugin::SyntheticSymbolDependenciesMap
@@ -661,7 +675,6 @@ MachOPlatform::MachOPlatformPlugin::getSyntheticSymbolDependencies(
Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol(
jitlink::LinkGraph &G, MaterializationResponsibility &MR) {
-
auto I = llvm::find_if(G.defined_symbols(), [this](jitlink::Symbol *Sym) {
return Sym->getName() == *MP.MachOHeaderStartSymbol;
});
@@ -670,10 +683,14 @@ Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol(
auto &JD = MR.getTargetJITDylib();
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
auto HeaderAddr = (*I)->getAddress();
+ MP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
MP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
- assert(!MP.InitSeqs.count(&JD) && "InitSeq entry for JD already exists");
- MP.InitSeqs.insert(
- std::make_pair(&JD, MachOJITDylibInitializers(JD.getName(), HeaderAddr)));
+ G.allocActions().push_back(
+ {cantFail(
+ WrapperFunctionCall::Create<SPSArgList<SPSString, SPSExecutorAddr>>(
+ MP.orc_rt_macho_register_jitdylib, JD.getName(), HeaderAddr)),
+ cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddr>>(
+ MP.orc_rt_macho_deregister_jitdylib, HeaderAddr))});
return Error::success();
}
@@ -792,37 +809,6 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
return Error::success();
}
-Error MachOPlatform::MachOPlatformPlugin::registerInitSections(
- jitlink::LinkGraph &G, JITDylib &JD) {
-
- ExecutorAddr ObjCImageInfoAddr;
- SmallVector<jitlink::Section *> InitSections;
-
- if (auto *ObjCImageInfoSec = G.findSectionByName(ObjCImageInfoSectionName)) {
- if (auto Addr = jitlink::SectionRange(*ObjCImageInfoSec).getStart())
- ObjCImageInfoAddr = Addr;
- }
-
- for (auto InitSectionName : InitSectionNames)
- if (auto *Sec = G.findSectionByName(InitSectionName))
- InitSections.push_back(Sec);
-
- // Dump the scraped inits.
- LLVM_DEBUG({
- dbgs() << "MachOPlatform: Scraped " << G.getName() << " init sections:\n";
- if (ObjCImageInfoAddr)
- dbgs() << " " << ObjCImageInfoSectionName << ": "
- << formatv("{0:x}", ObjCImageInfoAddr.getValue()) << "\n";
- for (auto *Sec : InitSections) {
- jitlink::SectionRange R(*Sec);
- dbgs() << " " << Sec->getName() << ": "
- << formatv("[ {0:x} -- {1:x} ]", R.getStart(), R.getEnd()) << "\n";
- }
- });
-
- return MP.registerInitInfo(JD, ObjCImageInfoAddr, InitSections);
-}
-
Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
jitlink::LinkGraph &G, JITDylib &JD) {
@@ -879,11 +865,10 @@ Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
return Error::success();
}
-Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections(
- jitlink::LinkGraph &G) {
+Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
+ jitlink::LinkGraph &G, JITDylib &JD) {
- // Add a pass to register the final addresses of the eh-frame and TLV sections
- // with the runtime.
+ // Add an action to register the eh-frame.
if (auto *EHFrameSection = G.findSectionByName(EHFrameSectionName)) {
jitlink::SectionRange R(*EHFrameSection);
if (!R.empty())
@@ -912,6 +897,8 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections(
ThreadDataSection = ThreadBSSSection;
}
+ SmallVector<std::pair<StringRef, ExecutorAddrRange>, 8> MachOPlatformSecs;
+
// Having merged thread BSS (if present) and thread data (if present),
// record the resulting section range.
if (ThreadDataSection) {
@@ -922,16 +909,64 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections(
"MachOPlatform has not finished booting",
inconvertibleErrorCode());
- G.allocActions().push_back(
- {cantFail(
- WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>(
- MP.orc_rt_macho_register_thread_data_section, R.getRange())),
- cantFail(
- WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>(
- MP.orc_rt_macho_deregister_thread_data_section,
- R.getRange()))});
+ MachOPlatformSecs.push_back({ThreadDataSectionName, R.getRange()});
+ }
+ }
+
+ // If any platform sections were found then add an allocation action to call
+ // the registration function.
+ StringRef PlatformSections[] = {
+ ModInitFuncSectionName, ObjCClassListSectionName,
+ ObjCImageInfoSectionName, ObjCSelRefsSectionName,
+ Swift5ProtoSectionName, Swift5ProtosSectionName,
+ Swift5TypesSectionName,
+ };
+
+ for (auto &SecName : PlatformSections) {
+ auto *Sec = G.findSectionByName(SecName);
+ if (!Sec)
+ continue;
+ jitlink::SectionRange R(*Sec);
+ if (R.empty())
+ continue;
+
+ MachOPlatformSecs.push_back({SecName, R.getRange()});
+ }
+
+ if (!MachOPlatformSecs.empty()) {
+ Optional<ExecutorAddr> HeaderAddr;
+ {
+ std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
+ auto I = MP.JITDylibToHeaderAddr.find(&JD);
+ if (I != MP.JITDylibToHeaderAddr.end())
+ HeaderAddr = I->second;
}
+
+ if (!HeaderAddr)
+ return make_error<StringError>("Missing header for " + JD.getName(),
+ inconvertibleErrorCode());
+
+ // Dump the scraped inits.
+ LLVM_DEBUG({
+ dbgs() << "MachOPlatform: Scraped " << G.getName() << " init sections:\n";
+ for (auto &KV : MachOPlatformSecs)
+ dbgs() << " " << KV.first << ": " << KV.second << "\n";
+ });
+
+ using SPSRegisterObjectPlatformSectionsArgs =
+ SPSArgList<SPSExecutorAddr,
+ SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRange>>>;
+ G.allocActions().push_back(
+ {cantFail(
+ WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
+ MP.orc_rt_macho_register_object_platform_sections, *HeaderAddr,
+ MachOPlatformSecs)),
+ cantFail(
+ WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
+ MP.orc_rt_macho_deregister_object_platform_sections,
+ *HeaderAddr, MachOPlatformSecs))});
}
+
return Error::success();
}
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
new file mode 100644
index 000000000000..8b3fbd7117e2
--- /dev/null
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
@@ -0,0 +1,152 @@
+//===- MemoryMapper.cpp - Cross-process memory mapper ------------*- C++ -*-==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ExecutionEngine/Orc/MemoryMapper.h"
+
+namespace llvm {
+namespace orc {
+
+MemoryMapper::~MemoryMapper() {}
+
+void InProcessMemoryMapper::reserve(size_t NumBytes,
+ OnReservedFunction OnReserved) {
+ std::error_code EC;
+ auto MB = sys::Memory::allocateMappedMemory(
+ NumBytes, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
+
+ if (EC)
+ return OnReserved(errorCodeToError(EC));
+
+ {
+ std::lock_guard<std::mutex> Lock(Mutex);
+ Reservations[MB.base()].Size = MB.allocatedSize();
+ }
+
+ OnReserved(
+ ExecutorAddrRange(ExecutorAddr::fromPtr(MB.base()), MB.allocatedSize()));
+}
+
+char *InProcessMemoryMapper::prepare(ExecutorAddr Addr, size_t ContentSize) {
+ return Addr.toPtr<char *>();
+}
+
+void InProcessMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
+ OnInitializedFunction OnInitialized) {
+ ExecutorAddr MinAddr(~0ULL);
+
+ for (auto &Segment : AI.Segments) {
+ auto Base = AI.MappingBase + Segment.Offset;
+ auto Size = Segment.ContentSize + Segment.ZeroFillSize;
+
+ if (Base < MinAddr)
+ MinAddr = Base;
+
+ std::memset((Base + Segment.ContentSize).toPtr<void *>(), 0,
+ Segment.ZeroFillSize);
+
+ if (auto EC = sys::Memory::protectMappedMemory({Base.toPtr<void *>(), Size},
+ Segment.Prot)) {
+ return OnInitialized(errorCodeToError(EC));
+ }
+ if (Segment.Prot & sys::Memory::MF_EXEC)
+ sys::Memory::InvalidateInstructionCache(Base.toPtr<void *>(), Size);
+ }
+
+ auto DeinitializeActions = shared::runFinalizeActions(AI.Actions);
+ if (!DeinitializeActions)
+ return OnInitialized(DeinitializeActions.takeError());
+
+ {
+ std::lock_guard<std::mutex> Lock(Mutex);
+ Allocations[MinAddr].DeinitializationActions =
+ std::move(*DeinitializeActions);
+ Reservations[AI.MappingBase.toPtr<void *>()].Allocations.push_back(MinAddr);
+ }
+
+ OnInitialized(MinAddr);
+}
+
+void InProcessMemoryMapper::deinitialize(
+ ArrayRef<ExecutorAddr> Bases,
+ MemoryMapper::OnDeinitializedFunction OnDeinitialized) {
+ Error AllErr = Error::success();
+
+ {
+ std::lock_guard<std::mutex> Lock(Mutex);
+
+ for (auto Base : Bases) {
+
+ if (Error Err = shared::runDeallocActions(
+ Allocations[Base].DeinitializationActions)) {
+ AllErr = joinErrors(std::move(AllErr), std::move(Err));
+ }
+
+ Allocations.erase(Base);
+ }
+ }
+
+ OnDeinitialized(std::move(AllErr));
+}
+
+void InProcessMemoryMapper::release(ArrayRef<ExecutorAddr> Bases,
+ OnReleasedFunction OnReleased) {
+ Error Err = Error::success();
+
+ for (auto Base : Bases) {
+ std::vector<ExecutorAddr> AllocAddrs;
+ size_t Size;
+ {
+ std::lock_guard<std::mutex> Lock(Mutex);
+ auto &R = Reservations[Base.toPtr<void *>()];
+ Size = R.Size;
+ AllocAddrs.swap(R.Allocations);
+ }
+
+ // deinitialize sub allocations
+ std::promise<MSVCPError> P;
+ auto F = P.get_future();
+ deinitialize(AllocAddrs, [&](Error Err) { P.set_value(std::move(Err)); });
+ if (Error E = F.get()) {
+ Err = joinErrors(std::move(Err), std::move(E));
+ }
+
+ // free the memory
+ auto MB = sys::MemoryBlock(Base.toPtr<void *>(), Size);
+
+ auto EC = sys::Memory::releaseMappedMemory(MB);
+ if (EC) {
+ Err = joinErrors(std::move(Err), errorCodeToError(EC));
+ }
+
+ std::lock_guard<std::mutex> Lock(Mutex);
+ Reservations.erase(Base.toPtr<void *>());
+ }
+
+ OnReleased(std::move(Err));
+}
+
+InProcessMemoryMapper::~InProcessMemoryMapper() {
+ std::vector<ExecutorAddr> ReservationAddrs;
+ {
+ std::lock_guard<std::mutex> Lock(Mutex);
+
+ ReservationAddrs.reserve(Reservations.size());
+ for (const auto &R : Reservations) {
+ ReservationAddrs.push_back(ExecutorAddr::fromPtr(R.getFirst()));
+ }
+ }
+
+ std::promise<MSVCPError> P;
+ auto F = P.get_future();
+ release(ReservationAddrs, [&](Error Err) { P.set_value(std::move(Err)); });
+ cantFail(F.get());
+}
+
+} // namespace orc
+
+} // namespace llvm
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
index c1ad569dd65d..394a555e453b 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp
@@ -63,7 +63,6 @@ getMachOObjectFileSymbolInfo(ExecutionSession &ES,
auto Name = Sym.getName();
if (!Name)
return Name.takeError();
- auto InternedName = ES.intern(*Name);
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
if (!SymFlags)
return SymFlags.takeError();
@@ -72,7 +71,7 @@ getMachOObjectFileSymbolInfo(ExecutionSession &ES,
if (Name->startswith("l"))
*SymFlags &= ~JITSymbolFlags::Exported;
- I.SymbolFlags[InternedName] = std::move(*SymFlags);
+ I.SymbolFlags[ES.intern(*Name)] = std::move(*SymFlags);
}
for (auto &Sec : Obj.sections()) {
@@ -121,7 +120,7 @@ getELFObjectFileSymbolInfo(ExecutionSession &ES,
auto Name = Sym.getName();
if (!Name)
return Name.takeError();
- auto InternedName = ES.intern(*Name);
+
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
if (!SymFlags)
return SymFlags.takeError();
@@ -130,7 +129,7 @@ getELFObjectFileSymbolInfo(ExecutionSession &ES,
if (Sym.getBinding() == ELF::STB_GNU_UNIQUE)
*SymFlags |= JITSymbolFlags::Weak;
- I.SymbolFlags[InternedName] = std::move(*SymFlags);
+ I.SymbolFlags[ES.intern(*Name)] = std::move(*SymFlags);
}
SymbolStringPtr InitSymbol;
@@ -175,12 +174,12 @@ getGenericObjectFileSymbolInfo(ExecutionSession &ES,
auto Name = Sym.getName();
if (!Name)
return Name.takeError();
- auto InternedName = ES.intern(*Name);
+
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
if (!SymFlags)
return SymFlags.takeError();
- I.SymbolFlags[InternedName] = std::move(*SymFlags);
+ I.SymbolFlags[ES.intern(*Name)] = std::move(*SymFlags);
}
return I;
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index 32c5998a789b..5ddb35cbafd5 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -78,9 +78,12 @@ private:
}
static bool hasELFInitSection(LinkGraph &G) {
- for (auto &Sec : G.sections())
- if (Sec.getName() == ".init_array")
+ for (auto &Sec : G.sections()) {
+ auto SecName = Sec.getName();
+ if (SecName.consume_front(".init_array") &&
+ (SecName.empty() || SecName[0] == '.'))
return true;
+ }
return false;
}
@@ -226,12 +229,13 @@ public:
}
for (auto *Sym : G.absolute_symbols())
- if (Sym->hasName()) {
+ if (Sym->hasName() && Sym->getScope() != Scope::Local) {
auto InternedName = ES.intern(Sym->getName());
JITSymbolFlags Flags;
- Flags |= JITSymbolFlags::Absolute;
if (Sym->isCallable())
Flags |= JITSymbolFlags::Callable;
+ if (Sym->getScope() == Scope::Default)
+ Flags |= JITSymbolFlags::Exported;
if (Sym->getLinkage() == Linkage::Weak)
Flags |= JITSymbolFlags::Weak;
InternedResult[InternedName] =
@@ -607,7 +611,7 @@ private:
DenseMap<SymbolStringPtr, SymbolNameSet> InternalNamedSymbolDeps;
};
-ObjectLinkingLayer::Plugin::~Plugin() {}
+ObjectLinkingLayer::Plugin::~Plugin() = default;
char ObjectLinkingLayer::ID;
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp
index 18b3c5e12b1c..ef764a3f0d7f 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp
@@ -906,5 +906,176 @@ void OrcMips64::writeIndirectStubsBlock(
Stub[8 * I + 7] = 0x00000000; // nop
}
}
+
+void OrcRiscv64::writeResolverCode(char *ResolverWorkingMem,
+ JITTargetAddress ResolverTargetAddress,
+ JITTargetAddress ReentryFnAddr,
+ JITTargetAddress ReentryCtxAddr) {
+
+ const uint32_t ResolverCode[] = {
+ 0xef810113, // 0x00: addi sp,sp,-264
+ 0x00813023, // 0x04: sd s0,0(sp)
+ 0x00913423, // 0x08: sd s1,8(sp)
+ 0x01213823, // 0x0c: sd s2,16(sp)
+ 0x01313c23, // 0x10: sd s3,24(sp)
+ 0x03413023, // 0x14: sd s4,32(sp)
+ 0x03513423, // 0x18: sd s5,40(sp)
+ 0x03613823, // 0x1c: sd s6,48(sp)
+ 0x03713c23, // 0x20: sd s7,56(sp)
+ 0x05813023, // 0x24: sd s8,64(sp)
+ 0x05913423, // 0x28: sd s9,72(sp)
+ 0x05a13823, // 0x2c: sd s10,80(sp)
+ 0x05b13c23, // 0x30: sd s11,88(sp)
+ 0x06113023, // 0x34: sd ra,96(sp)
+ 0x06a13423, // 0x38: sd a0,104(sp)
+ 0x06b13823, // 0x3c: sd a1,112(sp)
+ 0x06c13c23, // 0x40: sd a2,120(sp)
+ 0x08d13023, // 0x44: sd a3,128(sp)
+ 0x08e13423, // 0x48: sd a4,136(sp)
+ 0x08f13823, // 0x4c: sd a5,144(sp)
+ 0x09013c23, // 0x50: sd a6,152(sp)
+ 0x0b113023, // 0x54: sd a7,160(sp)
+ 0x0a813427, // 0x58: fsd fs0,168(sp)
+ 0x0a913827, // 0x5c: fsd fs1,176(sp)
+ 0x0b213c27, // 0x60: fsd fs2,184(sp)
+ 0x0d313027, // 0x64: fsd fs3,192(sp)
+ 0x0d413427, // 0x68: fsd fs4,200(sp)
+ 0x0d513827, // 0x6c: fsd fs5,208(sp)
+ 0x0d613c27, // 0x70: fsd fs6,216(sp)
+ 0x0f713027, // 0x74: fsd fs7,224(sp)
+ 0x0f813427, // 0x78: fsd fs8,232(sp)
+ 0x0f913827, // 0x7c: fsd fs9,240(sp)
+ 0x0fa13c27, // 0x80: fsd fs10,248(sp)
+ 0x11b13027, // 0x84: fsd fs11,256(sp)
+ 0x00000517, // 0x88: auipc a0,0x0
+ 0x0b053503, // 0x8c: ld a0,176(a0) # 0x138
+ 0x00030593, // 0x90: mv a1,t1
+ 0xff458593, // 0x94: addi a1,a1,-12
+ 0x00000617, // 0x98: auipc a2,0x0
+ 0x0a863603, // 0x9c: ld a2,168(a2) # 0x140
+ 0x000600e7, // 0xa0: jalr a2
+ 0x00050293, // 0xa4: mv t0,a0
+ 0x00013403, // 0xa8: ld s0,0(sp)
+ 0x00813483, // 0xac: ld s1,8(sp)
+ 0x01013903, // 0xb0: ld s2,16(sp)
+ 0x01813983, // 0xb4: ld s3,24(sp)
+ 0x02013a03, // 0xb8: ld s4,32(sp)
+ 0x02813a83, // 0xbc: ld s5,40(sp)
+ 0x03013b03, // 0xc0: ld s6,48(sp)
+ 0x03813b83, // 0xc4: ld s7,56(sp)
+ 0x04013c03, // 0xc8: ld s8,64(sp)
+ 0x04813c83, // 0xcc: ld s9,72(sp)
+ 0x05013d03, // 0xd0: ld s10,80(sp)
+ 0x05813d83, // 0xd4: ld s11,88(sp)
+ 0x06013083, // 0xd8: ld ra,96(sp)
+ 0x06813503, // 0xdc: ld a0,104(sp)
+ 0x07013583, // 0xe0: ld a1,112(sp)
+ 0x07813603, // 0xe4: ld a2,120(sp)
+ 0x08013683, // 0xe8: ld a3,128(sp)
+ 0x08813703, // 0xec: ld a4,136(sp)
+ 0x09013783, // 0xf0: ld a5,144(sp)
+ 0x09813803, // 0xf4: ld a6,152(sp)
+ 0x0a013883, // 0xf8: ld a7,160(sp)
+ 0x0a813407, // 0xfc: fld fs0,168(sp)
+ 0x0b013487, // 0x100: fld fs1,176(sp)
+ 0x0b813907, // 0x104: fld fs2,184(sp)
+ 0x0c013987, // 0x108: fld fs3,192(sp)
+ 0x0c813a07, // 0x10c: fld fs4,200(sp)
+ 0x0d013a87, // 0x110: fld fs5,208(sp)
+ 0x0d813b07, // 0x114: fld fs6,216(sp)
+ 0x0e013b87, // 0x118: fld fs7,224(sp)
+ 0x0e813c07, // 0x11c: fld fs8,232(sp)
+ 0x0f013c87, // 0x120: fld fs9,240(sp)
+ 0x0f813d07, // 0x124: fld fs10,248(sp)
+ 0x10013d87, // 0x128: fld fs11,256(sp)
+ 0x10810113, // 0x12c: addi sp,sp,264
+ 0x00028067, // 0x130: jr t0
+ 0x12345678, // 0x134: padding to align at 8 byte
+ 0x12345678, // 0x138: Lreentry_ctx_ptr:
+ 0xdeadbeef, // 0x13c: .quad 0
+ 0x98765432, // 0x140: Lreentry_fn_ptr:
+ 0xcafef00d // 0x144: .quad 0
+ };
+
+ const unsigned ReentryCtxAddrOffset = 0x138;
+ const unsigned ReentryFnAddrOffset = 0x140;
+
+ memcpy(ResolverWorkingMem, ResolverCode, sizeof(ResolverCode));
+ memcpy(ResolverWorkingMem + ReentryFnAddrOffset, &ReentryFnAddr,
+ sizeof(uint64_t));
+ memcpy(ResolverWorkingMem + ReentryCtxAddrOffset, &ReentryCtxAddr,
+ sizeof(uint64_t));
+}
+
+void OrcRiscv64::writeTrampolines(char *TrampolineBlockWorkingMem,
+ JITTargetAddress TrampolineBlockTargetAddress,
+ JITTargetAddress ResolverAddr,
+ unsigned NumTrampolines) {
+
+ unsigned OffsetToPtr = alignTo(NumTrampolines * TrampolineSize, 8);
+
+ memcpy(TrampolineBlockWorkingMem + OffsetToPtr, &ResolverAddr,
+ sizeof(uint64_t));
+
+ uint32_t *Trampolines =
+ reinterpret_cast<uint32_t *>(TrampolineBlockWorkingMem);
+ for (unsigned I = 0; I < NumTrampolines; ++I, OffsetToPtr -= TrampolineSize) {
+ uint32_t Hi20 = (OffsetToPtr + 0x800) & 0xFFFFF000;
+ uint32_t Lo12 = OffsetToPtr - Hi20;
+ Trampolines[4 * I + 0] = 0x00000297 | Hi20; // auipc t0, %hi(Lptr)
+ Trampolines[4 * I + 1] =
+ 0x0002b283 | ((Lo12 & 0xFFF) << 20); // ld t0, %lo(Lptr)
+ Trampolines[4 * I + 2] = 0x00028367; // jalr t1, t0
+ Trampolines[4 * I + 3] = 0xdeadface; // padding
+ }
+}
+
+void OrcRiscv64::writeIndirectStubsBlock(
+ char *StubsBlockWorkingMem, JITTargetAddress StubsBlockTargetAddress,
+ JITTargetAddress PointersBlockTargetAddress, unsigned NumStubs) {
+ // Stub format is:
+ //
+ // .section __orc_stubs
+ // stub1:
+ // auipc t0, %hi(ptr1) ; PC-rel load of ptr1
+ // ld t0, %lo(t0)
+ // jr t0 ; Jump to resolver
+ // .quad 0 ; Pad to 16 bytes
+ // stub2:
+ // auipc t0, %hi(ptr1) ; PC-rel load of ptr1
+ // ld t0, %lo(t0)
+ // jr t0 ; Jump to resolver
+ // .quad 0
+ //
+ // ...
+ //
+ // .section __orc_ptrs
+ // ptr1:
+ // .quad 0x0
+ // ptr2:
+ // .quad 0x0
+ //
+ // ...
+
+ assert(stubAndPointerRangesOk<OrcRiscv64>(
+ StubsBlockTargetAddress, PointersBlockTargetAddress, NumStubs) &&
+ "PointersBlock is out of range");
+
+ uint32_t *Stub = reinterpret_cast<uint32_t *>(StubsBlockWorkingMem);
+
+ for (unsigned I = 0; I < NumStubs; ++I) {
+ uint64_t PtrDisplacement =
+ PointersBlockTargetAddress - StubsBlockTargetAddress;
+ uint32_t Hi20 = (PtrDisplacement + 0x800) & 0xFFFFF000;
+ uint32_t Lo12 = PtrDisplacement - Hi20;
+ Stub[4 * I + 0] = 0x00000297 | Hi20; // auipc t0, %hi(Lptr)
+ Stub[4 * I + 1] = 0x0002b283 | ((Lo12 & 0xFFF) << 20); // ld t0, %lo(Lptr)
+ Stub[4 * I + 2] = 0x00028067; // jr t0
+ Stub[4 * I + 3] = 0xfeedbeef; // padding
+ PointersBlockTargetAddress += PointerSize;
+ StubsBlockTargetAddress += StubSize;
+ }
+}
+
} // End namespace orc.
} // End namespace llvm.
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
index 71be8dfdc004..b7eab6b85ecf 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
@@ -106,82 +106,6 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLJITBuilder, LLVMOrcLLJITBuilderRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLJIT, LLVMOrcLLJITRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
-namespace llvm {
-namespace orc {
-
-class CAPIDefinitionGenerator final : public DefinitionGenerator {
-public:
- CAPIDefinitionGenerator(
- void *Ctx,
- LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction TryToGenerate)
- : Ctx(Ctx), TryToGenerate(TryToGenerate) {}
-
- Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
- JITDylibLookupFlags JDLookupFlags,
- const SymbolLookupSet &LookupSet) override {
-
- // Take the lookup state.
- LLVMOrcLookupStateRef LSR = ::wrap(OrcV2CAPIHelper::extractLookupState(LS));
-
- // Translate the lookup kind.
- LLVMOrcLookupKind CLookupKind;
- switch (K) {
- case LookupKind::Static:
- CLookupKind = LLVMOrcLookupKindStatic;
- break;
- case LookupKind::DLSym:
- CLookupKind = LLVMOrcLookupKindDLSym;
- break;
- }
-
- // Translate the JITDylibSearchFlags.
- LLVMOrcJITDylibLookupFlags CJDLookupFlags;
- switch (JDLookupFlags) {
- case JITDylibLookupFlags::MatchExportedSymbolsOnly:
- CJDLookupFlags = LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly;
- break;
- case JITDylibLookupFlags::MatchAllSymbols:
- CJDLookupFlags = LLVMOrcJITDylibLookupFlagsMatchAllSymbols;
- break;
- }
-
- // Translate the lookup set.
- std::vector<LLVMOrcCLookupSetElement> CLookupSet;
- CLookupSet.reserve(LookupSet.size());
- for (auto &KV : LookupSet) {
- LLVMOrcSymbolLookupFlags SLF;
- LLVMOrcSymbolStringPoolEntryRef Name =
- ::wrap(OrcV2CAPIHelper::getRawPoolEntryPtr(KV.first));
- switch (KV.second) {
- case SymbolLookupFlags::RequiredSymbol:
- SLF = LLVMOrcSymbolLookupFlagsRequiredSymbol;
- break;
- case SymbolLookupFlags::WeaklyReferencedSymbol:
- SLF = LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol;
- break;
- }
- CLookupSet.push_back({Name, SLF});
- }
-
- // Run the C TryToGenerate function.
- auto Err = unwrap(TryToGenerate(::wrap(this), Ctx, &LSR, CLookupKind,
- ::wrap(&JD), CJDLookupFlags,
- CLookupSet.data(), CLookupSet.size()));
-
- // Restore the lookup state.
- OrcV2CAPIHelper::resetLookupState(LS, ::unwrap(LSR));
-
- return Err;
- }
-
-private:
- void *Ctx;
- LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction TryToGenerate;
-};
-
-} // end namespace orc
-} // end namespace llvm
-
namespace {
class OrcCAPIMaterializationUnit : public llvm::orc::MaterializationUnit {
@@ -282,8 +206,134 @@ toSymbolDependenceMap(LLVMOrcCDependenceMapPairs Pairs, size_t NumPairs) {
return SDM;
}
+static LookupKind toLookupKind(LLVMOrcLookupKind K) {
+ switch (K) {
+ case LLVMOrcLookupKindStatic:
+ return LookupKind::Static;
+ case LLVMOrcLookupKindDLSym:
+ return LookupKind::DLSym;
+ }
+ llvm_unreachable("unrecognized LLVMOrcLookupKind value");
+}
+
+static LLVMOrcLookupKind fromLookupKind(LookupKind K) {
+ switch (K) {
+ case LookupKind::Static:
+ return LLVMOrcLookupKindStatic;
+ case LookupKind::DLSym:
+ return LLVMOrcLookupKindDLSym;
+ }
+ llvm_unreachable("unrecognized LookupKind value");
+}
+
+static JITDylibLookupFlags
+toJITDylibLookupFlags(LLVMOrcJITDylibLookupFlags LF) {
+ switch (LF) {
+ case LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly:
+ return JITDylibLookupFlags::MatchExportedSymbolsOnly;
+ case LLVMOrcJITDylibLookupFlagsMatchAllSymbols:
+ return JITDylibLookupFlags::MatchAllSymbols;
+ }
+ llvm_unreachable("unrecognized LLVMOrcJITDylibLookupFlags value");
+}
+
+static LLVMOrcJITDylibLookupFlags
+fromJITDylibLookupFlags(JITDylibLookupFlags LF) {
+ switch (LF) {
+ case JITDylibLookupFlags::MatchExportedSymbolsOnly:
+ return LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly;
+ case JITDylibLookupFlags::MatchAllSymbols:
+ return LLVMOrcJITDylibLookupFlagsMatchAllSymbols;
+ }
+ llvm_unreachable("unrecognized JITDylibLookupFlags value");
+}
+
+static SymbolLookupFlags toSymbolLookupFlags(LLVMOrcSymbolLookupFlags SLF) {
+ switch (SLF) {
+ case LLVMOrcSymbolLookupFlagsRequiredSymbol:
+ return SymbolLookupFlags::RequiredSymbol;
+ case LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol:
+ return SymbolLookupFlags::WeaklyReferencedSymbol;
+ }
+ llvm_unreachable("unrecognized LLVMOrcSymbolLookupFlags value");
+}
+
+static LLVMOrcSymbolLookupFlags fromSymbolLookupFlags(SymbolLookupFlags SLF) {
+ switch (SLF) {
+ case SymbolLookupFlags::RequiredSymbol:
+ return LLVMOrcSymbolLookupFlagsRequiredSymbol;
+ case SymbolLookupFlags::WeaklyReferencedSymbol:
+ return LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol;
+ }
+ llvm_unreachable("unrecognized SymbolLookupFlags value");
+}
+
+static LLVMJITEvaluatedSymbol
+fromJITEvaluatedSymbol(const JITEvaluatedSymbol &S) {
+ return {S.getAddress(), fromJITSymbolFlags(S.getFlags())};
+}
+
} // end anonymous namespace
+namespace llvm {
+namespace orc {
+
+class CAPIDefinitionGenerator final : public DefinitionGenerator {
+public:
+ CAPIDefinitionGenerator(
+ LLVMOrcDisposeCAPIDefinitionGeneratorFunction Dispose, void *Ctx,
+ LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction TryToGenerate)
+ : Dispose(Dispose), Ctx(Ctx), TryToGenerate(TryToGenerate) {}
+
+ ~CAPIDefinitionGenerator() {
+ if (Dispose)
+ Dispose(Ctx);
+ }
+
+ Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
+ JITDylibLookupFlags JDLookupFlags,
+ const SymbolLookupSet &LookupSet) override {
+
+ // Take the lookup state.
+ LLVMOrcLookupStateRef LSR = ::wrap(OrcV2CAPIHelper::extractLookupState(LS));
+
+ // Translate the lookup kind.
+ LLVMOrcLookupKind CLookupKind = fromLookupKind(K);
+
+ // Translate the JITDylibLookupFlags.
+ LLVMOrcJITDylibLookupFlags CJDLookupFlags =
+ fromJITDylibLookupFlags(JDLookupFlags);
+
+ // Translate the lookup set.
+ std::vector<LLVMOrcCLookupSetElement> CLookupSet;
+ CLookupSet.reserve(LookupSet.size());
+ for (auto &KV : LookupSet) {
+ LLVMOrcSymbolStringPoolEntryRef Name =
+ ::wrap(OrcV2CAPIHelper::getRawPoolEntryPtr(KV.first));
+ LLVMOrcSymbolLookupFlags SLF = fromSymbolLookupFlags(KV.second);
+ CLookupSet.push_back({Name, SLF});
+ }
+
+ // Run the C TryToGenerate function.
+ auto Err = unwrap(TryToGenerate(::wrap(this), Ctx, &LSR, CLookupKind,
+ ::wrap(&JD), CJDLookupFlags,
+ CLookupSet.data(), CLookupSet.size()));
+
+ // Restore the lookup state.
+ OrcV2CAPIHelper::resetLookupState(LS, ::unwrap(LSR));
+
+ return Err;
+ }
+
+private:
+ LLVMOrcDisposeCAPIDefinitionGeneratorFunction Dispose;
+ void *Ctx;
+ LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction TryToGenerate;
+};
+
+} // end namespace orc
+} // end namespace llvm
+
void LLVMOrcExecutionSessionSetErrorReporter(
LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError,
void *Ctx) {
@@ -307,6 +357,42 @@ LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name) {
OrcV2CAPIHelper::moveFromSymbolStringPtr(unwrap(ES)->intern(Name)));
}
+void LLVMOrcExecutionSessionLookup(
+ LLVMOrcExecutionSessionRef ES, LLVMOrcLookupKind K,
+ LLVMOrcCJITDylibSearchOrder SearchOrder, size_t SearchOrderSize,
+ LLVMOrcCLookupSet Symbols, size_t SymbolsSize,
+ LLVMOrcExecutionSessionLookupHandleResultFunction HandleResult, void *Ctx) {
+ assert(ES && "ES cannot be null");
+ assert(SearchOrder && "SearchOrder cannot be null");
+ assert(Symbols && "Symbols cannot be null");
+ assert(HandleResult && "HandleResult cannot be null");
+
+ JITDylibSearchOrder SO;
+ for (size_t I = 0; I != SearchOrderSize; ++I)
+ SO.push_back({unwrap(SearchOrder[I].JD),
+ toJITDylibLookupFlags(SearchOrder[I].JDLookupFlags)});
+
+ SymbolLookupSet SLS;
+ for (size_t I = 0; I != SymbolsSize; ++I)
+ SLS.add(OrcV2CAPIHelper::moveToSymbolStringPtr(unwrap(Symbols[I].Name)),
+ toSymbolLookupFlags(Symbols[I].LookupFlags));
+
+ unwrap(ES)->lookup(
+ toLookupKind(K), SO, std::move(SLS), SymbolState::Ready,
+ [HandleResult, Ctx](Expected<SymbolMap> Result) {
+ if (Result) {
+ SmallVector<LLVMOrcCSymbolMapPair> CResult;
+ for (auto &KV : *Result)
+ CResult.push_back(LLVMOrcCSymbolMapPair{
+ wrap(OrcV2CAPIHelper::getRawPoolEntryPtr(KV.first)),
+ fromJITEvaluatedSymbol(KV.second)});
+ HandleResult(LLVMErrorSuccess, CResult.data(), CResult.size(), Ctx);
+ } else
+ HandleResult(wrap(Result.takeError()), nullptr, 0, Ctx);
+ },
+ NoDependenciesToRegister);
+}
+
void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S) {
OrcV2CAPIHelper::retainPoolEntry(unwrap(S));
}
@@ -589,11 +675,19 @@ void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD,
}
LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator(
- LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx) {
- auto DG = std::make_unique<CAPIDefinitionGenerator>(Ctx, F);
+ LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx,
+ LLVMOrcDisposeCAPIDefinitionGeneratorFunction Dispose) {
+ auto DG = std::make_unique<CAPIDefinitionGenerator>(Dispose, Ctx, F);
return wrap(DG.release());
}
+void LLVMOrcLookupStateContinueLookup(LLVMOrcLookupStateRef S,
+ LLVMErrorRef Err) {
+ LookupState LS;
+ OrcV2CAPIHelper::resetLookupState(LS, ::unwrap(S));
+ LS.continueLookup(unwrap(Err));
+}
+
LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefix,
LLVMOrcSymbolPredicate Filter, void *FilterCtx) {
@@ -951,7 +1045,7 @@ LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J,
return wrap(Sym.takeError());
}
- *Result = Sym->getAddress();
+ *Result = Sym->getValue();
return LLVMErrorSuccess;
}
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
index 64fc717b7b56..2bb204e688fc 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
@@ -43,8 +43,8 @@ const char *DispatchFnName = "__llvm_orc_SimpleRemoteEPC_dispatch_fn";
} // end namespace SimpleRemoteEPCDefaultBootstrapSymbolNames
-SimpleRemoteEPCTransportClient::~SimpleRemoteEPCTransportClient() {}
-SimpleRemoteEPCTransport::~SimpleRemoteEPCTransport() {}
+SimpleRemoteEPCTransportClient::~SimpleRemoteEPCTransportClient() = default;
+SimpleRemoteEPCTransport::~SimpleRemoteEPCTransport() = default;
Expected<std::unique_ptr<FDSimpleRemoteEPCTransport>>
FDSimpleRemoteEPCTransport::Create(SimpleRemoteEPCTransportClient &C, int InFD,
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Speculation.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Speculation.cpp
index 0b4755fe23cf..b52d01318c0d 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Speculation.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Speculation.cpp
@@ -85,7 +85,7 @@ void IRSpeculationLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
auto IRNames = QueryAnalysis(Fn);
// Instrument and register if Query has result
- if (IRNames.hasValue()) {
+ if (IRNames) {
// Emit globals for each function.
auto LoadValueTy = Type::getInt8Ty(MContext);
@@ -126,7 +126,7 @@ void IRSpeculationLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
assert(Mutator.GetInsertBlock()->getParent() == &Fn &&
"IR builder association mismatch?");
- S.registerSymbols(internToJITSymbols(IRNames.getValue()),
+ S.registerSymbols(internToJITSymbols(*IRNames),
&R->getTargetJITDylib());
}
}
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.cpp
index b6b21bde1182..8ab0af3eab6e 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.cpp
@@ -22,9 +22,9 @@ using namespace llvm::orc::shared;
namespace llvm {
namespace orc {
-ExecutorBootstrapService::~ExecutorBootstrapService() {}
+ExecutorBootstrapService::~ExecutorBootstrapService() = default;
-SimpleRemoteEPCServer::Dispatcher::~Dispatcher() {}
+SimpleRemoteEPCServer::Dispatcher::~Dispatcher() = default;
#if LLVM_ENABLE_THREADS
void SimpleRemoteEPCServer::ThreadDispatcher::dispatch(
diff --git a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp
index 111c84ec87ed..11a99986f2ee 100644
--- a/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp
+++ b/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp
@@ -16,7 +16,7 @@ char GenericNamedTask::ID = 0;
const char *GenericNamedTask::DefaultDescription = "Generic Task";
void Task::anchor() {}
-TaskDispatcher::~TaskDispatcher() {}
+TaskDispatcher::~TaskDispatcher() = default;
void InPlaceTaskDispatcher::dispatch(std::unique_ptr<Task> T) { T->run(); }