Lines Matching +full:actions +full:- +full:builder

1 //===------ MachOPlatform.cpp - Utilities for executing MachO in Orc ------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
103 // Creates a Bootstrap-Complete LinkGraph to run deferred actions.
138 G->createSection("__orc_rt_cplt_bs", MemProt::Read);
140 G->createZeroFillBlock(PlaceholderSection, 1, ExecutorAddr(), 1, 0);
141 G->addDefinedSymbol(PlaceholderBlock, 0, *CompleteBootstrapSymbol, 1,
144 // Reserve space for the stolen actions, plus two extras.
145 G->allocActions().reserve(DeferredAAs.size() + 3);
148 G->allocActions().push_back(
154 G->allocActions().push_back(
162 G->allocActions().push_back(
168 // 4. Add the deferred actions to the graph.
170 std::back_inserter(G->allocActions()));
303 // Add JIT-dispatch function support symbols.
356 assert(HeaderAddrToJITDylib.count(I->second) &&
358 HeaderAddrToJITDylib.erase(I->second);
486 // Bootstrap process -- here be phase-ordering dragons.
488 // The MachOPlatform class uses allocation actions to register metadata
491 // register (e.g. the frame-info registration functions have frame-info).
494 // itself (to build the allocation actions that will call the registration
502 // allocation actions generated by MachOPlatform are appended to a list of
503 // deferred allocation actions, rather than to the graphs themselves. At the
504 // end of the bootstrap process the deferred actions are attached to a final
505 // "complete-bootstrap" graph that causes them to be run.
518 // addresses in a post-allocation pass injected by the platform runtime
524 // deferred-actions vector: the lookup for the runtime registration
527 // are still being linked, and we need to capture any allocation actions
530 // 4. Once all active links are complete we transfer the deferred actions to
533 // all deferred actions to be run, and once this lookup returns we can
537 // the corresponding jit-dispatch tag variables in the ORC runtime to make
542 this->BuildMachOHeaderMU(*this, std::move(PlatformJDOpts)))))
568 // Step (4) Add complete-bootstrap materialization unit and request.
589 // bootstrap completion actions use them (e.g. the ORC runtime
633 DepJD->withLinkOrderDo([&](const JITDylibSearchOrder &O) {
645 NewInitSymbols[DepJD] = std::move(RISItr->second);
658 // through setupJITDylib) -- bare JITDylibs aren't managed by the platform.
666 HeaderAddrs[KV.first] = I->second;
678 auto H = HI->second;
683 DepInfo.DepHeaders.push_back(HJ->second);
691 // Otherwise issue a lookup and re-run this phase when it completes.
709 JD = I->second;
715 dbgs() << "pushing initializers for " << JD->getName() << "\n";
740 JD = I->second;
745 dbgs() << "\"" << JD->getName() << "\", [ ";
803 ++MP.Bootstrap->ActiveGraphs;
807 // Get the dso-base address if available.
810 HeaderAddr = I->second;
813 // Point the libunwind dso-base absolute symbol at the header for the
826 // --- Handle Initializers ---
830 // register it and then bail out -- the header materialization unit
862 // all symbols to the c-strings section, and build a symbol table registration
881 // If we're in the bootstrap phase then steal allocation actions and then
892 {*MP.MachOHeaderStartSymbol, &MP.Bootstrap->MachOHeaderAddr},
913 if (Sym->hasName() && *Sym->getName() == RTSym.first) {
920 if (Sym->getName() == MP.MachOHeaderStartSymbol)
923 *RTSym.second = Sym->getAddress();
932 MP.JITDylibToHeaderAddr[&MP.PlatformJD] = MP.Bootstrap->MachOHeaderAddr;
933 MP.HeaderAddrToJITDylib[MP.Bootstrap->MachOHeaderAddr] = &MP.PlatformJD;
941 std::lock_guard<std::mutex> Lock(MP.Bootstrap->Mutex);
943 --MP.Bootstrap->ActiveGraphs;
944 // Notify Bootstrap->CV while holding the mutex because the mutex is
945 // also keeping Bootstrap->CV alive.
946 if (MP.Bootstrap->ActiveGraphs == 0)
947 MP.Bootstrap->CV.notify_all();
954 return Sym->getName() == MP.MachOHeaderStartSymbol;
960 auto HeaderAddr = (*I)->getAddress();
963 // We can unconditionally add these actions to the Graph because this pass
978 // in all subsequent graphs. In this pass we preserve unconditionally -- we'll
982 if (ObjCImageInfoSec->blocks_size() != 1)
987 G.addAnonymousSymbol(**ObjCImageInfoSec->blocks().begin(), 0, 0, false,
990 for (auto *B : ObjCImageInfoSec->blocks())
991 if (!B->edges_empty())
1005 // Skip ObjCImageInfo -- this shouldn't have any dependencies, and we may
1010 // Skip non-init sections.
1012 if (!InitSection || InitSection->empty())
1018 auto &B = **InitSection->blocks().begin();
1024 // Add keep-alive edges to anonymous symbols in all other init blocks.
1025 for (auto *B : InitSection->blocks()) {
1026 if (B == &InitSym->getBlock())
1029 auto &S = G.addAnonymousSymbol(*B, 0, B->getSize(), false, true);
1030 InitSym->getBlock().addEdge(jitlink::Edge::KeepAlive, 0, S, 0);
1051 auto ObjCImageInfoBlocks = ObjCImageInfo->blocks();
1067 // FIXME: We could optimize this check if Symbols had a ref-count.
1071 for (auto &E : B->edges())
1093 if (ObjCImageInfoItr->second.Version != Version)
1098 if (ObjCImageInfoItr->second.Flags != Flags)
1099 if (Error E = mergeImageInfoFlags(G, MR, ObjCImageInfoItr->second, Flags))
1103 for (auto *S : ObjCImageInfo->symbols())
1113 // move on. The section should already be marked no-dead-strip.
1184 << " -> " << formatv("{0:x4}", New.rawFlags()) << "\n";
1196 if (Sym->getName() == TLVBootStrapSymbolName) {
1199 Sym->setName(std::move(TLSGetADDR));
1210 Key = I->second;
1223 for (auto *B : ThreadDataSec->blocks()) {
1224 if (B->getSize() != 3 * G.getPointerSize())
1226 formatv("{0:x}", B->getAddress()) +
1230 auto NewBlockContent = G.allocateBuffer(B->getSize());
1231 llvm::copy(B->getContent(), NewBlockContent.data());
1234 B->setContent(NewBlockContent);
1240 for (auto &E : B->edges())
1262 SecRange = (*Sec.blocks().begin())->getRange();
1264 auto R = B->getRange();
1267 for (auto &E : B->edges()) {
1285 // If we didn't find any pointed-to code-blocks then there's no need to
1293 return LHS->getAddress() < RHS->getAddress();
1296 if (US.CodeRanges.empty() || US.CodeRanges.back().End != B->getAddress())
1297 US.CodeRanges.push_back(B->getRange());
1299 US.CodeRanges.back().End = B->getRange().End;
1309 dbgs() << " Compact-unwind: ";
1387 UnwindInfo = std::make_tuple(std::move(UI->CodeRanges), UI->DwarfSection,
1388 UI->CompactUnwindSection);
1418 std::lock_guard<std::mutex> Lock(MP.Bootstrap->Mutex);
1419 MP.Bootstrap->DeferredAAs.push_back(std::move(AllocActions));
1482 auto &SecBlock = **ObjCRuntimeObjectSec->blocks().begin();
1494 memcpy(SD.Sec.sectname, FQName.drop_front(7).data(), FQName.size() - 7);
1496 SD.Sec.addr = SR.getStart() - SecBlock.getAddress();
1527 It->second.Finalized = true;
1528 Flags = It->second.Flags;
1535 auto Content = ObjCImageInfoSym->getBlock().getMutableContent(G);
1548 RecordOffset + ((char *)&SD.Sec.addr - (char *)&SD.Sec),
1549 *ObjCImageInfoSym, -SecBlock.getAddress().getValue());
1567 assert(ObjCRuntimeObjectSec->blocks_size() == 1 &&
1570 // Build the header struct up-front. This also gives us a chance to check
1615 SD.AddFixups(P - SecContent.data());
1638 // Make a map of existing strings so that we can re-use them:
1640 for (auto *Sym : CStringSec->symbols()) {
1642 // The LinkGraph builder should have created single strings blocks, and all
1644 auto Content = Sym->getBlock().getContent();
1659 if (!Sym->hasName())
1662 auto I = ExistingStrings.find(*Sym->getName());
1665 *CStringSec, G.allocateCString(*Sym->getName()),
1671 JITSymTabInfo.push_back({Sym, I->second});
1687 assert(I->second && "Null header registered for JD");
1688 HeaderAddr = I->second;
1693 // bootstrap object and then bail out -- registration will be attached to
1695 std::lock_guard<std::mutex> Lock(MP.Bootstrap->Mutex);
1696 auto &SymTab = MP.Bootstrap->SymTab;
1698 SymTab.push_back({NameSym->getAddress(), OriginalSymbol->getAddress(),
1705 SymTab.push_back({NameSym->getAddress(), OriginalSymbol->getAddress(),
1732 Opts.IDDylib->Name, Opts.IDDylib->Timestamp,
1733 Opts.IDDylib->CurrentVersion, Opts.IDDylib->CompatibilityVersion);
1763 addMachOHeader(R->getTargetJITDylib(), *G, R->getInitializerSymbol());
1776 // Init symbol is header-start symbol.