diff options
author | Lang Hames <lhames@gmail.com> | 2022-01-05 17:00:06 +1100 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2022-01-06 13:48:12 +1100 |
commit | 133f86e95492b2a00b944e070878424cfa73f87c (patch) | |
tree | 0a4c362d62f68957247c1a7f4d2a78aa039168c9 /llvm/lib/ExecutionEngine/Orc | |
parent | 9e2cfb061a8821236944b3c8f40641846ab6bc94 (diff) | |
download | llvm-133f86e95492b2a00b944e070878424cfa73f87c.zip llvm-133f86e95492b2a00b944e070878424cfa73f87c.tar.gz llvm-133f86e95492b2a00b944e070878424cfa73f87c.tar.bz2 |
[JITLink] Update JITLink to use ExecutorAddr rather than JITTargetAddress.
ExecutorAddr is the preferred representation for executor process addresses now.
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc')
9 files changed, 67 insertions, 64 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp index fcfe389..4ff6b7f 100644 --- a/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp +++ b/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp @@ -67,9 +67,9 @@ private: template <typename ELFT> void ELFDebugObjectSection<ELFT>::setTargetMemoryRange(SectionRange Range) { // Only patch load-addresses for executable and data sections. - if (isTextOrDataSection()) { - Header->sh_addr = static_cast<typename ELFT::uint>(Range.getStart()); - } + if (isTextOrDataSection()) + Header->sh_addr = + static_cast<typename ELFT::uint>(Range.getStart().getValue()); } template <typename ELFT> diff --git a/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp index fe62138..9265780 100644 --- a/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp +++ b/llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp @@ -129,8 +129,8 @@ public: Section *Sec = nullptr; StringRef SegName; StringRef SecName; - JITTargetAddress Alignment = 0; - JITTargetAddress StartAddr = 0; + uint64_t Alignment = 0; + orc::ExecutorAddr StartAddr; uint64_t Size = 0; }; @@ -153,7 +153,8 @@ public: return Error::success(); } DebugSecInfos.push_back({&Sec, Sec.getName().substr(0, SepPos), - Sec.getName().substr(SepPos + 1), 0, 0}); + Sec.getName().substr(SepPos + 1), 0, + orc::ExecutorAddr(), 0}); } else { NonDebugSections.push_back(&Sec); @@ -182,11 +183,11 @@ public: size_t ContainerBlockSize = sizeof(typename MachOTraits::Header) + SegmentLCSize; auto ContainerBlockContent = G.allocateBuffer(ContainerBlockSize); - MachOContainerBlock = - &G.createMutableContentBlock(SDOSec, ContainerBlockContent, 0, 8, 0); + MachOContainerBlock = &G.createMutableContentBlock( + SDOSec, ContainerBlockContent, orc::ExecutorAddr(), 8, 0); // Copy debug section blocks and symbols. - JITTargetAddress NextBlockAddr = MachOContainerBlock->getSize(); + orc::ExecutorAddr NextBlockAddr(MachOContainerBlock->getSize()); for (auto &SI : DebugSecInfos) { assert(!llvm::empty(SI.Sec->blocks()) && "Empty debug info section?"); @@ -219,7 +220,8 @@ public: G.mergeSections(SDOSec, *SI.Sec); SI.Sec = nullptr; } - size_t DebugSectionsSize = NextBlockAddr - MachOContainerBlock->getSize(); + size_t DebugSectionsSize = + NextBlockAddr - orc::ExecutorAddr(MachOContainerBlock->getSize()); // Write MachO header and debug section load commands. MachOStructWriter Writer(MachOContainerBlock->getAlreadyMutableContent()); @@ -266,9 +268,9 @@ public: memset(&Sec, 0, sizeof(Sec)); memcpy(Sec.sectname, SI.SecName.data(), SI.SecName.size()); memcpy(Sec.segname, SI.SegName.data(), SI.SegName.size()); - Sec.addr = SI.StartAddr; + Sec.addr = SI.StartAddr.getValue(); Sec.size = SI.Size; - Sec.offset = SI.StartAddr; + Sec.offset = SI.StartAddr.getValue(); Sec.align = SI.Alignment; Sec.reloff = 0; Sec.nreloc = 0; @@ -336,7 +338,7 @@ public: memset(&SecCmd, 0, sizeof(SecCmd)); memcpy(SecCmd.sectname, SecName.data(), SecName.size()); memcpy(SecCmd.segname, SegName.data(), SegName.size()); - SecCmd.addr = R.getStart(); + SecCmd.addr = R.getStart().getValue(); SecCmd.size = R.getSize(); SecCmd.offset = 0; SecCmd.align = R.getFirstBlock()->getAlignment(); @@ -348,7 +350,7 @@ public: SectionRange R(MachOContainerBlock->getSection()); G.allocActions().push_back( - {{RegisterActionAddr.getValue(), R.getStart(), R.getSize()}, {}}); + {{RegisterActionAddr, R.getStart(), R.getSize()}, {}}); return Error::success(); } diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp index eded54f..e25d7c4 100644 --- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp @@ -58,7 +58,8 @@ public: auto &DSOHandleSection = G->createSection(".data.__dso_handle", jitlink::MemProt::Read); auto &DSOHandleBlock = G->createContentBlock( - DSOHandleSection, getDSOHandleContent(PointerSize), 0, 8, 0); + DSOHandleSection, getDSOHandleContent(PointerSize), orc::ExecutorAddr(), + 8, 0); auto &DSOHandleSymbol = G->addDefinedSymbol( DSOHandleBlock, 0, *R->getInitializerSymbol(), DSOHandleBlock.getSize(), jitlink::Linkage::Strong, jitlink::Scope::Default, false, true); @@ -375,7 +376,7 @@ void ELFNixPlatform::rt_getDeinitializers( { std::lock_guard<std::mutex> Lock(PlatformMutex); - auto I = HandleAddrToJITDylib.find(Handle.getValue()); + auto I = HandleAddrToJITDylib.find(Handle); if (I != HandleAddrToJITDylib.end()) JD = I->second; } @@ -406,7 +407,7 @@ void ELFNixPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult, { std::lock_guard<std::mutex> Lock(PlatformMutex); - auto I = HandleAddrToJITDylib.find(Handle.getValue()); + auto I = HandleAddrToJITDylib.find(Handle); if (I != HandleAddrToJITDylib.end()) JD = I->second; } @@ -630,12 +631,11 @@ void ELFNixPlatform::ELFNixPlatformPlugin::addDSOHandleSupportPasses( assert(I != G.defined_symbols().end() && "Missing DSO handle symbol"); { std::lock_guard<std::mutex> Lock(MP.PlatformMutex); - JITTargetAddress HandleAddr = (*I)->getAddress(); + auto HandleAddr = (*I)->getAddress(); MP.HandleAddrToJITDylib[HandleAddr] = &JD; assert(!MP.InitSeqs.count(&JD) && "InitSeq entry for JD already exists"); MP.InitSeqs.insert(std::make_pair( - &JD, - ELFNixJITDylibInitializers(JD.getName(), ExecutorAddr(HandleAddr)))); + &JD, ELFNixJITDylibInitializers(JD.getName(), HandleAddr))); } return Error::success(); }); diff --git a/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp b/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp index 4c0fab8..99cacd1 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp @@ -56,17 +56,17 @@ EPCEHFrameRegistrar::Create(ExecutionSession &ES) { ExecutorAddr(DeregisterEHFrameWrapperFnAddr)); } -Error EPCEHFrameRegistrar::registerEHFrames(JITTargetAddress EHFrameSectionAddr, +Error EPCEHFrameRegistrar::registerEHFrames(ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize) { return ES.callSPSWrapper<void(SPSExecutorAddr, uint64_t)>( - RegisterEHFrameWrapperFnAddr, ExecutorAddr(EHFrameSectionAddr), + RegisterEHFrameWrapperFnAddr, EHFrameSectionAddr, static_cast<uint64_t>(EHFrameSectionSize)); } -Error EPCEHFrameRegistrar::deregisterEHFrames( - JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) { +Error EPCEHFrameRegistrar::deregisterEHFrames(ExecutorAddr EHFrameSectionAddr, + size_t EHFrameSectionSize) { return ES.callSPSWrapper<void(SPSExecutorAddr, uint64_t)>( - DeregisterEHFrameWrapperFnAddr, ExecutorAddr(EHFrameSectionAddr), + DeregisterEHFrameWrapperFnAddr, EHFrameSectionAddr, static_cast<uint64_t>(EHFrameSectionSize)); } diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp index 9b712cb..247be79 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp @@ -80,7 +80,7 @@ public: } else if (FinalizeErr) OnFinalize(std::move(FinalizeErr)); else - OnFinalize(FinalizedAlloc(AllocAddr.getValue())); + OnFinalize(FinalizedAlloc(AllocAddr)); }, Parent.SAs.Allocator, std::move(FR)); } @@ -161,7 +161,7 @@ void EPCGenericJITLinkMemoryManager::completeAllocation( const auto &AG = KV.first; auto &Seg = KV.second; - Seg.Addr = NextSegAddr.getValue(); + Seg.Addr = NextSegAddr; KV.second.WorkingMem = BL.getGraph().allocateBuffer(Seg.ContentSize).data(); NextSegAddr += ExecutorAddrDiff( alignTo(Seg.ContentSize + Seg.ZeroFillSize, EPC.getPageSize())); diff --git a/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp index 818b6b5..b901a2d 100644 --- a/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp @@ -119,10 +119,12 @@ Error EPCTrampolinePool::grow() { unsigned NumTrampolines = TrampolinesPerPage; auto SegInfo = Alloc->getSegInfo(MemProt::Read | MemProt::Exec); - EPCIU.getABISupport().writeTrampolines( - SegInfo.WorkingMem.data(), SegInfo.Addr, ResolverAddress, NumTrampolines); + EPCIU.getABISupport().writeTrampolines(SegInfo.WorkingMem.data(), + SegInfo.Addr.getValue(), + ResolverAddress, NumTrampolines); for (unsigned I = 0; I < NumTrampolines; ++I) - AvailableTrampolines.push_back(SegInfo.Addr + (I * TrampolineSize)); + AvailableTrampolines.push_back(SegInfo.Addr.getValue() + + (I * TrampolineSize)); auto FA = Alloc->finalize(); if (!FA) @@ -300,15 +302,15 @@ EPCIndirectionUtils::writeResolverBlock(JITTargetAddress ReentryFnAddr, return Alloc.takeError(); auto SegInfo = Alloc->getSegInfo(MemProt::Read | MemProt::Exec); - ABI->writeResolverCode(SegInfo.WorkingMem.data(), SegInfo.Addr, ReentryFnAddr, - ReentryCtxAddr); + ABI->writeResolverCode(SegInfo.WorkingMem.data(), SegInfo.Addr.getValue(), + ReentryFnAddr, ReentryCtxAddr); auto FA = Alloc->finalize(); if (!FA) return FA.takeError(); ResolverBlock = std::move(*FA); - return SegInfo.Addr; + return SegInfo.Addr.getValue(); } std::unique_ptr<IndirectStubsManager> @@ -369,8 +371,9 @@ EPCIndirectionUtils::getIndirectStubs(unsigned NumStubs) { auto StubSeg = Alloc->getSegInfo(StubProt); auto PtrSeg = Alloc->getSegInfo(PtrProt); - ABI->writeIndirectStubsBlock(StubSeg.WorkingMem.data(), StubSeg.Addr, - PtrSeg.Addr, NumStubsToAllocate); + ABI->writeIndirectStubsBlock(StubSeg.WorkingMem.data(), + StubSeg.Addr.getValue(), + PtrSeg.Addr.getValue(), NumStubsToAllocate); auto FA = Alloc->finalize(); if (!FA) @@ -381,8 +384,8 @@ EPCIndirectionUtils::getIndirectStubs(unsigned NumStubs) { auto StubExecutorAddr = StubSeg.Addr; auto PtrExecutorAddr = PtrSeg.Addr; for (unsigned I = 0; I != NumStubsToAllocate; ++I) { - AvailableIndirectStubs.push_back( - IndirectStubInfo(StubExecutorAddr, PtrExecutorAddr)); + AvailableIndirectStubs.push_back(IndirectStubInfo( + StubExecutorAddr.getValue(), PtrExecutorAddr.getValue())); StubExecutorAddr += ABI->getStubSize(); PtrExecutorAddr += ABI->getPointerSize(); } diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index f427271..7a71d2f 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -410,7 +410,7 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, while (I < Content.size()) { MCInst Instr; uint64_t InstrSize = 0; - uint64_t InstrStart = SymAddress + I; + uint64_t InstrStart = SymAddress.getValue() + I; auto DecodeStatus = Disassembler.getInstruction( Instr, InstrSize, Content.drop_front(I), InstrStart, CommentStream); if (DecodeStatus != MCDisassembler::Success) { @@ -426,7 +426,7 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, // Check for a PC-relative address equal to the symbol itself. auto PCRelAddr = MIA.evaluateMemoryOperandAddress(Instr, &STI, InstrStart, InstrSize); - if (!PCRelAddr.hasValue() || PCRelAddr.getValue() != SymAddress) + if (!PCRelAddr || *PCRelAddr != SymAddress.getValue()) continue; auto RelocOffInInstr = @@ -438,8 +438,8 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, continue; } - auto RelocOffInBlock = - InstrStart + *RelocOffInInstr - SymAddress + Sym.getOffset(); + auto RelocOffInBlock = orc::ExecutorAddr(InstrStart) + *RelocOffInInstr - + SymAddress + Sym.getOffset(); if (ExistingRelocations.contains(RelocOffInBlock)) continue; diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index fb2e90e..ab978ed 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -106,7 +106,8 @@ private: auto HeaderContent = G.allocateString( StringRef(reinterpret_cast<const char *>(&Hdr), sizeof(Hdr))); - return G.createContentBlock(HeaderSection, HeaderContent, 0, 8, 0); + return G.createContentBlock(HeaderSection, HeaderContent, + orc::ExecutorAddr(), 8, 0); } static MaterializationUnit::Interface @@ -439,7 +440,7 @@ void MachOPlatform::rt_getDeinitializers(SendDeinitializerSequenceFn SendResult, { std::lock_guard<std::mutex> Lock(PlatformMutex); - auto I = HeaderAddrToJITDylib.find(Handle.getValue()); + auto I = HeaderAddrToJITDylib.find(Handle); if (I != HeaderAddrToJITDylib.end()) JD = I->second; } @@ -469,7 +470,7 @@ void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult, { std::lock_guard<std::mutex> Lock(PlatformMutex); - auto I = HeaderAddrToJITDylib.find(Handle.getValue()); + auto I = HeaderAddrToJITDylib.find(Handle); if (I != HeaderAddrToJITDylib.end()) JD = I->second; } @@ -661,11 +662,11 @@ Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol( auto &JD = MR.getTargetJITDylib(); std::lock_guard<std::mutex> Lock(MP.PlatformMutex); - JITTargetAddress HeaderAddr = (*I)->getAddress(); + auto HeaderAddr = (*I)->getAddress(); MP.HeaderAddrToJITDylib[HeaderAddr] = &JD; assert(!MP.InitSeqs.count(&JD) && "InitSeq entry for JD already exists"); - MP.InitSeqs.insert(std::make_pair( - &JD, MachOJITDylibInitializers(JD.getName(), ExecutorAddr(HeaderAddr)))); + MP.InitSeqs.insert( + std::make_pair(&JD, MachOJITDylibInitializers(JD.getName(), HeaderAddr))); return Error::success(); } @@ -792,7 +793,7 @@ Error MachOPlatform::MachOPlatformPlugin::registerInitSections( if (auto *ObjCImageInfoSec = G.findSectionByName(ObjCImageInfoSectionName)) { if (auto Addr = jitlink::SectionRange(*ObjCImageInfoSec).getStart()) - ObjCImageInfoAddr.setValue(Addr); + ObjCImageInfoAddr = Addr; } for (auto InitSectionName : InitSectionNames) @@ -879,11 +880,10 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections( if (auto *EHFrameSection = G.findSectionByName(EHFrameSectionName)) { jitlink::SectionRange R(*EHFrameSection); if (!R.empty()) - G.allocActions().push_back( - {{MP.orc_rt_macho_register_ehframe_section.getValue(), R.getStart(), - R.getSize()}, - {MP.orc_rt_macho_deregister_ehframe_section.getValue(), R.getStart(), - R.getSize()}}); + G.allocActions().push_back({{MP.orc_rt_macho_register_ehframe_section, + R.getStart(), R.getSize()}, + {MP.orc_rt_macho_deregister_ehframe_section, + R.getStart(), R.getSize()}}); } // Get a pointer to the thread data section if there is one. It will be used @@ -913,10 +913,10 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections( inconvertibleErrorCode()); G.allocActions().push_back( - {{MP.orc_rt_macho_register_thread_data_section.getValue(), - R.getStart(), R.getSize()}, - {MP.orc_rt_macho_deregister_thread_data_section.getValue(), - R.getStart(), R.getSize()}}); + {{MP.orc_rt_macho_register_thread_data_section, R.getStart(), + R.getSize()}, + {MP.orc_rt_macho_deregister_thread_data_section, R.getStart(), + R.getSize()}}); } } return Error::success(); @@ -963,10 +963,8 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHSectionsPhase1( // Otherwise, add allocation actions to the graph to register eh-frames for // this object. G.allocActions().push_back( - {{orc_rt_macho_register_ehframe_section.getValue(), R.getStart(), - R.getSize()}, - {orc_rt_macho_deregister_ehframe_section.getValue(), R.getStart(), - R.getSize()}}); + {{orc_rt_macho_register_ehframe_section, R.getStart(), R.getSize()}, + {orc_rt_macho_deregister_ehframe_section, R.getStart(), R.getSize()}}); return Error::success(); } diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp index 0d6a33c..8b4347f 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -217,7 +217,7 @@ public: Flags |= JITSymbolFlags::Exported; InternedResult[InternedName] = - JITEvaluatedSymbol(Sym->getAddress(), Flags); + JITEvaluatedSymbol(Sym->getAddress().getValue(), Flags); if (AutoClaim && !MR->getSymbols().count(InternedName)) { assert(!ExtraSymbolsToClaim.count(InternedName) && "Duplicate symbol to claim?"); @@ -235,7 +235,7 @@ public: if (Sym->getLinkage() == Linkage::Weak) Flags |= JITSymbolFlags::Weak; InternedResult[InternedName] = - JITEvaluatedSymbol(Sym->getAddress(), Flags); + JITEvaluatedSymbol(Sym->getAddress().getValue(), Flags); if (AutoClaim && !MR->getSymbols().count(InternedName)) { assert(!ExtraSymbolsToClaim.count(InternedName) && "Duplicate symbol to claim?"); @@ -743,7 +743,7 @@ void EHFrameRegistrationPlugin::modifyPassConfig( PassConfiguration &PassConfig) { PassConfig.PostFixupPasses.push_back(createEHFrameRecorderPass( - G.getTargetTriple(), [this, &MR](JITTargetAddress Addr, size_t Size) { + G.getTargetTriple(), [this, &MR](ExecutorAddr Addr, size_t Size) { if (Addr) { std::lock_guard<std::mutex> Lock(EHFramePluginMutex); assert(!InProcessLinks.count(&MR) && |