diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index 89644994bc1d83..7f8dd7303050fd 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -19,8 +19,8 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h" -#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h" #include "llvm/ExecutionEngine/JITSymbol.h" +#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" @@ -667,7 +667,7 @@ class Section { friend class LinkGraph; private: - Section(StringRef Name, MemProt Prot, SectionOrdinal SecOrdinal) + Section(StringRef Name, orc::MemProt Prot, SectionOrdinal SecOrdinal) : Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {} using SymbolSet = DenseSet; @@ -692,16 +692,16 @@ class Section { StringRef getName() const { return Name; } /// Returns the protection flags for this section. - MemProt getMemProt() const { return Prot; } + orc::MemProt getMemProt() const { return Prot; } /// Set the protection flags for this section. - void setMemProt(MemProt Prot) { this->Prot = Prot; } + void setMemProt(orc::MemProt Prot) { this->Prot = Prot; } /// Get the deallocation policy for this section. - MemDeallocPolicy getMemDeallocPolicy() const { return MDP; } + orc::MemDeallocPolicy getMemDeallocPolicy() const { return MDP; } /// Set the deallocation policy for this section. - void setMemDeallocPolicy(MemDeallocPolicy MDP) { this->MDP = MDP; } + void setMemDeallocPolicy(orc::MemDeallocPolicy MDP) { this->MDP = MDP; } /// Returns the ordinal for this section. SectionOrdinal getOrdinal() const { return SecOrdinal; } @@ -765,8 +765,8 @@ class Section { } StringRef Name; - MemProt Prot; - MemDeallocPolicy MDP = MemDeallocPolicy::Standard; + orc::MemProt Prot; + orc::MemDeallocPolicy MDP = orc::MemDeallocPolicy::Standard; SectionOrdinal SecOrdinal = 0; BlockSet Blocks; SymbolSet Symbols; @@ -1003,7 +1003,7 @@ class LinkGraph { } /// Create a section with the given name, protection flags, and alignment. - Section &createSection(StringRef Name, MemProt Prot) { + Section &createSection(StringRef Name, orc::MemProt Prot) { assert(llvm::none_of(Sections, [&](std::unique_ptr
&Sec) { return Sec->getName() == Name; diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h index abfeafe798e79c..6ef4a0bd0c982d 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h @@ -16,9 +16,9 @@ #include "llvm/ADT/FunctionExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h" -#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h" #include "llvm/ExecutionEngine/Orc/Shared/AllocationActions.h" #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h" +#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" #include "llvm/Support/MSVCErrorWorkarounds.h" @@ -246,7 +246,7 @@ class BasicLayout { }; private: - using SegmentMap = AllocGroupSmallMap; + using SegmentMap = orc::AllocGroupSmallMap; public: BasicLayout(LinkGraph &G); @@ -309,7 +309,7 @@ class SimpleSegmentAlloc { MutableArrayRef WorkingMem; }; - using SegmentMap = AllocGroupSmallMap; + using SegmentMap = orc::AllocGroupSmallMap; using OnCreatedFunction = unique_function)>; @@ -328,7 +328,7 @@ class SimpleSegmentAlloc { ~SimpleSegmentAlloc(); /// Returns the SegmentInfo for the given group. - SegmentInfo getSegInfo(AllocGroup AG); + SegmentInfo getSegInfo(orc::AllocGroup AG); /// Finalize all groups (async version). void finalize(OnFinalizedFunction OnFinalized) { @@ -342,11 +342,12 @@ class SimpleSegmentAlloc { private: SimpleSegmentAlloc( - std::unique_ptr G, AllocGroupSmallMap ContentBlocks, + std::unique_ptr G, + orc::AllocGroupSmallMap ContentBlocks, std::unique_ptr Alloc); std::unique_ptr G; - AllocGroupSmallMap ContentBlocks; + orc::AllocGroupSmallMap ContentBlocks; std::unique_ptr Alloc; }; diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h index 11fbbbd579d00c..76aaadd8816f60 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h @@ -15,7 +15,7 @@ #include "TableManager.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" -#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h" +#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" namespace llvm { namespace jitlink { @@ -309,8 +309,8 @@ class GOTTableManager : public TableManager { private: Section &getGOTSection(LinkGraph &G) { if (!GOTSection) - GOTSection = - &G.createSection(getSectionName(), MemProt::Read | MemProt::Exec); + GOTSection = &G.createSection(getSectionName(), + orc::MemProt::Read | orc::MemProt::Exec); return *GOTSection; } @@ -354,8 +354,8 @@ class PLTTableManager : public TableManager { public: Section &getStubsSection(LinkGraph &G) { if (!StubsSection) - StubsSection = - &G.createSection(getSectionName(), MemProt::Read | MemProt::Exec); + StubsSection = &G.createSection(getSectionName(), + orc::MemProt::Read | orc::MemProt::Exec); return *StubsSection; } diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h index 2de949f21656d1..8e1fbba4e173a1 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h @@ -607,7 +607,7 @@ class GOTTableManager : public TableManager { private: Section &getGOTSection(LinkGraph &G) { if (!GOTSection) - GOTSection = &G.createSection(getSectionName(), MemProt::Read); + GOTSection = &G.createSection(getSectionName(), orc::MemProt::Read); return *GOTSection; } @@ -645,8 +645,8 @@ class PLTTableManager : public TableManager { public: Section &getStubsSection(LinkGraph &G) { if (!PLTSection) - PLTSection = - &G.createSection(getSectionName(), MemProt::Read | MemProt::Exec); + PLTSection = &G.createSection(getSectionName(), + orc::MemProt::Read | orc::MemProt::Exec); return *PLTSection; } diff --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h index 29d282372b1f66..8fa1a4cd6355a5 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h @@ -77,9 +77,9 @@ class EPCGenericRTDyldMemoryManager : public RuntimeDyld::MemoryManager { bool finalizeMemory(std::string *ErrMsg = nullptr) override; private: - struct Alloc { + struct SectionAlloc { public: - Alloc(uint64_t Size, unsigned Align) + SectionAlloc(uint64_t Size, unsigned Align) : Size(Size), Align(Align), Contents(std::make_unique(Size + Align - 1)) {} @@ -92,30 +92,31 @@ class EPCGenericRTDyldMemoryManager : public RuntimeDyld::MemoryManager { // Group of section allocations to be allocated together in the executor. The // RemoteCodeAddr will stand in as the id of the group for deallocation // purposes. - struct AllocGroup { - AllocGroup() = default; - AllocGroup(const AllocGroup &) = delete; - AllocGroup &operator=(const AllocGroup &) = delete; - AllocGroup(AllocGroup &&) = default; - AllocGroup &operator=(AllocGroup &&) = default; + struct SectionAllocGroup { + SectionAllocGroup() = default; + SectionAllocGroup(const SectionAllocGroup &) = delete; + SectionAllocGroup &operator=(const SectionAllocGroup &) = delete; + SectionAllocGroup(SectionAllocGroup &&) = default; + SectionAllocGroup &operator=(SectionAllocGroup &&) = default; ExecutorAddrRange RemoteCode; ExecutorAddrRange RemoteROData; ExecutorAddrRange RemoteRWData; std::vector UnfinalizedEHFrames; - std::vector CodeAllocs, RODataAllocs, RWDataAllocs; + std::vector CodeAllocs, RODataAllocs, RWDataAllocs; }; - // Maps all allocations in Allocs to aligned blocks - void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld, std::vector &Allocs, + // Maps all allocations in SectionAllocs to aligned blocks + void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld, + std::vector &SecAllocs, ExecutorAddr NextAddr); ExecutorProcessControl &EPC; SymbolAddrs SAs; std::mutex M; - std::vector Unmapped; - std::vector Unfinalized; + std::vector Unmapped; + std::vector Unfinalized; std::vector FinalizedAllocs; std::string ErrMsg; }; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h b/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h index 17072d2fa5b123..9f9ff06b2c2f68 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h @@ -14,6 +14,7 @@ #define LLVM_EXECUTIONENGINE_ORC_MEMORYMAPPER_H #include "llvm/ExecutionEngine/Orc/Core.h" +#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" #include "llvm/Support/Process.h" #include @@ -32,7 +33,7 @@ class MemoryMapper { const char *WorkingMem; size_t ContentSize; size_t ZeroFillSize; - unsigned Prot; + AllocGroup AG; }; ExecutorAddr MappingBase; diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h similarity index 77% rename from llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h rename to llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h index a18098e5a1a928..2642e6c241b6e7 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_EXECUTIONENGINE_JITLINK_MEMORYFLAGS_H -#define LLVM_EXECUTIONENGINE_JITLINK_MEMORYFLAGS_H +#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H +#define LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H #include "llvm/ADT/BitmaskEnum.h" #include "llvm/ADT/DenseMapInfo.h" @@ -21,7 +21,7 @@ #include "llvm/Support/raw_ostream.h" namespace llvm { -namespace jitlink { +namespace orc { /// Describes Read/Write/Exec permissions for memory. enum class MemProt { @@ -33,7 +33,11 @@ enum class MemProt { }; /// Print a MemProt as an RWX triple. -raw_ostream &operator<<(raw_ostream &OS, MemProt MP); +inline raw_ostream &operator<<(raw_ostream &OS, MemProt MP) { + return OS << (((MP & MemProt::Read) != MemProt::None) ? 'R' : '-') + << (((MP & MemProt::Write) != MemProt::None) ? 'W' : '-') + << (((MP & MemProt::Exec) != MemProt::None) ? 'X' : '-'); +} /// Convert a MemProt value to a corresponding sys::Memory::ProtectionFlags /// value. @@ -79,7 +83,9 @@ enum class MemDeallocPolicy { }; /// Print a MemDeallocPolicy. -raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP); +inline raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP) { + return OS << (MDP == MemDeallocPolicy::Standard ? "standard" : "finalize"); +} /// A pair of memory protections and allocation policies. /// @@ -179,44 +185,42 @@ template class AllocGroupSmallMap { }; /// Print an AllocGroup. -raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG); +inline raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG) { + return OS << '(' << AG.getMemProt() << ", " << AG.getMemDeallocPolicy() + << ')'; +} -} // end namespace jitlink +} // end namespace orc -template <> struct DenseMapInfo { - static inline jitlink::MemProt getEmptyKey() { - return jitlink::MemProt(~uint8_t(0)); - } - static inline jitlink::MemProt getTombstoneKey() { - return jitlink::MemProt(~uint8_t(0) - 1); +template <> struct DenseMapInfo { + static inline orc::MemProt getEmptyKey() { return orc::MemProt(~uint8_t(0)); } + static inline orc::MemProt getTombstoneKey() { + return orc::MemProt(~uint8_t(0) - 1); } - static unsigned getHashValue(const jitlink::MemProt &Val) { - using UT = std::underlying_type_t; + static unsigned getHashValue(const orc::MemProt &Val) { + using UT = std::underlying_type_t; return DenseMapInfo::getHashValue(static_cast(Val)); } - static bool isEqual(const jitlink::MemProt &LHS, - const jitlink::MemProt &RHS) { + static bool isEqual(const orc::MemProt &LHS, const orc::MemProt &RHS) { return LHS == RHS; } }; -template <> struct DenseMapInfo { - static inline jitlink::AllocGroup getEmptyKey() { - return jitlink::AllocGroup(~uint8_t(0)); +template <> struct DenseMapInfo { + static inline orc::AllocGroup getEmptyKey() { + return orc::AllocGroup(~uint8_t(0)); } - static inline jitlink::AllocGroup getTombstoneKey() { - return jitlink::AllocGroup(~uint8_t(0) - 1); + static inline orc::AllocGroup getTombstoneKey() { + return orc::AllocGroup(~uint8_t(0) - 1); } - static unsigned getHashValue(const jitlink::AllocGroup &Val) { - return DenseMapInfo::getHashValue( - Val.Id); + static unsigned getHashValue(const orc::AllocGroup &Val) { + return DenseMapInfo::getHashValue(Val.Id); } - static bool isEqual(const jitlink::AllocGroup &LHS, - const jitlink::AllocGroup &RHS) { + static bool isEqual(const orc::AllocGroup &LHS, const orc::AllocGroup &RHS) { return LHS == RHS; } }; } // end namespace llvm -#endif // LLVM_EXECUTIONENGINE_JITLINK_MEMORYFLAGS_H +#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_MEMORYFLAGS_H diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h index 502c7c1f70694e..4096366d2e36e7 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h @@ -19,6 +19,7 @@ #include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/Shared/AllocationActions.h" #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h" +#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h" #include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h" #include "llvm/Support/Memory.h" @@ -29,49 +30,8 @@ namespace llvm { namespace orc { namespace tpctypes { -enum WireProtectionFlags : uint8_t { - WPF_None = 0, - WPF_Read = 1U << 0, - WPF_Write = 1U << 1, - WPF_Exec = 1U << 2, - LLVM_MARK_AS_BITMASK_ENUM(WPF_Exec) -}; - -/// Convert from sys::Memory::ProtectionFlags -inline WireProtectionFlags -toWireProtectionFlags(sys::Memory::ProtectionFlags PF) { - WireProtectionFlags WPF = WPF_None; - if (PF & sys::Memory::MF_READ) - WPF |= WPF_Read; - if (PF & sys::Memory::MF_WRITE) - WPF |= WPF_Write; - if (PF & sys::Memory::MF_EXEC) - WPF |= WPF_Exec; - return WPF; -} - -inline sys::Memory::ProtectionFlags -fromWireProtectionFlags(WireProtectionFlags WPF) { - int PF = 0; - if (WPF & WPF_Read) - PF |= sys::Memory::MF_READ; - if (WPF & WPF_Write) - PF |= sys::Memory::MF_WRITE; - if (WPF & WPF_Exec) - PF |= sys::Memory::MF_EXEC; - return static_cast(PF); -} - -inline std::string getWireProtectionFlagsStr(WireProtectionFlags WPF) { - std::string Result; - Result += (WPF & WPF_Read) ? 'R' : '-'; - Result += (WPF & WPF_Write) ? 'W' : '-'; - Result += (WPF & WPF_Exec) ? 'X' : '-'; - return Result; -} - struct SegFinalizeRequest { - WireProtectionFlags Prot; + AllocGroup AG; ExecutorAddr Addr; uint64_t Size; ArrayRef Content; @@ -83,7 +43,7 @@ struct FinalizeRequest { }; struct SharedMemorySegFinalizeRequest { - WireProtectionFlags Prot; + AllocGroup AG; ExecutorAddr Addr; uint64_t Size; }; @@ -133,17 +93,16 @@ using LookupResult = std::vector; namespace shared { -class SPSMemoryProtectionFlags {}; +class SPSAllocGroup {}; using SPSSegFinalizeRequest = - SPSTuple>; + SPSTuple>; using SPSFinalizeRequest = SPSTuple, SPSSequence>; using SPSSharedMemorySegFinalizeRequest = - SPSTuple; + SPSTuple; using SPSSharedMemoryFinalizeRequest = SPSTuple, @@ -159,25 +118,47 @@ using SPSMemoryAccessUInt64Write = SPSMemoryAccessUIntWrite; using SPSMemoryAccessBufferWrite = SPSTuple>; -template <> -class SPSSerializationTraits { +template <> class SPSSerializationTraits { + enum WireBits { + ReadBit = 1 << 0, + WriteBit = 1 << 1, + ExecBit = 1 << 2, + FinalizeBit = 1 << 3 + }; + public: - static size_t size(const tpctypes::WireProtectionFlags &WPF) { - return SPSArgList::size(static_cast(WPF)); + static size_t size(const AllocGroup &AG) { + // All AllocGroup values encode to the same size. + return SPSArgList::size(uint8_t(0)); } - static bool serialize(SPSOutputBuffer &OB, - const tpctypes::WireProtectionFlags &WPF) { - return SPSArgList::serialize(OB, static_cast(WPF)); + static bool serialize(SPSOutputBuffer &OB, const AllocGroup &AG) { + uint8_t WireValue = 0; + if ((AG.getMemProt() & MemProt::Read) != MemProt::None) + WireValue |= ReadBit; + if ((AG.getMemProt() & MemProt::Write) != MemProt::None) + WireValue |= WriteBit; + if ((AG.getMemProt() & MemProt::Exec) != MemProt::None) + WireValue |= ExecBit; + if (AG.getMemDeallocPolicy() == MemDeallocPolicy::Finalize) + WireValue |= FinalizeBit; + return SPSArgList::serialize(OB, WireValue); } - static bool deserialize(SPSInputBuffer &IB, - tpctypes::WireProtectionFlags &WPF) { + static bool deserialize(SPSInputBuffer &IB, AllocGroup &AG) { uint8_t Val; if (!SPSArgList::deserialize(IB, Val)) return false; - WPF = static_cast(Val); + MemProt MP = MemProt::None; + if (Val & ReadBit) + MP |= MemProt::Read; + if (Val & WriteBit) + MP |= MemProt::Write; + if (Val & ExecBit) + MP |= MemProt::Exec; + MemDeallocPolicy MDP = (Val & FinalizeBit) ? MemDeallocPolicy::Finalize + : MemDeallocPolicy::Standard; + AG = AllocGroup(MP, MDP); return true; } }; @@ -189,17 +170,17 @@ class SPSSerializationTraitscreateSection(CommonSectionName, MemProt::Read | MemProt::Write); + CommonSection = &G->createSection(CommonSectionName, + orc::MemProt::Read | orc::MemProt::Write); return *CommonSection; } @@ -142,13 +142,13 @@ Error COFFLinkGraphBuilder::graphifySections() { }); // Get the section's memory protection flags. - MemProt Prot = MemProt::Read; + orc::MemProt Prot = orc::MemProt::Read; if ((*Sec)->Characteristics & COFF::IMAGE_SCN_MEM_EXECUTE) - Prot |= MemProt::Exec; + Prot |= orc::MemProt::Exec; if ((*Sec)->Characteristics & COFF::IMAGE_SCN_MEM_READ) - Prot |= MemProt::Read; + Prot |= orc::MemProt::Read; if ((*Sec)->Characteristics & COFF::IMAGE_SCN_MEM_WRITE) - Prot |= MemProt::Write; + Prot |= orc::MemProt::Write; // Look for existing sections first. auto *GraphSec = G->findSectionByName(SectionName); diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h index d21dd606dc1979..7f881966bcba2a 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -37,8 +37,8 @@ class ELFLinkGraphBuilderBase { Section &getCommonSection() { if (!CommonSection) - CommonSection = - &G->createSection(CommonSectionName, MemProt::Read | MemProt::Write); + CommonSection = &G->createSection( + CommonSectionName, orc::MemProt::Read | orc::MemProt::Write); return *CommonSection; } @@ -310,11 +310,11 @@ template Error ELFLinkGraphBuilder::graphifySections() { }); // Get the section's memory protection flags. - MemProt Prot; + orc::MemProt Prot; if (Sec.sh_flags & ELF::SHF_EXECINSTR) - Prot = MemProt::Read | MemProt::Exec; + Prot = orc::MemProt::Read | orc::MemProt::Exec; else - Prot = MemProt::Read | MemProt::Write; + Prot = orc::MemProt::Read | orc::MemProt::Write; // Look for existing sections first. auto *GraphSec = G->findSectionByName(*Name); diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp index b1fe9c1624e844..da998140a3fa55 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp @@ -413,7 +413,7 @@ class TLSInfoTableManager_ELF_aarch64 private: Section &getTLSInfoSection(LinkGraph &G) { if (!TLSInfoTable) - TLSInfoTable = &G.createSection(getSectionName(), MemProt::Read); + TLSInfoTable = &G.createSection(getSectionName(), orc::MemProt::Read); return *TLSInfoTable; } @@ -481,7 +481,7 @@ class TLSDescTableManager_ELF_aarch64 private: Section &getTLSDescSection(LinkGraph &G) { if (!GOTSection) - GOTSection = &G.createSection(getSectionName(), MemProt::Read); + GOTSection = &G.createSection(getSectionName(), orc::MemProt::Read); return *GOTSection; } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp index c7596efe2bb8ca..36c736835a83cf 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp @@ -82,14 +82,14 @@ class PerGraphGOTAndPLTStubsBuilder_ELF_riscv private: Section &getGOTSection() const { if (!GOTSection) - GOTSection = &G.createSection("$__GOT", MemProt::Read); + GOTSection = &G.createSection("$__GOT", orc::MemProt::Read); return *GOTSection; } Section &getStubsSection() const { if (!StubsSection) StubsSection = - &G.createSection("$__STUBS", MemProt::Read | MemProt::Exec); + &G.createSection("$__STUBS", orc::MemProt::Read | orc::MemProt::Exec); return *StubsSection; } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp index 60d44d5f0ce6ee..a0d559b10bfbe1 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -68,7 +68,8 @@ class TLSInfoTableManager_ELF_x86_64 private: Section &getTLSInfoSection(LinkGraph &G) { if (!TLSInfoTable) - TLSInfoTable = &G.createSection(ELFTLSInfoSectionName, MemProt::Read); + TLSInfoTable = + &G.createSection(ELFTLSInfoSectionName, orc::MemProt::Read); return *TLSInfoTable; } diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp index 6bf2381fd571df..bd44b86f308199 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp @@ -89,7 +89,7 @@ BasicLayout::getContiguousPageBasedLayoutSizes(uint64_t PageSize) { inconvertibleErrorCode()); uint64_t SegSize = alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize); - if (AG.getMemDeallocPolicy() == MemDeallocPolicy::Standard) + if (AG.getMemDeallocPolicy() == orc::MemDeallocPolicy::Standard) SegsSizes.StandardSegs += SegSize; else SegsSizes.FinalizeSegs += SegSize; @@ -146,7 +146,7 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD, SegmentMap Segments, OnCreatedFunction OnCreated) { - static_assert(AllocGroup::NumGroups == 16, + static_assert(orc::AllocGroup::NumGroups == 16, "AllocGroup has changed. Section names below must be updated"); StringRef AGSectionNames[] = { "__---.standard", "__R--.standard", "__-W-.standard", "__RW-.standard", @@ -156,7 +156,7 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr, auto G = std::make_unique("", Triple(), 0, support::native, nullptr); - AllocGroupSmallMap ContentBlocks; + orc::AllocGroupSmallMap ContentBlocks; orc::ExecutorAddr NextAddr(0x100000); for (auto &KV : Segments) { @@ -213,7 +213,8 @@ SimpleSegmentAlloc & SimpleSegmentAlloc::operator=(SimpleSegmentAlloc &&) = default; SimpleSegmentAlloc::~SimpleSegmentAlloc() = default; -SimpleSegmentAlloc::SegmentInfo SimpleSegmentAlloc::getSegInfo(AllocGroup AG) { +SimpleSegmentAlloc::SegmentInfo +SimpleSegmentAlloc::getSegInfo(orc::AllocGroup AG) { auto I = ContentBlocks.find(AG); if (I != ContentBlocks.end()) { auto &B = *I->second; @@ -223,7 +224,8 @@ SimpleSegmentAlloc::SegmentInfo SimpleSegmentAlloc::getSegInfo(AllocGroup AG) { } SimpleSegmentAlloc::SimpleSegmentAlloc( - std::unique_ptr G, AllocGroupSmallMap ContentBlocks, + std::unique_ptr G, + orc::AllocGroupSmallMap ContentBlocks, std::unique_ptr Alloc) : G(std::move(G)), ContentBlocks(std::move(ContentBlocks)), Alloc(std::move(Alloc)) {} @@ -394,9 +396,10 @@ void InProcessMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G, auto &AG = KV.first; auto &Seg = KV.second; - auto &SegAddr = (AG.getMemDeallocPolicy() == MemDeallocPolicy::Standard) - ? NextStandardSegAddr - : NextFinalizeSegAddr; + auto &SegAddr = + (AG.getMemDeallocPolicy() == orc::MemDeallocPolicy::Standard) + ? NextStandardSegAddr + : NextFinalizeSegAddr; Seg.WorkingMem = SegAddr.toPtr(); Seg.Addr = SegAddr; diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp index ff3ecf9af6ddda..d16259bc31cd6c 100644 --- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp @@ -111,8 +111,8 @@ MachOLinkGraphBuilder::getEndianness(const object::MachOObjectFile &Obj) { Section &MachOLinkGraphBuilder::getCommonSection() { if (!CommonSection) - CommonSection = - &G->createSection(CommonSectionName, MemProt::Read | MemProt::Write); + CommonSection = &G->createSection(CommonSectionName, + orc::MemProt::Read | orc::MemProt::Write); return *CommonSection; } @@ -177,11 +177,11 @@ Error MachOLinkGraphBuilder::createNormalizedSections() { // Get prot flags. // FIXME: Make sure this test is correct (it's probably missing cases // as-is). - MemProt Prot; + orc::MemProt Prot; if (NSec.Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) - Prot = MemProt::Read | MemProt::Exec; + Prot = orc::MemProt::Read | orc::MemProt::Exec; else - Prot = MemProt::Read | MemProt::Write; + Prot = orc::MemProt::Read | orc::MemProt::Write; auto FullyQualifiedName = G->allocateString(StringRef(NSec.SegName) + "," + NSec.SectName); diff --git a/llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp b/llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp deleted file mode 100644 index b73a310b2910dd..00000000000000 --- a/llvm/lib/ExecutionEngine/JITLink/MemoryFlags.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===------------- MemoryFlags.cpp - Memory allocation flags --------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h" - -#define DEBUG_TYPE "jitlink" - -namespace llvm { -namespace jitlink { - -raw_ostream &operator<<(raw_ostream &OS, MemProt MP) { - return OS << (((MP & MemProt::Read) != MemProt::None) ? 'R' : '-') - << (((MP & MemProt::Write) != MemProt::None) ? 'W' : '-') - << (((MP & MemProt::Exec) != MemProt::None) ? 'X' : '-'); -} - -raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP) { - return OS << (MDP == MemDeallocPolicy::Standard ? "standard" : "finalize"); -} - -raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG) { - return OS << '(' << AG.getMemProt() << ", " << AG.getMemDeallocPolicy() - << ')'; -} - -} // end namespace jitlink -} // end namespace llvm diff --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp index 8bd9c294c4c924..642aa74bd48493 100644 --- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp @@ -69,7 +69,7 @@ class COFFHeaderMaterializationUnit : public MaterializationUnit { auto G = std::make_unique( "", TT, PointerSize, Endianness, jitlink::getGenericEdgeKindName); - auto &HeaderSection = G->createSection("__header", jitlink::MemProt::Read); + auto &HeaderSection = G->createSection("__header", MemProt::Read); auto &HeaderBlock = createHeaderBlock(*G, HeaderSection); // Init symbol is __ImageBase symbol. diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp index e7ca636c83e95c..0a90847db221ed 100644 --- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp @@ -62,7 +62,7 @@ class DSOHandleMaterializationUnit : public MaterializationUnit { "", TT, PointerSize, Endianness, jitlink::getGenericEdgeKindName); auto &DSOHandleSection = - G->createSection(".data.__dso_handle", jitlink::MemProt::Read); + G->createSection(".data.__dso_handle", MemProt::Read); auto &DSOHandleBlock = G->createContentBlock( DSOHandleSection, getDSOHandleContent(PointerSize), orc::ExecutorAddr(), 8, 0); diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp index 75cc30753f416e..a3d857c3bfc4e8 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp @@ -47,8 +47,7 @@ class EPCGenericJITLinkMemoryManager::InFlightAlloc for (auto &KV : Segs) { assert(KV.second.ContentSize <= std::numeric_limits::max()); FR.Segments.push_back(tpctypes::SegFinalizeRequest{ - tpctypes::toWireProtectionFlags( - toSysMemoryProtectionFlags(KV.first.getMemProt())), + KV.first, KV.second.Addr, alignTo(KV.second.ContentSize + KV.second.ZeroFillSize, Parent.EPC.getPageSize()), diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp index cdac367e11a326..62f906657ffe64 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp @@ -142,7 +142,7 @@ void EPCGenericRTDyldMemoryManager::reserveAllocationSpace( } std::lock_guard Lock(M); - Unmapped.push_back(AllocGroup()); + Unmapped.push_back(SectionAllocGroup()); Unmapped.back().RemoteCode = { *TargetAllocAddr, ExecutorAddrDiff(alignTo(CodeSize, EPC.getPageSize()))}; Unmapped.back().RemoteROData = { @@ -170,10 +170,11 @@ void EPCGenericRTDyldMemoryManager::registerEHFrames(uint8_t *Addr, return; ExecutorAddr LA(LoadAddr); - for (auto &Alloc : llvm::reverse(Unfinalized)) { - if (Alloc.RemoteCode.contains(LA) || Alloc.RemoteROData.contains(LA) || - Alloc.RemoteRWData.contains(LA)) { - Alloc.UnfinalizedEHFrames.push_back({LA, Size}); + for (auto &SecAllocGroup : llvm::reverse(Unfinalized)) { + if (SecAllocGroup.RemoteCode.contains(LA) || + SecAllocGroup.RemoteROData.contains(LA) || + SecAllocGroup.RemoteRWData.contains(LA)) { + SecAllocGroup.UnfinalizedEHFrames.push_back({LA, Size}); return; } } @@ -204,35 +205,29 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) { LLVM_DEBUG(dbgs() << "Allocator " << (void *)this << " finalizing:\n"); // If there's an error then bail out here. - std::vector Allocs; + std::vector SecAllocGroups; { std::lock_guard Lock(M); if (ErrMsg && !this->ErrMsg.empty()) { *ErrMsg = std::move(this->ErrMsg); return true; } - std::swap(Allocs, Unfinalized); + std::swap(SecAllocGroups, Unfinalized); } // Loop over unfinalized objects to make finalization requests. - for (auto &ObjAllocs : Allocs) { + for (auto &SecAllocGroup : SecAllocGroups) { - tpctypes::WireProtectionFlags SegProts[3] = { - tpctypes::toWireProtectionFlags( - static_cast(sys::Memory::MF_READ | - sys::Memory::MF_EXEC)), - tpctypes::toWireProtectionFlags(sys::Memory::MF_READ), - tpctypes::toWireProtectionFlags( - static_cast(sys::Memory::MF_READ | - sys::Memory::MF_WRITE))}; + MemProt SegMemProts[3] = {MemProt::Read | MemProt::Exec, MemProt::Read, + MemProt::Read | MemProt::Write}; - ExecutorAddrRange *RemoteAddrs[3] = {&ObjAllocs.RemoteCode, - &ObjAllocs.RemoteROData, - &ObjAllocs.RemoteRWData}; + ExecutorAddrRange *RemoteAddrs[3] = {&SecAllocGroup.RemoteCode, + &SecAllocGroup.RemoteROData, + &SecAllocGroup.RemoteRWData}; - std::vector *SegSections[3] = {&ObjAllocs.CodeAllocs, - &ObjAllocs.RODataAllocs, - &ObjAllocs.RWDataAllocs}; + std::vector *SegSections[3] = {&SecAllocGroup.CodeAllocs, + &SecAllocGroup.RODataAllocs, + &SecAllocGroup.RWDataAllocs}; tpctypes::FinalizeRequest FR; std::unique_ptr AggregateContents[3]; @@ -240,7 +235,7 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) { for (unsigned I = 0; I != 3; ++I) { FR.Segments.push_back({}); auto &Seg = FR.Segments.back(); - Seg.Prot = SegProts[I]; + Seg.AG = SegMemProts[I]; Seg.Addr = RemoteAddrs[I]->Start; for (auto &SecAlloc : *SegSections[I]) { Seg.Size = alignTo(Seg.Size, SecAlloc.Align); @@ -261,7 +256,7 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) { Seg.Content = {AggregateContents[I].get(), SecOffset}; } - for (auto &Frame : ObjAllocs.UnfinalizedEHFrames) + for (auto &Frame : SecAllocGroup.UnfinalizedEHFrames) FR.Actions.push_back( {cantFail( WrapperFunctionCall::Create>( @@ -297,7 +292,8 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) { } void EPCGenericRTDyldMemoryManager::mapAllocsToRemoteAddrs( - RuntimeDyld &Dyld, std::vector &Allocs, ExecutorAddr NextAddr) { + RuntimeDyld &Dyld, std::vector &Allocs, + ExecutorAddr NextAddr) { for (auto &Alloc : Allocs) { NextAddr.setValue(alignTo(NextAddr.getValue(), Alloc.Align)); LLVM_DEBUG({ diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp index 2577318e832639..377a59993eb0e8 100644 --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -517,8 +517,8 @@ DLLImportDefinitionGenerator::createStubsGraph(const SymbolMap &Resolved) { auto G = std::make_unique( "", TT, *PointerSize, *Endianness, jitlink::getGenericEdgeKindName); - jitlink::Section &Sec = G->createSection( - getSectionName(), jitlink::MemProt::Read | jitlink::MemProt::Exec); + jitlink::Section &Sec = + G->createSection(getSectionName(), MemProt::Read | MemProt::Exec); for (auto &KV : Resolved) { jitlink::Symbol &Target = G->addAbsoluteSymbol( diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index e92986f1d0506e..01a4c3b9837d80 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -85,7 +85,7 @@ class MachOHeaderMaterializationUnit : public MaterializationUnit { auto G = std::make_unique( "", TT, PointerSize, Endianness, jitlink::getGenericEdgeKindName); - auto &HeaderSection = G->createSection("__header", jitlink::MemProt::Read); + auto &HeaderSection = G->createSection("__header", MemProt::Read); auto &HeaderBlock = createHeaderBlock(*G, HeaderSection); // Init symbol is header-start symbol. diff --git a/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp index eb3a5acb06cc17..d099a251232e7e 100644 --- a/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp @@ -99,7 +99,7 @@ void MapperJITLinkMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G, SI.Offset = Seg.Addr - Result->Start; SI.ContentSize = Seg.ContentSize; SI.ZeroFillSize = Seg.ZeroFillSize; - SI.Prot = toSysMemoryProtectionFlags(AG.getMemProt()); + SI.AG = AG; SI.WorkingMem = Seg.WorkingMem; SegInfos.push_back(SI); diff --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp index 384b5ae14e21d4..7389d1e72562e1 100644 --- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp @@ -64,6 +64,7 @@ void InProcessMemoryMapper::initialize(MemoryMapper::AllocInfo &AI, ExecutorAddr MinAddr(~0ULL); ExecutorAddr MaxAddr(0); + // FIXME: Release finalize lifetime segments. for (auto &Segment : AI.Segments) { auto Base = AI.MappingBase + Segment.Offset; auto Size = Segment.ContentSize + Segment.ZeroFillSize; @@ -77,11 +78,12 @@ void InProcessMemoryMapper::initialize(MemoryMapper::AllocInfo &AI, std::memset((Base + Segment.ContentSize).toPtr(), 0, Segment.ZeroFillSize); - if (auto EC = sys::Memory::protectMappedMemory({Base.toPtr(), Size}, - Segment.Prot)) { + if (auto EC = sys::Memory::protectMappedMemory( + {Base.toPtr(), Size}, + toSysMemoryProtectionFlags(Segment.AG.getMemProt()))) { return OnInitialized(errorCodeToError(EC)); } - if (Segment.Prot & sys::Memory::MF_EXEC) + if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec) sys::Memory::InvalidateInstructionCache(Base.toPtr(), Size); } @@ -320,8 +322,7 @@ void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI, std::memset(Base + Segment.ContentSize, 0, Segment.ZeroFillSize); tpctypes::SharedMemorySegFinalizeRequest SegReq; - SegReq.Prot = tpctypes::toWireProtectionFlags( - static_cast(Segment.Prot)); + SegReq.AG = Segment.AG; SegReq.Addr = AI.MappingBase + Segment.Offset; SegReq.Size = Segment.ContentSize + Segment.ZeroFillSize; diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp index a8d5dc5a94e42d..d876c717881d50 100644 --- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp @@ -137,11 +137,11 @@ Expected ExecutorSharedMemoryMapperService::initialize( #if defined(LLVM_ON_UNIX) int NativeProt = 0; - if (Segment.Prot & tpctypes::WPF_Read) + if ((Segment.AG.getMemProt() & MemProt::Read) == MemProt::Read) NativeProt |= PROT_READ; - if (Segment.Prot & tpctypes::WPF_Write) + if ((Segment.AG.getMemProt() & MemProt::Write) == MemProt::Write) NativeProt |= PROT_WRITE; - if (Segment.Prot & tpctypes::WPF_Exec) + if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec) NativeProt |= PROT_EXEC; if (mprotect(Segment.Addr.toPtr(), Segment.Size, NativeProt)) @@ -158,7 +158,7 @@ Expected ExecutorSharedMemoryMapperService::initialize( #endif - if (Segment.Prot & tpctypes::WPF_Exec) + if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec) sys::Memory::InvalidateInstructionCache(Segment.Addr.toPtr(), Segment.Size); } diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp index c848dd65fa7e48..ce94bf1e039aad 100644 --- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp @@ -132,9 +132,9 @@ Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) { assert(Seg.Size <= std::numeric_limits::max()); if (auto EC = sys::Memory::protectMappedMemory( {Mem, static_cast(Seg.Size)}, - tpctypes::fromWireProtectionFlags(Seg.Prot))) + toSysMemoryProtectionFlags(Seg.AG.getMemProt()))) return BailOut(errorCodeToError(EC)); - if (Seg.Prot & tpctypes::WPF_Exec) + if ((Seg.AG.getMemProt() & MemProt::Exec) == MemProt::Exec) sys::Memory::InvalidateInstructionCache(Mem, Seg.Size); } diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp index 63b161ed73e0b9..bbb93ceb4b2432 100644 --- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp @@ -75,7 +75,8 @@ TEST(LinkGraphTest, AddressAccess) { LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write); + auto &Sec1 = + G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); orc::ExecutorAddr B1Addr(0x1000); auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0); auto &S1 = G.addDefinedSymbol(B1, 4, "S1", 4, Linkage::Strong, Scope::Default, @@ -92,7 +93,8 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) { // Check that we can iterate over blocks within Sections and across sections. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write); + auto &Sec1 = + G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); orc::ExecutorAddr B1Addr(0x1000); auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0); orc::ExecutorAddr B2Addr(0x2000); @@ -102,7 +104,8 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) { auto &S2 = G.addDefinedSymbol(B2, 4, "S2", 4, Linkage::Strong, Scope::Default, false, false); - auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write); + auto &Sec2 = + G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write); orc::ExecutorAddr B3Addr(0x3000); auto &B3 = G.createContentBlock(Sec2, BlockContent, B3Addr, 8, 0); orc::ExecutorAddr B4Addr(0x4000); @@ -143,7 +146,8 @@ TEST(LinkGraphTest, ContentAccessAndUpdate) { // Check that we can make a defined symbol external. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); // Create an initial block. orc::ExecutorAddr BAddr(0x1000); @@ -212,7 +216,8 @@ TEST(LinkGraphTest, MakeExternal) { // Check that we can make defined and absolute symbols external. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); // Create an initial block. auto &B1 = @@ -281,7 +286,8 @@ TEST(LinkGraphTest, MakeAbsolute) { // Check that we can make defined and external symbols absolute. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); // Create an initial block. auto &B1 = @@ -349,7 +355,8 @@ TEST(LinkGraphTest, MakeDefined) { // Check that we can make an external symbol defined. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); // Create an initial block. orc::ExecutorAddr B1Addr(0x1000); @@ -396,7 +403,8 @@ TEST(LinkGraphTest, TransferDefinedSymbol) { // Check that we can transfer a defined symbol from one block to another. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); // Create initial blocks. orc::ExecutorAddr B1Addr(0x1000); @@ -430,8 +438,10 @@ TEST(LinkGraphTest, TransferDefinedSymbolAcrossSections) { // section to another. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write); - auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write); + auto &Sec1 = + G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); + auto &Sec2 = + G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write); // Create blocks in each section. orc::ExecutorAddr B1Addr(0x1000); @@ -462,8 +472,10 @@ TEST(LinkGraphTest, TransferBlock) { // section to another. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write); - auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write); + auto &Sec1 = + G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); + auto &Sec2 = + G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write); // Create an initial block. orc::ExecutorAddr B1Addr(0x1000); @@ -508,9 +520,12 @@ TEST(LinkGraphTest, MergeSections) { // section to another. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write); - auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write); - auto &Sec3 = G.createSection("__data.3", MemProt::Read | MemProt::Write); + auto &Sec1 = + G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write); + auto &Sec2 = + G.createSection("__data.2", orc::MemProt::Read | orc::MemProt::Write); + auto &Sec3 = + G.createSection("__data.3", orc::MemProt::Read | orc::MemProt::Write); // Create an initial block. orc::ExecutorAddr B1Addr(0x1000); @@ -591,7 +606,8 @@ TEST(LinkGraphTest, SplitBlock) { // Check that the LinkGraph::splitBlock test works as expected. LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, getGenericEdgeKindName); - auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); // Create the block to split. orc::ExecutorAddr B1Addr(0x1000); diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp index ff326e0782f354..7a34dfc9e23047 100644 --- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp @@ -46,9 +46,9 @@ class SimpleAllocator { assert(Seg.Size <= std::numeric_limits::max()); if (auto EC = sys::Memory::protectMappedMemory( {Mem, static_cast(Seg.Size)}, - tpctypes::fromWireProtectionFlags(Seg.Prot))) + toSysMemoryProtectionFlags(Seg.AG.getMemProt()))) return errorCodeToError(EC); - if (Seg.Prot & tpctypes::WPF_Exec) + if ((Seg.AG.getMemProt() & MemProt::Exec) != MemProt::Exec) sys::Memory::InvalidateInstructionCache(Mem, Seg.Size); } return Error::success(); @@ -117,9 +117,9 @@ TEST(EPCGenericJITLinkMemoryManagerTest, AllocFinalizeFree) { StringRef Hello = "hello"; auto SSA = jitlink::SimpleSegmentAlloc::Create( - *MemMgr, nullptr, {{jitlink::MemProt::Read, {Hello.size(), Align(1)}}}); + *MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}}); EXPECT_THAT_EXPECTED(SSA, Succeeded()); - auto SegInfo = SSA->getSegInfo(jitlink::MemProt::Read); + auto SegInfo = SSA->getSegInfo(MemProt::Read); memcpy(SegInfo.WorkingMem.data(), Hello.data(), Hello.size()); auto FA = SSA->finalize(); diff --git a/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp index 94a7b4e2526e1a..46e558aad0d00a 100644 --- a/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp @@ -76,13 +76,13 @@ TEST(MapperJITLinkMemoryManagerTest, InProcess) { StringRef Hello = "hello"; auto SSA1 = jitlink::SimpleSegmentAlloc::Create( - *MemMgr, nullptr, {{jitlink::MemProt::Read, {Hello.size(), Align(1)}}}); + *MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}}); EXPECT_THAT_EXPECTED(SSA1, Succeeded()); EXPECT_EQ(Counter->ReserveCount, 1); EXPECT_EQ(Counter->InitCount, 0); - auto SegInfo1 = SSA1->getSegInfo(jitlink::MemProt::Read); + auto SegInfo1 = SSA1->getSegInfo(MemProt::Read); memcpy(SegInfo1.WorkingMem.data(), Hello.data(), Hello.size()); auto FA1 = SSA1->finalize(); @@ -92,14 +92,14 @@ TEST(MapperJITLinkMemoryManagerTest, InProcess) { EXPECT_EQ(Counter->InitCount, 1); auto SSA2 = jitlink::SimpleSegmentAlloc::Create( - *MemMgr, nullptr, {{jitlink::MemProt::Read, {Hello.size(), Align(1)}}}); + *MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}}); EXPECT_THAT_EXPECTED(SSA2, Succeeded()); // last reservation should be reused EXPECT_EQ(Counter->ReserveCount, 1); EXPECT_EQ(Counter->InitCount, 1); - auto SegInfo2 = SSA2->getSegInfo(jitlink::MemProt::Read); + auto SegInfo2 = SSA2->getSegInfo(MemProt::Read); memcpy(SegInfo2.WorkingMem.data(), Hello.data(), Hello.size()); auto FA2 = SSA2->finalize(); EXPECT_THAT_EXPECTED(FA2, Succeeded()); @@ -137,15 +137,15 @@ TEST(MapperJITLinkMemoryManagerTest, Coalescing) { std::move(Mapper)); auto SSA1 = jitlink::SimpleSegmentAlloc::Create( - *MemMgr, nullptr, {{jitlink::MemProt::Read, {1024, Align(1)}}}); + *MemMgr, nullptr, {{MemProt::Read, {1024, Align(1)}}}); EXPECT_THAT_EXPECTED(SSA1, Succeeded()); - auto SegInfo1 = SSA1->getSegInfo(jitlink::MemProt::Read); + auto SegInfo1 = SSA1->getSegInfo(MemProt::Read); ExecutorAddr TargetAddr1(SegInfo1.Addr); auto FA1 = SSA1->finalize(); EXPECT_THAT_EXPECTED(FA1, Succeeded()); auto SSA2 = jitlink::SimpleSegmentAlloc::Create( - *MemMgr, nullptr, {{jitlink::MemProt::Read, {1024, Align(1)}}}); + *MemMgr, nullptr, {{MemProt::Read, {1024, Align(1)}}}); EXPECT_THAT_EXPECTED(SSA2, Succeeded()); auto FA2 = SSA2->finalize(); EXPECT_THAT_EXPECTED(FA2, Succeeded()); @@ -157,10 +157,10 @@ TEST(MapperJITLinkMemoryManagerTest, Coalescing) { EXPECT_THAT_ERROR(std::move(Err3), Succeeded()); auto SSA3 = jitlink::SimpleSegmentAlloc::Create( - *MemMgr, nullptr, {{jitlink::MemProt::Read, {2048, Align(1)}}}); + *MemMgr, nullptr, {{MemProt::Read, {2048, Align(1)}}}); EXPECT_THAT_EXPECTED(SSA3, Succeeded()); - auto SegInfo3 = SSA3->getSegInfo(jitlink::MemProt::Read); + auto SegInfo3 = SSA3->getSegInfo(MemProt::Read); ExecutorAddr TargetAddr3(SegInfo3.Addr); auto FA3 = SSA3->finalize(); diff --git a/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp b/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp index 57a9fac77d84c8..e015bd09d354b6 100644 --- a/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/MemoryMapperTest.cpp @@ -92,7 +92,7 @@ TEST(MemoryMapperTest, InitializeDeinitialize) { Seg1.Offset = 0; Seg1.ContentSize = HW.size(); Seg1.ZeroFillSize = PageSize - Seg1.ContentSize; - Seg1.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE; + Seg1.AG = MemProt::Read | MemProt::Write; Alloc1.MappingBase = Mem1->Start; Alloc1.Segments.push_back(Seg1); @@ -116,7 +116,7 @@ TEST(MemoryMapperTest, InitializeDeinitialize) { Seg2.Offset = PageSize; Seg2.ContentSize = HW.size(); Seg2.ZeroFillSize = PageSize - Seg2.ContentSize; - Seg2.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE; + Seg2.AG = MemProt::Read | MemProt::Write; Alloc2.MappingBase = Mem1->Start; Alloc2.Segments.push_back(Seg2); @@ -168,7 +168,7 @@ TEST(MemoryMapperTest, InitializeDeinitialize) { Seg3.Offset = 0; Seg3.ContentSize = HW.size(); Seg3.ZeroFillSize = PageSize - Seg3.ContentSize; - Seg3.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE; + Seg3.AG = MemProt::Read | MemProt::Write; Alloc3.MappingBase = Mem2->Start; Alloc3.Segments.push_back(Seg3); diff --git a/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp b/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp index 9f44184ccc77b9..0fcc863c207d5a 100644 --- a/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp @@ -81,7 +81,7 @@ TEST(SharedMemoryMapperTest, MemReserveInitializeDeinitializeRelease) { SI.Offset = 0; SI.ContentSize = TestString.size() + 1; SI.ZeroFillSize = PageSize - SI.ContentSize; - SI.Prot = sys::Memory::MF_READ | sys::Memory::MF_WRITE; + SI.AG = MemProt::Read | MemProt::Write; AI.MappingBase = Reservation.Start; AI.Segments.push_back(SI); diff --git a/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp index f127e7713c5eb1..cb42bca3690b9a 100644 --- a/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/SimpleExecutorMemoryManagerTest.cpp @@ -45,7 +45,7 @@ TEST(SimpleExecutorMemoryManagerTest, AllocFinalizeFree) { tpctypes::FinalizeRequest FR; FR.Segments.push_back( - tpctypes::SegFinalizeRequest{tpctypes::WPF_Read | tpctypes::WPF_Write, + tpctypes::SegFinalizeRequest{MemProt::Read | MemProt::Write, *Mem, AllocSize, {HW.data(), HW.size() + 1}});