1 //===-- COFFDump.cpp - COFF-specific dumper ---------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
11 /// 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
16 //===----------------------------------------------------------------------===//
18 #include "llvm-objdump.h"
19 #include "llvm/Demangle/Demangle.h"
20 #include "llvm/Object/COFF.h"
21 #include "llvm/Object/COFFImportFile.h"
22 #include "llvm/Object/ObjectFile.h"
23 #include "llvm/Support/Format.h"
24 #include "llvm/Support/Win64EH.h"
25 #include "llvm/Support/WithColor.h"
26 #include "llvm/Support/raw_ostream.h"
29 using namespace object
;
30 using namespace llvm::Win64EH
;
32 // Returns the name of the unwind code.
33 static StringRef
getUnwindCodeTypeName(uint8_t Code
) {
35 default: llvm_unreachable("Invalid unwind code");
36 case UOP_PushNonVol
: return "UOP_PushNonVol";
37 case UOP_AllocLarge
: return "UOP_AllocLarge";
38 case UOP_AllocSmall
: return "UOP_AllocSmall";
39 case UOP_SetFPReg
: return "UOP_SetFPReg";
40 case UOP_SaveNonVol
: return "UOP_SaveNonVol";
41 case UOP_SaveNonVolBig
: return "UOP_SaveNonVolBig";
42 case UOP_SaveXMM128
: return "UOP_SaveXMM128";
43 case UOP_SaveXMM128Big
: return "UOP_SaveXMM128Big";
44 case UOP_PushMachFrame
: return "UOP_PushMachFrame";
48 // Returns the name of a referenced register.
49 static StringRef
getUnwindRegisterName(uint8_t Reg
) {
51 default: llvm_unreachable("Invalid register");
62 case 10: return "R10";
63 case 11: return "R11";
64 case 12: return "R12";
65 case 13: return "R13";
66 case 14: return "R14";
67 case 15: return "R15";
71 // Calculates the number of array slots required for the unwind code.
72 static unsigned getNumUsedSlots(const UnwindCode
&UnwindCode
) {
73 switch (UnwindCode
.getUnwindOp()) {
74 default: llvm_unreachable("Invalid unwind code");
78 case UOP_PushMachFrame
:
83 case UOP_SaveNonVolBig
:
84 case UOP_SaveXMM128Big
:
87 return (UnwindCode
.getOpInfo() == 0) ? 2 : 3;
91 // Prints one unwind code. Because an unwind code can occupy up to 3 slots in
92 // the unwind codes array, this function requires that the correct number of
94 static void printUnwindCode(ArrayRef
<UnwindCode
> UCs
) {
95 assert(UCs
.size() >= getNumUsedSlots(UCs
[0]));
96 outs() << format(" 0x%02x: ", unsigned(UCs
[0].u
.CodeOffset
))
97 << getUnwindCodeTypeName(UCs
[0].getUnwindOp());
98 switch (UCs
[0].getUnwindOp()) {
100 outs() << " " << getUnwindRegisterName(UCs
[0].getOpInfo());
103 if (UCs
[0].getOpInfo() == 0) {
104 outs() << " " << UCs
[1].FrameOffset
;
106 outs() << " " << UCs
[1].FrameOffset
107 + (static_cast<uint32_t>(UCs
[2].FrameOffset
) << 16);
111 outs() << " " << ((UCs
[0].getOpInfo() + 1) * 8);
117 outs() << " " << getUnwindRegisterName(UCs
[0].getOpInfo())
118 << format(" [0x%04x]", 8 * UCs
[1].FrameOffset
);
120 case UOP_SaveNonVolBig
:
121 outs() << " " << getUnwindRegisterName(UCs
[0].getOpInfo())
122 << format(" [0x%08x]", UCs
[1].FrameOffset
123 + (static_cast<uint32_t>(UCs
[2].FrameOffset
) << 16));
126 outs() << " XMM" << static_cast<uint32_t>(UCs
[0].getOpInfo())
127 << format(" [0x%04x]", 16 * UCs
[1].FrameOffset
);
129 case UOP_SaveXMM128Big
:
130 outs() << " XMM" << UCs
[0].getOpInfo()
131 << format(" [0x%08x]", UCs
[1].FrameOffset
132 + (static_cast<uint32_t>(UCs
[2].FrameOffset
) << 16));
134 case UOP_PushMachFrame
:
135 outs() << " " << (UCs
[0].getOpInfo() ? "w/o" : "w")
142 static void printAllUnwindCodes(ArrayRef
<UnwindCode
> UCs
) {
143 for (const UnwindCode
*I
= UCs
.begin(), *E
= UCs
.end(); I
< E
; ) {
144 unsigned UsedSlots
= getNumUsedSlots(*I
);
145 if (UsedSlots
> UCs
.size()) {
146 outs() << "Unwind data corrupted: Encountered unwind op "
147 << getUnwindCodeTypeName((*I
).getUnwindOp())
148 << " which requires " << UsedSlots
149 << " slots, but only " << UCs
.size()
150 << " remaining in buffer";
153 printUnwindCode(makeArrayRef(I
, E
));
158 // Given a symbol sym this functions returns the address and section of it.
159 static std::error_code
160 resolveSectionAndAddress(const COFFObjectFile
*Obj
, const SymbolRef
&Sym
,
161 const coff_section
*&ResolvedSection
,
162 uint64_t &ResolvedAddr
) {
163 Expected
<uint64_t> ResolvedAddrOrErr
= Sym
.getAddress();
164 if (!ResolvedAddrOrErr
)
165 return errorToErrorCode(ResolvedAddrOrErr
.takeError());
166 ResolvedAddr
= *ResolvedAddrOrErr
;
167 Expected
<section_iterator
> Iter
= Sym
.getSection();
169 return errorToErrorCode(Iter
.takeError());
170 ResolvedSection
= Obj
->getCOFFSection(**Iter
);
171 return std::error_code();
174 // Given a vector of relocations for a section and an offset into this section
175 // the function returns the symbol used for the relocation at the offset.
176 static std::error_code
resolveSymbol(const std::vector
<RelocationRef
> &Rels
,
177 uint64_t Offset
, SymbolRef
&Sym
) {
178 for (auto &R
: Rels
) {
179 uint64_t Ofs
= R
.getOffset();
181 Sym
= *R
.getSymbol();
182 return std::error_code();
185 return object_error::parse_failed
;
188 // Given a vector of relocations for a section and an offset into this section
189 // the function resolves the symbol used for the relocation at the offset and
190 // returns the section content and the address inside the content pointed to
192 static std::error_code
193 getSectionContents(const COFFObjectFile
*Obj
,
194 const std::vector
<RelocationRef
> &Rels
, uint64_t Offset
,
195 ArrayRef
<uint8_t> &Contents
, uint64_t &Addr
) {
197 if (std::error_code EC
= resolveSymbol(Rels
, Offset
, Sym
))
199 const coff_section
*Section
;
200 if (std::error_code EC
= resolveSectionAndAddress(Obj
, Sym
, Section
, Addr
))
202 if (std::error_code EC
= Obj
->getSectionContents(Section
, Contents
))
204 return std::error_code();
207 // Given a vector of relocations for a section and an offset into this section
208 // the function returns the name of the symbol used for the relocation at the
210 static std::error_code
resolveSymbolName(const std::vector
<RelocationRef
> &Rels
,
211 uint64_t Offset
, StringRef
&Name
) {
213 if (std::error_code EC
= resolveSymbol(Rels
, Offset
, Sym
))
215 Expected
<StringRef
> NameOrErr
= Sym
.getName();
217 return errorToErrorCode(NameOrErr
.takeError());
219 return std::error_code();
222 static void printCOFFSymbolAddress(llvm::raw_ostream
&Out
,
223 const std::vector
<RelocationRef
> &Rels
,
224 uint64_t Offset
, uint32_t Disp
) {
226 if (!resolveSymbolName(Rels
, Offset
, Sym
)) {
229 Out
<< format(" + 0x%04x", Disp
);
231 Out
<< format("0x%04x", Disp
);
236 printSEHTable(const COFFObjectFile
*Obj
, uint32_t TableVA
, int Count
) {
240 const pe32_header
*PE32Header
;
241 error(Obj
->getPE32Header(PE32Header
));
242 uint32_t ImageBase
= PE32Header
->ImageBase
;
243 uintptr_t IntPtr
= 0;
244 error(Obj
->getVaPtr(TableVA
, IntPtr
));
245 const support::ulittle32_t
*P
= (const support::ulittle32_t
*)IntPtr
;
246 outs() << "SEH Table:";
247 for (int I
= 0; I
< Count
; ++I
)
248 outs() << format(" 0x%x", P
[I
] + ImageBase
);
252 template <typename T
>
253 static void printTLSDirectoryT(const coff_tls_directory
<T
> *TLSDir
) {
254 size_t FormatWidth
= sizeof(T
) * 2;
255 outs() << "TLS directory:"
256 << "\n StartAddressOfRawData: "
257 << format_hex(TLSDir
->StartAddressOfRawData
, FormatWidth
)
258 << "\n EndAddressOfRawData: "
259 << format_hex(TLSDir
->EndAddressOfRawData
, FormatWidth
)
260 << "\n AddressOfIndex: "
261 << format_hex(TLSDir
->AddressOfIndex
, FormatWidth
)
262 << "\n AddressOfCallBacks: "
263 << format_hex(TLSDir
->AddressOfCallBacks
, FormatWidth
)
264 << "\n SizeOfZeroFill: "
265 << TLSDir
->SizeOfZeroFill
266 << "\n Characteristics: "
267 << TLSDir
->Characteristics
269 << TLSDir
->getAlignment()
273 static void printTLSDirectory(const COFFObjectFile
*Obj
) {
274 const pe32_header
*PE32Header
;
275 error(Obj
->getPE32Header(PE32Header
));
277 const pe32plus_header
*PE32PlusHeader
;
278 error(Obj
->getPE32PlusHeader(PE32PlusHeader
));
280 // Skip if it's not executable.
281 if (!PE32Header
&& !PE32PlusHeader
)
284 const data_directory
*DataDir
;
285 error(Obj
->getDataDirectory(COFF::TLS_TABLE
, DataDir
));
286 uintptr_t IntPtr
= 0;
287 if (DataDir
->RelativeVirtualAddress
== 0)
289 error(Obj
->getRvaPtr(DataDir
->RelativeVirtualAddress
, IntPtr
));
292 auto *TLSDir
= reinterpret_cast<const coff_tls_directory32
*>(IntPtr
);
293 printTLSDirectoryT(TLSDir
);
295 auto *TLSDir
= reinterpret_cast<const coff_tls_directory64
*>(IntPtr
);
296 printTLSDirectoryT(TLSDir
);
302 static void printLoadConfiguration(const COFFObjectFile
*Obj
) {
303 // Skip if it's not executable.
304 const pe32_header
*PE32Header
;
305 error(Obj
->getPE32Header(PE32Header
));
309 // Currently only x86 is supported
310 if (Obj
->getMachine() != COFF::IMAGE_FILE_MACHINE_I386
)
313 const data_directory
*DataDir
;
314 error(Obj
->getDataDirectory(COFF::LOAD_CONFIG_TABLE
, DataDir
));
315 uintptr_t IntPtr
= 0;
316 if (DataDir
->RelativeVirtualAddress
== 0)
318 error(Obj
->getRvaPtr(DataDir
->RelativeVirtualAddress
, IntPtr
));
320 auto *LoadConf
= reinterpret_cast<const coff_load_configuration32
*>(IntPtr
);
321 outs() << "Load configuration:"
322 << "\n Timestamp: " << LoadConf
->TimeDateStamp
323 << "\n Major Version: " << LoadConf
->MajorVersion
324 << "\n Minor Version: " << LoadConf
->MinorVersion
325 << "\n GlobalFlags Clear: " << LoadConf
->GlobalFlagsClear
326 << "\n GlobalFlags Set: " << LoadConf
->GlobalFlagsSet
327 << "\n Critical Section Default Timeout: " << LoadConf
->CriticalSectionDefaultTimeout
328 << "\n Decommit Free Block Threshold: " << LoadConf
->DeCommitFreeBlockThreshold
329 << "\n Decommit Total Free Threshold: " << LoadConf
->DeCommitTotalFreeThreshold
330 << "\n Lock Prefix Table: " << LoadConf
->LockPrefixTable
331 << "\n Maximum Allocation Size: " << LoadConf
->MaximumAllocationSize
332 << "\n Virtual Memory Threshold: " << LoadConf
->VirtualMemoryThreshold
333 << "\n Process Affinity Mask: " << LoadConf
->ProcessAffinityMask
334 << "\n Process Heap Flags: " << LoadConf
->ProcessHeapFlags
335 << "\n CSD Version: " << LoadConf
->CSDVersion
336 << "\n Security Cookie: " << LoadConf
->SecurityCookie
337 << "\n SEH Table: " << LoadConf
->SEHandlerTable
338 << "\n SEH Count: " << LoadConf
->SEHandlerCount
340 printSEHTable(Obj
, LoadConf
->SEHandlerTable
, LoadConf
->SEHandlerCount
);
344 // Prints import tables. The import table is a table containing the list of
345 // DLL name and symbol names which will be linked by the loader.
346 static void printImportTables(const COFFObjectFile
*Obj
) {
347 import_directory_iterator I
= Obj
->import_directory_begin();
348 import_directory_iterator E
= Obj
->import_directory_end();
351 outs() << "The Import Tables:\n";
352 for (const ImportDirectoryEntryRef
&DirRef
: Obj
->import_directories()) {
353 const coff_import_directory_table_entry
*Dir
;
355 if (DirRef
.getImportTableEntry(Dir
)) return;
356 if (DirRef
.getName(Name
)) return;
358 outs() << format(" lookup %08x time %08x fwd %08x name %08x addr %08x\n\n",
359 static_cast<uint32_t>(Dir
->ImportLookupTableRVA
),
360 static_cast<uint32_t>(Dir
->TimeDateStamp
),
361 static_cast<uint32_t>(Dir
->ForwarderChain
),
362 static_cast<uint32_t>(Dir
->NameRVA
),
363 static_cast<uint32_t>(Dir
->ImportAddressTableRVA
));
364 outs() << " DLL Name: " << Name
<< "\n";
365 outs() << " Hint/Ord Name\n";
366 for (const ImportedSymbolRef
&Entry
: DirRef
.imported_symbols()) {
368 if (Entry
.isOrdinal(IsOrdinal
))
372 if (Entry
.getOrdinal(Ordinal
))
374 outs() << format(" % 6d\n", Ordinal
);
377 uint32_t HintNameRVA
;
378 if (Entry
.getHintNameRVA(HintNameRVA
))
382 if (Obj
->getHintName(HintNameRVA
, Hint
, Name
))
384 outs() << format(" % 6d ", Hint
) << Name
<< "\n";
390 // Prints export tables. The export table is a table containing the list of
391 // exported symbol from the DLL.
392 static void printExportTable(const COFFObjectFile
*Obj
) {
393 outs() << "Export Table:\n";
394 export_directory_iterator I
= Obj
->export_directory_begin();
395 export_directory_iterator E
= Obj
->export_directory_end();
399 uint32_t OrdinalBase
;
400 if (I
->getDllName(DllName
))
402 if (I
->getOrdinalBase(OrdinalBase
))
404 outs() << " DLL name: " << DllName
<< "\n";
405 outs() << " Ordinal base: " << OrdinalBase
<< "\n";
406 outs() << " Ordinal RVA Name\n";
407 for (; I
!= E
; I
= ++I
) {
409 if (I
->getOrdinal(Ordinal
))
412 if (I
->getExportRVA(RVA
))
415 if (I
->isForwarder(IsForwarder
))
419 // Export table entries can be used to re-export symbols that
420 // this COFF file is imported from some DLLs. This is rare.
421 // In most cases IsForwarder is false.
422 outs() << format(" % 4d ", Ordinal
);
424 outs() << format(" % 4d %# 8x", Ordinal
, RVA
);
428 if (I
->getSymbolName(Name
))
431 outs() << " " << Name
;
434 if (I
->getForwardTo(S
))
436 outs() << " (forwarded to " << S
<< ")";
442 // Given the COFF object file, this function returns the relocations for .pdata
443 // and the pointer to "runtime function" structs.
444 static bool getPDataSection(const COFFObjectFile
*Obj
,
445 std::vector
<RelocationRef
> &Rels
,
446 const RuntimeFunction
*&RFStart
, int &NumRFs
) {
447 for (const SectionRef
&Section
: Obj
->sections()) {
449 error(Section
.getName(Name
));
450 if (Name
!= ".pdata")
453 const coff_section
*Pdata
= Obj
->getCOFFSection(Section
);
454 for (const RelocationRef
&Reloc
: Section
.relocations())
455 Rels
.push_back(Reloc
);
457 // Sort relocations by address.
458 llvm::sort(Rels
, RelocAddressLess
);
460 ArrayRef
<uint8_t> Contents
;
461 error(Obj
->getSectionContents(Pdata
, Contents
));
462 if (Contents
.empty())
465 RFStart
= reinterpret_cast<const RuntimeFunction
*>(Contents
.data());
466 NumRFs
= Contents
.size() / sizeof(RuntimeFunction
);
472 static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo
*UI
) {
473 // The casts to int are required in order to output the value as number.
474 // Without the casts the value would be interpreted as char data (which
475 // results in garbage output).
476 outs() << " Version: " << static_cast<int>(UI
->getVersion()) << "\n";
477 outs() << " Flags: " << static_cast<int>(UI
->getFlags());
478 if (UI
->getFlags()) {
479 if (UI
->getFlags() & UNW_ExceptionHandler
)
480 outs() << " UNW_ExceptionHandler";
481 if (UI
->getFlags() & UNW_TerminateHandler
)
482 outs() << " UNW_TerminateHandler";
483 if (UI
->getFlags() & UNW_ChainInfo
)
484 outs() << " UNW_ChainInfo";
487 outs() << " Size of prolog: " << static_cast<int>(UI
->PrologSize
) << "\n";
488 outs() << " Number of Codes: " << static_cast<int>(UI
->NumCodes
) << "\n";
489 // Maybe this should move to output of UOP_SetFPReg?
490 if (UI
->getFrameRegister()) {
491 outs() << " Frame register: "
492 << getUnwindRegisterName(UI
->getFrameRegister()) << "\n";
493 outs() << " Frame offset: " << 16 * UI
->getFrameOffset() << "\n";
495 outs() << " No frame pointer used\n";
497 if (UI
->getFlags() & (UNW_ExceptionHandler
| UNW_TerminateHandler
)) {
498 // FIXME: Output exception handler data
499 } else if (UI
->getFlags() & UNW_ChainInfo
) {
500 // FIXME: Output chained unwind info
504 outs() << " Unwind Codes:\n";
506 printAllUnwindCodes(makeArrayRef(&UI
->UnwindCodes
[0], UI
->NumCodes
));
512 /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
513 /// pointing to an executable file.
514 static void printRuntimeFunction(const COFFObjectFile
*Obj
,
515 const RuntimeFunction
&RF
) {
516 if (!RF
.StartAddress
)
518 outs() << "Function Table:\n"
519 << format(" Start Address: 0x%04x\n",
520 static_cast<uint32_t>(RF
.StartAddress
))
521 << format(" End Address: 0x%04x\n",
522 static_cast<uint32_t>(RF
.EndAddress
))
523 << format(" Unwind Info Address: 0x%04x\n",
524 static_cast<uint32_t>(RF
.UnwindInfoOffset
));
526 if (Obj
->getRvaPtr(RF
.UnwindInfoOffset
, addr
))
528 printWin64EHUnwindInfo(reinterpret_cast<const Win64EH::UnwindInfo
*>(addr
));
531 /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
532 /// pointing to an object file. Unlike executable, fields in RuntimeFunction
533 /// struct are filled with zeros, but instead there are relocations pointing to
534 /// them so that the linker will fill targets' RVAs to the fields at link
535 /// time. This function interprets the relocations to find the data to be used
536 /// in the resulting executable.
537 static void printRuntimeFunctionRels(const COFFObjectFile
*Obj
,
538 const RuntimeFunction
&RF
,
539 uint64_t SectionOffset
,
540 const std::vector
<RelocationRef
> &Rels
) {
541 outs() << "Function Table:\n";
542 outs() << " Start Address: ";
543 printCOFFSymbolAddress(outs(), Rels
,
545 /*offsetof(RuntimeFunction, StartAddress)*/ 0,
549 outs() << " End Address: ";
550 printCOFFSymbolAddress(outs(), Rels
,
552 /*offsetof(RuntimeFunction, EndAddress)*/ 4,
556 outs() << " Unwind Info Address: ";
557 printCOFFSymbolAddress(outs(), Rels
,
559 /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
560 RF
.UnwindInfoOffset
);
563 ArrayRef
<uint8_t> XContents
;
564 uint64_t UnwindInfoOffset
= 0;
565 error(getSectionContents(
566 Obj
, Rels
, SectionOffset
+
567 /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
568 XContents
, UnwindInfoOffset
));
569 if (XContents
.empty())
572 UnwindInfoOffset
+= RF
.UnwindInfoOffset
;
573 if (UnwindInfoOffset
> XContents
.size())
576 auto *UI
= reinterpret_cast<const Win64EH::UnwindInfo
*>(XContents
.data() +
578 printWin64EHUnwindInfo(UI
);
581 void llvm::printCOFFUnwindInfo(const COFFObjectFile
*Obj
) {
582 if (Obj
->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64
) {
583 WithColor::error(errs(), "llvm-objdump")
584 << "unsupported image machine type "
585 "(currently only AMD64 is supported).\n";
589 std::vector
<RelocationRef
> Rels
;
590 const RuntimeFunction
*RFStart
;
592 if (!getPDataSection(Obj
, Rels
, RFStart
, NumRFs
))
594 ArrayRef
<RuntimeFunction
> RFs(RFStart
, NumRFs
);
596 bool IsExecutable
= Rels
.empty();
598 for (const RuntimeFunction
&RF
: RFs
)
599 printRuntimeFunction(Obj
, RF
);
603 for (const RuntimeFunction
&RF
: RFs
) {
604 uint64_t SectionOffset
=
605 std::distance(RFs
.begin(), &RF
) * sizeof(RuntimeFunction
);
606 printRuntimeFunctionRels(Obj
, RF
, SectionOffset
, Rels
);
610 void llvm::printCOFFFileHeader(const object::ObjectFile
*Obj
) {
611 const COFFObjectFile
*file
= dyn_cast
<const COFFObjectFile
>(Obj
);
612 printTLSDirectory(file
);
613 printLoadConfiguration(file
);
614 printImportTables(file
);
615 printExportTable(file
);
618 void llvm::printCOFFSymbolTable(const object::COFFImportFile
*i
) {
620 bool IsCode
= i
->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE
;
622 for (const object::BasicSymbolRef
&Sym
: i
->symbols()) {
624 raw_string_ostream
NS(Name
);
629 outs() << "[" << format("%2d", Index
) << "]"
630 << "(sec " << format("%2d", 0) << ")"
631 << "(fl 0x00)" // Flag bits, which COFF doesn't have.
632 << "(ty " << format("%3x", (IsCode
&& Index
) ? 32 : 0) << ")"
633 << "(scl " << format("%3x", 0) << ") "
634 << "(nx " << 0 << ") "
635 << "0x" << format("%08x", 0) << " " << Name
<< '\n';
641 void llvm::printCOFFSymbolTable(const COFFObjectFile
*coff
) {
642 for (unsigned SI
= 0, SE
= coff
->getNumberOfSymbols(); SI
!= SE
; ++SI
) {
643 Expected
<COFFSymbolRef
> Symbol
= coff
->getSymbol(SI
);
645 error(errorToErrorCode(Symbol
.takeError()));
646 error(coff
->getSymbolName(*Symbol
, Name
));
648 outs() << "[" << format("%2d", SI
) << "]"
649 << "(sec " << format("%2d", int(Symbol
->getSectionNumber())) << ")"
650 << "(fl 0x00)" // Flag bits, which COFF doesn't have.
651 << "(ty " << format("%3x", unsigned(Symbol
->getType())) << ")"
652 << "(scl " << format("%3x", unsigned(Symbol
->getStorageClass()))
654 << "(nx " << unsigned(Symbol
->getNumberOfAuxSymbols()) << ") "
655 << "0x" << format("%08x", unsigned(Symbol
->getValue())) << " "
657 if (Demangle
&& Name
.startswith("?")) {
658 char *DemangledSymbol
= nullptr;
662 microsoftDemangle(Name
.data(), DemangledSymbol
, &Size
, &Status
);
664 if (Status
== 0 && DemangledSymbol
) {
665 outs() << " (" << StringRef(DemangledSymbol
) << ")";
666 std::free(DemangledSymbol
);
668 outs() << " (invalid mangled name)";
673 for (unsigned AI
= 0, AE
= Symbol
->getNumberOfAuxSymbols(); AI
< AE
; ++AI
, ++SI
) {
674 if (Symbol
->isSectionDefinition()) {
675 const coff_aux_section_definition
*asd
;
676 error(coff
->getAuxSymbol
<coff_aux_section_definition
>(SI
+ 1, asd
));
678 int32_t AuxNumber
= asd
->getNumber(Symbol
->isBigObj());
681 << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
682 , unsigned(asd
->Length
)
683 , unsigned(asd
->NumberOfRelocations
)
684 , unsigned(asd
->NumberOfLinenumbers
)
685 , unsigned(asd
->CheckSum
))
686 << format("assoc %d comdat %d\n"
687 , unsigned(AuxNumber
)
688 , unsigned(asd
->Selection
));
689 } else if (Symbol
->isFileRecord()) {
690 const char *FileName
;
691 error(coff
->getAuxSymbol
<char>(SI
+ 1, FileName
));
693 StringRef
Name(FileName
, Symbol
->getNumberOfAuxSymbols() *
694 coff
->getSymbolTableEntrySize());
695 outs() << "AUX " << Name
.rtrim(StringRef("\0", 1)) << '\n';
697 SI
= SI
+ Symbol
->getNumberOfAuxSymbols();
699 } else if (Symbol
->isWeakExternal()) {
700 const coff_aux_weak_external
*awe
;
701 error(coff
->getAuxSymbol
<coff_aux_weak_external
>(SI
+ 1, awe
));
703 outs() << "AUX " << format("indx %d srch %d\n",
704 static_cast<uint32_t>(awe
->TagIndex
),
705 static_cast<uint32_t>(awe
->Characteristics
));
707 outs() << "AUX Unknown\n";