File indexing completed on 2026-05-10 08:43:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
0014 #define LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
0015
0016 #include "llvm/ADT/STLExtras.h"
0017 #include "llvm/ADT/StringRef.h"
0018 #include "llvm/ExecutionEngine/JITEventListener.h"
0019 #include "llvm/ExecutionEngine/JITSymbol.h"
0020 #include "llvm/ExecutionEngine/Orc/Core.h"
0021 #include "llvm/ExecutionEngine/Orc/Layer.h"
0022 #include "llvm/ExecutionEngine/RuntimeDyld.h"
0023 #include "llvm/Object/ObjectFile.h"
0024 #include "llvm/Support/Error.h"
0025 #include <algorithm>
0026 #include <cassert>
0027 #include <functional>
0028 #include <list>
0029 #include <memory>
0030 #include <utility>
0031 #include <vector>
0032
0033 namespace llvm {
0034 namespace orc {
0035
0036 class RTDyldObjectLinkingLayer
0037 : public RTTIExtends<RTDyldObjectLinkingLayer, ObjectLayer>,
0038 private ResourceManager {
0039 public:
0040 static char ID;
0041
0042
0043 using NotifyLoadedFunction = std::function<void(
0044 MaterializationResponsibility &R, const object::ObjectFile &Obj,
0045 const RuntimeDyld::LoadedObjectInfo &)>;
0046
0047
0048 using NotifyEmittedFunction = std::function<void(
0049 MaterializationResponsibility &R, std::unique_ptr<MemoryBuffer>)>;
0050
0051 using GetMemoryManagerFunction =
0052 unique_function<std::unique_ptr<RuntimeDyld::MemoryManager>()>;
0053
0054
0055
0056 RTDyldObjectLinkingLayer(ExecutionSession &ES,
0057 GetMemoryManagerFunction GetMemoryManager);
0058
0059 ~RTDyldObjectLinkingLayer();
0060
0061
0062 void emit(std::unique_ptr<MaterializationResponsibility> R,
0063 std::unique_ptr<MemoryBuffer> O) override;
0064
0065
0066 RTDyldObjectLinkingLayer &setNotifyLoaded(NotifyLoadedFunction NotifyLoaded) {
0067 this->NotifyLoaded = std::move(NotifyLoaded);
0068 return *this;
0069 }
0070
0071
0072 RTDyldObjectLinkingLayer &
0073 setNotifyEmitted(NotifyEmittedFunction NotifyEmitted) {
0074 this->NotifyEmitted = std::move(NotifyEmitted);
0075 return *this;
0076 }
0077
0078
0079
0080
0081
0082
0083
0084 RTDyldObjectLinkingLayer &setProcessAllSections(bool ProcessAllSections) {
0085 this->ProcessAllSections = ProcessAllSections;
0086 return *this;
0087 }
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 RTDyldObjectLinkingLayer &
0098 setOverrideObjectFlagsWithResponsibilityFlags(bool OverrideObjectFlags) {
0099 this->OverrideObjectFlags = OverrideObjectFlags;
0100 return *this;
0101 }
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 RTDyldObjectLinkingLayer &
0115 setAutoClaimResponsibilityForObjectSymbols(bool AutoClaimObjectSymbols) {
0116 this->AutoClaimObjectSymbols = AutoClaimObjectSymbols;
0117 return *this;
0118 }
0119
0120
0121 void registerJITEventListener(JITEventListener &L);
0122
0123
0124 void unregisterJITEventListener(JITEventListener &L);
0125
0126 private:
0127 using MemoryManagerUP = std::unique_ptr<RuntimeDyld::MemoryManager>;
0128
0129 Error onObjLoad(MaterializationResponsibility &R,
0130 const object::ObjectFile &Obj,
0131 RuntimeDyld::MemoryManager &MemMgr,
0132 RuntimeDyld::LoadedObjectInfo &LoadedObjInfo,
0133 std::map<StringRef, JITEvaluatedSymbol> Resolved,
0134 std::set<StringRef> &InternalSymbols);
0135
0136 void onObjEmit(MaterializationResponsibility &R,
0137 object::OwningBinary<object::ObjectFile> O,
0138 std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
0139 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
0140 std::unique_ptr<SymbolDependenceMap> Deps, Error Err);
0141
0142 Error handleRemoveResources(JITDylib &JD, ResourceKey K) override;
0143 void handleTransferResources(JITDylib &JD, ResourceKey DstKey,
0144 ResourceKey SrcKey) override;
0145
0146 mutable std::mutex RTDyldLayerMutex;
0147 GetMemoryManagerFunction GetMemoryManager;
0148 NotifyLoadedFunction NotifyLoaded;
0149 NotifyEmittedFunction NotifyEmitted;
0150 bool ProcessAllSections = false;
0151 bool OverrideObjectFlags = false;
0152 bool AutoClaimObjectSymbols = false;
0153 DenseMap<ResourceKey, std::vector<MemoryManagerUP>> MemMgrs;
0154 std::vector<JITEventListener *> EventListeners;
0155 };
0156
0157 }
0158 }
0159
0160 #endif