Buffers.push_back(std::move(Buffer));
}
- return BaseLayer.addObjectSet(std::move(Objects), std::move(MM));
+ ModuleSetHandleT H =
+ BaseLayer.addObjectSet(Objects, std::move(MM));
+
+ BaseLayer.takeOwnershipOfBuffers(H, std::move(Buffers));
+
+ return H;
}
/// @brief Remove the module set associated with the handle H.
RTDyld->resolveRelocations();
RTDyld->registerEHFrames();
MM->finalizeMemory();
+ OwnedBuffers.clear();
State = Finalized;
}
RTDyld->mapSectionAddress(LocalAddress, TargetAddress);
}
+ void takeOwnershipOfBuffer(std::unique_ptr<MemoryBuffer> B) {
+ OwnedBuffers.push_back(std::move(B));
+ }
+
private:
std::unique_ptr<RTDyldMemoryManager> MM;
std::unique_ptr<RuntimeDyld> RTDyld;
enum { Raw, Finalizing, Finalized } State;
+
+ // FIXME: This ownership hack only exists because RuntimeDyldELF still
+ // wants to be able to inspect the original object when resolving
+ // relocations. As soon as that can be fixed this should be removed.
+ std::vector<std::unique_ptr<MemoryBuffer>> OwnedBuffers;
};
typedef std::list<LinkedObjectSet> LinkedObjectSetListT;
public:
/// @brief Handle to a set of loaded objects.
typedef LinkedObjectSetListT::iterator ObjSetHandleT;
+
+ // Ownership hack.
+ // FIXME: Remove this as soon as RuntimeDyldELF can apply relocations without
+ // referencing the original object.
+ template <typename OwningMBSet>
+ void takeOwnershipOfBuffers(ObjSetHandleT H, OwningMBSet MBs) {
+ for (auto &MB : MBs)
+ H->takeOwnershipOfBuffer(std::move(MB));
+ }
+
};
/// @brief Default (no-op) action to perform when loading objects.