diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index fdf5ef8046a980..1123b35a4cd76f 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -704,11 +704,11 @@ class Section { /// Set the protection flags for this section. void setMemProt(orc::MemProt Prot) { this->Prot = Prot; } - /// Get the memory lifetime policy for this section. - orc::MemLifetimePolicy getMemLifetimePolicy() const { return MLP; } + /// Get the deallocation policy for this section. + orc::MemDeallocPolicy getMemDeallocPolicy() const { return MDP; } - /// Set the memory lifetime policy for this section. - void setMemLifetimePolicy(orc::MemLifetimePolicy MLP) { this->MLP = MLP; } + /// Set the deallocation policy for this section. + void setMemDeallocPolicy(orc::MemDeallocPolicy MDP) { this->MDP = MDP; } /// Returns the ordinal for this section. SectionOrdinal getOrdinal() const { return SecOrdinal; } @@ -773,7 +773,7 @@ class Section { StringRef Name; orc::MemProt Prot; - orc::MemLifetimePolicy MLP = orc::MemLifetimePolicy::Standard; + orc::MemDeallocPolicy MDP = orc::MemDeallocPolicy::Standard; SectionOrdinal SecOrdinal = 0; BlockSet Blocks; SymbolSet Symbols; diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h index 09e0d71cf0bd29..6ef4a0bd0c982d 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h @@ -291,9 +291,6 @@ class BasicLayout { /// Segment. Clients can obtain a pointer to the working memory and executor /// address of that block using the Segment's AllocGroup. Once memory has been /// populated, clients can call finalize to finalize the memory. -/// -/// Note: Segments with MemLifetimePolicy::NoAlloc are not permitted, since -/// they would not be useful, and their presence is likely to indicate a bug. class SimpleSegmentAlloc { public: /// Describes a segment to be allocated. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h index c20366cfbb3888..2642e6c241b6e7 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h @@ -65,43 +65,26 @@ inline MemProt fromSysMemoryProtectionFlags(sys::Memory::ProtectionFlags PF) { return MP; } -/// Describes a memory lifetime policy for memory to be allocated by a +/// Describes a memory deallocation policy for memory to be allocated by a /// JITLinkMemoryManager. /// /// All memory allocated by a call to JITLinkMemoryManager::allocate should be /// deallocated if a call is made to /// JITLinkMemoryManager::InFlightAllocation::abandon. The policies below apply /// to finalized allocations. -enum class MemLifetimePolicy { - /// Standard memory should be allocated by the allocator and then deallocated - /// when the deallocate method is called for the finalized allocation. +enum class MemDeallocPolicy { + /// Standard memory should be deallocated when the deallocate method is called + /// for the finalized allocation. Standard, - /// Finalize memory should be allocated by the allocator, and then be - /// overwritten and deallocated after all finalization functions have been - /// run. - Finalize, - - /// NoAlloc memory should not be allocated by the JITLinkMemoryManager at - /// all. It is used for sections that don't need to be transferred to the - /// executor process, typically metadata sections. - NoAlloc + /// Finalize memory should be overwritten and then deallocated after all + /// finalization functions have been run. + Finalize }; /// Print a MemDeallocPolicy. -inline raw_ostream &operator<<(raw_ostream &OS, MemLifetimePolicy MLP) { - switch (MLP) { - case MemLifetimePolicy::Standard: - OS << "standard"; - break; - case MemLifetimePolicy::Finalize: - OS << "finalize"; - break; - case MemLifetimePolicy::NoAlloc: - OS << "noalloc"; - break; - } - return OS; +inline raw_ostream &operator<<(raw_ostream &OS, MemDeallocPolicy MDP) { + return OS << (MDP == MemDeallocPolicy::Standard ? "standard" : "finalize"); } /// A pair of memory protections and allocation policies. @@ -112,34 +95,34 @@ class AllocGroup { using underlying_type = uint8_t; static constexpr unsigned BitsForProt = 3; - static constexpr unsigned BitsForLifetimePolicy = 2; + static constexpr unsigned BitsForDeallocPolicy = 1; static constexpr unsigned MaxIdentifiers = - 1U << (BitsForProt + BitsForLifetimePolicy); + 1U << (BitsForProt + BitsForDeallocPolicy); public: static constexpr unsigned NumGroups = MaxIdentifiers; /// Create a default AllocGroup. No memory protections, standard - /// lifetime policy. + /// deallocation policy. AllocGroup() = default; /// Create an AllocGroup from a MemProt only -- uses - /// MemLifetimePolicy::Standard. + /// MemoryDeallocationPolicy::Standard. AllocGroup(MemProt MP) : Id(static_cast(MP)) {} - /// Create an AllocGroup from a MemProt and a MemLifetimePolicy. - AllocGroup(MemProt MP, MemLifetimePolicy MLP) + /// Create an AllocGroup from a MemProt and a MemoryDeallocationPolicy. + AllocGroup(MemProt MP, MemDeallocPolicy MDP) : Id(static_cast(MP) | - (static_cast(MLP) << BitsForProt)) {} + (static_cast(MDP) << BitsForProt)) {} /// Returns the MemProt for this group. MemProt getMemProt() const { return static_cast(Id & ((1U << BitsForProt) - 1)); } - /// Returns the MemLifetimePolicy for this group. - MemLifetimePolicy getMemLifetimePolicy() const { - return static_cast(Id >> BitsForProt); + /// Returns the MemoryDeallocationPolicy for this group. + MemDeallocPolicy getMemDeallocPolicy() const { + return static_cast(Id >> BitsForProt); } friend bool operator==(const AllocGroup &LHS, const AllocGroup &RHS) { @@ -203,7 +186,7 @@ template class AllocGroupSmallMap { /// Print an AllocGroup. inline raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG) { - return OS << '(' << AG.getMemProt() << ", " << AG.getMemLifetimePolicy() + return OS << '(' << AG.getMemProt() << ", " << AG.getMemDeallocPolicy() << ')'; } diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h index 09c73db44a947b..565fb5477c4af2 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h @@ -30,24 +30,8 @@ namespace llvm { namespace orc { namespace tpctypes { -struct RemoteAllocGroup { - RemoteAllocGroup() = default; - RemoteAllocGroup(MemProt Prot) : Prot(Prot) {} - RemoteAllocGroup(MemProt Prot, bool FinalizeLifetime) - : Prot(Prot), FinalizeLifetime(FinalizeLifetime) {} - RemoteAllocGroup(const AllocGroup &AG) : Prot(AG.getMemProt()) { - assert(AG.getMemLifetimePolicy() != orc::MemLifetimePolicy::NoAlloc && - "Cannot use no-alloc memory in a remote alloc request"); - FinalizeLifetime = - AG.getMemLifetimePolicy() == orc::MemLifetimePolicy::Finalize; - } - - MemProt Prot; - bool FinalizeLifetime = false; -}; - struct SegFinalizeRequest { - RemoteAllocGroup RAG; + AllocGroup AG; ExecutorAddr Addr; uint64_t Size; ArrayRef Content; @@ -59,7 +43,7 @@ struct FinalizeRequest { }; struct SharedMemorySegFinalizeRequest { - RemoteAllocGroup RAG; + AllocGroup AG; ExecutorAddr Addr; uint64_t Size; }; @@ -109,16 +93,16 @@ using LookupResult = std::vector; namespace shared { -class SPSRemoteAllocGroup; +class SPSAllocGroup {}; using SPSSegFinalizeRequest = - SPSTuple>; + SPSTuple>; using SPSFinalizeRequest = SPSTuple, SPSSequence>; using SPSSharedMemorySegFinalizeRequest = - SPSTuple; + SPSTuple; using SPSSharedMemoryFinalizeRequest = SPSTuple, @@ -134,8 +118,7 @@ using SPSMemoryAccessUInt64Write = SPSMemoryAccessUIntWrite; using SPSMemoryAccessBufferWrite = SPSTuple>; -template <> -class SPSSerializationTraits { +template <> class SPSSerializationTraits { enum WireBits { ReadBit = 1 << 0, WriteBit = 1 << 1, @@ -144,26 +127,25 @@ class SPSSerializationTraits { }; public: - static size_t size(const tpctypes::RemoteAllocGroup &RAG) { + 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::RemoteAllocGroup &RAG) { + static bool serialize(SPSOutputBuffer &OB, const AllocGroup &AG) { uint8_t WireValue = 0; - if ((RAG.Prot & MemProt::Read) != MemProt::None) + if ((AG.getMemProt() & MemProt::Read) != MemProt::None) WireValue |= ReadBit; - if ((RAG.Prot & MemProt::Write) != MemProt::None) + if ((AG.getMemProt() & MemProt::Write) != MemProt::None) WireValue |= WriteBit; - if ((RAG.Prot & MemProt::Exec) != MemProt::None) + if ((AG.getMemProt() & MemProt::Exec) != MemProt::None) WireValue |= ExecBit; - if (RAG.FinalizeLifetime) + if (AG.getMemDeallocPolicy() == MemDeallocPolicy::Finalize) WireValue |= FinalizeBit; return SPSArgList::serialize(OB, WireValue); } - static bool deserialize(SPSInputBuffer &IB, tpctypes::RemoteAllocGroup &RAG) { + static bool deserialize(SPSInputBuffer &IB, AllocGroup &AG) { uint8_t Val; if (!SPSArgList::deserialize(IB, Val)) return false; @@ -174,8 +156,9 @@ class SPSSerializationTraits { MP |= MemProt::Write; if (Val & ExecBit) MP |= MemProt::Exec; - bool FinalizeLifetime = (Val & FinalizeBit) ? true : false; - RAG = {MP, FinalizeLifetime}; + MemDeallocPolicy MDP = (Val & FinalizeBit) ? MemDeallocPolicy::Finalize + : MemDeallocPolicy::Standard; + AG = AllocGroup(MP, MDP); return true; } }; @@ -187,17 +170,17 @@ class SPSSerializationTraitsfindSectionByName(SectionName); - if (!GraphSec) { + if (!GraphSec) GraphSec = &G->createSection(SectionName, Prot); - if ((*Sec)->Characteristics & COFF::IMAGE_SCN_LNK_REMOVE) - GraphSec->setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc); - } if (GraphSec->getMemProt() != Prot) return make_error("MemProt should match"); diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h index 9393607b6796e4..953a9f512784b5 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -319,6 +319,16 @@ template Error ELFLinkGraphBuilder::graphifySections() { continue; } + // Skip non-SHF_ALLOC sections + if (!(Sec.sh_flags & ELF::SHF_ALLOC)) { + LLVM_DEBUG({ + dbgs() << " " << SecIndex << ": \"" << *Name + << "\" is not an SHF_ALLOC section: " + "No graph section will be created.\n"; + }); + continue; + } + LLVM_DEBUG({ dbgs() << " " << SecIndex << ": Creating section for \"" << *Name << "\"\n"; @@ -333,19 +343,8 @@ template Error ELFLinkGraphBuilder::graphifySections() { // Look for existing sections first. auto *GraphSec = G->findSectionByName(*Name); - if (!GraphSec) { + if (!GraphSec) GraphSec = &G->createSection(*Name, Prot); - // Non-SHF_ALLOC sections get NoAlloc memory lifetimes. - if (!(Sec.sh_flags & ELF::SHF_ALLOC)) { - GraphSec->setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc); - LLVM_DEBUG({ - dbgs() << " " << SecIndex << ": \"" << *Name - << "\" is not a SHF_ALLOC section. Using NoAlloc lifetime"; - }); - } - continue; - } - assert(GraphSec->getMemProt() == Prot && "MemProt should match"); Block *B = nullptr; diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h index e69eddd6e11944..2c924452653643 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h @@ -123,47 +123,26 @@ template class JITLinker : public JITLinkerBase { Error fixUpBlocks(LinkGraph &G) const override { LLVM_DEBUG(dbgs() << "Fixing up blocks:\n"); - for (auto &Sec : G.sections()) { - bool NoAllocSection = - Sec.getMemLifetimePolicy() == orc::MemLifetimePolicy::NoAlloc; - - for (auto *B : Sec.blocks()) { - LLVM_DEBUG(dbgs() << " " << *B << ":\n"); - - // Copy Block data and apply fixups. - LLVM_DEBUG(dbgs() << " Applying fixups.\n"); - assert((!B->isZeroFill() || all_of(B->edges(), - [](const Edge &E) { - return E.getKind() == - Edge::KeepAlive; - })) && - "Non-KeepAlive edges in zero-fill block?"); - - // If this is a no-alloc section then copy the block content into - // memory allocated on the Graph's allocator (if it hasn't been - // already). - if (NoAllocSection) - (void)B->getMutableContent(G); - - for (auto &E : B->edges()) { - - // Skip non-relocation edges. - if (!E.isRelocation()) - continue; - - // If B is a block in a Standard or Finalize section then make sure - // that no edges point to symbols in NoAlloc sections. - assert( - (NoAllocSection || !E.getTarget().isDefined() || - E.getTarget().getBlock().getSection().getMemLifetimePolicy() != - orc::MemLifetimePolicy::NoAlloc) && - "Block in allocated section has edge pointing to no-alloc " - "section"); - - // Dispatch to LinkerImpl for fixup. - if (auto Err = impl().applyFixup(G, *B, E)) - return Err; - } + for (auto *B : G.blocks()) { + LLVM_DEBUG(dbgs() << " " << *B << ":\n"); + + // Copy Block data and apply fixups. + LLVM_DEBUG(dbgs() << " Applying fixups.\n"); + assert((!B->isZeroFill() || all_of(B->edges(), + [](const Edge &E) { + return E.getKind() == + Edge::KeepAlive; + })) && + "Non-KeepAlive edges in zero-fill block?"); + for (auto &E : B->edges()) { + + // Skip non-relocation edges. + if (!E.isRelocation()) + continue; + + // Dispatch to LinkerImpl for fixup. + if (auto Err = impl().applyFixup(G, *B, E)) + return Err; } } diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp index f481504135a5fb..e74aa059f40542 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp @@ -24,12 +24,11 @@ JITLinkMemoryManager::InFlightAlloc::~InFlightAlloc() = default; BasicLayout::BasicLayout(LinkGraph &G) : G(G) { for (auto &Sec : G.sections()) { - // Skip empty sections, and sections with NoAlloc lifetime policies. - if (Sec.blocks().empty() || - Sec.getMemLifetimePolicy() == orc::MemLifetimePolicy::NoAlloc) + // Skip empty sections. + if (Sec.blocks().empty()) continue; - auto &Seg = Segments[{Sec.getMemProt(), Sec.getMemLifetimePolicy()}]; + auto &Seg = Segments[{Sec.getMemProt(), Sec.getMemDeallocPolicy()}]; for (auto *B : Sec.blocks()) if (LLVM_LIKELY(!B->isZeroFill())) Seg.ContentBlocks.push_back(B); @@ -90,7 +89,7 @@ BasicLayout::getContiguousPageBasedLayoutSizes(uint64_t PageSize) { inconvertibleErrorCode()); uint64_t SegSize = alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize); - if (AG.getMemLifetimePolicy() == orc::MemLifetimePolicy::Standard) + if (AG.getMemDeallocPolicy() == orc::MemDeallocPolicy::Standard) SegsSizes.StandardSegs += SegSize; else SegsSizes.FinalizeSegs += SegSize; @@ -147,7 +146,7 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD, SegmentMap Segments, OnCreatedFunction OnCreated) { - static_assert(orc::AllocGroup::NumGroups == 32, + static_assert(orc::AllocGroup::NumGroups == 16, "AllocGroup has changed. Section names below must be updated"); StringRef AGSectionNames[] = { "__---.standard", "__R--.standard", "__-W-.standard", "__RW-.standard", @@ -164,15 +163,12 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr, auto &AG = KV.first; auto &Seg = KV.second; - assert(AG.getMemLifetimePolicy() != orc::MemLifetimePolicy::NoAlloc && - "NoAlloc segments are not supported by SimpleSegmentAlloc"); - auto AGSectionName = AGSectionNames[static_cast(AG.getMemProt()) | - static_cast(AG.getMemLifetimePolicy()) << 3]; + static_cast(AG.getMemDeallocPolicy()) << 3]; auto &Sec = G->createSection(AGSectionName, AG.getMemProt()); - Sec.setMemLifetimePolicy(AG.getMemLifetimePolicy()); + Sec.setMemDeallocPolicy(AG.getMemDeallocPolicy()); if (Seg.ContentSize != 0) { NextAddr = @@ -420,7 +416,7 @@ void InProcessMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G, auto &Seg = KV.second; auto &SegAddr = - (AG.getMemLifetimePolicy() == orc::MemLifetimePolicy::Standard) + (AG.getMemDeallocPolicy() == orc::MemDeallocPolicy::Standard) ? NextStandardSegAddr : NextFinalizeSegAddr; diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp index 385230c53f9144..bdf0eb60128921 100644 --- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp @@ -189,10 +189,6 @@ Error MachOLinkGraphBuilder::createNormalizedSections() { NSec.GraphSection = &G->createSection( StringRef(FullyQualifiedName.data(), FullyQualifiedName.size()), Prot); - // TODO: Are there any other criteria for NoAlloc lifetime? - if (NSec.Flags & MachO::S_ATTR_DEBUG) - NSec.GraphSection->setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc); - IndexToSection.insert(std::make_pair(SecIndex, std::move(NSec))); } diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp index fbe25d70c38a28..ec82081937e220 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.cpp @@ -235,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.RAG = SegMemProts[I]; + Seg.AG = SegMemProts[I]; Seg.Addr = RemoteAddrs[I]->Start; for (auto &SecAlloc : *SegSections[I]) { Seg.Size = alignTo(Seg.Size, SecAlloc.Align); diff --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp index ca4950077ffe92..b457c7297bed66 100644 --- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp @@ -322,8 +322,7 @@ void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI, std::memset(Base + Segment.ContentSize, 0, Segment.ZeroFillSize); tpctypes::SharedMemorySegFinalizeRequest SegReq; - SegReq.RAG = {Segment.AG.getMemProt(), Segment.AG.getMemLifetimePolicy() == - MemLifetimePolicy::Finalize}; + 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 3f70dbf60437a5..147f915f61d6a9 100644 --- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp @@ -132,11 +132,11 @@ Expected ExecutorSharedMemoryMapperService::initialize( #if defined(LLVM_ON_UNIX) int NativeProt = 0; - if ((Segment.RAG.Prot & MemProt::Read) == MemProt::Read) + if ((Segment.AG.getMemProt() & MemProt::Read) == MemProt::Read) NativeProt |= PROT_READ; - if ((Segment.RAG.Prot & MemProt::Write) == MemProt::Write) + if ((Segment.AG.getMemProt() & MemProt::Write) == MemProt::Write) NativeProt |= PROT_WRITE; - if ((Segment.RAG.Prot & MemProt::Exec) == MemProt::Exec) + if ((Segment.AG.getMemProt() & MemProt::Exec) == MemProt::Exec) NativeProt |= PROT_EXEC; if (mprotect(Segment.Addr.toPtr(), Segment.Size, NativeProt)) @@ -144,7 +144,8 @@ Expected ExecutorSharedMemoryMapperService::initialize( #elif defined(_WIN32) - DWORD NativeProt = getWindowsProtectionFlags(Segment.RAG.Prot); + DWORD NativeProt = + getWindowsProtectionFlags(Segment.AG.getMemProt()); if (!VirtualProtect(Segment.Addr.toPtr(), Segment.Size, NativeProt, &NativeProt)) @@ -152,7 +153,7 @@ Expected ExecutorSharedMemoryMapperService::initialize( #endif - if ((Segment.RAG.Prot & MemProt::Exec) == MemProt::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 4da031716e32ab..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)}, - toSysMemoryProtectionFlags(Seg.RAG.Prot))) + toSysMemoryProtectionFlags(Seg.AG.getMemProt()))) return BailOut(errorCodeToError(EC)); - if ((Seg.RAG.Prot & MemProt::Exec) == MemProt::Exec) + if ((Seg.AG.getMemProt() & MemProt::Exec) == MemProt::Exec) sys::Memory::InvalidateInstructionCache(Mem, Seg.Size); } diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 5e91ad068cdbcf..be0fe1750a7181 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -511,7 +511,8 @@ class InProcessDeltaMapper final : public InProcessMemoryMapper { auto FixedAI = std::move(AI); FixedAI.MappingBase -= DeltaAddr; for (auto &Seg : FixedAI.Segments) - Seg.AG = {MemProt::Read | MemProt::Write, Seg.AG.getMemLifetimePolicy()}; + Seg.AG = AllocGroup(MemProt::Read | MemProt::Write, + Seg.AG.getMemDeallocPolicy()); FixedAI.Actions.clear(); InProcessMemoryMapper::initialize( FixedAI, [this, OnInitialized = std::move(OnInitialized)]( diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp index 0146c3b4cf6e02..80f557122ec207 100644 --- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp @@ -756,31 +756,3 @@ TEST(LinkGraphTest, IsCStringBlockTest) { EXPECT_TRUE(isCStringBlock(SizeOneZeroFillBlock)); EXPECT_FALSE(isCStringBlock(LargerZeroFillBlock)); } - -TEST(LinkGraphTest, BasicLayoutHonorsNoAlloc) { - // Check that BasicLayout honors NoAlloc. - LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little, - getGenericEdgeKindName); - - // Create a regular section and block. - auto &Sec1 = - G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); - G.createContentBlock(Sec1, BlockContent.slice(0, 8), orc::ExecutorAddr(), 8, - 0); - - // Create a NoAlloc section and block. - auto &Sec2 = - G.createSection("__metadata", orc::MemProt::Read | orc::MemProt::Write); - Sec2.setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc); - G.createContentBlock(Sec2, BlockContent.slice(0, 8), orc::ExecutorAddr(), 8, - 0); - - BasicLayout BL(G); - - EXPECT_EQ(std::distance(BL.segments().begin(), BL.segments().end()), 1U); - EXPECT_EQ(BL.segments().begin()->first, - orc::MemProt::Read | orc::MemProt::Write); - auto &SegInfo = BL.segments().begin()->second; - EXPECT_EQ(SegInfo.Alignment, 8U); - EXPECT_EQ(SegInfo.ContentSize, 8U); -} diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp index d3a66294bd5719..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)}, - toSysMemoryProtectionFlags(Seg.RAG.Prot))) + toSysMemoryProtectionFlags(Seg.AG.getMemProt()))) return errorCodeToError(EC); - if ((Seg.RAG.Prot & MemProt::Exec) != MemProt::Exec) + if ((Seg.AG.getMemProt() & MemProt::Exec) != MemProt::Exec) sys::Memory::InvalidateInstructionCache(Mem, Seg.Size); } return Error::success();