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() override {}
180 void preallocateSlab(uint64_t Size) {
182 sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
184 report_fatal_error("Can't allocate enough memory: " + Err);
187 UsePreallocation = true;
191 uint8_t *allocateFromSlab(uintptr_t Size, unsigned Alignment, bool isCode) {
192 Size = alignTo(Size, Alignment);
193 if (CurrentSlabOffset + Size > SlabSize)
194 report_fatal_error("Can't allocate enough memory. Tune --preallocate");
196 uintptr_t OldSlabOffset = CurrentSlabOffset;
197 sys::MemoryBlock MB((void *)OldSlabOffset, Size);
199 FunctionMemory.push_back(MB);
201 DataMemory.push_back(MB);
202 CurrentSlabOffset += Size;
203 return (uint8_t*)OldSlabOffset;
207 std::map<std::string, uint64_t> DummyExterns;
208 sys::MemoryBlock PreallocSlab;
209 bool UsePreallocation = false;
210 uintptr_t SlabSize = 0;
211 uintptr_t CurrentSlabOffset = 0;
214 uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size,
217 StringRef SectionName) {
218 if (PrintAllocationRequests)
219 outs() << "allocateCodeSection(Size = " << Size << ", Alignment = "
220 << Alignment << ", SectionName = " << SectionName << ")\n";
222 if (UsePreallocation)
223 return allocateFromSlab(Size, Alignment, true /* isCode */);
226 sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
228 report_fatal_error("MemoryManager allocation failed: " + Err);
229 FunctionMemory.push_back(MB);
230 return (uint8_t*)MB.base();
233 uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size,
236 StringRef SectionName,
238 if (PrintAllocationRequests)
239 outs() << "allocateDataSection(Size = " << Size << ", Alignment = "
240 << Alignment << ", SectionName = " << SectionName << ")\n";
242 if (UsePreallocation)
243 return allocateFromSlab(Size, Alignment, false /* isCode */);
246 sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
248 report_fatal_error("MemoryManager allocation failed: " + Err);
249 DataMemory.push_back(MB);
250 return (uint8_t*)MB.base();
253 static const char *ProgramName;
255 static void ErrorAndExit(const Twine &Msg) {
256 errs() << ProgramName << ": error: " << Msg << "\n";
260 static void loadDylibs() {
261 for (const std::string &Dylib : Dylibs) {
262 if (!sys::fs::is_regular_file(Dylib))
263 report_fatal_error("Dylib not found: '" + Dylib + "'.");
265 if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))
266 report_fatal_error("Error loading '" + Dylib + "': " + ErrMsg);
272 static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
273 assert(LoadObjects || !UseDebugObj);
275 // Load any dylibs requested on the command line.
278 // If we don't have any input files, read from stdin.
279 if (!InputFileList.size())
280 InputFileList.push_back("-");
281 for (auto &File : InputFileList) {
282 // Instantiate a dynamic linker.
283 TrivialMemoryManager MemMgr;
284 RuntimeDyld Dyld(MemMgr, MemMgr);
286 // Load the input memory buffer.
288 ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
289 MemoryBuffer::getFileOrSTDIN(File);
290 if (std::error_code EC = InputBuffer.getError())
291 ErrorAndExit("unable to read input: '" + EC.message() + "'");
293 Expected<std::unique_ptr<ObjectFile>> MaybeObj(
294 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
298 raw_string_ostream OS(Buf);
299 logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
301 ErrorAndExit("unable to create object file: '" + Buf + "'");
304 ObjectFile &Obj = **MaybeObj;
306 OwningBinary<ObjectFile> DebugObj;
307 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo = nullptr;
308 ObjectFile *SymbolObj = &Obj;
310 // Load the object file
312 Dyld.loadObject(Obj);
315 ErrorAndExit(Dyld.getErrorString());
317 // Resolve all the relocations we can.
318 Dyld.resolveRelocations();
321 DebugObj = LoadedObjInfo->getObjectForDebug(Obj);
322 SymbolObj = DebugObj.getBinary();
323 LoadedObjInfo.reset();
327 std::unique_ptr<DIContext> Context(
328 new DWARFContextInMemory(*SymbolObj,LoadedObjInfo.get()));
330 std::vector<std::pair<SymbolRef, uint64_t>> SymAddr =
331 object::computeSymbolSizes(*SymbolObj);
333 // Use symbol info to iterate functions in the object.
334 for (const auto &P : SymAddr) {
335 object::SymbolRef Sym = P.first;
336 Expected<SymbolRef::Type> TypeOrErr = Sym.getType();
338 // TODO: Actually report errors helpfully.
339 consumeError(TypeOrErr.takeError());
342 SymbolRef::Type Type = *TypeOrErr;
343 if (Type == object::SymbolRef::ST_Function) {
344 Expected<StringRef> Name = Sym.getName();
346 // TODO: Actually report errors helpfully.
347 consumeError(Name.takeError());
350 Expected<uint64_t> AddrOrErr = Sym.getAddress();
352 // TODO: Actually report errors helpfully.
353 consumeError(AddrOrErr.takeError());
356 uint64_t Addr = *AddrOrErr;
358 uint64_t Size = P.second;
359 // If we're not using the debug object, compute the address of the
360 // symbol in memory (rather than that in the unrelocated object file)
361 // and use that to query the DWARFContext.
362 if (!UseDebugObj && LoadObjects) {
363 auto SecOrErr = Sym.getSection();
365 // TODO: Actually report errors helpfully.
366 consumeError(SecOrErr.takeError());
369 object::section_iterator Sec = *SecOrErr;
371 Sec->getName(SecName);
372 uint64_t SectionLoadAddress =
373 LoadedObjInfo->getSectionLoadAddress(*Sec);
374 if (SectionLoadAddress != 0)
375 Addr += SectionLoadAddress - Sec->getAddress();
378 outs() << "Function: " << *Name << ", Size = " << Size
379 << ", Addr = " << Addr << "\n";
381 DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
382 for (auto &D : Lines) {
383 outs() << " Line info @ " << D.first - Addr << ": "
384 << D.second.FileName << ", line:" << D.second.Line << "\n";
393 static void doPreallocation(TrivialMemoryManager &MemMgr) {
394 // Allocate a slab of memory upfront, if required. This is used if
395 // we want to test small code models.
396 if (static_cast<intptr_t>(PreallocMemory) < 0)
397 report_fatal_error("Pre-allocated bytes of memory must be a positive integer.");
399 // FIXME: Limit the amount of memory that can be preallocated?
400 if (PreallocMemory != 0)
401 MemMgr.preallocateSlab(PreallocMemory);
404 static int executeInput() {
405 // Load any dylibs requested on the command line.
408 // Instantiate a dynamic linker.
409 TrivialMemoryManager MemMgr;
410 doPreallocation(MemMgr);
411 RuntimeDyld Dyld(MemMgr, MemMgr);
413 // If we don't have any input files, read from stdin.
414 if (!InputFileList.size())
415 InputFileList.push_back("-");
416 for (auto &File : InputFileList) {
417 // Load the input memory buffer.
418 ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
419 MemoryBuffer::getFileOrSTDIN(File);
420 if (std::error_code EC = InputBuffer.getError())
421 ErrorAndExit("unable to read input: '" + EC.message() + "'");
422 Expected<std::unique_ptr<ObjectFile>> MaybeObj(
423 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
427 raw_string_ostream OS(Buf);
428 logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
430 ErrorAndExit("unable to create object file: '" + Buf + "'");
433 ObjectFile &Obj = **MaybeObj;
435 // Load the object file
436 Dyld.loadObject(Obj);
437 if (Dyld.hasError()) {
438 ErrorAndExit(Dyld.getErrorString());
442 // Resove all the relocations we can.
443 // FIXME: Error out if there are unresolved relocations.
444 Dyld.resolveRelocations();
446 // Get the address of the entry point (_main by default).
447 void *MainAddress = Dyld.getSymbolLocalAddress(EntryPoint);
449 ErrorAndExit("no definition for '" + EntryPoint + "'");
451 // Invalidate the instruction cache for each loaded function.
452 for (auto &FM : MemMgr.FunctionMemory) {
454 // Make sure the memory is executable.
455 // setExecutable will call InvalidateInstructionCache.
456 std::string ErrorStr;
457 if (!sys::Memory::setExecutable(FM, &ErrorStr))
458 ErrorAndExit("unable to mark function executable: '" + ErrorStr + "'");
461 // Dispatch to _main().
462 errs() << "loaded '" << EntryPoint << "' at: " << (void*)MainAddress << "\n";
464 int (*Main)(int, const char**) =
465 (int(*)(int,const char**)) uintptr_t(MainAddress);
466 const char **Argv = new const char*[2];
467 // Use the name of the first input object module as argv[0] for the target.
468 Argv[0] = InputFileList[0].c_str();
470 return Main(1, Argv);
473 static int checkAllExpressions(RuntimeDyldChecker &Checker) {
474 for (const auto& CheckerFileName : CheckFiles) {
475 ErrorOr<std::unique_ptr<MemoryBuffer>> CheckerFileBuf =
476 MemoryBuffer::getFileOrSTDIN(CheckerFileName);
477 if (std::error_code EC = CheckerFileBuf.getError())
478 ErrorAndExit("unable to read input '" + CheckerFileName + "': " +
481 if (!Checker.checkAllRulesInBuffer("# rtdyld-check:",
482 CheckerFileBuf.get().get()))
483 ErrorAndExit("some checks in '" + CheckerFileName + "' failed");
488 void applySpecificSectionMappings(RuntimeDyldChecker &Checker) {
490 for (StringRef Mapping : SpecificSectionMappings) {
492 size_t EqualsIdx = Mapping.find_first_of("=");
493 std::string SectionIDStr = Mapping.substr(0, EqualsIdx);
494 size_t ComaIdx = Mapping.find_first_of(",");
496 if (ComaIdx == StringRef::npos)
497 report_fatal_error("Invalid section specification '" + Mapping +
498 "'. Should be '<file name>,<section name>=<addr>'");
500 std::string FileName = SectionIDStr.substr(0, ComaIdx);
501 std::string SectionName = SectionIDStr.substr(ComaIdx + 1);
504 std::string ErrorMsg;
505 std::tie(OldAddrInt, ErrorMsg) =
506 Checker.getSectionAddr(FileName, SectionName, true);
509 report_fatal_error(ErrorMsg);
511 void* OldAddr = reinterpret_cast<void*>(static_cast<uintptr_t>(OldAddrInt));
513 std::string NewAddrStr = Mapping.substr(EqualsIdx + 1);
516 if (StringRef(NewAddrStr).getAsInteger(0, NewAddr))
517 report_fatal_error("Invalid section address in mapping '" + Mapping +
520 Checker.getRTDyld().mapSectionAddress(OldAddr, NewAddr);
524 // Scatter sections in all directions!
525 // Remaps section addresses for -verify mode. The following command line options
526 // can be used to customize the layout of the memory within the phony target's
528 // -target-addr-start <s> -- Specify where the phony target address range starts.
529 // -target-addr-end <e> -- Specify where the phony target address range ends.
530 // -target-section-sep <d> -- Specify how big a gap should be left between the
531 // end of one section and the start of the next.
532 // Defaults to zero. Set to something big
533 // (e.g. 1 << 32) to stress-test stubs, GOTs, etc.
535 static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple,
536 TrivialMemoryManager &MemMgr,
537 RuntimeDyldChecker &Checker) {
539 // Set up a work list (section addr/size pairs).
540 typedef std::list<std::pair<void*, uint64_t>> WorklistT;
543 for (const auto& CodeSection : MemMgr.FunctionMemory)
544 Worklist.push_back(std::make_pair(CodeSection.base(), CodeSection.size()));
545 for (const auto& DataSection : MemMgr.DataMemory)
546 Worklist.push_back(std::make_pair(DataSection.base(), DataSection.size()));
548 // Apply any section-specific mappings that were requested on the command
550 applySpecificSectionMappings(Checker);
552 // Keep an "already allocated" mapping of section target addresses to sizes.
553 // Sections whose address mappings aren't specified on the command line will
554 // allocated around the explicitly mapped sections while maintaining the
555 // minimum separation.
556 std::map<uint64_t, uint64_t> AlreadyAllocated;
558 // Move the previously applied mappings (whether explicitly specified on the
559 // command line, or implicitly set by RuntimeDyld) into the already-allocated
561 for (WorklistT::iterator I = Worklist.begin(), E = Worklist.end();
563 WorklistT::iterator Tmp = I;
565 auto LoadAddr = Checker.getSectionLoadAddress(Tmp->first);
568 *LoadAddr != static_cast<uint64_t>(
569 reinterpret_cast<uintptr_t>(Tmp->first))) {
570 AlreadyAllocated[*LoadAddr] = Tmp->second;
575 // If the -target-addr-end option wasn't explicitly passed, then set it to a
576 // sensible default based on the target triple.
577 if (TargetAddrEnd.getNumOccurrences() == 0) {
578 if (TargetTriple.isArch16Bit())
579 TargetAddrEnd = (1ULL << 16) - 1;
580 else if (TargetTriple.isArch32Bit())
581 TargetAddrEnd = (1ULL << 32) - 1;
582 // TargetAddrEnd already has a sensible default for 64-bit systems, so
583 // there's nothing to do in the 64-bit case.
586 // Process any elements remaining in the worklist.
587 while (!Worklist.empty()) {
588 std::pair<void*, uint64_t> CurEntry = Worklist.front();
589 Worklist.pop_front();
591 uint64_t NextSectionAddr = TargetAddrStart;
593 for (const auto &Alloc : AlreadyAllocated)
594 if (NextSectionAddr + CurEntry.second + TargetSectionSep <= Alloc.first)
597 NextSectionAddr = Alloc.first + Alloc.second + TargetSectionSep;
599 AlreadyAllocated[NextSectionAddr] = CurEntry.second;
600 Checker.getRTDyld().mapSectionAddress(CurEntry.first, NextSectionAddr);
603 // Add dummy symbols to the memory manager.
604 for (const auto &Mapping : DummySymbolMappings) {
605 size_t EqualsIdx = Mapping.find_first_of('=');
607 if (EqualsIdx == StringRef::npos)
608 report_fatal_error("Invalid dummy symbol specification '" + Mapping +
609 "'. Should be '<symbol name>=<addr>'");
611 std::string Symbol = Mapping.substr(0, EqualsIdx);
612 std::string AddrStr = Mapping.substr(EqualsIdx + 1);
615 if (StringRef(AddrStr).getAsInteger(0, Addr))
616 report_fatal_error("Invalid symbol mapping '" + Mapping + "'.");
618 MemMgr.addDummySymbol(Symbol, Addr);
622 // Load and link the objects specified on the command line, but do not execute
623 // anything. Instead, attach a RuntimeDyldChecker instance and call it to
624 // verify the correctness of the linked memory.
625 static int linkAndVerify() {
627 // Check for missing triple.
628 if (TripleName == "")
629 ErrorAndExit("-triple required when running in -verify mode.");
631 // Look up the target and build the disassembler.
632 Triple TheTriple(Triple::normalize(TripleName));
633 std::string ErrorStr;
634 const Target *TheTarget =
635 TargetRegistry::lookupTarget("", TheTriple, ErrorStr);
637 ErrorAndExit("Error accessing target '" + TripleName + "': " + ErrorStr);
639 TripleName = TheTriple.getTriple();
641 std::unique_ptr<MCSubtargetInfo> STI(
642 TheTarget->createMCSubtargetInfo(TripleName, MCPU, ""));
644 ErrorAndExit("Unable to create subtarget info!");
646 std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
648 ErrorAndExit("Unable to create target register info!");
650 std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));
652 ErrorAndExit("Unable to create target asm info!");
654 MCContext Ctx(MAI.get(), MRI.get(), nullptr);
656 std::unique_ptr<MCDisassembler> Disassembler(
657 TheTarget->createMCDisassembler(*STI, Ctx));
659 ErrorAndExit("Unable to create disassembler!");
661 std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo());
663 std::unique_ptr<MCInstPrinter> InstPrinter(
664 TheTarget->createMCInstPrinter(Triple(TripleName), 0, *MAI, *MII, *MRI));
666 // Load any dylibs requested on the command line.
669 // Instantiate a dynamic linker.
670 TrivialMemoryManager MemMgr;
671 doPreallocation(MemMgr);
672 RuntimeDyld Dyld(MemMgr, MemMgr);
673 Dyld.setProcessAllSections(true);
674 RuntimeDyldChecker Checker(Dyld, Disassembler.get(), InstPrinter.get(),
677 // If we don't have any input files, read from stdin.
678 if (!InputFileList.size())
679 InputFileList.push_back("-");
680 for (auto &Filename : InputFileList) {
681 // Load the input memory buffer.
682 ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
683 MemoryBuffer::getFileOrSTDIN(Filename);
685 if (std::error_code EC = InputBuffer.getError())
686 ErrorAndExit("unable to read input: '" + EC.message() + "'");
688 Expected<std::unique_ptr<ObjectFile>> MaybeObj(
689 ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
693 raw_string_ostream OS(Buf);
694 logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
696 ErrorAndExit("unable to create object file: '" + Buf + "'");
699 ObjectFile &Obj = **MaybeObj;
701 // Load the object file
702 Dyld.loadObject(Obj);
703 if (Dyld.hasError()) {
704 ErrorAndExit(Dyld.getErrorString());
708 // Re-map the section addresses into the phony target address space and add
710 remapSectionsAndSymbols(TheTriple, MemMgr, Checker);
712 // Resolve all the relocations we can.
713 Dyld.resolveRelocations();
715 // Register EH frames.
716 Dyld.registerEHFrames();
718 int ErrorCode = checkAllExpressions(Checker);
720 ErrorAndExit("RTDyld reported an error applying relocations:\n " +
721 Dyld.getErrorString());
726 int main(int argc, char **argv) {
727 sys::PrintStackTraceOnErrorSignal(argv[0]);
728 PrettyStackTraceProgram X(argc, argv);
730 ProgramName = argv[0];
731 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
733 llvm::InitializeAllTargetInfos();
734 llvm::InitializeAllTargetMCs();
735 llvm::InitializeAllDisassemblers();
737 cl::ParseCommandLineOptions(argc, argv, "llvm MC-JIT tool\n");
741 return executeInput();
742 case AC_PrintDebugLineInfo:
743 return printLineInfoForInput(/* LoadObjects */ true,/* UseDebugObj */ true);
744 case AC_PrintLineInfo:
745 return printLineInfoForInput(/* LoadObjects */ true,/* UseDebugObj */false);
746 case AC_PrintObjectLineInfo:
747 return printLineInfoForInput(/* LoadObjects */false,/* UseDebugObj */false);
749 return linkAndVerify();