blob: f3333f23faf774a4877bf30edb020b22fc98ad86 [file] [log] [blame]
Lang Hames11c8dfa52019-04-20 17:10:34 +00001//===- llvm-jitlink.cpp -- Command line interface/tester for llvm-jitlink -===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This utility provides a simple command line interface to the llvm jitlink
10// library, which makes relocatable object files executable in memory. Its
11// primary function is as a testing utility for the jitlink library.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm-jitlink.h"
16
17#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
18#include "llvm/MC/MCAsmInfo.h"
19#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCDisassembler/MCDisassembler.h"
21#include "llvm/MC/MCInstPrinter.h"
22#include "llvm/MC/MCInstrInfo.h"
23#include "llvm/MC/MCRegisterInfo.h"
24#include "llvm/MC/MCSubtargetInfo.h"
25#include "llvm/Object/COFF.h"
26#include "llvm/Object/MachO.h"
27#include "llvm/Object/ObjectFile.h"
28#include "llvm/Support/CommandLine.h"
29#include "llvm/Support/Debug.h"
30#include "llvm/Support/DynamicLibrary.h"
31#include "llvm/Support/InitLLVM.h"
32#include "llvm/Support/MemoryBuffer.h"
33#include "llvm/Support/TargetRegistry.h"
34#include "llvm/Support/TargetSelect.h"
35
36#include <list>
37#include <string>
38
Lang Hames11c8dfa52019-04-20 17:10:34 +000039#define DEBUG_TYPE "llvm-jitlink"
40
41using namespace llvm;
42using namespace llvm::jitlink;
43using namespace llvm::orc;
44
45static cl::list<std::string> InputFiles(cl::Positional, cl::OneOrMore,
46 cl::desc("input files"));
47
48static cl::opt<bool> NoExec("noexec", cl::desc("Do not execute loaded code"),
49 cl::init(false));
50
51static cl::list<std::string>
52 CheckFiles("check", cl::desc("File containing verifier checks"),
53 cl::ZeroOrMore);
54
55static cl::opt<std::string>
56 EntryPointName("entry", cl::desc("Symbol to call as main entry point"),
57 cl::init(""));
58
59static cl::list<std::string> JITLinkDylibs(
60 "jld", cl::desc("Specifies the JITDylib to be used for any subsequent "
61 "input file arguments"));
62
63static cl::list<std::string>
64 Dylibs("dlopen", cl::desc("Dynamic libraries to load before linking"),
65 cl::ZeroOrMore);
66
67static cl::opt<bool>
68 NoProcessSymbols("no-process-syms",
69 cl::desc("Do not resolve to llvm-jitlink process symbols"),
70 cl::init(false));
71
Nico Weber405e62b2019-04-21 23:50:24 +000072static cl::list<std::string> AbsoluteDefs(
73 "define-abs",
74 cl::desc("Inject absolute symbol definitions (syntax: <name>=<addr>)"),
75 cl::ZeroOrMore);
Lang Hames11c8dfa52019-04-20 17:10:34 +000076
77static cl::opt<bool> ShowAddrs(
78 "show-addrs",
79 cl::desc("Print registered symbol, section, got and stub addresses"),
80 cl::init(false));
81
82static cl::opt<bool> ShowAtomGraph(
83 "show-graph",
84 cl::desc("Print the atom graph after fixups have been applied"),
85 cl::init(false));
86
87static cl::opt<bool> ShowSizes(
Lang Hamesbc76bbc2019-04-21 20:34:19 +000088 "show-sizes",
89 cl::desc("Show sizes pre- and post-dead stripping, and allocations"),
90 cl::init(false));
91
92static cl::opt<bool> ShowRelocatedSectionContents(
93 "show-relocated-section-contents",
94 cl::desc("show section contents after fixups have been applied"),
95 cl::init(false));
Lang Hames11c8dfa52019-04-20 17:10:34 +000096
97ExitOnError ExitOnErr;
98
99namespace llvm {
100
101static raw_ostream &
102operator<<(raw_ostream &OS, const Session::MemoryRegionInfo &MRI) {
103 return OS << "target addr = " << format("0x%016" PRIx64, MRI.TargetAddress)
104 << ", content: " << (const void *)MRI.Content.data() << " -- "
105 << (const void *)(MRI.Content.data() + MRI.Content.size()) << " ("
106 << MRI.Content.size() << " bytes)";
107}
108
109static raw_ostream &
110operator<<(raw_ostream &OS, const Session::SymbolInfoMap &SIM) {
111 OS << "Symbols:\n";
112 for (auto &SKV : SIM)
113 OS << " \"" << SKV.first() << "\" " << SKV.second << "\n";
114 return OS;
115}
116
117static raw_ostream &
118operator<<(raw_ostream &OS, const Session::FileInfo &FI) {
119 for (auto &SIKV : FI.SectionInfos)
120 OS << " Section \"" << SIKV.first() << "\": " << SIKV.second << "\n";
121 for (auto &GOTKV : FI.GOTEntryInfos)
122 OS << " GOT \"" << GOTKV.first() << "\": " << GOTKV.second << "\n";
123 for (auto &StubKV : FI.StubInfos)
124 OS << " Stub \"" << StubKV.first() << "\": " << StubKV.second << "\n";
125 return OS;
126}
127
128static raw_ostream &
129operator<<(raw_ostream &OS, const Session::FileInfoMap &FIM) {
130 for (auto &FIKV : FIM)
131 OS << "File \"" << FIKV.first() << "\":\n" << FIKV.second;
132 return OS;
133}
134
135static uint64_t computeTotalAtomSizes(AtomGraph &G) {
136 uint64_t TotalSize = 0;
137 for (auto *DA : G.defined_atoms())
138 if (DA->isZeroFill())
139 TotalSize += DA->getZeroFillSize();
140 else
141 TotalSize += DA->getContent().size();
142 return TotalSize;
143}
144
Lang Hamesbc76bbc2019-04-21 20:34:19 +0000145static void dumpSectionContents(raw_ostream &OS, AtomGraph &G) {
146 constexpr JITTargetAddress DumpWidth = 16;
147 static_assert(isPowerOf2_64(DumpWidth), "DumpWidth must be a power of two");
148
149 // Put sections in address order.
150 std::vector<Section *> Sections;
151 for (auto &S : G.sections())
152 Sections.push_back(&S);
153
154 std::sort(Sections.begin(), Sections.end(),
155 [](const Section *LHS, const Section *RHS) {
156 if (LHS->atoms_empty() && RHS->atoms_empty())
157 return false;
158 if (LHS->atoms_empty())
159 return false;
160 if (RHS->atoms_empty())
161 return true;
162 return (*LHS->atoms().begin())->getAddress() <
163 (*RHS->atoms().begin())->getAddress();
164 });
165
166 for (auto *S : Sections) {
167 OS << S->getName() << " content:";
168 if (S->atoms_empty()) {
169 OS << "\n section empty\n";
170 continue;
171 }
172
173 // Sort atoms into order, then render.
174 std::vector<DefinedAtom *> Atoms(S->atoms().begin(), S->atoms().end());
175 std::sort(Atoms.begin(), Atoms.end(),
176 [](const DefinedAtom *LHS, const DefinedAtom *RHS) {
177 return LHS->getAddress() < RHS->getAddress();
178 });
179
180 JITTargetAddress NextAddr = Atoms.front()->getAddress() & ~(DumpWidth - 1);
181 for (auto *DA : Atoms) {
182 bool IsZeroFill = DA->isZeroFill();
183 JITTargetAddress AtomStart = DA->getAddress();
184 JITTargetAddress AtomSize =
185 IsZeroFill ? DA->getZeroFillSize() : DA->getContent().size();
186 JITTargetAddress AtomEnd = AtomStart + AtomSize;
187 const uint8_t *AtomData =
188 IsZeroFill ? nullptr : DA->getContent().bytes_begin();
189
190 // Pad any space before the atom starts.
191 while (NextAddr != AtomStart) {
192 if (NextAddr % DumpWidth == 0)
193 OS << formatv("\n{0:x16}:", NextAddr);
194 OS << " ";
195 ++NextAddr;
196 }
197
198 // Render the atom content.
199 while (NextAddr != AtomEnd) {
200 if (NextAddr % DumpWidth == 0)
201 OS << formatv("\n{0:x16}:", NextAddr);
202 if (IsZeroFill)
203 OS << " 00";
204 else
205 OS << formatv(" {0:x-2}", AtomData[NextAddr - AtomStart]);
206 ++NextAddr;
207 }
208 }
209 OS << "\n";
210 }
211}
212
Lang Hames11c8dfa52019-04-20 17:10:34 +0000213Session::Session(Triple TT)
214 : ObjLayer(ES, MemMgr, ObjectLinkingLayer::NotifyLoadedFunction(),
215 ObjectLinkingLayer::NotifyEmittedFunction(),
216 [this](const Triple &TT, PassConfiguration &PassConfig) {
217 modifyPassConfig(TT, PassConfig);
218 }),
219 TT(std::move(TT)) {}
220
221void Session::dumpSessionInfo(raw_ostream &OS) {
222 OS << "Registered addresses:\n" << SymbolInfos << FileInfos;
223}
224
225void Session::modifyPassConfig(const Triple &FTT,
226 PassConfiguration &PassConfig) {
227 if (!CheckFiles.empty())
228 PassConfig.PostFixupPasses.push_back([this](AtomGraph &G) {
229 if (TT.getObjectFormat() == Triple::MachO)
230 return registerMachOStubsAndGOT(*this, G);
231 return make_error<StringError>("Unsupported object format for GOT/stub "
232 "registration",
233 inconvertibleErrorCode());
234 });
235
236 if (ShowAtomGraph)
237 PassConfig.PostFixupPasses.push_back([](AtomGraph &G) -> Error {
238 outs() << "Atom graph post-fixup:\n";
239 G.dump(outs());
240 return Error::success();
241 });
242
243
244 if (ShowSizes) {
245 PassConfig.PrePrunePasses.push_back([this](AtomGraph &G) -> Error {
246 SizeBeforePruning += computeTotalAtomSizes(G);
247 return Error::success();
248 });
249 PassConfig.PostFixupPasses.push_back([this](AtomGraph &G) -> Error {
250 SizeAfterFixups += computeTotalAtomSizes(G);
251 return Error::success();
252 });
253 }
254
Lang Hamesbc76bbc2019-04-21 20:34:19 +0000255 if (ShowRelocatedSectionContents)
256 PassConfig.PostFixupPasses.push_back([](AtomGraph &G) -> Error {
257 outs() << "Relocated section contents for " << G.getName() << ":\n";
258 dumpSectionContents(outs(), G);
259 return Error::success();
260 });
Lang Hames11c8dfa52019-04-20 17:10:34 +0000261}
262
263Expected<Session::FileInfo &> Session::findFileInfo(StringRef FileName) {
264 auto FileInfoItr = FileInfos.find(FileName);
265 if (FileInfoItr == FileInfos.end())
266 return make_error<StringError>("file \"" + FileName + "\" not recognized",
267 inconvertibleErrorCode());
268 return FileInfoItr->second;
269}
270
271Expected<Session::MemoryRegionInfo &>
272Session::findSectionInfo(StringRef FileName, StringRef SectionName) {
273 auto FI = findFileInfo(FileName);
274 if (!FI)
275 return FI.takeError();
276 auto SecInfoItr = FI->SectionInfos.find(SectionName);
277 if (SecInfoItr == FI->SectionInfos.end())
278 return make_error<StringError>("no section \"" + SectionName +
279 "\" registered for file \"" + FileName +
280 "\"",
281 inconvertibleErrorCode());
282 return SecInfoItr->second;
283}
284
285Expected<Session::MemoryRegionInfo &>
286Session::findStubInfo(StringRef FileName, StringRef TargetName) {
287 auto FI = findFileInfo(FileName);
288 if (!FI)
289 return FI.takeError();
290 auto StubInfoItr = FI->StubInfos.find(TargetName);
291 if (StubInfoItr == FI->StubInfos.end())
292 return make_error<StringError>("no stub for \"" + TargetName +
293 "\" registered for file \"" + FileName +
294 "\"",
295 inconvertibleErrorCode());
296 return StubInfoItr->second;
297}
298
299Expected<Session::MemoryRegionInfo &>
300Session::findGOTEntryInfo(StringRef FileName, StringRef TargetName) {
301 auto FI = findFileInfo(FileName);
302 if (!FI)
303 return FI.takeError();
304 auto GOTInfoItr = FI->GOTEntryInfos.find(TargetName);
305 if (GOTInfoItr == FI->GOTEntryInfos.end())
306 return make_error<StringError>("no GOT entry for \"" + TargetName +
307 "\" registered for file \"" + FileName +
308 "\"",
309 inconvertibleErrorCode());
310 return GOTInfoItr->second;
311}
312
313bool Session::isSymbolRegistered(StringRef SymbolName) {
314 return SymbolInfos.count(SymbolName);
315}
316
317Expected<Session::MemoryRegionInfo &>
318Session::findSymbolInfo(StringRef SymbolName, Twine ErrorMsgStem) {
319 auto SymInfoItr = SymbolInfos.find(SymbolName);
320 if (SymInfoItr == SymbolInfos.end())
321 return make_error<StringError>(ErrorMsgStem + ": symbol " + SymbolName +
322 " not found",
323 inconvertibleErrorCode());
324 return SymInfoItr->second;
325}
326
327} // end namespace llvm
328
329Error loadProcessSymbols(Session &S) {
330 std::string ErrMsg;
331 if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &ErrMsg))
332 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
333
334 char GlobalPrefix = S.TT.getObjectFormat() == Triple::MachO ? '_' : '\0';
335 S.ES.getMainJITDylib().setGenerator(ExitOnErr(
336 orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(GlobalPrefix)));
337
338 return Error::success();
339}
340
341Error loadDylibs() {
342 // FIXME: This should all be handled inside DynamicLibrary.
343 for (const auto &Dylib : Dylibs) {
344 if (!sys::fs::is_regular_file(Dylib))
345 return make_error<StringError>("\"" + Dylib + "\" is not a regular file",
346 inconvertibleErrorCode());
347 std::string ErrMsg;
348 if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))
349 return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
350 }
351
352 return Error::success();
353}
354
355Triple getFirstFileTriple() {
356 assert(!InputFiles.empty() && "InputFiles can not be empty");
357 auto ObjBuffer =
358 ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFiles.front())));
359 auto Obj = ExitOnErr(
360 object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef()));
361 return Obj->makeTriple();
362}
363
364Error loadObjects(Session &S) {
365
366 std::map<unsigned, JITDylib *> IdxToJLD;
367
368 // First, set up JITDylibs.
369 LLVM_DEBUG(dbgs() << "Creating JITDylibs...\n");
370 {
371 // Create a "main" JITLinkDylib.
372 auto &MainJD = S.ES.getMainJITDylib();
373 IdxToJLD[0] = &MainJD;
374 S.JDSearchOrder.push_back(&MainJD);
375 LLVM_DEBUG(dbgs() << " 0: " << MainJD.getName() << "\n");
376
377 // Add any extra JITLinkDylibs from the command line.
378 std::string JDNamePrefix("lib");
379 for (auto JLDItr = JITLinkDylibs.begin(), JLDEnd = JITLinkDylibs.end();
380 JLDItr != JLDEnd; ++JLDItr) {
381 auto &JD = S.ES.createJITDylib(JDNamePrefix + *JLDItr);
382 unsigned JDIdx =
383 JITLinkDylibs.getPosition(JLDItr - JITLinkDylibs.begin());
384 IdxToJLD[JDIdx] = &JD;
385 S.JDSearchOrder.push_back(&JD);
386 LLVM_DEBUG(dbgs() << " " << JDIdx << ": " << JD.getName() << "\n");
387 }
388
389 // Set every dylib to link against every other, in command line order.
390 for (auto *JD : S.JDSearchOrder) {
391 JITDylibSearchList O;
392 for (auto *JD2 : S.JDSearchOrder) {
393 if (JD2 == JD)
394 continue;
395 O.push_back(std::make_pair(JD2, false));
396 }
397 JD->setSearchOrder(std::move(O));
398 }
399 }
400
401 // Load each object into the corresponding JITDylib..
402 LLVM_DEBUG(dbgs() << "Adding objects...\n");
403 for (auto InputFileItr = InputFiles.begin(), InputFileEnd = InputFiles.end();
404 InputFileItr != InputFileEnd; ++InputFileItr) {
405 unsigned InputFileArgIdx =
406 InputFiles.getPosition(InputFileItr - InputFiles.begin());
407 StringRef InputFile = *InputFileItr;
408 auto &JD = *std::prev(IdxToJLD.lower_bound(InputFileArgIdx))->second;
409 LLVM_DEBUG(dbgs() << " " << InputFileArgIdx << ": \"" << InputFile
410 << "\" to " << JD.getName() << "\n";);
411 auto ObjBuffer =
412 ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFile)));
413 ExitOnErr(S.ObjLayer.add(JD, std::move(ObjBuffer)));
414 }
415
416 // Define absolute symbols.
417 LLVM_DEBUG(dbgs() << "Defining absolute symbols...\n");
418 for (auto AbsDefItr = AbsoluteDefs.begin(), AbsDefEnd = AbsoluteDefs.end();
419 AbsDefItr != AbsDefEnd; ++AbsDefItr) {
420 unsigned AbsDefArgIdx =
421 AbsoluteDefs.getPosition(AbsDefItr - AbsoluteDefs.begin());
422 auto &JD = *std::prev(IdxToJLD.lower_bound(AbsDefArgIdx))->second;
423
424 StringRef AbsDefStmt = *AbsDefItr;
425 size_t EqIdx = AbsDefStmt.find_first_of('=');
426 if (EqIdx == StringRef::npos)
427 return make_error<StringError>("Invalid absolute define \"" + AbsDefStmt +
428 "\". Syntax: <name>=<addr>",
429 inconvertibleErrorCode());
430 StringRef Name = AbsDefStmt.substr(0, EqIdx).trim();
431 StringRef AddrStr = AbsDefStmt.substr(EqIdx + 1).trim();
432
433 uint64_t Addr;
434 if (AddrStr.getAsInteger(0, Addr))
435 return make_error<StringError>("Invalid address expression \"" + AddrStr +
436 "\" in absolute define \"" + AbsDefStmt +
437 "\"",
438 inconvertibleErrorCode());
439 JITEvaluatedSymbol AbsDef(Addr, JITSymbolFlags::Exported);
440 if (auto Err = JD.define(absoluteSymbols({{S.ES.intern(Name), AbsDef}})))
441 return Err;
442
443 // Register the absolute symbol with the session symbol infos.
444 S.SymbolInfos[Name] = { StringRef(), Addr };
445 }
446
447 LLVM_DEBUG({
448 dbgs() << "Dylib search order is [ ";
449 for (auto *JD : S.JDSearchOrder)
450 dbgs() << JD->getName() << " ";
451 dbgs() << "]\n";
452 });
453
454 return Error::success();
455}
456
457Error runChecks(Session &S) {
458
459 auto TripleName = S.TT.str();
460 std::string ErrorStr;
461 const Target *TheTarget = TargetRegistry::lookupTarget("", S.TT, ErrorStr);
462 if (!TheTarget)
463 ExitOnErr(make_error<StringError>("Error accessing target '" + TripleName +
464 "': " + ErrorStr,
465 inconvertibleErrorCode()));
466
467 std::unique_ptr<MCSubtargetInfo> STI(
468 TheTarget->createMCSubtargetInfo(TripleName, "", ""));
469 if (!STI)
470 ExitOnErr(
471 make_error<StringError>("Unable to create subtarget for " + TripleName,
472 inconvertibleErrorCode()));
473
474 std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
475 if (!MRI)
476 ExitOnErr(make_error<StringError>("Unable to create target register info "
477 "for " +
478 TripleName,
479 inconvertibleErrorCode()));
480
481 std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));
482 if (!MAI)
483 ExitOnErr(make_error<StringError>("Unable to create target asm info " +
484 TripleName,
485 inconvertibleErrorCode()));
486
487 MCContext Ctx(MAI.get(), MRI.get(), nullptr);
488
489 std::unique_ptr<MCDisassembler> Disassembler(
490 TheTarget->createMCDisassembler(*STI, Ctx));
491 if (!Disassembler)
492 ExitOnErr(make_error<StringError>("Unable to create disassembler for " +
493 TripleName,
494 inconvertibleErrorCode()));
495
496 std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo());
497
498 std::unique_ptr<MCInstPrinter> InstPrinter(
499 TheTarget->createMCInstPrinter(Triple(TripleName), 0, *MAI, *MII, *MRI));
500
501 auto IsSymbolValid = [&S](StringRef Symbol) {
502 return S.isSymbolRegistered(Symbol);
503 };
504
505 auto GetSymbolInfo = [&S](StringRef Symbol) {
506 return S.findSymbolInfo(Symbol, "Can not get symbol info");
507 };
508
509 auto GetSectionInfo = [&S](StringRef FileName, StringRef SectionName) {
510 return S.findSectionInfo(FileName, SectionName);
511 };
512
513 auto GetStubInfo = [&S](StringRef FileName, StringRef SectionName) {
514 return S.findStubInfo(FileName, SectionName);
515 };
516
517 auto GetGOTInfo = [&S](StringRef FileName, StringRef SectionName) {
518 return S.findGOTEntryInfo(FileName, SectionName);
519 };
520
521 RuntimeDyldChecker Checker(
522 IsSymbolValid, GetSymbolInfo, GetSectionInfo, GetStubInfo, GetGOTInfo,
523 S.TT.isLittleEndian() ? support::little : support::big,
524 Disassembler.get(), InstPrinter.get(), dbgs());
525
526 for (auto &CheckFile : CheckFiles) {
527 auto CheckerFileBuf =
528 ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(CheckFile)));
529 if (!Checker.checkAllRulesInBuffer("# jitlink-check:", &*CheckerFileBuf))
530 ExitOnErr(make_error<StringError>(
531 "Some checks in " + CheckFile + " failed", inconvertibleErrorCode()));
532 }
533
534 return Error::success();
535}
536
537static void dumpSessionStats(Session &S) {
538 if (ShowSizes)
539 outs() << "Total size of all atoms before pruning: " << S.SizeBeforePruning
540 << "\nTotal size of all atoms after fixups: " << S.SizeAfterFixups
541 << "\n";
542}
543
544static Expected<JITEvaluatedSymbol> getMainEntryPoint(Session &S) {
545
546 // First, if the entry point has not been set, set it to a sensible default
547 // for this process.
548 if (EntryPointName.empty()) {
549 if (S.TT.getObjectFormat() == Triple::MachO)
550 EntryPointName = "_main";
551 else
552 EntryPointName = "main";
553 }
554
555 return S.ES.lookup(S.JDSearchOrder, EntryPointName);
556}
557
558Expected<int> runEntryPoint(Session &S, JITEvaluatedSymbol EntryPoint) {
559 assert(EntryPoint.getAddress() && "Entry point address should not be null");
560
561 constexpr const char *JITProgramName = "<llvm-jitlink jit'd code>";
562 auto PNStorage = llvm::make_unique<char[]>(strlen(JITProgramName) + 1);
563 strcpy(PNStorage.get(), JITProgramName);
564
565 std::vector<const char *> EntryPointArgs;
566 EntryPointArgs.push_back(PNStorage.get());
567 EntryPointArgs.push_back(nullptr);
568
569 using MainTy = int (*)(int, const char *[]);
570 MainTy EntryPointPtr = reinterpret_cast<MainTy>(EntryPoint.getAddress());
571
572 return EntryPointPtr(EntryPointArgs.size() - 1, EntryPointArgs.data());
573}
574
575int main(int argc, char *argv[]) {
576 InitLLVM X(argc, argv);
577
578 InitializeAllTargetInfos();
579 InitializeAllTargetMCs();
580 InitializeAllDisassemblers();
581
582 cl::ParseCommandLineOptions(argc, argv, "llvm jitlink tool");
583 ExitOnErr.setBanner(std::string(argv[0]) + ": ");
584
585 Session S(getFirstFileTriple());
586
587 if (!NoProcessSymbols)
588 ExitOnErr(loadProcessSymbols(S));
589 ExitOnErr(loadDylibs());
590
591 ExitOnErr(loadObjects(S));
592
593 auto EntryPoint = ExitOnErr(getMainEntryPoint(S));
594
595 if (ShowAddrs)
596 S.dumpSessionInfo(outs());
597
598 ExitOnErr(runChecks(S));
599
600 dumpSessionStats(S);
601
602 if (NoExec)
603 return 0;
604
605 return ExitOnErr(runEntryPoint(S, EntryPoint));
606}