1 //===-- llvm-rtdyld.cpp - MCJIT Testing Tool ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is a testing tool for use with the MC-JIT LLVM components.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/DebugInfo/DIContext.h"
16 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
17 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
18 #include "llvm/ExecutionEngine/RuntimeDyld.h"
19 #include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
23 #include "llvm/MC/MCInstPrinter.h"
24 #include "llvm/MC/MCInstrInfo.h"
25 #include "llvm/MC/MCRegisterInfo.h"
26 #include "llvm/MC/MCSubtargetInfo.h"
27 #include "llvm/Object/MachO.h"
28 #include "llvm/Object/SymbolSize.h"
29 #include "llvm/Support/CommandLine.h"
30 #include "llvm/Support/DynamicLibrary.h"
31 #include "llvm/Support/ManagedStatic.h"
32 #include "llvm/Support/Memory.h"
33 #include "llvm/Support/MemoryBuffer.h"
34 #include "llvm/Support/PrettyStackTrace.h"
35 #include "llvm/Support/Signals.h"
36 #include "llvm/Support/TargetRegistry.h"
37 #include "llvm/Support/TargetSelect.h"
38 #include "llvm/Support/raw_ostream.h"
40 #include <system_error>
43 using namespace llvm::object;
45 static cl::list<std::string>
46 InputFileList(cl::Positional, cl::ZeroOrMore,
47 cl::desc("<input file>"));
51 AC_PrintObjectLineInfo,
53 AC_PrintDebugLineInfo,
57 static cl::opt<ActionType>
58 Action(cl::desc("Action to perform:"),
60 cl::values(clEnumValN(AC_Execute, "execute",
61 "Load, link, and execute the inputs."),
62 clEnumValN(AC_PrintLineInfo, "printline",
63 "Load, link, and print line information for each function."),
64 clEnumValN(AC_PrintDebugLineInfo, "printdebugline",
65 "Load, link, and print line information for each function using the debug object"),
66 clEnumValN(AC_PrintObjectLineInfo, "printobjline",
67 "Like -printlineinfo but does not load the object first"),
68 clEnumValN(AC_Verify, "verify",
69 "Load, link and verify the resulting memory image.")));
71 static cl::opt<std::string>
73 cl::desc("Function to call as entry point."),
76 static cl::list<std::string>
78 cl::desc("Add library."),
81 static cl::opt<std::string>
82 TripleName("triple", cl::desc("Target triple for disassembler"));
84 static cl::opt<std::string>
86 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
87 cl::value_desc("cpu-name"),
90 static cl::list<std::string>
92 cl::desc("File containing RuntimeDyld verifier checks."),
95 static cl::opt<uint64_t>
96 PreallocMemory("preallocate",
97 cl::desc("Allocate memory upfront rather than on-demand"),
100 static cl::opt<uint64_t>
101 TargetAddrStart("target-addr-start",
102 cl::desc("For -verify only: start of phony target address "
104 cl::init(4096), // Start at "page 1" - no allocating at "null".
107 static cl::opt<uint64_t>
108 TargetAddrEnd("target-addr-end",
109 cl::desc("For -verify only: end of phony target address range."),
113 static cl::opt<uint64_t>
114 TargetSectionSep("target-section-sep",
115 cl::desc("For -verify only: Separation between sections in "
116 "phony target address space."),
120 static cl::list<std::string>
121 SpecificSectionMappings("map-section",
122 cl::desc("For -verify only: Map a section to a "
123 "specific address."),
127 static cl::list<std::string>
128 DummySymbolMappings("dummy-extern",
129 cl::desc("For -verify only: Inject a symbol into the extern "
135 PrintAllocationRequests("print-alloc-requests",
136 cl::desc("Print allocation requests made to the memory "
137 "manager by RuntimeDyld"),
142 // A trivial memory manager that doesn't do anything fancy, just uses the
143 // support library allocation routines directly.
144 class TrivialMemoryManager : public RTDyldMemoryManager {
146 SmallVector<sys::MemoryBlock, 16> FunctionMemory;
147 SmallVector<sys::MemoryBlock, 16> DataMemory;
149 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
151 StringRef SectionName) override;
152 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
153 unsigned SectionID, StringRef SectionName,
154 bool IsReadOnly) override;
156 void *getPointerToNamedFunction(const std::string &Name,
157 bool AbortOnFailure = true) override {
161 bool finalizeMemory(std::string *ErrMsg) override { return false; }
163 void addDummySymbol(const std::string &Name, uint64_t Addr) {
164 DummyExterns[Name] = Addr;
167 JITSymbol findSymbol(const std::string &Name) override {
168 auto I = DummyExterns.find(Name);
170 if (I != DummyExterns.end())
171 return JITSymbol(I->second, JITSymbolFlags::Exported);
173 return RTDyldMemoryManager::findSymbol(Name);
176 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
177 size_t Size) override {}
178 void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr,
179 size_t Size) override {}
181 void preallocateSlab(uint64_t Size) {
183 sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
185 report_fatal_error("Can't allocate enough memory: " + Err);
188 UsePreallocation = true;
192 uint8_t *allocateFromSlab(uintptr_t Size, unsigned Alignment, bool isCode) {
193 Size = alignTo(Size, Alignment);
194 if (CurrentSlabOffset + Size > SlabSize)
195 report_fatal_error("Can't allocate enough memory. Tune --preallocate");
197 uintptr_t OldSlabOffset = CurrentSlabOffset;
198 sys::MemoryBlock MB((void *)OldSlabOffset, Size);
200 FunctionMemory.push_back(MB);
202 DataMemory.push_back(MB);
203 CurrentSlabOffset += Size;
204 return (uint8_t*)OldSlabOffset;
208 std::map<std::string, uint64_t> DummyExterns;
209 sys::MemoryBlock PreallocSlab;
210 bool UsePreallocation = false;
211 uintptr_t SlabSize = 0;
212 uintptr_t CurrentSlabOffset = 0;
215 uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size,
218 StringRef SectionName) {
219 if (PrintAllocationRequests)
220 outs() << "allocateCodeSection(Size = " << Size << ", Alignment = "
221 << Alignment << ", SectionName = " << SectionName << ")\n";
223 if (UsePreallocation)
224 return allocateFromSlab(Size, Alignment, true /* isCode */);
227 sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
229 report_fatal_error("MemoryManager allocation failed: " + Err);
230 FunctionMemory.push_back(MB);
231 return (uint8_t*)MB.base();
234 uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size,
237 StringRef SectionName,
239 if (PrintAllocationRequests)
240 outs() << "allocateDataSection(Size = " << Size << ", Alignment = "
241 << Alignment << ", SectionName = " << SectionName << ")\n";
243 if (UsePreallocation)
244 return allocateFromSlab(Size, Alignment, false /* isCode */);
247 sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
249 report_fatal_error("MemoryManager allocation failed: " + Err);
250 DataMemory.push_back(MB);
251 return (uint8_t*)MB.base();
254 static const char *ProgramName;
256 static void ErrorAndExit(const Twine &Msg) {
257 errs() << ProgramName << ": error: " << Msg << "\n";
261 static void loadDylibs() {
262 for (const std::string &Dylib : Dylibs) {
263 if (!sys::fs::is_regular_file(Dylib))
264 report_fatal_error("Dylib not found: '" + Dylib + "'.");
266 if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))
267 report_fatal_error("Error loading '" + Dylib + "': " + ErrMsg);
273 static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
274 assert(LoadObjects || !UseDebugObj);
276 // Load any dylibs requested on the command line.
279 // If we don't have any input files, read from stdin.
280 if (!InputFileList.size())
281 InputFileList.push_back("-");
282 for (auto &File : InputFileList) {
283 // Instantiate a dynamic linker.
284 TrivialMemoryManager MemMgr;
285 RuntimeDyld Dyld(MemMgr, MemMgr);
287 // Load the input memory buffer.
289 ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
290 MemoryBuffer::getFileOrSTDIN(File);
291 if (std::error_code EC = InputBuffer.getError())
292 ErrorAndExit("unable to read input: '" + EC.message() + "'");
294 Expected<std::unique_ptr<ObjectFile>> MaybeObj(
295 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
299 raw_string_ostream OS(Buf);
300 logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
302 ErrorAndExit("unable to create object file: '" + Buf + "'");
305 ObjectFile &Obj = **MaybeObj;
307 OwningBinary<ObjectFile> DebugObj;
308 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo = nullptr;
309 ObjectFile *SymbolObj = &Obj;
311 // Load the object file
313 Dyld.loadObject(Obj);
316 ErrorAndExit(Dyld.getErrorString());
318 // Resolve all the relocations we can.
319 Dyld.resolveRelocations();
322 DebugObj = LoadedObjInfo->getObjectForDebug(Obj);
323 SymbolObj = DebugObj.getBinary();
324 LoadedObjInfo.reset();
328 std::unique_ptr<DIContext> Context(
329 new DWARFContextInMemory(*SymbolObj,LoadedObjInfo.get()));
331 std::vector<std::pair<SymbolRef, uint64_t>> SymAddr =
332 object::computeSymbolSizes(*SymbolObj);
334 // Use symbol info to iterate functions in the object.
335 for (const auto &P : SymAddr) {
336 object::SymbolRef Sym = P.first;
337 Expected<SymbolRef::Type> TypeOrErr = Sym.getType();
339 // TODO: Actually report errors helpfully.
340 consumeError(TypeOrErr.takeError());
343 SymbolRef::Type Type = *TypeOrErr;
344 if (Type == object::SymbolRef::ST_Function) {
345 Expected<StringRef> Name = Sym.getName();
347 // TODO: Actually report errors helpfully.
348 consumeError(Name.takeError());
351 Expected<uint64_t> AddrOrErr = Sym.getAddress();
353 // TODO: Actually report errors helpfully.
354 consumeError(AddrOrErr.takeError());
357 uint64_t Addr = *AddrOrErr;
359 uint64_t Size = P.second;
360 // If we're not using the debug object, compute the address of the
361 // symbol in memory (rather than that in the unrelocated object file)
362 // and use that to query the DWARFContext.
363 if (!UseDebugObj && LoadObjects) {
364 auto SecOrErr = Sym.getSection();
366 // TODO: Actually report errors helpfully.
367 consumeError(SecOrErr.takeError());
370 object::section_iterator Sec = *SecOrErr;
372 Sec->getName(SecName);
373 uint64_t SectionLoadAddress =
374 LoadedObjInfo->getSectionLoadAddress(*Sec);
375 if (SectionLoadAddress != 0)
376 Addr += SectionLoadAddress - Sec->getAddress();
379 outs() << "Function: " << *Name << ", Size = " << Size
380 << ", Addr = " << Addr << "\n";
382 DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
383 for (auto &D : Lines) {
384 outs() << " Line info @ " << D.first - Addr << ": "
385 << D.second.FileName << ", line:" << D.second.Line << "\n";
394 static void doPreallocation(TrivialMemoryManager &MemMgr) {
395 // Allocate a slab of memory upfront, if required. This is used if
396 // we want to test small code models.
397 if (static_cast<intptr_t>(PreallocMemory) < 0)
398 report_fatal_error("Pre-allocated bytes of memory must be a positive integer.");
400 // FIXME: Limit the amount of memory that can be preallocated?
401 if (PreallocMemory != 0)
402 MemMgr.preallocateSlab(PreallocMemory);
405 static int executeInput() {
406 // Load any dylibs requested on the command line.
409 // Instantiate a dynamic linker.
410 TrivialMemoryManager MemMgr;
411 doPreallocation(MemMgr);
412 RuntimeDyld Dyld(MemMgr, MemMgr);
414 // If we don't have any input files, read from stdin.
415 if (!InputFileList.size())
416 InputFileList.push_back("-");
417 for (auto &File : InputFileList) {
418 // Load the input memory buffer.
419 ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
420 MemoryBuffer::getFileOrSTDIN(File);
421 if (std::error_code EC = InputBuffer.getError())
422 ErrorAndExit("unable to read input: '" + EC.message() + "'");
423 Expected<std::unique_ptr<ObjectFile>> MaybeObj(
424 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
428 raw_string_ostream OS(Buf);
429 logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
431 ErrorAndExit("unable to create object file: '" + Buf + "'");
434 ObjectFile &Obj = **MaybeObj;
436 // Load the object file
437 Dyld.loadObject(Obj);
438 if (Dyld.hasError()) {
439 ErrorAndExit(Dyld.getErrorString());
443 // Resove all the relocations we can.
444 // FIXME: Error out if there are unresolved relocations.
445 Dyld.resolveRelocations();
447 // Get the address of the entry point (_main by default).
448 void *MainAddress = Dyld.getSymbolLocalAddress(EntryPoint);
450 ErrorAndExit("no definition for '" + EntryPoint + "'");
452 // Invalidate the instruction cache for each loaded function.
453 for (auto &FM : MemMgr.FunctionMemory) {
455 // Make sure the memory is executable.
456 // setExecutable will call InvalidateInstructionCache.
457 std::string ErrorStr;
458 if (!sys::Memory::setExecutable(FM, &ErrorStr))
459 ErrorAndExit("unable to mark function executable: '" + ErrorStr + "'");
462 // Dispatch to _main().
463 errs() << "loaded '" << EntryPoint << "' at: " << (void*)MainAddress << "\n";
465 int (*Main)(int, const char**) =
466 (int(*)(int,const char**)) uintptr_t(MainAddress);
467 const char **Argv = new const char*[2];
468 // Use the name of the first input object module as argv[0] for the target.
469 Argv[0] = InputFileList[0].c_str();
471 return Main(1, Argv);
474 static int checkAllExpressions(RuntimeDyldChecker &Checker) {
475 for (const auto& CheckerFileName : CheckFiles) {
476 ErrorOr<std::unique_ptr<MemoryBuffer>> CheckerFileBuf =
477 MemoryBuffer::getFileOrSTDIN(CheckerFileName);
478 if (std::error_code EC = CheckerFileBuf.getError())
479 ErrorAndExit("unable to read input '" + CheckerFileName + "': " +
482 if (!Checker.checkAllRulesInBuffer("# rtdyld-check:",
483 CheckerFileBuf.get().get()))
484 ErrorAndExit("some checks in '" + CheckerFileName + "' failed");
489 static std::map<void *, uint64_t>
490 applySpecificSectionMappings(RuntimeDyldChecker &Checker) {
492 std::map<void*, uint64_t> SpecificMappings;
494 for (StringRef Mapping : SpecificSectionMappings) {
496 size_t EqualsIdx = Mapping.find_first_of("=");
497 std::string SectionIDStr = Mapping.substr(0, EqualsIdx);
498 size_t ComaIdx = Mapping.find_first_of(",");
500 if (ComaIdx == StringRef::npos)
501 report_fatal_error("Invalid section specification '" + Mapping +
502 "'. Should be '<file name>,<section name>=<addr>'");
504 std::string FileName = SectionIDStr.substr(0, ComaIdx);
505 std::string SectionName = SectionIDStr.substr(ComaIdx + 1);
508 std::string ErrorMsg;
509 std::tie(OldAddrInt, ErrorMsg) =
510 Checker.getSectionAddr(FileName, SectionName, true);
513 report_fatal_error(ErrorMsg);
515 void* OldAddr = reinterpret_cast<void*>(static_cast<uintptr_t>(OldAddrInt));
517 std::string NewAddrStr = Mapping.substr(EqualsIdx + 1);
520 if (StringRef(NewAddrStr).getAsInteger(0, NewAddr))
521 report_fatal_error("Invalid section address in mapping '" + Mapping +
524 Checker.getRTDyld().mapSectionAddress(OldAddr, NewAddr);
525 SpecificMappings[OldAddr] = NewAddr;
528 return SpecificMappings;
531 // Scatter sections in all directions!
532 // Remaps section addresses for -verify mode. The following command line options
533 // can be used to customize the layout of the memory within the phony target's
535 // -target-addr-start <s> -- Specify where the phony target address range starts.
536 // -target-addr-end <e> -- Specify where the phony target address range ends.
537 // -target-section-sep <d> -- Specify how big a gap should be left between the
538 // end of one section and the start of the next.
539 // Defaults to zero. Set to something big
540 // (e.g. 1 << 32) to stress-test stubs, GOTs, etc.
542 static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple,
543 TrivialMemoryManager &MemMgr,
544 RuntimeDyldChecker &Checker) {
546 // Set up a work list (section addr/size pairs).
547 typedef std::list<std::pair<void*, uint64_t>> WorklistT;
550 for (const auto& CodeSection : MemMgr.FunctionMemory)
551 Worklist.push_back(std::make_pair(CodeSection.base(), CodeSection.size()));
552 for (const auto& DataSection : MemMgr.DataMemory)
553 Worklist.push_back(std::make_pair(DataSection.base(), DataSection.size()));
555 // Apply any section-specific mappings that were requested on the command
557 typedef std::map<void*, uint64_t> AppliedMappingsT;
558 AppliedMappingsT AppliedMappings = applySpecificSectionMappings(Checker);
560 // Keep an "already allocated" mapping of section target addresses to sizes.
561 // Sections whose address mappings aren't specified on the command line will
562 // allocated around the explicitly mapped sections while maintaining the
563 // minimum separation.
564 std::map<uint64_t, uint64_t> AlreadyAllocated;
566 // Move the previously applied mappings into the already-allocated map.
567 for (WorklistT::iterator I = Worklist.begin(), E = Worklist.end();
569 WorklistT::iterator Tmp = I;
571 AppliedMappingsT::iterator AI = AppliedMappings.find(Tmp->first);
573 if (AI != AppliedMappings.end()) {
574 AlreadyAllocated[AI->second] = Tmp->second;
579 // If the -target-addr-end option wasn't explicitly passed, then set it to a
580 // sensible default based on the target triple.
581 if (TargetAddrEnd.getNumOccurrences() == 0) {
582 if (TargetTriple.isArch16Bit())
583 TargetAddrEnd = (1ULL << 16) - 1;
584 else if (TargetTriple.isArch32Bit())
585 TargetAddrEnd = (1ULL << 32) - 1;
586 // TargetAddrEnd already has a sensible default for 64-bit systems, so
587 // there's nothing to do in the 64-bit case.
590 // Process any elements remaining in the worklist.
591 while (!Worklist.empty()) {
592 std::pair<void*, uint64_t> CurEntry = Worklist.front();
593 Worklist.pop_front();
595 uint64_t NextSectionAddr = TargetAddrStart;
597 for (const auto &Alloc : AlreadyAllocated)
598 if (NextSectionAddr + CurEntry.second + TargetSectionSep <= Alloc.first)
601 NextSectionAddr = Alloc.first + Alloc.second + TargetSectionSep;
603 AlreadyAllocated[NextSectionAddr] = CurEntry.second;
604 Checker.getRTDyld().mapSectionAddress(CurEntry.first, NextSectionAddr);
607 // Add dummy symbols to the memory manager.
608 for (const auto &Mapping : DummySymbolMappings) {
609 size_t EqualsIdx = Mapping.find_first_of('=');
611 if (EqualsIdx == StringRef::npos)
612 report_fatal_error("Invalid dummy symbol specification '" + Mapping +
613 "'. Should be '<symbol name>=<addr>'");
615 std::string Symbol = Mapping.substr(0, EqualsIdx);
616 std::string AddrStr = Mapping.substr(EqualsIdx + 1);
619 if (StringRef(AddrStr).getAsInteger(0, Addr))
620 report_fatal_error("Invalid symbol mapping '" + Mapping + "'.");
622 MemMgr.addDummySymbol(Symbol, Addr);
626 // Load and link the objects specified on the command line, but do not execute
627 // anything. Instead, attach a RuntimeDyldChecker instance and call it to
628 // verify the correctness of the linked memory.
629 static int linkAndVerify() {
631 // Check for missing triple.
632 if (TripleName == "")
633 ErrorAndExit("-triple required when running in -verify mode.");
635 // Look up the target and build the disassembler.
636 Triple TheTriple(Triple::normalize(TripleName));
637 std::string ErrorStr;
638 const Target *TheTarget =
639 TargetRegistry::lookupTarget("", TheTriple, ErrorStr);
641 ErrorAndExit("Error accessing target '" + TripleName + "': " + ErrorStr);
643 TripleName = TheTriple.getTriple();
645 std::unique_ptr<MCSubtargetInfo> STI(
646 TheTarget->createMCSubtargetInfo(TripleName, MCPU, ""));
648 ErrorAndExit("Unable to create subtarget info!");
650 std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
652 ErrorAndExit("Unable to create target register info!");
654 std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));
656 ErrorAndExit("Unable to create target asm info!");
658 MCContext Ctx(MAI.get(), MRI.get(), nullptr);
660 std::unique_ptr<MCDisassembler> Disassembler(
661 TheTarget->createMCDisassembler(*STI, Ctx));
663 ErrorAndExit("Unable to create disassembler!");
665 std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo());
667 std::unique_ptr<MCInstPrinter> InstPrinter(
668 TheTarget->createMCInstPrinter(Triple(TripleName), 0, *MAI, *MII, *MRI));
670 // Load any dylibs requested on the command line.
673 // Instantiate a dynamic linker.
674 TrivialMemoryManager MemMgr;
675 doPreallocation(MemMgr);
676 RuntimeDyld Dyld(MemMgr, MemMgr);
677 Dyld.setProcessAllSections(true);
678 RuntimeDyldChecker Checker(Dyld, Disassembler.get(), InstPrinter.get(),
681 // If we don't have any input files, read from stdin.
682 if (!InputFileList.size())
683 InputFileList.push_back("-");
684 for (auto &Filename : InputFileList) {
685 // Load the input memory buffer.
686 ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
687 MemoryBuffer::getFileOrSTDIN(Filename);
689 if (std::error_code EC = InputBuffer.getError())
690 ErrorAndExit("unable to read input: '" + EC.message() + "'");
692 Expected<std::unique_ptr<ObjectFile>> MaybeObj(
693 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
697 raw_string_ostream OS(Buf);
698 logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
700 ErrorAndExit("unable to create object file: '" + Buf + "'");
703 ObjectFile &Obj = **MaybeObj;
705 // Load the object file
706 Dyld.loadObject(Obj);
707 if (Dyld.hasError()) {
708 ErrorAndExit(Dyld.getErrorString());
712 // Re-map the section addresses into the phony target address space and add
714 remapSectionsAndSymbols(TheTriple, MemMgr, Checker);
716 // Resolve all the relocations we can.
717 Dyld.resolveRelocations();
719 // Register EH frames.
720 Dyld.registerEHFrames();
722 int ErrorCode = checkAllExpressions(Checker);
724 ErrorAndExit("RTDyld reported an error applying relocations:\n " +
725 Dyld.getErrorString());
730 int main(int argc, char **argv) {
731 sys::PrintStackTraceOnErrorSignal(argv[0]);
732 PrettyStackTraceProgram X(argc, argv);
734 ProgramName = argv[0];
735 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
737 llvm::InitializeAllTargetInfos();
738 llvm::InitializeAllTargetMCs();
739 llvm::InitializeAllDisassemblers();
741 cl::ParseCommandLineOptions(argc, argv, "llvm MC-JIT tool\n");
745 return executeInput();
746 case AC_PrintDebugLineInfo:
747 return printLineInfoForInput(/* LoadObjects */ true,/* UseDebugObj */ true);
748 case AC_PrintLineInfo:
749 return printLineInfoForInput(/* LoadObjects */ true,/* UseDebugObj */false);
750 case AC_PrintObjectLineInfo:
751 return printLineInfoForInput(/* LoadObjects */false,/* UseDebugObj */false);
753 return linkAndVerify();