1 //===-- COFFDump.cpp - COFF-specific dumper ---------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file implements the COFF-specific dumper for llvm-objdump.
11 /// It outputs the Win64 EH data structures as plain text.
12 /// The encoding of the unwind codes is described in MSDN:
13 /// http://msdn.microsoft.com/en-us/library/ck9asaa9.aspx
15 //===----------------------------------------------------------------------===//
17 #include "llvm-objdump.h"
18 #include "llvm/Demangle/Demangle.h"
19 #include "llvm/Object/COFF.h"
20 #include "llvm/Object/COFFImportFile.h"
21 #include "llvm/Object/ObjectFile.h"
22 #include "llvm/Support/Format.h"
23 #include "llvm/Support/Win64EH.h"
24 #include "llvm/Support/WithColor.h"
25 #include "llvm/Support/raw_ostream.h"
27 using namespace llvm::object
;
28 using namespace llvm::Win64EH
;
31 // Returns the name of the unwind code.
32 static StringRef
getUnwindCodeTypeName(uint8_t Code
) {
34 default: llvm_unreachable("Invalid unwind code");
35 case UOP_PushNonVol
: return "UOP_PushNonVol";
36 case UOP_AllocLarge
: return "UOP_AllocLarge";
37 case UOP_AllocSmall
: return "UOP_AllocSmall";
38 case UOP_SetFPReg
: return "UOP_SetFPReg";
39 case UOP_SaveNonVol
: return "UOP_SaveNonVol";
40 case UOP_SaveNonVolBig
: return "UOP_SaveNonVolBig";
41 case UOP_SaveXMM128
: return "UOP_SaveXMM128";
42 case UOP_SaveXMM128Big
: return "UOP_SaveXMM128Big";
43 case UOP_PushMachFrame
: return "UOP_PushMachFrame";
47 // Returns the name of a referenced register.
48 static StringRef
getUnwindRegisterName(uint8_t Reg
) {
50 default: llvm_unreachable("Invalid register");
61 case 10: return "R10";
62 case 11: return "R11";
63 case 12: return "R12";
64 case 13: return "R13";
65 case 14: return "R14";
66 case 15: return "R15";
70 // Calculates the number of array slots required for the unwind code.
71 static unsigned getNumUsedSlots(const UnwindCode
&UnwindCode
) {
72 switch (UnwindCode
.getUnwindOp()) {
73 default: llvm_unreachable("Invalid unwind code");
77 case UOP_PushMachFrame
:
82 case UOP_SaveNonVolBig
:
83 case UOP_SaveXMM128Big
:
86 return (UnwindCode
.getOpInfo() == 0) ? 2 : 3;
90 // Prints one unwind code. Because an unwind code can occupy up to 3 slots in
91 // the unwind codes array, this function requires that the correct number of
93 static void printUnwindCode(ArrayRef
<UnwindCode
> UCs
) {
94 assert(UCs
.size() >= getNumUsedSlots(UCs
[0]));
95 outs() << format(" 0x%02x: ", unsigned(UCs
[0].u
.CodeOffset
))
96 << getUnwindCodeTypeName(UCs
[0].getUnwindOp());
97 switch (UCs
[0].getUnwindOp()) {
99 outs() << " " << getUnwindRegisterName(UCs
[0].getOpInfo());
102 if (UCs
[0].getOpInfo() == 0) {
103 outs() << " " << UCs
[1].FrameOffset
;
105 outs() << " " << UCs
[1].FrameOffset
106 + (static_cast<uint32_t>(UCs
[2].FrameOffset
) << 16);
110 outs() << " " << ((UCs
[0].getOpInfo() + 1) * 8);
116 outs() << " " << getUnwindRegisterName(UCs
[0].getOpInfo())
117 << format(" [0x%04x]", 8 * UCs
[1].FrameOffset
);
119 case UOP_SaveNonVolBig
:
120 outs() << " " << getUnwindRegisterName(UCs
[0].getOpInfo())
121 << format(" [0x%08x]", UCs
[1].FrameOffset
122 + (static_cast<uint32_t>(UCs
[2].FrameOffset
) << 16));
125 outs() << " XMM" << static_cast<uint32_t>(UCs
[0].getOpInfo())
126 << format(" [0x%04x]", 16 * UCs
[1].FrameOffset
);
128 case UOP_SaveXMM128Big
:
129 outs() << " XMM" << UCs
[0].getOpInfo()
130 << format(" [0x%08x]", UCs
[1].FrameOffset
131 + (static_cast<uint32_t>(UCs
[2].FrameOffset
) << 16));
133 case UOP_PushMachFrame
:
134 outs() << " " << (UCs
[0].getOpInfo() ? "w/o" : "w")
141 static void printAllUnwindCodes(ArrayRef
<UnwindCode
> UCs
) {
142 for (const UnwindCode
*I
= UCs
.begin(), *E
= UCs
.end(); I
< E
; ) {
143 unsigned UsedSlots
= getNumUsedSlots(*I
);
144 if (UsedSlots
> UCs
.size()) {
145 outs() << "Unwind data corrupted: Encountered unwind op "
146 << getUnwindCodeTypeName((*I
).getUnwindOp())
147 << " which requires " << UsedSlots
148 << " slots, but only " << UCs
.size()
149 << " remaining in buffer";
152 printUnwindCode(makeArrayRef(I
, E
));
157 // Given a symbol sym this functions returns the address and section of it.
158 static Error
resolveSectionAndAddress(const COFFObjectFile
*Obj
,
159 const SymbolRef
&Sym
,
160 const coff_section
*&ResolvedSection
,
161 uint64_t &ResolvedAddr
) {
162 Expected
<uint64_t> ResolvedAddrOrErr
= Sym
.getAddress();
163 if (!ResolvedAddrOrErr
)
164 return ResolvedAddrOrErr
.takeError();
165 ResolvedAddr
= *ResolvedAddrOrErr
;
166 Expected
<section_iterator
> Iter
= Sym
.getSection();
168 return Iter
.takeError();
169 ResolvedSection
= Obj
->getCOFFSection(**Iter
);
170 return Error::success();
173 // Given a vector of relocations for a section and an offset into this section
174 // the function returns the symbol used for the relocation at the offset.
175 static Error
resolveSymbol(const std::vector
<RelocationRef
> &Rels
,
176 uint64_t Offset
, SymbolRef
&Sym
) {
177 for (auto &R
: Rels
) {
178 uint64_t Ofs
= R
.getOffset();
180 Sym
= *R
.getSymbol();
181 return Error::success();
184 return make_error
<BinaryError
>();
187 // Given a vector of relocations for a section and an offset into this section
188 // the function resolves the symbol used for the relocation at the offset and
189 // returns the section content and the address inside the content pointed to
192 getSectionContents(const COFFObjectFile
*Obj
,
193 const std::vector
<RelocationRef
> &Rels
, uint64_t Offset
,
194 ArrayRef
<uint8_t> &Contents
, uint64_t &Addr
) {
196 if (Error E
= resolveSymbol(Rels
, Offset
, Sym
))
198 const coff_section
*Section
;
199 if (Error E
= resolveSectionAndAddress(Obj
, Sym
, Section
, Addr
))
201 if (std::error_code EC
= Obj
->getSectionContents(Section
, Contents
))
202 return errorCodeToError(EC
);
203 return Error::success();
206 // Given a vector of relocations for a section and an offset into this section
207 // the function returns the name of the symbol used for the relocation at the
209 static Error
resolveSymbolName(const std::vector
<RelocationRef
> &Rels
,
210 uint64_t Offset
, StringRef
&Name
) {
212 if (Error EC
= resolveSymbol(Rels
, Offset
, Sym
))
214 Expected
<StringRef
> NameOrErr
= Sym
.getName();
216 return NameOrErr
.takeError();
218 return Error::success();
221 static void printCOFFSymbolAddress(raw_ostream
&Out
,
222 const std::vector
<RelocationRef
> &Rels
,
223 uint64_t Offset
, uint32_t Disp
) {
225 if (!resolveSymbolName(Rels
, Offset
, Sym
)) {
228 Out
<< format(" + 0x%04x", Disp
);
230 Out
<< format("0x%04x", Disp
);
235 printSEHTable(const COFFObjectFile
*Obj
, uint32_t TableVA
, int Count
) {
239 const pe32_header
*PE32Header
;
240 error(Obj
->getPE32Header(PE32Header
));
241 uint32_t ImageBase
= PE32Header
->ImageBase
;
242 uintptr_t IntPtr
= 0;
243 error(Obj
->getVaPtr(TableVA
, IntPtr
));
244 const support::ulittle32_t
*P
= (const support::ulittle32_t
*)IntPtr
;
245 outs() << "SEH Table:";
246 for (int I
= 0; I
< Count
; ++I
)
247 outs() << format(" 0x%x", P
[I
] + ImageBase
);
251 template <typename T
>
252 static void printTLSDirectoryT(const coff_tls_directory
<T
> *TLSDir
) {
253 size_t FormatWidth
= sizeof(T
) * 2;
254 outs() << "TLS directory:"
255 << "\n StartAddressOfRawData: "
256 << format_hex(TLSDir
->StartAddressOfRawData
, FormatWidth
)
257 << "\n EndAddressOfRawData: "
258 << format_hex(TLSDir
->EndAddressOfRawData
, FormatWidth
)
259 << "\n AddressOfIndex: "
260 << format_hex(TLSDir
->AddressOfIndex
, FormatWidth
)
261 << "\n AddressOfCallBacks: "
262 << format_hex(TLSDir
->AddressOfCallBacks
, FormatWidth
)
263 << "\n SizeOfZeroFill: "
264 << TLSDir
->SizeOfZeroFill
265 << "\n Characteristics: "
266 << TLSDir
->Characteristics
268 << TLSDir
->getAlignment()
272 static void printTLSDirectory(const COFFObjectFile
*Obj
) {
273 const pe32_header
*PE32Header
;
274 error(Obj
->getPE32Header(PE32Header
));
276 const pe32plus_header
*PE32PlusHeader
;
277 error(Obj
->getPE32PlusHeader(PE32PlusHeader
));
279 // Skip if it's not executable.
280 if (!PE32Header
&& !PE32PlusHeader
)
283 const data_directory
*DataDir
;
284 error(Obj
->getDataDirectory(COFF::TLS_TABLE
, DataDir
));
285 uintptr_t IntPtr
= 0;
286 if (DataDir
->RelativeVirtualAddress
== 0)
288 error(Obj
->getRvaPtr(DataDir
->RelativeVirtualAddress
, IntPtr
));
291 auto *TLSDir
= reinterpret_cast<const coff_tls_directory32
*>(IntPtr
);
292 printTLSDirectoryT(TLSDir
);
294 auto *TLSDir
= reinterpret_cast<const coff_tls_directory64
*>(IntPtr
);
295 printTLSDirectoryT(TLSDir
);
301 static void printLoadConfiguration(const COFFObjectFile
*Obj
) {
302 // Skip if it's not executable.
303 const pe32_header
*PE32Header
;
304 error(Obj
->getPE32Header(PE32Header
));
308 // Currently only x86 is supported
309 if (Obj
->getMachine() != COFF::IMAGE_FILE_MACHINE_I386
)
312 const data_directory
*DataDir
;
313 error(Obj
->getDataDirectory(COFF::LOAD_CONFIG_TABLE
, DataDir
));
314 uintptr_t IntPtr
= 0;
315 if (DataDir
->RelativeVirtualAddress
== 0)
317 error(Obj
->getRvaPtr(DataDir
->RelativeVirtualAddress
, IntPtr
));
319 auto *LoadConf
= reinterpret_cast<const coff_load_configuration32
*>(IntPtr
);
320 outs() << "Load configuration:"
321 << "\n Timestamp: " << LoadConf
->TimeDateStamp
322 << "\n Major Version: " << LoadConf
->MajorVersion
323 << "\n Minor Version: " << LoadConf
->MinorVersion
324 << "\n GlobalFlags Clear: " << LoadConf
->GlobalFlagsClear
325 << "\n GlobalFlags Set: " << LoadConf
->GlobalFlagsSet
326 << "\n Critical Section Default Timeout: " << LoadConf
->CriticalSectionDefaultTimeout
327 << "\n Decommit Free Block Threshold: " << LoadConf
->DeCommitFreeBlockThreshold
328 << "\n Decommit Total Free Threshold: " << LoadConf
->DeCommitTotalFreeThreshold
329 << "\n Lock Prefix Table: " << LoadConf
->LockPrefixTable
330 << "\n Maximum Allocation Size: " << LoadConf
->MaximumAllocationSize
331 << "\n Virtual Memory Threshold: " << LoadConf
->VirtualMemoryThreshold
332 << "\n Process Affinity Mask: " << LoadConf
->ProcessAffinityMask
333 << "\n Process Heap Flags: " << LoadConf
->ProcessHeapFlags
334 << "\n CSD Version: " << LoadConf
->CSDVersion
335 << "\n Security Cookie: " << LoadConf
->SecurityCookie
336 << "\n SEH Table: " << LoadConf
->SEHandlerTable
337 << "\n SEH Count: " << LoadConf
->SEHandlerCount
339 printSEHTable(Obj
, LoadConf
->SEHandlerTable
, LoadConf
->SEHandlerCount
);
343 // Prints import tables. The import table is a table containing the list of
344 // DLL name and symbol names which will be linked by the loader.
345 static void printImportTables(const COFFObjectFile
*Obj
) {
346 import_directory_iterator I
= Obj
->import_directory_begin();
347 import_directory_iterator E
= Obj
->import_directory_end();
350 outs() << "The Import Tables:\n";
351 for (const ImportDirectoryEntryRef
&DirRef
: Obj
->import_directories()) {
352 const coff_import_directory_table_entry
*Dir
;
354 if (DirRef
.getImportTableEntry(Dir
)) return;
355 if (DirRef
.getName(Name
)) return;
357 outs() << format(" lookup %08x time %08x fwd %08x name %08x addr %08x\n\n",
358 static_cast<uint32_t>(Dir
->ImportLookupTableRVA
),
359 static_cast<uint32_t>(Dir
->TimeDateStamp
),
360 static_cast<uint32_t>(Dir
->ForwarderChain
),
361 static_cast<uint32_t>(Dir
->NameRVA
),
362 static_cast<uint32_t>(Dir
->ImportAddressTableRVA
));
363 outs() << " DLL Name: " << Name
<< "\n";
364 outs() << " Hint/Ord Name\n";
365 for (const ImportedSymbolRef
&Entry
: DirRef
.imported_symbols()) {
367 if (Entry
.isOrdinal(IsOrdinal
))
371 if (Entry
.getOrdinal(Ordinal
))
373 outs() << format(" % 6d\n", Ordinal
);
376 uint32_t HintNameRVA
;
377 if (Entry
.getHintNameRVA(HintNameRVA
))
381 if (Obj
->getHintName(HintNameRVA
, Hint
, Name
))
383 outs() << format(" % 6d ", Hint
) << Name
<< "\n";
389 // Prints export tables. The export table is a table containing the list of
390 // exported symbol from the DLL.
391 static void printExportTable(const COFFObjectFile
*Obj
) {
392 outs() << "Export Table:\n";
393 export_directory_iterator I
= Obj
->export_directory_begin();
394 export_directory_iterator E
= Obj
->export_directory_end();
398 uint32_t OrdinalBase
;
399 if (I
->getDllName(DllName
))
401 if (I
->getOrdinalBase(OrdinalBase
))
403 outs() << " DLL name: " << DllName
<< "\n";
404 outs() << " Ordinal base: " << OrdinalBase
<< "\n";
405 outs() << " Ordinal RVA Name\n";
406 for (; I
!= E
; I
= ++I
) {
408 if (I
->getOrdinal(Ordinal
))
411 if (I
->getExportRVA(RVA
))
414 if (I
->isForwarder(IsForwarder
))
418 // Export table entries can be used to re-export symbols that
419 // this COFF file is imported from some DLLs. This is rare.
420 // In most cases IsForwarder is false.
421 outs() << format(" % 4d ", Ordinal
);
423 outs() << format(" % 4d %# 8x", Ordinal
, RVA
);
427 if (I
->getSymbolName(Name
))
430 outs() << " " << Name
;
433 if (I
->getForwardTo(S
))
435 outs() << " (forwarded to " << S
<< ")";
441 // Given the COFF object file, this function returns the relocations for .pdata
442 // and the pointer to "runtime function" structs.
443 static bool getPDataSection(const COFFObjectFile
*Obj
,
444 std::vector
<RelocationRef
> &Rels
,
445 const RuntimeFunction
*&RFStart
, int &NumRFs
) {
446 for (const SectionRef
&Section
: Obj
->sections()) {
448 error(Section
.getName(Name
));
449 if (Name
!= ".pdata")
452 const coff_section
*Pdata
= Obj
->getCOFFSection(Section
);
453 for (const RelocationRef
&Reloc
: Section
.relocations())
454 Rels
.push_back(Reloc
);
456 // Sort relocations by address.
457 llvm::sort(Rels
, isRelocAddressLess
);
459 ArrayRef
<uint8_t> Contents
;
460 error(Obj
->getSectionContents(Pdata
, Contents
));
461 if (Contents
.empty())
464 RFStart
= reinterpret_cast<const RuntimeFunction
*>(Contents
.data());
465 NumRFs
= Contents
.size() / sizeof(RuntimeFunction
);
471 Error
getCOFFRelocationValueString(const COFFObjectFile
*Obj
,
472 const RelocationRef
&Rel
,
473 SmallVectorImpl
<char> &Result
) {
474 symbol_iterator SymI
= Rel
.getSymbol();
475 Expected
<StringRef
> SymNameOrErr
= SymI
->getName();
477 return SymNameOrErr
.takeError();
478 StringRef SymName
= *SymNameOrErr
;
479 Result
.append(SymName
.begin(), SymName
.end());
480 return Error::success();
483 static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo
*UI
) {
484 // The casts to int are required in order to output the value as number.
485 // Without the casts the value would be interpreted as char data (which
486 // results in garbage output).
487 outs() << " Version: " << static_cast<int>(UI
->getVersion()) << "\n";
488 outs() << " Flags: " << static_cast<int>(UI
->getFlags());
489 if (UI
->getFlags()) {
490 if (UI
->getFlags() & UNW_ExceptionHandler
)
491 outs() << " UNW_ExceptionHandler";
492 if (UI
->getFlags() & UNW_TerminateHandler
)
493 outs() << " UNW_TerminateHandler";
494 if (UI
->getFlags() & UNW_ChainInfo
)
495 outs() << " UNW_ChainInfo";
498 outs() << " Size of prolog: " << static_cast<int>(UI
->PrologSize
) << "\n";
499 outs() << " Number of Codes: " << static_cast<int>(UI
->NumCodes
) << "\n";
500 // Maybe this should move to output of UOP_SetFPReg?
501 if (UI
->getFrameRegister()) {
502 outs() << " Frame register: "
503 << getUnwindRegisterName(UI
->getFrameRegister()) << "\n";
504 outs() << " Frame offset: " << 16 * UI
->getFrameOffset() << "\n";
506 outs() << " No frame pointer used\n";
508 if (UI
->getFlags() & (UNW_ExceptionHandler
| UNW_TerminateHandler
)) {
509 // FIXME: Output exception handler data
510 } else if (UI
->getFlags() & UNW_ChainInfo
) {
511 // FIXME: Output chained unwind info
515 outs() << " Unwind Codes:\n";
517 printAllUnwindCodes(makeArrayRef(&UI
->UnwindCodes
[0], UI
->NumCodes
));
523 /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
524 /// pointing to an executable file.
525 static void printRuntimeFunction(const COFFObjectFile
*Obj
,
526 const RuntimeFunction
&RF
) {
527 if (!RF
.StartAddress
)
529 outs() << "Function Table:\n"
530 << format(" Start Address: 0x%04x\n",
531 static_cast<uint32_t>(RF
.StartAddress
))
532 << format(" End Address: 0x%04x\n",
533 static_cast<uint32_t>(RF
.EndAddress
))
534 << format(" Unwind Info Address: 0x%04x\n",
535 static_cast<uint32_t>(RF
.UnwindInfoOffset
));
537 if (Obj
->getRvaPtr(RF
.UnwindInfoOffset
, addr
))
539 printWin64EHUnwindInfo(reinterpret_cast<const Win64EH::UnwindInfo
*>(addr
));
542 /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
543 /// pointing to an object file. Unlike executable, fields in RuntimeFunction
544 /// struct are filled with zeros, but instead there are relocations pointing to
545 /// them so that the linker will fill targets' RVAs to the fields at link
546 /// time. This function interprets the relocations to find the data to be used
547 /// in the resulting executable.
548 static void printRuntimeFunctionRels(const COFFObjectFile
*Obj
,
549 const RuntimeFunction
&RF
,
550 uint64_t SectionOffset
,
551 const std::vector
<RelocationRef
> &Rels
) {
552 outs() << "Function Table:\n";
553 outs() << " Start Address: ";
554 printCOFFSymbolAddress(outs(), Rels
,
556 /*offsetof(RuntimeFunction, StartAddress)*/ 0,
560 outs() << " End Address: ";
561 printCOFFSymbolAddress(outs(), Rels
,
563 /*offsetof(RuntimeFunction, EndAddress)*/ 4,
567 outs() << " Unwind Info Address: ";
568 printCOFFSymbolAddress(outs(), Rels
,
570 /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
571 RF
.UnwindInfoOffset
);
574 ArrayRef
<uint8_t> XContents
;
575 uint64_t UnwindInfoOffset
= 0;
576 error(getSectionContents(
577 Obj
, Rels
, SectionOffset
+
578 /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
579 XContents
, UnwindInfoOffset
));
580 if (XContents
.empty())
583 UnwindInfoOffset
+= RF
.UnwindInfoOffset
;
584 if (UnwindInfoOffset
> XContents
.size())
587 auto *UI
= reinterpret_cast<const Win64EH::UnwindInfo
*>(XContents
.data() +
589 printWin64EHUnwindInfo(UI
);
592 void printCOFFUnwindInfo(const COFFObjectFile
*Obj
) {
593 if (Obj
->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64
) {
594 WithColor::error(errs(), "llvm-objdump")
595 << "unsupported image machine type "
596 "(currently only AMD64 is supported).\n";
600 std::vector
<RelocationRef
> Rels
;
601 const RuntimeFunction
*RFStart
;
603 if (!getPDataSection(Obj
, Rels
, RFStart
, NumRFs
))
605 ArrayRef
<RuntimeFunction
> RFs(RFStart
, NumRFs
);
607 bool IsExecutable
= Rels
.empty();
609 for (const RuntimeFunction
&RF
: RFs
)
610 printRuntimeFunction(Obj
, RF
);
614 for (const RuntimeFunction
&RF
: RFs
) {
615 uint64_t SectionOffset
=
616 std::distance(RFs
.begin(), &RF
) * sizeof(RuntimeFunction
);
617 printRuntimeFunctionRels(Obj
, RF
, SectionOffset
, Rels
);
621 void printCOFFFileHeader(const object::ObjectFile
*Obj
) {
622 const COFFObjectFile
*file
= dyn_cast
<const COFFObjectFile
>(Obj
);
623 printTLSDirectory(file
);
624 printLoadConfiguration(file
);
625 printImportTables(file
);
626 printExportTable(file
);
629 void printCOFFSymbolTable(const object::COFFImportFile
*i
) {
631 bool IsCode
= i
->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE
;
633 for (const object::BasicSymbolRef
&Sym
: i
->symbols()) {
635 raw_string_ostream
NS(Name
);
637 cantFail(Sym
.printName(NS
));
640 outs() << "[" << format("%2d", Index
) << "]"
641 << "(sec " << format("%2d", 0) << ")"
642 << "(fl 0x00)" // Flag bits, which COFF doesn't have.
643 << "(ty " << format("%3x", (IsCode
&& Index
) ? 32 : 0) << ")"
644 << "(scl " << format("%3x", 0) << ") "
645 << "(nx " << 0 << ") "
646 << "0x" << format("%08x", 0) << " " << Name
<< '\n';
652 void printCOFFSymbolTable(const COFFObjectFile
*coff
) {
653 for (unsigned SI
= 0, SE
= coff
->getNumberOfSymbols(); SI
!= SE
; ++SI
) {
654 Expected
<COFFSymbolRef
> Symbol
= coff
->getSymbol(SI
);
656 error(Symbol
.takeError());
657 error(coff
->getSymbolName(*Symbol
, Name
));
659 outs() << "[" << format("%2d", SI
) << "]"
660 << "(sec " << format("%2d", int(Symbol
->getSectionNumber())) << ")"
661 << "(fl 0x00)" // Flag bits, which COFF doesn't have.
662 << "(ty " << format("%3x", unsigned(Symbol
->getType())) << ")"
663 << "(scl " << format("%3x", unsigned(Symbol
->getStorageClass()))
665 << "(nx " << unsigned(Symbol
->getNumberOfAuxSymbols()) << ") "
666 << "0x" << format("%08x", unsigned(Symbol
->getValue())) << " "
668 if (Demangle
&& Name
.startswith("?")) {
669 char *DemangledSymbol
= nullptr;
673 microsoftDemangle(Name
.data(), DemangledSymbol
, &Size
, &Status
);
675 if (Status
== 0 && DemangledSymbol
) {
676 outs() << " (" << StringRef(DemangledSymbol
) << ")";
677 std::free(DemangledSymbol
);
679 outs() << " (invalid mangled name)";
684 for (unsigned AI
= 0, AE
= Symbol
->getNumberOfAuxSymbols(); AI
< AE
; ++AI
, ++SI
) {
685 if (Symbol
->isSectionDefinition()) {
686 const coff_aux_section_definition
*asd
;
687 error(coff
->getAuxSymbol
<coff_aux_section_definition
>(SI
+ 1, asd
));
689 int32_t AuxNumber
= asd
->getNumber(Symbol
->isBigObj());
692 << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
693 , unsigned(asd
->Length
)
694 , unsigned(asd
->NumberOfRelocations
)
695 , unsigned(asd
->NumberOfLinenumbers
)
696 , unsigned(asd
->CheckSum
))
697 << format("assoc %d comdat %d\n"
698 , unsigned(AuxNumber
)
699 , unsigned(asd
->Selection
));
700 } else if (Symbol
->isFileRecord()) {
701 const char *FileName
;
702 error(coff
->getAuxSymbol
<char>(SI
+ 1, FileName
));
704 StringRef
Name(FileName
, Symbol
->getNumberOfAuxSymbols() *
705 coff
->getSymbolTableEntrySize());
706 outs() << "AUX " << Name
.rtrim(StringRef("\0", 1)) << '\n';
708 SI
= SI
+ Symbol
->getNumberOfAuxSymbols();
710 } else if (Symbol
->isWeakExternal()) {
711 const coff_aux_weak_external
*awe
;
712 error(coff
->getAuxSymbol
<coff_aux_weak_external
>(SI
+ 1, awe
));
714 outs() << "AUX " << format("indx %d srch %d\n",
715 static_cast<uint32_t>(awe
->TagIndex
),
716 static_cast<uint32_t>(awe
->Characteristics
));
718 outs() << "AUX Unknown\n";