Lines Matching +full:auto +full:- +full:load

1 //===-- llvm-rtdyld.cpp - MCJIT Testing Tool ------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This is a testing tool for use with the MC-JIT LLVM components.
11 //===----------------------------------------------------------------------===//
65 "Load, link, and execute the inputs."),
67 "Load, link, and print line information for each function."),
69 "Load, link, and print line information for each function "
72 "Like -printlineinfo but does not load the object first"),
74 "Load, link and verify the resulting memory image.")),
95 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
96 cl::value_desc("cpu-name"), cl::init(""), cl::cat(RTDyldCategory));
105 cl::desc("Allocate memory upfront rather than on-demand"),
109 "target-addr-start",
110 cl::desc("For -verify only: start of phony target address "
112 cl::init(4096), // Start at "page 1" - no allocating at "null".
116 "target-addr-end",
117 cl::desc("For -verify only: end of phony target address range."),
121 "target-section-sep",
122 cl::desc("For -verify only: Separation between sections in "
127 SpecificSectionMappings("map-section",
128 cl::desc("For -verify only: Map a section to a "
133 "dummy-extern",
134 cl::desc("For -verify only: Inject a symbol into the extern "
139 "print-alloc-requests",
144 static cl::opt<bool> ShowTimes("show-times",
145 cl::desc("Show times for llvm-rtdyld phases"),
151 TimerGroup RTDyldTG{"llvm-rtdyld timers", "timers for llvm-rtdyld phases"};
152 Timer LoadObjectsTimer{"load", "time to load/add object files", RTDyldTG};
165 for (const auto &KV : FileToSecIDMap) { in dumpFileToSectionIDMap()
167 for (auto &KV2 : KV.second) in dumpFileToSectionIDMap()
168 llvm::dbgs() << " \"" << KV2.first() << "\" -> " << KV2.second << "\n"; in dumpFileToSectionIDMap()
174 auto I = FileToSecIDMap.find(FileName); in getSectionId()
178 auto &SectionIDs = I->second; in getSectionId()
179 auto J = SectionIDs.find(SectionName); in getSectionId()
184 return J->second; in getSectionId()
212 /// If non null, records subsequent Name -> SectionID mappings.
214 this->SecIDMap = SecIDMap; in setSectionIDsMap()
229 auto I = DummyExterns.find(Name); in findSymbol()
232 return JITSymbol(I->second, JITSymbolFlags::Exported); in findSymbol()
234 if (auto Sym = RTDyldMemoryManager::findSymbol(Name)) in findSymbol()
236 else if (auto Err = Sym.takeError()) in findSymbol()
269 report_fatal_error("Can't allocate enough memory. Tune --preallocate"); in allocateFromSlab()
354 alignas(16) __attribute__((visibility("hidden"), tls_model("initial-exec"),
376 // initialized correctly. This means, llvm-rtdyld will only support TLS in a in allocateTLSSection()
412 // Load any dylibs requested on the command line. in printLineInfoForInput()
417 InputFileList.push_back("-"); in printLineInfoForInput()
418 for (auto &File : InputFileList) { in printLineInfoForInput()
423 // Load the input memory buffer. in printLineInfoForInput()
431 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef())); in printLineInfoForInput()
447 // Load the object file in printLineInfoForInput()
458 DebugObj = LoadedObjInfo->getObjectForDebug(Obj); in printLineInfoForInput()
472 for (const auto &P : SymAddr) { in printLineInfoForInput()
503 auto SecOrErr = Sym.getSection(); in printLineInfoForInput()
510 Address.SectionIndex = Sec->getIndex(); in printLineInfoForInput()
512 LoadedObjInfo->getSectionLoadAddress(*Sec); in printLineInfoForInput()
514 Addr += SectionLoadAddress - Sec->getAddress(); in printLineInfoForInput()
515 } else if (auto SecOrErr = Sym.getSection()) in printLineInfoForInput()
516 Address.SectionIndex = SecOrErr.get()->getIndex(); in printLineInfoForInput()
523 Context->getLineInfoForAddressRange(Address, Size); in printLineInfoForInput()
524 for (auto &D : Lines) { in printLineInfoForInput()
525 outs() << " Line info @ " << D.first - Addr << ": " in printLineInfoForInput()
539 report_fatal_error("Pre-allocated bytes of memory must be a positive integer."); in doPreallocation()
547 // Load any dylibs requested on the command line. in executeInput()
557 InputFileList.push_back("-"); in executeInput()
559 TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr); in executeInput()
560 for (auto &File : InputFileList) { in executeInput()
561 // Load the input memory buffer. in executeInput()
567 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef())); in executeInput()
579 // Load the object file in executeInput()
588 TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr); in executeInput()
600 for (auto &FM : MemMgr.FunctionMemory) { in executeInput()
602 auto &FM_MB = FM.MB; in executeInput()
606 if (auto EC = sys::Memory::protectMappedMemory(FM_MB, in executeInput()
621 for (auto &Arg : InputArgv) in executeInput()
626 TimeRegion TR(Timers ? &Timers->RunTimer : nullptr); in executeInput()
627 Result = Main(Argv.size() - 1, Argv.data()); in executeInput()
634 for (const auto& CheckerFileName : CheckFiles) { in checkAllExpressions()
641 if (!Checker.checkAllRulesInBuffer("# rtdyld-check:", in checkAllExpressions()
665 auto* OldAddr = Dyld.getSectionContent(SectionID).data(); in applySpecificSectionMappings()
678 // Remaps section addresses for -verify mode. The following command line options
681 // -target-addr-start <s> -- Specify where the phony target address range starts.
682 // -target-addr-end <e> -- Specify where the phony target address range ends.
683 // -target-section-sep <d> -- Specify how big a gap should be left between the
686 // (e.g. 1 << 32) to stress-test stubs, GOTs, etc.
696 for (const auto& CodeSection : MemMgr.FunctionMemory) in remapSectionsAndSymbols()
698 for (const auto& DataSection : MemMgr.DataMemory) in remapSectionsAndSymbols()
708 // command line, or implicitly set by RuntimeDyld) into the already-allocated in remapSectionsAndSymbols()
715 auto LoadAddr = Dyld.getSectionLoadAddress((*Tmp)->SectionID); in remapSectionsAndSymbols()
718 reinterpret_cast<uintptr_t>((*Tmp)->MB.base()))) { in remapSectionsAndSymbols()
723 AlreadyAllocated[LoadAddr] = (*Tmp)->MB.allocatedSize(); in remapSectionsAndSymbols()
728 // If the -target-addr-end option wasn't explicitly passed, then set it to a in remapSectionsAndSymbols()
732 TargetAddrEnd = (1ULL << 16) - 1; in remapSectionsAndSymbols()
734 TargetAddrEnd = (1ULL << 32) - 1; in remapSectionsAndSymbols()
735 // TargetAddrEnd already has a sensible default for 64-bit systems, so in remapSectionsAndSymbols()
736 // there's nothing to do in the 64-bit case. in remapSectionsAndSymbols()
741 auto *CurEntry = Worklist.front(); in remapSectionsAndSymbols()
746 for (const auto &Alloc : AlreadyAllocated) in remapSectionsAndSymbols()
747 if (NextSectionAddr + CurEntry->MB.allocatedSize() + TargetSectionSep <= in remapSectionsAndSymbols()
753 Dyld.mapSectionAddress(CurEntry->MB.base(), NextSectionAddr); in remapSectionsAndSymbols()
754 AlreadyAllocated[NextSectionAddr] = CurEntry->MB.allocatedSize(); in remapSectionsAndSymbols()
758 for (const auto &Mapping : DummySymbolMappings) { in remapSectionsAndSymbols()
776 // Load and link the objects specified on the command line, but do not execute
783 ErrorAndExit("-triple required when running in -verify mode."); in linkAndVerify()
796 TheTarget->createMCSubtargetInfo(TripleName, MCPU, "")); in linkAndVerify()
800 std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); in linkAndVerify()
806 TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions)); in linkAndVerify()
813 TheTarget->createMCDisassembler(*STI, Ctx)); in linkAndVerify()
817 std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo()); in linkAndVerify()
822 TheTarget->createMCInstPrinter(Triple(TripleName), 0, *MAI, *MII, *MRI)); in linkAndVerify()
824 // Load any dylibs requested on the command line. in linkAndVerify()
851 auto GetSymbolInfo = in linkAndVerify()
853 StringRef Symbol) -> Expected<RuntimeDyldChecker::MemoryRegionInfo> { in linkAndVerify()
857 if (auto InternalSymbol = Dyld.getSymbol(Symbol)) in linkAndVerify()
868 auto ResultP = std::make_shared<std::promise<ExpectedLookupResult>>(); in linkAndVerify()
869 auto ResultF = ResultP->get_future(); in linkAndVerify()
873 ResultP->set_value(std::move(Result)); in linkAndVerify()
876 auto Result = ResultF.get(); in linkAndVerify()
880 auto I = Result->find(Symbol); in linkAndVerify()
881 assert(I != Result->end() && in linkAndVerify()
883 SymInfo.setTargetAddress(I->second.getAddress()); in linkAndVerify()
887 // default-constructed StringRef). in linkAndVerify()
888 if (auto *SymAddr = Dyld.getSymbolLocalAddress(Symbol)) { in linkAndVerify()
893 uint64_t SymSize = SecContent.size() - (CSymAddr - SecContent.data()); in linkAndVerify()
902 auto IsSymbolValid = [&Dyld, GetSymbolInfo](StringRef Symbol) { in linkAndVerify()
905 auto SymInfo = GetSymbolInfo(Symbol); in linkAndVerify()
910 return SymInfo->getTargetAddress() != 0; in linkAndVerify()
915 auto GetSectionInfo = [&Dyld, &FileToSecIDMap](StringRef FileName, in linkAndVerify()
917 -> Expected<RuntimeDyldChecker::MemoryRegionInfo> { in linkAndVerify()
918 auto SectionID = getSectionId(FileToSecIDMap, FileName, SectionName); in linkAndVerify()
928 auto GetStubInfo = [&Dyld, &StubMap](StringRef StubContainer, in linkAndVerify()
931 -> Expected<RuntimeDyldChecker::MemoryRegionInfo> { in linkAndVerify()
940 auto &SI = StubMap[StubContainer][SymbolName]; in linkAndVerify()
951 auto GetGOTInfo = [&GetStubInfo](StringRef StubContainer, in linkAndVerify()
962 InputFileList.push_back("-"); in linkAndVerify()
963 for (auto &InputFile : InputFileList) { in linkAndVerify()
964 // Load the input memory buffer. in linkAndVerify()
972 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef())); in linkAndVerify()
991 auto FileName = sys::path::filename(InputFile); in linkAndVerify()
994 // Load the object file in linkAndVerify()
1001 // Re-map the section addresses into the phony target address space and add in linkAndVerify()
1029 cl::ParseCommandLineOptions(argc, argv, "llvm MC-JIT tool\n"); in main()