COFFDump.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //===-- COFFDump.cpp - COFF-specific dumper ---------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. ///
  10. /// \file
  11. /// \brief This file implements the COFF-specific dumper for llvm-objdump.
  12. /// It outputs the Win64 EH data structures as plain text.
  13. /// The encoding of the unwind codes is described in MSDN:
  14. /// http://msdn.microsoft.com/en-us/library/ck9asaa9.aspx
  15. ///
  16. //===----------------------------------------------------------------------===//
  17. #include "llvm-objdump.h"
  18. #include "llvm/Object/COFF.h"
  19. #include "llvm/Object/ObjectFile.h"
  20. #include "llvm/Support/Format.h"
  21. #include "llvm/Support/SourceMgr.h"
  22. #include "llvm/Support/Win64EH.h"
  23. #include "llvm/Support/raw_ostream.h"
  24. #include <algorithm>
  25. #include <cstring>
  26. #include <system_error>
  27. using namespace llvm;
  28. using namespace object;
  29. using namespace llvm::Win64EH;
  30. // Returns the name of the unwind code.
  31. static StringRef getUnwindCodeTypeName(uint8_t Code) {
  32. switch(Code) {
  33. default: llvm_unreachable("Invalid unwind code");
  34. case UOP_PushNonVol: return "UOP_PushNonVol";
  35. case UOP_AllocLarge: return "UOP_AllocLarge";
  36. case UOP_AllocSmall: return "UOP_AllocSmall";
  37. case UOP_SetFPReg: return "UOP_SetFPReg";
  38. case UOP_SaveNonVol: return "UOP_SaveNonVol";
  39. case UOP_SaveNonVolBig: return "UOP_SaveNonVolBig";
  40. case UOP_SaveXMM128: return "UOP_SaveXMM128";
  41. case UOP_SaveXMM128Big: return "UOP_SaveXMM128Big";
  42. case UOP_PushMachFrame: return "UOP_PushMachFrame";
  43. }
  44. }
  45. // Returns the name of a referenced register.
  46. static StringRef getUnwindRegisterName(uint8_t Reg) {
  47. switch(Reg) {
  48. default: llvm_unreachable("Invalid register");
  49. case 0: return "RAX";
  50. case 1: return "RCX";
  51. case 2: return "RDX";
  52. case 3: return "RBX";
  53. case 4: return "RSP";
  54. case 5: return "RBP";
  55. case 6: return "RSI";
  56. case 7: return "RDI";
  57. case 8: return "R8";
  58. case 9: return "R9";
  59. case 10: return "R10";
  60. case 11: return "R11";
  61. case 12: return "R12";
  62. case 13: return "R13";
  63. case 14: return "R14";
  64. case 15: return "R15";
  65. }
  66. }
  67. // Calculates the number of array slots required for the unwind code.
  68. static unsigned getNumUsedSlots(const UnwindCode &UnwindCode) {
  69. switch (UnwindCode.getUnwindOp()) {
  70. default: llvm_unreachable("Invalid unwind code");
  71. case UOP_PushNonVol:
  72. case UOP_AllocSmall:
  73. case UOP_SetFPReg:
  74. case UOP_PushMachFrame:
  75. return 1;
  76. case UOP_SaveNonVol:
  77. case UOP_SaveXMM128:
  78. return 2;
  79. case UOP_SaveNonVolBig:
  80. case UOP_SaveXMM128Big:
  81. return 3;
  82. case UOP_AllocLarge:
  83. return (UnwindCode.getOpInfo() == 0) ? 2 : 3;
  84. }
  85. }
  86. // Prints one unwind code. Because an unwind code can occupy up to 3 slots in
  87. // the unwind codes array, this function requires that the correct number of
  88. // slots is provided.
  89. static void printUnwindCode(ArrayRef<UnwindCode> UCs) {
  90. assert(UCs.size() >= getNumUsedSlots(UCs[0]));
  91. outs() << format(" 0x%02x: ", unsigned(UCs[0].u.CodeOffset))
  92. << getUnwindCodeTypeName(UCs[0].getUnwindOp());
  93. switch (UCs[0].getUnwindOp()) {
  94. case UOP_PushNonVol:
  95. outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo());
  96. break;
  97. case UOP_AllocLarge:
  98. if (UCs[0].getOpInfo() == 0) {
  99. outs() << " " << UCs[1].FrameOffset;
  100. } else {
  101. outs() << " " << UCs[1].FrameOffset
  102. + (static_cast<uint32_t>(UCs[2].FrameOffset) << 16);
  103. }
  104. break;
  105. case UOP_AllocSmall:
  106. outs() << " " << ((UCs[0].getOpInfo() + 1) * 8);
  107. break;
  108. case UOP_SetFPReg:
  109. outs() << " ";
  110. break;
  111. case UOP_SaveNonVol:
  112. outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo())
  113. << format(" [0x%04x]", 8 * UCs[1].FrameOffset);
  114. break;
  115. case UOP_SaveNonVolBig:
  116. outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo())
  117. << format(" [0x%08x]", UCs[1].FrameOffset
  118. + (static_cast<uint32_t>(UCs[2].FrameOffset) << 16));
  119. break;
  120. case UOP_SaveXMM128:
  121. outs() << " XMM" << static_cast<uint32_t>(UCs[0].getOpInfo())
  122. << format(" [0x%04x]", 16 * UCs[1].FrameOffset);
  123. break;
  124. case UOP_SaveXMM128Big:
  125. outs() << " XMM" << UCs[0].getOpInfo()
  126. << format(" [0x%08x]", UCs[1].FrameOffset
  127. + (static_cast<uint32_t>(UCs[2].FrameOffset) << 16));
  128. break;
  129. case UOP_PushMachFrame:
  130. outs() << " " << (UCs[0].getOpInfo() ? "w/o" : "w")
  131. << " error code";
  132. break;
  133. }
  134. outs() << "\n";
  135. }
  136. static void printAllUnwindCodes(ArrayRef<UnwindCode> UCs) {
  137. for (const UnwindCode *I = UCs.begin(), *E = UCs.end(); I < E; ) {
  138. unsigned UsedSlots = getNumUsedSlots(*I);
  139. if (UsedSlots > UCs.size()) {
  140. outs() << "Unwind data corrupted: Encountered unwind op "
  141. << getUnwindCodeTypeName((*I).getUnwindOp())
  142. << " which requires " << UsedSlots
  143. << " slots, but only " << UCs.size()
  144. << " remaining in buffer";
  145. return ;
  146. }
  147. printUnwindCode(ArrayRef<UnwindCode>(I, E));
  148. I += UsedSlots;
  149. }
  150. }
  151. // Given a symbol sym this functions returns the address and section of it.
  152. static std::error_code
  153. resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
  154. const coff_section *&ResolvedSection,
  155. uint64_t &ResolvedAddr) {
  156. ErrorOr<uint64_t> ResolvedAddrOrErr = Sym.getAddress();
  157. if (std::error_code EC = ResolvedAddrOrErr.getError())
  158. return EC;
  159. ResolvedAddr = *ResolvedAddrOrErr;
  160. section_iterator iter(Obj->section_begin());
  161. if (std::error_code EC = Sym.getSection(iter))
  162. return EC;
  163. ResolvedSection = Obj->getCOFFSection(*iter);
  164. return std::error_code();
  165. }
  166. // Given a vector of relocations for a section and an offset into this section
  167. // the function returns the symbol used for the relocation at the offset.
  168. static std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
  169. uint64_t Offset, SymbolRef &Sym) {
  170. for (std::vector<RelocationRef>::const_iterator I = Rels.begin(),
  171. E = Rels.end();
  172. I != E; ++I) {
  173. uint64_t Ofs = I->getOffset();
  174. if (Ofs == Offset) {
  175. Sym = *I->getSymbol();
  176. return std::error_code();
  177. }
  178. }
  179. return object_error::parse_failed;
  180. }
  181. // Given a vector of relocations for a section and an offset into this section
  182. // the function resolves the symbol used for the relocation at the offset and
  183. // returns the section content and the address inside the content pointed to
  184. // by the symbol.
  185. static std::error_code
  186. getSectionContents(const COFFObjectFile *Obj,
  187. const std::vector<RelocationRef> &Rels, uint64_t Offset,
  188. ArrayRef<uint8_t> &Contents, uint64_t &Addr) {
  189. SymbolRef Sym;
  190. if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
  191. return EC;
  192. const coff_section *Section;
  193. if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
  194. return EC;
  195. if (std::error_code EC = Obj->getSectionContents(Section, Contents))
  196. return EC;
  197. return std::error_code();
  198. }
  199. // Given a vector of relocations for a section and an offset into this section
  200. // the function returns the name of the symbol used for the relocation at the
  201. // offset.
  202. static std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels,
  203. uint64_t Offset, StringRef &Name) {
  204. SymbolRef Sym;
  205. if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
  206. return EC;
  207. ErrorOr<StringRef> NameOrErr = Sym.getName();
  208. if (std::error_code EC = NameOrErr.getError())
  209. return EC;
  210. Name = *NameOrErr;
  211. return std::error_code();
  212. }
  213. static void printCOFFSymbolAddress(llvm::raw_ostream &Out,
  214. const std::vector<RelocationRef> &Rels,
  215. uint64_t Offset, uint32_t Disp) {
  216. StringRef Sym;
  217. if (!resolveSymbolName(Rels, Offset, Sym)) {
  218. Out << Sym;
  219. if (Disp > 0)
  220. Out << format(" + 0x%04x", Disp);
  221. } else {
  222. Out << format("0x%04x", Disp);
  223. }
  224. }
  225. static void
  226. printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) {
  227. if (Count == 0)
  228. return;
  229. const pe32_header *PE32Header;
  230. if (error(Obj->getPE32Header(PE32Header)))
  231. return;
  232. uint32_t ImageBase = PE32Header->ImageBase;
  233. uintptr_t IntPtr = 0;
  234. if (error(Obj->getVaPtr(TableVA, IntPtr)))
  235. return;
  236. const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
  237. outs() << "SEH Table:";
  238. for (int I = 0; I < Count; ++I)
  239. outs() << format(" 0x%x", P[I] + ImageBase);
  240. outs() << "\n\n";
  241. }
  242. static void printLoadConfiguration(const COFFObjectFile *Obj) {
  243. // Skip if it's not executable.
  244. const pe32_header *PE32Header;
  245. if (error(Obj->getPE32Header(PE32Header)))
  246. return;
  247. if (!PE32Header)
  248. return;
  249. // Currently only x86 is supported
  250. if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_I386)
  251. return;
  252. const data_directory *DataDir;
  253. if (error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir)))
  254. return;
  255. uintptr_t IntPtr = 0;
  256. if (DataDir->RelativeVirtualAddress == 0)
  257. return;
  258. if (error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr)))
  259. return;
  260. auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
  261. outs() << "Load configuration:"
  262. << "\n Timestamp: " << LoadConf->TimeDateStamp
  263. << "\n Major Version: " << LoadConf->MajorVersion
  264. << "\n Minor Version: " << LoadConf->MinorVersion
  265. << "\n GlobalFlags Clear: " << LoadConf->GlobalFlagsClear
  266. << "\n GlobalFlags Set: " << LoadConf->GlobalFlagsSet
  267. << "\n Critical Section Default Timeout: " << LoadConf->CriticalSectionDefaultTimeout
  268. << "\n Decommit Free Block Threshold: " << LoadConf->DeCommitFreeBlockThreshold
  269. << "\n Decommit Total Free Threshold: " << LoadConf->DeCommitTotalFreeThreshold
  270. << "\n Lock Prefix Table: " << LoadConf->LockPrefixTable
  271. << "\n Maximum Allocation Size: " << LoadConf->MaximumAllocationSize
  272. << "\n Virtual Memory Threshold: " << LoadConf->VirtualMemoryThreshold
  273. << "\n Process Affinity Mask: " << LoadConf->ProcessAffinityMask
  274. << "\n Process Heap Flags: " << LoadConf->ProcessHeapFlags
  275. << "\n CSD Version: " << LoadConf->CSDVersion
  276. << "\n Security Cookie: " << LoadConf->SecurityCookie
  277. << "\n SEH Table: " << LoadConf->SEHandlerTable
  278. << "\n SEH Count: " << LoadConf->SEHandlerCount
  279. << "\n\n";
  280. printSEHTable(Obj, LoadConf->SEHandlerTable, LoadConf->SEHandlerCount);
  281. outs() << "\n";
  282. }
  283. // Prints import tables. The import table is a table containing the list of
  284. // DLL name and symbol names which will be linked by the loader.
  285. static void printImportTables(const COFFObjectFile *Obj) {
  286. import_directory_iterator I = Obj->import_directory_begin();
  287. import_directory_iterator E = Obj->import_directory_end();
  288. if (I == E)
  289. return;
  290. outs() << "The Import Tables:\n";
  291. for (; I != E; I = ++I) {
  292. const import_directory_table_entry *Dir;
  293. StringRef Name;
  294. if (I->getImportTableEntry(Dir)) return;
  295. if (I->getName(Name)) return;
  296. outs() << format(" lookup %08x time %08x fwd %08x name %08x addr %08x\n\n",
  297. static_cast<uint32_t>(Dir->ImportLookupTableRVA),
  298. static_cast<uint32_t>(Dir->TimeDateStamp),
  299. static_cast<uint32_t>(Dir->ForwarderChain),
  300. static_cast<uint32_t>(Dir->NameRVA),
  301. static_cast<uint32_t>(Dir->ImportAddressTableRVA));
  302. outs() << " DLL Name: " << Name << "\n";
  303. outs() << " Hint/Ord Name\n";
  304. const import_lookup_table_entry32 *entry;
  305. if (I->getImportLookupEntry(entry))
  306. return;
  307. for (; entry->Data; ++entry) {
  308. if (entry->isOrdinal()) {
  309. outs() << format(" % 6d\n", entry->getOrdinal());
  310. continue;
  311. }
  312. uint16_t Hint;
  313. StringRef Name;
  314. if (Obj->getHintName(entry->getHintNameRVA(), Hint, Name))
  315. return;
  316. outs() << format(" % 6d ", Hint) << Name << "\n";
  317. }
  318. outs() << "\n";
  319. }
  320. }
  321. // Prints export tables. The export table is a table containing the list of
  322. // exported symbol from the DLL.
  323. static void printExportTable(const COFFObjectFile *Obj) {
  324. outs() << "Export Table:\n";
  325. export_directory_iterator I = Obj->export_directory_begin();
  326. export_directory_iterator E = Obj->export_directory_end();
  327. if (I == E)
  328. return;
  329. StringRef DllName;
  330. uint32_t OrdinalBase;
  331. if (I->getDllName(DllName))
  332. return;
  333. if (I->getOrdinalBase(OrdinalBase))
  334. return;
  335. outs() << " DLL name: " << DllName << "\n";
  336. outs() << " Ordinal base: " << OrdinalBase << "\n";
  337. outs() << " Ordinal RVA Name\n";
  338. for (; I != E; I = ++I) {
  339. uint32_t Ordinal;
  340. if (I->getOrdinal(Ordinal))
  341. return;
  342. uint32_t RVA;
  343. if (I->getExportRVA(RVA))
  344. return;
  345. outs() << format(" % 4d %# 8x", Ordinal, RVA);
  346. StringRef Name;
  347. if (I->getSymbolName(Name))
  348. continue;
  349. if (!Name.empty())
  350. outs() << " " << Name;
  351. outs() << "\n";
  352. }
  353. }
  354. // Given the COFF object file, this function returns the relocations for .pdata
  355. // and the pointer to "runtime function" structs.
  356. static bool getPDataSection(const COFFObjectFile *Obj,
  357. std::vector<RelocationRef> &Rels,
  358. const RuntimeFunction *&RFStart, int &NumRFs) {
  359. for (const SectionRef &Section : Obj->sections()) {
  360. StringRef Name;
  361. if (error(Section.getName(Name)))
  362. continue;
  363. if (Name != ".pdata")
  364. continue;
  365. const coff_section *Pdata = Obj->getCOFFSection(Section);
  366. for (const RelocationRef &Reloc : Section.relocations())
  367. Rels.push_back(Reloc);
  368. // Sort relocations by address.
  369. std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
  370. ArrayRef<uint8_t> Contents;
  371. if (error(Obj->getSectionContents(Pdata, Contents)))
  372. continue;
  373. if (Contents.empty())
  374. continue;
  375. RFStart = reinterpret_cast<const RuntimeFunction *>(Contents.data());
  376. NumRFs = Contents.size() / sizeof(RuntimeFunction);
  377. return true;
  378. }
  379. return false;
  380. }
  381. static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo *UI) {
  382. // The casts to int are required in order to output the value as number.
  383. // Without the casts the value would be interpreted as char data (which
  384. // results in garbage output).
  385. outs() << " Version: " << static_cast<int>(UI->getVersion()) << "\n";
  386. outs() << " Flags: " << static_cast<int>(UI->getFlags());
  387. if (UI->getFlags()) {
  388. if (UI->getFlags() & UNW_ExceptionHandler)
  389. outs() << " UNW_ExceptionHandler";
  390. if (UI->getFlags() & UNW_TerminateHandler)
  391. outs() << " UNW_TerminateHandler";
  392. if (UI->getFlags() & UNW_ChainInfo)
  393. outs() << " UNW_ChainInfo";
  394. }
  395. outs() << "\n";
  396. outs() << " Size of prolog: " << static_cast<int>(UI->PrologSize) << "\n";
  397. outs() << " Number of Codes: " << static_cast<int>(UI->NumCodes) << "\n";
  398. // Maybe this should move to output of UOP_SetFPReg?
  399. if (UI->getFrameRegister()) {
  400. outs() << " Frame register: "
  401. << getUnwindRegisterName(UI->getFrameRegister()) << "\n";
  402. outs() << " Frame offset: " << 16 * UI->getFrameOffset() << "\n";
  403. } else {
  404. outs() << " No frame pointer used\n";
  405. }
  406. if (UI->getFlags() & (UNW_ExceptionHandler | UNW_TerminateHandler)) {
  407. // FIXME: Output exception handler data
  408. } else if (UI->getFlags() & UNW_ChainInfo) {
  409. // FIXME: Output chained unwind info
  410. }
  411. if (UI->NumCodes)
  412. outs() << " Unwind Codes:\n";
  413. printAllUnwindCodes(ArrayRef<UnwindCode>(&UI->UnwindCodes[0], UI->NumCodes));
  414. outs() << "\n";
  415. outs().flush();
  416. }
  417. /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
  418. /// pointing to an executable file.
  419. static void printRuntimeFunction(const COFFObjectFile *Obj,
  420. const RuntimeFunction &RF) {
  421. if (!RF.StartAddress)
  422. return;
  423. outs() << "Function Table:\n"
  424. << format(" Start Address: 0x%04x\n",
  425. static_cast<uint32_t>(RF.StartAddress))
  426. << format(" End Address: 0x%04x\n",
  427. static_cast<uint32_t>(RF.EndAddress))
  428. << format(" Unwind Info Address: 0x%04x\n",
  429. static_cast<uint32_t>(RF.UnwindInfoOffset));
  430. uintptr_t addr;
  431. if (Obj->getRvaPtr(RF.UnwindInfoOffset, addr))
  432. return;
  433. printWin64EHUnwindInfo(reinterpret_cast<const Win64EH::UnwindInfo *>(addr));
  434. }
  435. /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
  436. /// pointing to an object file. Unlike executable, fields in RuntimeFunction
  437. /// struct are filled with zeros, but instead there are relocations pointing to
  438. /// them so that the linker will fill targets' RVAs to the fields at link
  439. /// time. This function interprets the relocations to find the data to be used
  440. /// in the resulting executable.
  441. static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
  442. const RuntimeFunction &RF,
  443. uint64_t SectionOffset,
  444. const std::vector<RelocationRef> &Rels) {
  445. outs() << "Function Table:\n";
  446. outs() << " Start Address: ";
  447. printCOFFSymbolAddress(outs(), Rels,
  448. SectionOffset +
  449. /*offsetof(RuntimeFunction, StartAddress)*/ 0,
  450. RF.StartAddress);
  451. outs() << "\n";
  452. outs() << " End Address: ";
  453. printCOFFSymbolAddress(outs(), Rels,
  454. SectionOffset +
  455. /*offsetof(RuntimeFunction, EndAddress)*/ 4,
  456. RF.EndAddress);
  457. outs() << "\n";
  458. outs() << " Unwind Info Address: ";
  459. printCOFFSymbolAddress(outs(), Rels,
  460. SectionOffset +
  461. /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
  462. RF.UnwindInfoOffset);
  463. outs() << "\n";
  464. ArrayRef<uint8_t> XContents;
  465. uint64_t UnwindInfoOffset = 0;
  466. if (error(getSectionContents(
  467. Obj, Rels, SectionOffset +
  468. /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
  469. XContents, UnwindInfoOffset)))
  470. return;
  471. if (XContents.empty())
  472. return;
  473. UnwindInfoOffset += RF.UnwindInfoOffset;
  474. if (UnwindInfoOffset > XContents.size())
  475. return;
  476. auto *UI = reinterpret_cast<const Win64EH::UnwindInfo *>(XContents.data() +
  477. UnwindInfoOffset);
  478. printWin64EHUnwindInfo(UI);
  479. }
  480. void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
  481. if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) {
  482. errs() << "Unsupported image machine type "
  483. "(currently only AMD64 is supported).\n";
  484. return;
  485. }
  486. std::vector<RelocationRef> Rels;
  487. const RuntimeFunction *RFStart;
  488. int NumRFs;
  489. if (!getPDataSection(Obj, Rels, RFStart, NumRFs))
  490. return;
  491. ArrayRef<RuntimeFunction> RFs(RFStart, NumRFs);
  492. bool IsExecutable = Rels.empty();
  493. if (IsExecutable) {
  494. for (const RuntimeFunction &RF : RFs)
  495. printRuntimeFunction(Obj, RF);
  496. return;
  497. }
  498. for (const RuntimeFunction &RF : RFs) {
  499. uint64_t SectionOffset =
  500. std::distance(RFs.begin(), &RF) * sizeof(RuntimeFunction);
  501. printRuntimeFunctionRels(Obj, RF, SectionOffset, Rels);
  502. }
  503. }
  504. void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) {
  505. const COFFObjectFile *file = dyn_cast<const COFFObjectFile>(Obj);
  506. printLoadConfiguration(file);
  507. printImportTables(file);
  508. printExportTable(file);
  509. }