Skip to content

Drop EHFrameRegistrar, use AllocActions for eh-frame registration. #130719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,9 @@ class EHFrameCFIBlockInspector {
};
};

/// Supports registration/deregistration of EH-frames in a target process.
class EHFrameRegistrar {
public:
virtual ~EHFrameRegistrar();
virtual Error registerEHFrames(orc::ExecutorAddrRange EHFrameSection) = 0;
virtual Error deregisterEHFrames(orc::ExecutorAddrRange EHFrameSection) = 0;
};

/// Registers / Deregisters EH-frames in the current process.
class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
public:
Error registerEHFrames(orc::ExecutorAddrRange EHFrameSection) override;

Error deregisterEHFrames(orc::ExecutorAddrRange EHFrameSection) override;
};

using StoreFrameRangeFunction = std::function<void(
orc::ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize)>;

/// Creates a pass that records the address and size of the EH frame section.
/// If no eh-frame section is found then the address and size will both be given
/// as zero.
///
/// Authors of JITLinkContexts can use this function to register a post-fixup
/// pass that records the range of the eh-frame section. This range can
/// be used after finalization to register and deregister the frame.
LinkGraphPassFunction
createEHFrameRecorderPass(const Triple &TT,
StoreFrameRangeFunction StoreFrameRange);
/// Returns a pointer to the DWARF eh-frame section if the graph contains a
/// non-empty one, otherwise returns null.
Section *getEHFrameSection(LinkGraph &G);

} // end namespace jitlink
} // end namespace llvm
Expand Down
42 changes: 21 additions & 21 deletions llvm/include/llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@
#include <mutex>
#include <vector>

namespace llvm {

namespace jitlink {
class EHFrameRegistrar;
} // namespace jitlink

namespace orc {
namespace llvm::orc {

/// Adds AllocationActions to register and deregister eh-frame sections in the
/// absence of native Platform support.
class EHFrameRegistrationPlugin : public LinkGraphLinkingLayer::Plugin {
public:
EHFrameRegistrationPlugin(
ExecutionSession &ES,
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar);
static Expected<std::unique_ptr<EHFrameRegistrationPlugin>>
Create(ExecutionSession &ES);

EHFrameRegistrationPlugin(ExecutorAddr RegisterEHFrame,
ExecutorAddr DeregisterEHFrame)
: RegisterEHFrame(RegisterEHFrame), DeregisterEHFrame(DeregisterEHFrame) {
}

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;
Error notifyFailed(MaterializationResponsibility &MR) override {
return Error::success();
}
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override {
return Error::success();
}
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
ResourceKey SrcKey) override;
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;
ExecutorAddr RegisterEHFrame;
ExecutorAddr DeregisterEHFrame;
};

} // end namespace orc
} // end namespace llvm
} // namespace llvm::orc

#endif // LLVM_EXECUTIONENGINE_ORC_EHFRAMEREGISTRATIONPLUGIN_H
58 changes: 0 additions & 58 deletions llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h

This file was deleted.

4 changes: 2 additions & 2 deletions llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ extern const char *MemoryWriteUInt64sWrapperName;
extern const char *MemoryWriteBuffersWrapperName;
extern const char *MemoryWritePointersWrapperName;

extern const char *RegisterEHFrameSectionWrapperName;
extern const char *DeregisterEHFrameSectionWrapperName;
extern const char *RegisterEHFrameSectionAllocActionName;
extern const char *DeregisterEHFrameSectionAllocActionName;

extern const char *RunAsMainWrapperName;
extern const char *RunAsVoidFunctionWrapperName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
} // end namespace llvm

extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size);
llvm_orc_registerEHFrameSectionAllocAction(const char *Data, uint64_t Size);

extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult
llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size);
llvm_orc_deregisterEHFrameSectionAllocAction(const char *Data, uint64_t Size);

#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_REGISTEREHFRAMES_H
52 changes: 13 additions & 39 deletions llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,20 +639,6 @@ Error EHFrameNullTerminator::operator()(LinkGraph &G) {
return Error::success();
}

EHFrameRegistrar::~EHFrameRegistrar() = default;

Error InProcessEHFrameRegistrar::registerEHFrames(
orc::ExecutorAddrRange EHFrameSection) {
return orc::registerEHFrameSection(EHFrameSection.Start.toPtr<void *>(),
EHFrameSection.size());
}

Error InProcessEHFrameRegistrar::deregisterEHFrames(
orc::ExecutorAddrRange EHFrameSection) {
return orc::deregisterEHFrameSection(EHFrameSection.Start.toPtr<void *>(),
EHFrameSection.size());
}

EHFrameCFIBlockInspector EHFrameCFIBlockInspector::FromEdgeScan(Block &B) {
if (B.edges_empty())
return EHFrameCFIBlockInspector(nullptr);
Expand All @@ -678,36 +664,24 @@ EHFrameCFIBlockInspector::EHFrameCFIBlockInspector(Edge &CIEEdge,
Edge *LSDAEdge)
: CIEEdge(&CIEEdge), PCBeginEdge(&PCBeginEdge), LSDAEdge(LSDAEdge) {}

LinkGraphPassFunction
createEHFrameRecorderPass(const Triple &TT,
StoreFrameRangeFunction StoreRangeAddress) {
Section *getEHFrameSection(LinkGraph &G) {
const char *EHFrameSectionName = nullptr;
if (TT.getObjectFormat() == Triple::MachO)
switch (G.getTargetTriple().getObjectFormat()) {
case Triple::MachO:
EHFrameSectionName = "__TEXT,__eh_frame";
else
break;
case Triple::ELF:
EHFrameSectionName = ".eh_frame";
break;
default:
return nullptr;
}

auto RecordEHFrame =
[EHFrameSectionName,
StoreFrameRange = std::move(StoreRangeAddress)](LinkGraph &G) -> Error {
// Search for a non-empty eh-frame and record the address of the first
// symbol in it.
orc::ExecutorAddr Addr;
size_t Size = 0;
if (auto *S = G.findSectionByName(EHFrameSectionName)) {
auto R = SectionRange(*S);
Addr = R.getStart();
Size = R.getSize();
}
if (!Addr && Size != 0)
return make_error<JITLinkError>(
StringRef(EHFrameSectionName) +
" section can not have zero address with non-zero size");
StoreFrameRange(Addr, Size);
return Error::success();
};
if (auto *S = G.findSectionByName(EHFrameSectionName))
if (!S->empty())
return S;

return RecordEHFrame;
return nullptr;
}

} // end namespace jitlink
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_llvm_component_library(LLVMOrcJIT
EHFrameRegistrationPlugin.cpp
EPCDynamicLibrarySearchGenerator.cpp
EPCDebugObjectRegistrar.cpp
EPCEHFrameRegistrar.cpp
EPCGenericDylibManager.cpp
EPCGenericJITLinkMemoryManager.cpp
EPCGenericRTDyldMemoryManager.cpp
Expand Down
Loading