[ORC] Move EHFrameRegistrationPlugin into its own header + source file. NFC.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
//===----- EHFrameRegistrationPlugin.h - Register eh-frames -----*- 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Register eh-frame sections with a registrar.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_EHFRAMEREGISTRATIONPLUGIN_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_EHFRAMEREGISTRATIONPLUGIN_H
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/LinkGraphLinkingLayer.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace jitlink {
|
||||
class EHFrameRegistrar;
|
||||
} // namespace jitlink
|
||||
|
||||
namespace orc {
|
||||
|
||||
class EHFrameRegistrationPlugin : public LinkGraphLinkingLayer::Plugin {
|
||||
public:
|
||||
EHFrameRegistrationPlugin(
|
||||
ExecutionSession &ES,
|
||||
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar);
|
||||
void modifyPassConfig(MaterializationResponsibility &MR,
|
||||
jitlink::LinkGraph &G,
|
||||
jitlink::PassConfiguration &PassConfig) override;
|
||||
Error notifyEmitted(MaterializationResponsibility &MR) override;
|
||||
Error notifyFailed(MaterializationResponsibility &MR) override;
|
||||
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override;
|
||||
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
|
||||
ResourceKey SrcKey) override;
|
||||
|
||||
private:
|
||||
std::mutex EHFramePluginMutex;
|
||||
ExecutionSession &ES;
|
||||
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar;
|
||||
DenseMap<MaterializationResponsibility *, ExecutorAddrRange> InProcessLinks;
|
||||
DenseMap<ResourceKey, std::vector<ExecutorAddrRange>> EHFrameRanges;
|
||||
};
|
||||
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_EHFRAMEREGISTRATIONPLUGIN_H
|
||||
@@ -173,28 +173,6 @@ private:
|
||||
std::vector<std::shared_ptr<Plugin>> Plugins;
|
||||
};
|
||||
|
||||
class EHFrameRegistrationPlugin : public LinkGraphLinkingLayer::Plugin {
|
||||
public:
|
||||
EHFrameRegistrationPlugin(
|
||||
ExecutionSession &ES,
|
||||
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar);
|
||||
void modifyPassConfig(MaterializationResponsibility &MR,
|
||||
jitlink::LinkGraph &G,
|
||||
jitlink::PassConfiguration &PassConfig) override;
|
||||
Error notifyEmitted(MaterializationResponsibility &MR) override;
|
||||
Error notifyFailed(MaterializationResponsibility &MR) override;
|
||||
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override;
|
||||
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
|
||||
ResourceKey SrcKey) override;
|
||||
|
||||
private:
|
||||
std::mutex EHFramePluginMutex;
|
||||
ExecutionSession &ES;
|
||||
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar;
|
||||
DenseMap<MaterializationResponsibility *, ExecutorAddrRange> InProcessLinks;
|
||||
DenseMap<ResourceKey, std::vector<ExecutorAddrRange>> EHFrameRanges;
|
||||
};
|
||||
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ add_llvm_component_library(LLVMOrcJIT
|
||||
Core.cpp
|
||||
DebugObjectManagerPlugin.cpp
|
||||
DebugUtils.cpp
|
||||
EHFrameRegistrationPlugin.cpp
|
||||
EPCDynamicLibrarySearchGenerator.cpp
|
||||
EPCDebugObjectRegistrar.cpp
|
||||
EPCEHFrameRegistrar.cpp
|
||||
|
||||
115
llvm/lib/ExecutionEngine/Orc/EHFrameRegistrationPlugin.cpp
Normal file
115
llvm/lib/ExecutionEngine/Orc/EHFrameRegistrationPlugin.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
//===--------- EHFrameRegistrationPlugin.cpp - Register eh-frames ---------===//
|
||||
//
|
||||
// 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/EHFrameRegistrationPlugin.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
|
||||
using namespace llvm::jitlink;
|
||||
|
||||
namespace llvm::orc {
|
||||
|
||||
EHFrameRegistrationPlugin::EHFrameRegistrationPlugin(
|
||||
ExecutionSession &ES, std::unique_ptr<EHFrameRegistrar> Registrar)
|
||||
: ES(ES), Registrar(std::move(Registrar)) {}
|
||||
|
||||
void EHFrameRegistrationPlugin::modifyPassConfig(
|
||||
MaterializationResponsibility &MR, LinkGraph &G,
|
||||
PassConfiguration &PassConfig) {
|
||||
|
||||
PassConfig.PostFixupPasses.push_back(createEHFrameRecorderPass(
|
||||
G.getTargetTriple(), [this, &MR](ExecutorAddr Addr, size_t Size) {
|
||||
if (Addr) {
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
assert(!InProcessLinks.count(&MR) &&
|
||||
"Link for MR already being tracked?");
|
||||
InProcessLinks[&MR] = {Addr, Size};
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Error EHFrameRegistrationPlugin::notifyEmitted(
|
||||
MaterializationResponsibility &MR) {
|
||||
|
||||
ExecutorAddrRange EmittedRange;
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
|
||||
auto EHFrameRangeItr = InProcessLinks.find(&MR);
|
||||
if (EHFrameRangeItr == InProcessLinks.end())
|
||||
return Error::success();
|
||||
|
||||
EmittedRange = EHFrameRangeItr->second;
|
||||
assert(EmittedRange.Start && "eh-frame addr to register can not be null");
|
||||
InProcessLinks.erase(EHFrameRangeItr);
|
||||
}
|
||||
|
||||
if (auto Err = MR.withResourceKeyDo(
|
||||
[&](ResourceKey K) { EHFrameRanges[K].push_back(EmittedRange); }))
|
||||
return Err;
|
||||
|
||||
return Registrar->registerEHFrames(EmittedRange);
|
||||
}
|
||||
|
||||
Error EHFrameRegistrationPlugin::notifyFailed(
|
||||
MaterializationResponsibility &MR) {
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
InProcessLinks.erase(&MR);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
Error EHFrameRegistrationPlugin::notifyRemovingResources(JITDylib &JD,
|
||||
ResourceKey K) {
|
||||
std::vector<ExecutorAddrRange> RangesToRemove;
|
||||
|
||||
ES.runSessionLocked([&] {
|
||||
auto I = EHFrameRanges.find(K);
|
||||
if (I != EHFrameRanges.end()) {
|
||||
RangesToRemove = std::move(I->second);
|
||||
EHFrameRanges.erase(I);
|
||||
}
|
||||
});
|
||||
|
||||
Error Err = Error::success();
|
||||
while (!RangesToRemove.empty()) {
|
||||
auto RangeToRemove = RangesToRemove.back();
|
||||
RangesToRemove.pop_back();
|
||||
assert(RangeToRemove.Start && "Untracked eh-frame range must not be null");
|
||||
Err = joinErrors(std::move(Err),
|
||||
Registrar->deregisterEHFrames(RangeToRemove));
|
||||
}
|
||||
|
||||
return Err;
|
||||
}
|
||||
|
||||
void EHFrameRegistrationPlugin::notifyTransferringResources(
|
||||
JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) {
|
||||
auto SI = EHFrameRanges.find(SrcKey);
|
||||
if (SI == EHFrameRanges.end())
|
||||
return;
|
||||
|
||||
auto DI = EHFrameRanges.find(DstKey);
|
||||
if (DI != EHFrameRanges.end()) {
|
||||
auto &SrcRanges = SI->second;
|
||||
auto &DstRanges = DI->second;
|
||||
DstRanges.reserve(DstRanges.size() + SrcRanges.size());
|
||||
for (auto &SrcRange : SrcRanges)
|
||||
DstRanges.push_back(std::move(SrcRange));
|
||||
EHFrameRanges.erase(SI);
|
||||
} else {
|
||||
// We need to move SrcKey's ranges over without invalidating the SI
|
||||
// iterator.
|
||||
auto Tmp = std::move(SI->second);
|
||||
EHFrameRanges.erase(SI);
|
||||
EHFrameRanges[DstKey] = std::move(Tmp);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace llvm::orc
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
|
||||
#include "llvm/ExecutionEngine/Orc/COFFPlatform.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
|
||||
|
||||
@@ -581,101 +581,5 @@ void LinkGraphLinkingLayer::handleTransferResources(JITDylib &JD,
|
||||
P->notifyTransferringResources(JD, DstKey, SrcKey);
|
||||
}
|
||||
|
||||
EHFrameRegistrationPlugin::EHFrameRegistrationPlugin(
|
||||
ExecutionSession &ES, std::unique_ptr<EHFrameRegistrar> Registrar)
|
||||
: ES(ES), Registrar(std::move(Registrar)) {}
|
||||
|
||||
void EHFrameRegistrationPlugin::modifyPassConfig(
|
||||
MaterializationResponsibility &MR, LinkGraph &G,
|
||||
PassConfiguration &PassConfig) {
|
||||
|
||||
PassConfig.PostFixupPasses.push_back(createEHFrameRecorderPass(
|
||||
G.getTargetTriple(), [this, &MR](ExecutorAddr Addr, size_t Size) {
|
||||
if (Addr) {
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
assert(!InProcessLinks.count(&MR) &&
|
||||
"Link for MR already being tracked?");
|
||||
InProcessLinks[&MR] = {Addr, Size};
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Error EHFrameRegistrationPlugin::notifyEmitted(
|
||||
MaterializationResponsibility &MR) {
|
||||
|
||||
ExecutorAddrRange EmittedRange;
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
|
||||
auto EHFrameRangeItr = InProcessLinks.find(&MR);
|
||||
if (EHFrameRangeItr == InProcessLinks.end())
|
||||
return Error::success();
|
||||
|
||||
EmittedRange = EHFrameRangeItr->second;
|
||||
assert(EmittedRange.Start && "eh-frame addr to register can not be null");
|
||||
InProcessLinks.erase(EHFrameRangeItr);
|
||||
}
|
||||
|
||||
if (auto Err = MR.withResourceKeyDo(
|
||||
[&](ResourceKey K) { EHFrameRanges[K].push_back(EmittedRange); }))
|
||||
return Err;
|
||||
|
||||
return Registrar->registerEHFrames(EmittedRange);
|
||||
}
|
||||
|
||||
Error EHFrameRegistrationPlugin::notifyFailed(
|
||||
MaterializationResponsibility &MR) {
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
InProcessLinks.erase(&MR);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
Error EHFrameRegistrationPlugin::notifyRemovingResources(JITDylib &JD,
|
||||
ResourceKey K) {
|
||||
std::vector<ExecutorAddrRange> RangesToRemove;
|
||||
|
||||
ES.runSessionLocked([&] {
|
||||
auto I = EHFrameRanges.find(K);
|
||||
if (I != EHFrameRanges.end()) {
|
||||
RangesToRemove = std::move(I->second);
|
||||
EHFrameRanges.erase(I);
|
||||
}
|
||||
});
|
||||
|
||||
Error Err = Error::success();
|
||||
while (!RangesToRemove.empty()) {
|
||||
auto RangeToRemove = RangesToRemove.back();
|
||||
RangesToRemove.pop_back();
|
||||
assert(RangeToRemove.Start && "Untracked eh-frame range must not be null");
|
||||
Err = joinErrors(std::move(Err),
|
||||
Registrar->deregisterEHFrames(RangeToRemove));
|
||||
}
|
||||
|
||||
return Err;
|
||||
}
|
||||
|
||||
void EHFrameRegistrationPlugin::notifyTransferringResources(
|
||||
JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) {
|
||||
auto SI = EHFrameRanges.find(SrcKey);
|
||||
if (SI == EHFrameRanges.end())
|
||||
return;
|
||||
|
||||
auto DI = EHFrameRanges.find(DstKey);
|
||||
if (DI != EHFrameRanges.end()) {
|
||||
auto &SrcRanges = SI->second;
|
||||
auto &DstRanges = DI->second;
|
||||
DstRanges.reserve(DstRanges.size() + SrcRanges.size());
|
||||
for (auto &SrcRange : SrcRanges)
|
||||
DstRanges.push_back(std::move(SrcRange));
|
||||
EHFrameRanges.erase(SI);
|
||||
} else {
|
||||
// We need to move SrcKey's ranges over without invalidating the SI
|
||||
// iterator.
|
||||
auto Tmp = std::move(SI->second);
|
||||
EHFrameRanges.erase(SI);
|
||||
EHFrameRanges[DstKey] = std::move(Tmp);
|
||||
}
|
||||
}
|
||||
|
||||
} // End namespace orc.
|
||||
} // End namespace llvm.
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
|
||||
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h"
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
|
||||
|
||||
Reference in New Issue
Block a user