1 //===-- llvm-objdump.cpp - Object file dumping utility for llvm -----------===//
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 program is a utility that works like binutils "objdump", that is, it
11 // dumps out a plethora of information about an object file depending on the
14 // The flags and output of this program should be near identical to those of
17 //===----------------------------------------------------------------------===//
19 #include "llvm-objdump.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/Triple.h"
24 #include "llvm/CodeGen/FaultMaps.h"
25 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
26 #include "llvm/DebugInfo/Symbolize/Symbolize.h"
27 #include "llvm/MC/MCAsmInfo.h"
28 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
30 #include "llvm/MC/MCDisassembler/MCRelocationInfo.h"
31 #include "llvm/MC/MCInst.h"
32 #include "llvm/MC/MCInstPrinter.h"
33 #include "llvm/MC/MCInstrAnalysis.h"
34 #include "llvm/MC/MCInstrInfo.h"
35 #include "llvm/MC/MCObjectFileInfo.h"
36 #include "llvm/MC/MCRegisterInfo.h"
37 #include "llvm/MC/MCSubtargetInfo.h"
38 #include "llvm/Object/Archive.h"
39 #include "llvm/Object/COFF.h"
40 #include "llvm/Object/COFFImportFile.h"
41 #include "llvm/Object/ELFObjectFile.h"
42 #include "llvm/Object/MachO.h"
43 #include "llvm/Object/ObjectFile.h"
44 #include "llvm/Object/Wasm.h"
45 #include "llvm/Support/Casting.h"
46 #include "llvm/Support/CommandLine.h"
47 #include "llvm/Support/Debug.h"
48 #include "llvm/Support/Errc.h"
49 #include "llvm/Support/FileSystem.h"
50 #include "llvm/Support/Format.h"
51 #include "llvm/Support/GraphWriter.h"
52 #include "llvm/Support/Host.h"
53 #include "llvm/Support/ManagedStatic.h"
54 #include "llvm/Support/MemoryBuffer.h"
55 #include "llvm/Support/PrettyStackTrace.h"
56 #include "llvm/Support/Signals.h"
57 #include "llvm/Support/SourceMgr.h"
58 #include "llvm/Support/TargetRegistry.h"
59 #include "llvm/Support/TargetSelect.h"
60 #include "llvm/Support/raw_ostream.h"
64 #include <system_error>
65 #include <unordered_map>
69 using namespace object;
71 static cl::list<std::string>
72 InputFilenames(cl::Positional, cl::desc("<input object files>"),cl::ZeroOrMore);
75 llvm::Disassemble("disassemble",
76 cl::desc("Display assembler mnemonics for the machine instructions"));
78 Disassembled("d", cl::desc("Alias for --disassemble"),
79 cl::aliasopt(Disassemble));
82 llvm::DisassembleAll("disassemble-all",
83 cl::desc("Display assembler mnemonics for the machine instructions"));
85 DisassembleAlld("D", cl::desc("Alias for --disassemble-all"),
86 cl::aliasopt(DisassembleAll));
89 llvm::Relocations("r", cl::desc("Display the relocation entries in the file"));
92 llvm::SectionContents("s", cl::desc("Display the content of each section"));
95 llvm::SymbolTable("t", cl::desc("Display the symbol table"));
98 llvm::ExportsTrie("exports-trie", cl::desc("Display mach-o exported symbols"));
101 llvm::Rebase("rebase", cl::desc("Display mach-o rebasing info"));
104 llvm::Bind("bind", cl::desc("Display mach-o binding info"));
107 llvm::LazyBind("lazy-bind", cl::desc("Display mach-o lazy binding info"));
110 llvm::WeakBind("weak-bind", cl::desc("Display mach-o weak binding info"));
113 llvm::RawClangAST("raw-clang-ast",
114 cl::desc("Dump the raw binary contents of the clang AST section"));
117 MachOOpt("macho", cl::desc("Use MachO specific object file parser"));
119 MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt));
122 llvm::TripleName("triple", cl::desc("Target triple to disassemble for, "
123 "see -version for available targets"));
127 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
128 cl::value_desc("cpu-name"),
132 llvm::ArchName("arch-name", cl::desc("Target arch to disassemble for, "
133 "see -version for available targets"));
136 llvm::SectionHeaders("section-headers", cl::desc("Display summaries of the "
137 "headers for each section."));
139 SectionHeadersShort("headers", cl::desc("Alias for --section-headers"),
140 cl::aliasopt(SectionHeaders));
142 SectionHeadersShorter("h", cl::desc("Alias for --section-headers"),
143 cl::aliasopt(SectionHeaders));
145 cl::list<std::string>
146 llvm::FilterSections("section", cl::desc("Operate on the specified sections only. "
147 "With -macho dump segment,section"));
149 static FilterSectionsj("j", cl::desc("Alias for --section"),
150 cl::aliasopt(llvm::FilterSections));
152 cl::list<std::string>
153 llvm::MAttrs("mattr",
155 cl::desc("Target specific attributes"),
156 cl::value_desc("a1,+a2,-a3,..."));
159 llvm::NoShowRawInsn("no-show-raw-insn", cl::desc("When disassembling "
160 "instructions, do not print "
161 "the instruction bytes."));
163 llvm::NoLeadingAddr("no-leading-addr", cl::desc("Print no leading address"));
166 llvm::UnwindInfo("unwind-info", cl::desc("Display unwind information"));
169 UnwindInfoShort("u", cl::desc("Alias for --unwind-info"),
170 cl::aliasopt(UnwindInfo));
173 llvm::PrivateHeaders("private-headers",
174 cl::desc("Display format specific file headers"));
177 llvm::FirstPrivateHeader("private-header",
178 cl::desc("Display only the first format specific file "
182 PrivateHeadersShort("p", cl::desc("Alias for --private-headers"),
183 cl::aliasopt(PrivateHeaders));
186 llvm::PrintImmHex("print-imm-hex",
187 cl::desc("Use hex format for immediate values"));
189 cl::opt<bool> PrintFaultMaps("fault-map-section",
190 cl::desc("Display contents of faultmap section"));
192 cl::opt<DIDumpType> llvm::DwarfDumpType(
193 "dwarf", cl::init(DIDT_Null), cl::desc("Dump of dwarf debug sections:"),
194 cl::values(clEnumValN(DIDT_DebugFrame, "frames", ".debug_frame")));
196 cl::opt<bool> PrintSource(
199 "Display source inlined with disassembly. Implies disassmble object"));
201 cl::alias PrintSourceShort("S", cl::desc("Alias for -source"),
202 cl::aliasopt(PrintSource));
204 cl::opt<bool> PrintLines("line-numbers",
205 cl::desc("Display source line numbers with "
206 "disassembly. Implies disassemble object"));
208 cl::alias PrintLinesShort("l", cl::desc("Alias for -line-numbers"),
209 cl::aliasopt(PrintLines));
211 cl::opt<unsigned long long>
212 StartAddress("start-address", cl::desc("Disassemble beginning at address"),
213 cl::value_desc("address"), cl::init(0));
214 cl::opt<unsigned long long>
215 StopAddress("stop-address", cl::desc("Stop disassembly at address"),
216 cl::value_desc("address"), cl::init(UINT64_MAX));
217 static StringRef ToolName;
219 typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
222 typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
224 class SectionFilterIterator {
226 SectionFilterIterator(FilterPredicate P,
227 llvm::object::section_iterator const &I,
228 llvm::object::section_iterator const &E)
229 : Predicate(std::move(P)), Iterator(I), End(E) {
232 const llvm::object::SectionRef &operator*() const { return *Iterator; }
233 SectionFilterIterator &operator++() {
238 bool operator!=(SectionFilterIterator const &Other) const {
239 return Iterator != Other.Iterator;
243 void ScanPredicate() {
244 while (Iterator != End && !Predicate(*Iterator)) {
248 FilterPredicate Predicate;
249 llvm::object::section_iterator Iterator;
250 llvm::object::section_iterator End;
253 class SectionFilter {
255 SectionFilter(FilterPredicate P, llvm::object::ObjectFile const &O)
256 : Predicate(std::move(P)), Object(O) {}
257 SectionFilterIterator begin() {
258 return SectionFilterIterator(Predicate, Object.section_begin(),
259 Object.section_end());
261 SectionFilterIterator end() {
262 return SectionFilterIterator(Predicate, Object.section_end(),
263 Object.section_end());
267 FilterPredicate Predicate;
268 llvm::object::ObjectFile const &Object;
270 SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O) {
271 return SectionFilter(
272 [](llvm::object::SectionRef const &S) {
273 if (FilterSections.empty())
275 llvm::StringRef String;
276 std::error_code error = S.getName(String);
279 return is_contained(FilterSections, String);
285 void llvm::error(std::error_code EC) {
289 errs() << ToolName << ": error reading file: " << EC.message() << ".\n";
294 LLVM_ATTRIBUTE_NORETURN void llvm::error(Twine Message) {
295 errs() << ToolName << ": " << Message << ".\n";
300 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
302 errs() << ToolName << ": '" << File << "': " << Message << ".\n";
306 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
307 std::error_code EC) {
309 errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
313 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
317 raw_string_ostream OS(Buf);
318 logAllUnhandledErrors(std::move(E), OS, "");
320 errs() << ToolName << ": '" << File << "': " << Buf;
324 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef ArchiveName,
327 StringRef ArchitectureName) {
329 errs() << ToolName << ": ";
330 if (ArchiveName != "")
331 errs() << ArchiveName << "(" << FileName << ")";
333 errs() << "'" << FileName << "'";
334 if (!ArchitectureName.empty())
335 errs() << " (for architecture " << ArchitectureName << ")";
337 raw_string_ostream OS(Buf);
338 logAllUnhandledErrors(std::move(E), OS, "");
340 errs() << ": " << Buf;
344 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef ArchiveName,
345 const object::Archive::Child &C,
347 StringRef ArchitectureName) {
348 Expected<StringRef> NameOrErr = C.getName();
349 // TODO: if we have a error getting the name then it would be nice to print
350 // the index of which archive member this is and or its offset in the
351 // archive instead of "???" as the name.
353 consumeError(NameOrErr.takeError());
354 llvm::report_error(ArchiveName, "???", std::move(E), ArchitectureName);
356 llvm::report_error(ArchiveName, NameOrErr.get(), std::move(E),
360 static const Target *getTarget(const ObjectFile *Obj = nullptr) {
361 // Figure out the target triple.
362 llvm::Triple TheTriple("unknown-unknown-unknown");
363 if (TripleName.empty()) {
365 TheTriple = Obj->makeTriple();
368 TheTriple.setTriple(Triple::normalize(TripleName));
370 // Use the triple, but also try to combine with ARM build attributes.
372 auto Arch = Obj->getArch();
373 if (Arch == Triple::arm || Arch == Triple::armeb) {
374 Obj->setARMSubArch(TheTriple);
379 // Get the target specific parser.
381 const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
385 report_error(Obj->getFileName(), "can't find target: " + Error);
387 error("can't find target: " + Error);
390 // Update the triple name and return the found target.
391 TripleName = TheTriple.getTriple();
395 bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
396 return a.getOffset() < b.getOffset();
400 class SourcePrinter {
402 DILineInfo OldLineInfo;
403 const ObjectFile *Obj = nullptr;
404 std::unique_ptr<symbolize::LLVMSymbolizer> Symbolizer;
405 // File name to file contents of source
406 std::unordered_map<std::string, std::unique_ptr<MemoryBuffer>> SourceCache;
407 // Mark the line endings of the cached source
408 std::unordered_map<std::string, std::vector<StringRef>> LineCache;
411 bool cacheSource(const std::string& File);
414 SourcePrinter() = default;
415 SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch) : Obj(Obj) {
416 symbolize::LLVMSymbolizer::Options SymbolizerOpts(
417 DILineInfoSpecifier::FunctionNameKind::None, true, false, false,
419 Symbolizer.reset(new symbolize::LLVMSymbolizer(SymbolizerOpts));
421 virtual ~SourcePrinter() = default;
422 virtual void printSourceLine(raw_ostream &OS, uint64_t Address,
423 StringRef Delimiter = "; ");
426 bool SourcePrinter::cacheSource(const std::string& File) {
427 auto BufferOrError = MemoryBuffer::getFile(File);
430 // Chomp the file to get lines
431 size_t BufferSize = (*BufferOrError)->getBufferSize();
432 const char *BufferStart = (*BufferOrError)->getBufferStart();
433 for (const char *Start = BufferStart, *End = BufferStart;
434 End < BufferStart + BufferSize; End++)
435 if (*End == '\n' || End == BufferStart + BufferSize - 1 ||
436 (*End == '\r' && *(End + 1) == '\n')) {
437 LineCache[File].push_back(StringRef(Start, End - Start));
442 SourceCache[File] = std::move(*BufferOrError);
446 void SourcePrinter::printSourceLine(raw_ostream &OS, uint64_t Address,
447 StringRef Delimiter) {
450 DILineInfo LineInfo = DILineInfo();
451 auto ExpectecLineInfo =
452 Symbolizer->symbolizeCode(Obj->getFileName(), Address);
453 if (!ExpectecLineInfo)
454 consumeError(ExpectecLineInfo.takeError());
456 LineInfo = *ExpectecLineInfo;
458 if ((LineInfo.FileName == "<invalid>") || OldLineInfo.Line == LineInfo.Line ||
463 OS << Delimiter << LineInfo.FileName << ":" << LineInfo.Line << "\n";
465 if (SourceCache.find(LineInfo.FileName) == SourceCache.end())
466 if (!cacheSource(LineInfo.FileName))
468 auto FileBuffer = SourceCache.find(LineInfo.FileName);
469 if (FileBuffer != SourceCache.end()) {
470 auto LineBuffer = LineCache.find(LineInfo.FileName);
471 if (LineBuffer != LineCache.end()) {
472 if (LineInfo.Line > LineBuffer->second.size())
474 // Vector begins at 0, line numbers are non-zero
475 OS << Delimiter << LineBuffer->second[LineInfo.Line - 1].ltrim()
480 OldLineInfo = LineInfo;
483 static bool isArmElf(const ObjectFile *Obj) {
484 return (Obj->isELF() &&
485 (Obj->getArch() == Triple::aarch64 ||
486 Obj->getArch() == Triple::aarch64_be ||
487 Obj->getArch() == Triple::arm || Obj->getArch() == Triple::armeb ||
488 Obj->getArch() == Triple::thumb ||
489 Obj->getArch() == Triple::thumbeb));
492 class PrettyPrinter {
494 virtual ~PrettyPrinter() = default;
495 virtual void printInst(MCInstPrinter &IP, const MCInst *MI,
496 ArrayRef<uint8_t> Bytes, uint64_t Address,
497 raw_ostream &OS, StringRef Annot,
498 MCSubtargetInfo const &STI, SourcePrinter *SP) {
499 if (SP && (PrintSource || PrintLines))
500 SP->printSourceLine(OS, Address);
502 OS << format("%8" PRIx64 ":", Address);
503 if (!NoShowRawInsn) {
505 dumpBytes(Bytes, OS);
508 IP.printInst(MI, OS, "", STI);
513 PrettyPrinter PrettyPrinterInst;
514 class HexagonPrettyPrinter : public PrettyPrinter {
516 void printLead(ArrayRef<uint8_t> Bytes, uint64_t Address,
519 (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | Bytes[0];
521 OS << format("%8" PRIx64 ":", Address);
522 if (!NoShowRawInsn) {
524 dumpBytes(Bytes.slice(0, 4), OS);
525 OS << format("%08" PRIx32, opcode);
528 void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes,
529 uint64_t Address, raw_ostream &OS, StringRef Annot,
530 MCSubtargetInfo const &STI, SourcePrinter *SP) override {
531 if (SP && (PrintSource || PrintLines))
532 SP->printSourceLine(OS, Address, "");
534 printLead(Bytes, Address, OS);
540 raw_string_ostream TempStream(Buffer);
541 IP.printInst(MI, TempStream, "", STI);
543 StringRef Contents(Buffer);
544 // Split off bundle attributes
545 auto PacketBundle = Contents.rsplit('\n');
546 // Split off first instruction from the rest
547 auto HeadTail = PacketBundle.first.split('\n');
548 auto Preamble = " { ";
550 while(!HeadTail.first.empty()) {
553 if (SP && (PrintSource || PrintLines))
554 SP->printSourceLine(OS, Address, "");
555 printLead(Bytes, Address, OS);
559 auto Duplex = HeadTail.first.split('\v');
560 if(!Duplex.second.empty()){
563 Inst = Duplex.second;
566 Inst = HeadTail.first;
568 Bytes = Bytes.slice(4);
570 HeadTail = HeadTail.second.split('\n');
572 OS << " } " << PacketBundle.second;
575 HexagonPrettyPrinter HexagonPrettyPrinterInst;
577 class AMDGCNPrettyPrinter : public PrettyPrinter {
579 void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes,
580 uint64_t Address, raw_ostream &OS, StringRef Annot,
581 MCSubtargetInfo const &STI, SourcePrinter *SP) override {
582 if (SP && (PrintSource || PrintLines))
583 SP->printSourceLine(OS, Address);
590 SmallString<40> InstStr;
591 raw_svector_ostream IS(InstStr);
593 IP.printInst(MI, IS, "", STI);
595 OS << left_justify(IS.str(), 60) << format("// %012" PRIX64 ": ", Address);
596 typedef support::ulittle32_t U32;
597 for (auto D : makeArrayRef(reinterpret_cast<const U32*>(Bytes.data()),
598 Bytes.size() / sizeof(U32)))
599 // D should be explicitly casted to uint32_t here as it is passed
600 // by format to snprintf as vararg.
601 OS << format("%08" PRIX32 " ", static_cast<uint32_t>(D));
604 OS << "// " << Annot;
607 AMDGCNPrettyPrinter AMDGCNPrettyPrinterInst;
609 class BPFPrettyPrinter : public PrettyPrinter {
611 void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes,
612 uint64_t Address, raw_ostream &OS, StringRef Annot,
613 MCSubtargetInfo const &STI, SourcePrinter *SP) override {
614 if (SP && (PrintSource || PrintLines))
615 SP->printSourceLine(OS, Address);
617 OS << format("%8" PRId64 ":", Address / 8);
618 if (!NoShowRawInsn) {
620 dumpBytes(Bytes, OS);
623 IP.printInst(MI, OS, "", STI);
628 BPFPrettyPrinter BPFPrettyPrinterInst;
630 PrettyPrinter &selectPrettyPrinter(Triple const &Triple) {
631 switch(Triple.getArch()) {
633 return PrettyPrinterInst;
634 case Triple::hexagon:
635 return HexagonPrettyPrinterInst;
637 return AMDGCNPrettyPrinterInst;
640 return BPFPrettyPrinterInst;
645 template <class ELFT>
646 static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
647 const RelocationRef &RelRef,
648 SmallVectorImpl<char> &Result) {
649 DataRefImpl Rel = RelRef.getRawDataRefImpl();
651 typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
652 typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
653 typedef typename ELFObjectFile<ELFT>::Elf_Rela Elf_Rela;
655 const ELFFile<ELFT> &EF = *Obj->getELFFile();
657 auto SecOrErr = EF.getSection(Rel.d.a);
659 return errorToErrorCode(SecOrErr.takeError());
660 const Elf_Shdr *Sec = *SecOrErr;
661 auto SymTabOrErr = EF.getSection(Sec->sh_link);
663 return errorToErrorCode(SymTabOrErr.takeError());
664 const Elf_Shdr *SymTab = *SymTabOrErr;
665 assert(SymTab->sh_type == ELF::SHT_SYMTAB ||
666 SymTab->sh_type == ELF::SHT_DYNSYM);
667 auto StrTabSec = EF.getSection(SymTab->sh_link);
669 return errorToErrorCode(StrTabSec.takeError());
670 auto StrTabOrErr = EF.getStringTable(*StrTabSec);
672 return errorToErrorCode(StrTabOrErr.takeError());
673 StringRef StrTab = *StrTabOrErr;
674 uint8_t type = RelRef.getType();
677 switch (Sec->sh_type) {
679 return object_error::parse_failed;
681 // TODO: Read implicit addend from section data.
684 case ELF::SHT_RELA: {
685 const Elf_Rela *ERela = Obj->getRela(Rel);
686 addend = ERela->r_addend;
690 symbol_iterator SI = RelRef.getSymbol();
691 const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl());
693 if (symb->getType() == ELF::STT_SECTION) {
694 Expected<section_iterator> SymSI = SI->getSection();
696 return errorToErrorCode(SymSI.takeError());
697 const Elf_Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl());
698 auto SecName = EF.getSectionName(SymSec);
700 return errorToErrorCode(SecName.takeError());
703 Expected<StringRef> SymName = symb->getName(StrTab);
705 return errorToErrorCode(SymName.takeError());
708 switch (EF.getHeader()->e_machine) {
711 case ELF::R_X86_64_PC8:
712 case ELF::R_X86_64_PC16:
713 case ELF::R_X86_64_PC32: {
715 raw_string_ostream fmt(fmtbuf);
716 fmt << Target << (addend < 0 ? "" : "+") << addend << "-P";
718 Result.append(fmtbuf.begin(), fmtbuf.end());
720 case ELF::R_X86_64_8:
721 case ELF::R_X86_64_16:
722 case ELF::R_X86_64_32:
723 case ELF::R_X86_64_32S:
724 case ELF::R_X86_64_64: {
726 raw_string_ostream fmt(fmtbuf);
727 fmt << Target << (addend < 0 ? "" : "+") << addend;
729 Result.append(fmtbuf.begin(), fmtbuf.end());
737 case ELF::EM_AARCH64: {
739 raw_string_ostream fmt(fmtbuf);
742 fmt << (addend < 0 ? "" : "+") << addend;
744 Result.append(fmtbuf.begin(), fmtbuf.end());
750 case ELF::EM_HEXAGON:
756 case ELF::EM_WEBASSEMBLY:
758 case ELF::R_WEBASSEMBLY_DATA: {
760 raw_string_ostream fmt(fmtbuf);
761 fmt << Target << (addend < 0 ? "" : "+") << addend;
763 Result.append(fmtbuf.begin(), fmtbuf.end());
766 case ELF::R_WEBASSEMBLY_FUNCTION:
777 Result.append(res.begin(), res.end());
778 return std::error_code();
781 static std::error_code getRelocationValueString(const ELFObjectFileBase *Obj,
782 const RelocationRef &Rel,
783 SmallVectorImpl<char> &Result) {
784 if (auto *ELF32LE = dyn_cast<ELF32LEObjectFile>(Obj))
785 return getRelocationValueString(ELF32LE, Rel, Result);
786 if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
787 return getRelocationValueString(ELF64LE, Rel, Result);
788 if (auto *ELF32BE = dyn_cast<ELF32BEObjectFile>(Obj))
789 return getRelocationValueString(ELF32BE, Rel, Result);
790 auto *ELF64BE = cast<ELF64BEObjectFile>(Obj);
791 return getRelocationValueString(ELF64BE, Rel, Result);
794 static std::error_code getRelocationValueString(const COFFObjectFile *Obj,
795 const RelocationRef &Rel,
796 SmallVectorImpl<char> &Result) {
797 symbol_iterator SymI = Rel.getSymbol();
798 Expected<StringRef> SymNameOrErr = SymI->getName();
800 return errorToErrorCode(SymNameOrErr.takeError());
801 StringRef SymName = *SymNameOrErr;
802 Result.append(SymName.begin(), SymName.end());
803 return std::error_code();
806 static void printRelocationTargetName(const MachOObjectFile *O,
807 const MachO::any_relocation_info &RE,
808 raw_string_ostream &fmt) {
809 bool IsScattered = O->isRelocationScattered(RE);
811 // Target of a scattered relocation is an address. In the interest of
812 // generating pretty output, scan through the symbol table looking for a
813 // symbol that aligns with that address. If we find one, print it.
814 // Otherwise, we just print the hex address of the target.
816 uint32_t Val = O->getPlainRelocationSymbolNum(RE);
818 for (const SymbolRef &Symbol : O->symbols()) {
820 Expected<uint64_t> Addr = Symbol.getAddress();
822 report_error(O->getFileName(), Addr.takeError());
825 Expected<StringRef> Name = Symbol.getName();
827 report_error(O->getFileName(), Name.takeError());
832 // If we couldn't find a symbol that this relocation refers to, try
833 // to find a section beginning instead.
834 for (const SectionRef &Section : ToolSectionFilter(*O)) {
838 uint64_t Addr = Section.getAddress();
841 if ((ec = Section.getName(Name)))
842 report_error(O->getFileName(), ec);
847 fmt << format("0x%x", Val);
852 bool isExtern = O->getPlainRelocationExternal(RE);
853 uint64_t Val = O->getPlainRelocationSymbolNum(RE);
855 if (O->getAnyRelocationType(RE) == MachO::ARM64_RELOC_ADDEND) {
856 fmt << format("0x%0" PRIx64, Val);
858 } else if (isExtern) {
859 symbol_iterator SI = O->symbol_begin();
861 Expected<StringRef> SOrErr = SI->getName();
863 report_error(O->getFileName(), SOrErr.takeError());
866 section_iterator SI = O->section_begin();
867 // Adjust for the fact that sections are 1-indexed.
872 uint32_t i = Val - 1;
873 while (i != 0 && SI != O->section_end()) {
877 if (SI == O->section_end())
878 fmt << Val << " (?,?)";
886 static std::error_code getRelocationValueString(const WasmObjectFile *Obj,
887 const RelocationRef &RelRef,
888 SmallVectorImpl<char> &Result) {
889 const wasm::WasmRelocation& Rel = Obj->getWasmRelocation(RelRef);
891 raw_string_ostream fmt(fmtbuf);
892 fmt << Rel.Index << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
894 Result.append(fmtbuf.begin(), fmtbuf.end());
895 return std::error_code();
898 static std::error_code getRelocationValueString(const MachOObjectFile *Obj,
899 const RelocationRef &RelRef,
900 SmallVectorImpl<char> &Result) {
901 DataRefImpl Rel = RelRef.getRawDataRefImpl();
902 MachO::any_relocation_info RE = Obj->getRelocation(Rel);
904 unsigned Arch = Obj->getArch();
907 raw_string_ostream fmt(fmtbuf);
908 unsigned Type = Obj->getAnyRelocationType(RE);
909 bool IsPCRel = Obj->getAnyRelocationPCRel(RE);
911 // Determine any addends that should be displayed with the relocation.
912 // These require decoding the relocation type, which is triple-specific.
914 // X86_64 has entirely custom relocation types.
915 if (Arch == Triple::x86_64) {
916 bool isPCRel = Obj->getAnyRelocationPCRel(RE);
919 case MachO::X86_64_RELOC_GOT_LOAD:
920 case MachO::X86_64_RELOC_GOT: {
921 printRelocationTargetName(Obj, RE, fmt);
927 case MachO::X86_64_RELOC_SUBTRACTOR: {
928 DataRefImpl RelNext = Rel;
929 Obj->moveRelocationNext(RelNext);
930 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
932 // X86_64_RELOC_SUBTRACTOR must be followed by a relocation of type
933 // X86_64_RELOC_UNSIGNED.
934 // NOTE: Scattered relocations don't exist on x86_64.
935 unsigned RType = Obj->getAnyRelocationType(RENext);
936 if (RType != MachO::X86_64_RELOC_UNSIGNED)
937 report_error(Obj->getFileName(), "Expected X86_64_RELOC_UNSIGNED after "
938 "X86_64_RELOC_SUBTRACTOR.");
940 // The X86_64_RELOC_UNSIGNED contains the minuend symbol;
941 // X86_64_RELOC_SUBTRACTOR contains the subtrahend.
942 printRelocationTargetName(Obj, RENext, fmt);
944 printRelocationTargetName(Obj, RE, fmt);
947 case MachO::X86_64_RELOC_TLV:
948 printRelocationTargetName(Obj, RE, fmt);
953 case MachO::X86_64_RELOC_SIGNED_1:
954 printRelocationTargetName(Obj, RE, fmt);
957 case MachO::X86_64_RELOC_SIGNED_2:
958 printRelocationTargetName(Obj, RE, fmt);
961 case MachO::X86_64_RELOC_SIGNED_4:
962 printRelocationTargetName(Obj, RE, fmt);
966 printRelocationTargetName(Obj, RE, fmt);
969 // X86 and ARM share some relocation types in common.
970 } else if (Arch == Triple::x86 || Arch == Triple::arm ||
971 Arch == Triple::ppc) {
972 // Generic relocation types...
974 case MachO::GENERIC_RELOC_PAIR: // prints no info
975 return std::error_code();
976 case MachO::GENERIC_RELOC_SECTDIFF: {
977 DataRefImpl RelNext = Rel;
978 Obj->moveRelocationNext(RelNext);
979 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
981 // X86 sect diff's must be followed by a relocation of type
982 // GENERIC_RELOC_PAIR.
983 unsigned RType = Obj->getAnyRelocationType(RENext);
985 if (RType != MachO::GENERIC_RELOC_PAIR)
986 report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
987 "GENERIC_RELOC_SECTDIFF.");
989 printRelocationTargetName(Obj, RE, fmt);
991 printRelocationTargetName(Obj, RENext, fmt);
996 if (Arch == Triple::x86 || Arch == Triple::ppc) {
998 case MachO::GENERIC_RELOC_LOCAL_SECTDIFF: {
999 DataRefImpl RelNext = Rel;
1000 Obj->moveRelocationNext(RelNext);
1001 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
1003 // X86 sect diff's must be followed by a relocation of type
1004 // GENERIC_RELOC_PAIR.
1005 unsigned RType = Obj->getAnyRelocationType(RENext);
1006 if (RType != MachO::GENERIC_RELOC_PAIR)
1007 report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
1008 "GENERIC_RELOC_LOCAL_SECTDIFF.");
1010 printRelocationTargetName(Obj, RE, fmt);
1012 printRelocationTargetName(Obj, RENext, fmt);
1015 case MachO::GENERIC_RELOC_TLV: {
1016 printRelocationTargetName(Obj, RE, fmt);
1023 printRelocationTargetName(Obj, RE, fmt);
1025 } else { // ARM-specific relocations
1027 case MachO::ARM_RELOC_HALF:
1028 case MachO::ARM_RELOC_HALF_SECTDIFF: {
1029 // Half relocations steal a bit from the length field to encode
1030 // whether this is an upper16 or a lower16 relocation.
1031 bool isUpper = (Obj->getAnyRelocationLength(RE) & 0x1) == 1;
1034 fmt << ":upper16:(";
1036 fmt << ":lower16:(";
1037 printRelocationTargetName(Obj, RE, fmt);
1039 DataRefImpl RelNext = Rel;
1040 Obj->moveRelocationNext(RelNext);
1041 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
1043 // ARM half relocs must be followed by a relocation of type
1045 unsigned RType = Obj->getAnyRelocationType(RENext);
1046 if (RType != MachO::ARM_RELOC_PAIR)
1047 report_error(Obj->getFileName(), "Expected ARM_RELOC_PAIR after "
1050 // NOTE: The half of the target virtual address is stashed in the
1051 // address field of the secondary relocation, but we can't reverse
1052 // engineer the constant offset from it without decoding the movw/movt
1053 // instruction to find the other half in its immediate field.
1055 // ARM_RELOC_HALF_SECTDIFF encodes the second section in the
1056 // symbol/section pointer of the follow-on relocation.
1057 if (Type == MachO::ARM_RELOC_HALF_SECTDIFF) {
1059 printRelocationTargetName(Obj, RENext, fmt);
1065 default: { printRelocationTargetName(Obj, RE, fmt); }
1069 printRelocationTargetName(Obj, RE, fmt);
1072 Result.append(fmtbuf.begin(), fmtbuf.end());
1073 return std::error_code();
1076 static std::error_code getRelocationValueString(const RelocationRef &Rel,
1077 SmallVectorImpl<char> &Result) {
1078 const ObjectFile *Obj = Rel.getObject();
1079 if (auto *ELF = dyn_cast<ELFObjectFileBase>(Obj))
1080 return getRelocationValueString(ELF, Rel, Result);
1081 if (auto *COFF = dyn_cast<COFFObjectFile>(Obj))
1082 return getRelocationValueString(COFF, Rel, Result);
1083 if (auto *Wasm = dyn_cast<WasmObjectFile>(Obj))
1084 return getRelocationValueString(Wasm, Rel, Result);
1085 if (auto *MachO = dyn_cast<MachOObjectFile>(Obj))
1086 return getRelocationValueString(MachO, Rel, Result);
1087 llvm_unreachable("unknown object file format");
1090 /// @brief Indicates whether this relocation should hidden when listing
1091 /// relocations, usually because it is the trailing part of a multipart
1092 /// relocation that will be printed as part of the leading relocation.
1093 static bool getHidden(RelocationRef RelRef) {
1094 const ObjectFile *Obj = RelRef.getObject();
1095 auto *MachO = dyn_cast<MachOObjectFile>(Obj);
1099 unsigned Arch = MachO->getArch();
1100 DataRefImpl Rel = RelRef.getRawDataRefImpl();
1101 uint64_t Type = MachO->getRelocationType(Rel);
1103 // On arches that use the generic relocations, GENERIC_RELOC_PAIR
1104 // is always hidden.
1105 if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
1106 if (Type == MachO::GENERIC_RELOC_PAIR)
1108 } else if (Arch == Triple::x86_64) {
1109 // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
1110 // an X86_64_RELOC_SUBTRACTOR.
1111 if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
1112 DataRefImpl RelPrev = Rel;
1114 uint64_t PrevType = MachO->getRelocationType(RelPrev);
1115 if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
1123 static uint8_t getElfSymbolType(const ObjectFile *Obj, const SymbolRef &Sym) {
1124 assert(Obj->isELF());
1125 if (auto *Elf32LEObj = dyn_cast<ELF32LEObjectFile>(Obj))
1126 return Elf32LEObj->getSymbol(Sym.getRawDataRefImpl())->getType();
1127 if (auto *Elf64LEObj = dyn_cast<ELF64LEObjectFile>(Obj))
1128 return Elf64LEObj->getSymbol(Sym.getRawDataRefImpl())->getType();
1129 if (auto *Elf32BEObj = dyn_cast<ELF32BEObjectFile>(Obj))
1130 return Elf32BEObj->getSymbol(Sym.getRawDataRefImpl())->getType();
1131 if (auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj))
1132 return Elf64BEObj->getSymbol(Sym.getRawDataRefImpl())->getType();
1133 llvm_unreachable("Unsupported binary format");
1136 template <class ELFT> static void
1137 addDynamicElfSymbols(const ELFObjectFile<ELFT> *Obj,
1138 std::map<SectionRef, SectionSymbolsTy> &AllSymbols) {
1139 for (auto Symbol : Obj->getDynamicSymbolIterators()) {
1140 uint8_t SymbolType = Symbol.getELFType();
1141 if (SymbolType != ELF::STT_FUNC || Symbol.getSize() == 0)
1144 Expected<uint64_t> AddressOrErr = Symbol.getAddress();
1146 report_error(Obj->getFileName(), AddressOrErr.takeError());
1147 uint64_t Address = *AddressOrErr;
1149 Expected<StringRef> Name = Symbol.getName();
1151 report_error(Obj->getFileName(), Name.takeError());
1155 Expected<section_iterator> SectionOrErr = Symbol.getSection();
1157 report_error(Obj->getFileName(), SectionOrErr.takeError());
1158 section_iterator SecI = *SectionOrErr;
1159 if (SecI == Obj->section_end())
1162 AllSymbols[*SecI].emplace_back(Address, *Name, SymbolType);
1167 addDynamicElfSymbols(const ObjectFile *Obj,
1168 std::map<SectionRef, SectionSymbolsTy> &AllSymbols) {
1169 assert(Obj->isELF());
1170 if (auto *Elf32LEObj = dyn_cast<ELF32LEObjectFile>(Obj))
1171 addDynamicElfSymbols(Elf32LEObj, AllSymbols);
1172 else if (auto *Elf64LEObj = dyn_cast<ELF64LEObjectFile>(Obj))
1173 addDynamicElfSymbols(Elf64LEObj, AllSymbols);
1174 else if (auto *Elf32BEObj = dyn_cast<ELF32BEObjectFile>(Obj))
1175 addDynamicElfSymbols(Elf32BEObj, AllSymbols);
1176 else if (auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj))
1177 addDynamicElfSymbols(Elf64BEObj, AllSymbols);
1179 llvm_unreachable("Unsupported binary format");
1182 static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
1183 if (StartAddress > StopAddress)
1184 error("Start address should be less than stop address");
1186 const Target *TheTarget = getTarget(Obj);
1188 // Package up features to be passed to target/subtarget
1189 SubtargetFeatures Features = Obj->getFeatures();
1190 if (MAttrs.size()) {
1191 for (unsigned i = 0; i != MAttrs.size(); ++i)
1192 Features.AddFeature(MAttrs[i]);
1195 std::unique_ptr<const MCRegisterInfo> MRI(
1196 TheTarget->createMCRegInfo(TripleName));
1198 report_error(Obj->getFileName(), "no register info for target " +
1201 // Set up disassembler.
1202 std::unique_ptr<const MCAsmInfo> AsmInfo(
1203 TheTarget->createMCAsmInfo(*MRI, TripleName));
1205 report_error(Obj->getFileName(), "no assembly info for target " +
1207 std::unique_ptr<const MCSubtargetInfo> STI(
1208 TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
1210 report_error(Obj->getFileName(), "no subtarget info for target " +
1212 std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
1214 report_error(Obj->getFileName(), "no instruction info for target " +
1216 MCObjectFileInfo MOFI;
1217 MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
1218 // FIXME: for now initialize MCObjectFileInfo with default values
1219 MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx);
1221 std::unique_ptr<MCDisassembler> DisAsm(
1222 TheTarget->createMCDisassembler(*STI, Ctx));
1224 report_error(Obj->getFileName(), "no disassembler for target " +
1227 std::unique_ptr<const MCInstrAnalysis> MIA(
1228 TheTarget->createMCInstrAnalysis(MII.get()));
1230 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
1231 std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
1232 Triple(TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
1234 report_error(Obj->getFileName(), "no instruction printer for target " +
1236 IP->setPrintImmHex(PrintImmHex);
1237 PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
1239 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": " :
1240 "\t\t\t%08" PRIx64 ": ";
1242 SourcePrinter SP(Obj, TheTarget->getName());
1244 // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
1245 // in RelocSecs contain the relocations for section S.
1247 std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap;
1248 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1249 section_iterator Sec2 = Section.getRelocatedSection();
1250 if (Sec2 != Obj->section_end())
1251 SectionRelocMap[*Sec2].push_back(Section);
1254 // Create a mapping from virtual address to symbol name. This is used to
1255 // pretty print the symbols while disassembling.
1256 std::map<SectionRef, SectionSymbolsTy> AllSymbols;
1257 for (const SymbolRef &Symbol : Obj->symbols()) {
1258 Expected<uint64_t> AddressOrErr = Symbol.getAddress();
1260 report_error(Obj->getFileName(), AddressOrErr.takeError());
1261 uint64_t Address = *AddressOrErr;
1263 Expected<StringRef> Name = Symbol.getName();
1265 report_error(Obj->getFileName(), Name.takeError());
1269 Expected<section_iterator> SectionOrErr = Symbol.getSection();
1271 report_error(Obj->getFileName(), SectionOrErr.takeError());
1272 section_iterator SecI = *SectionOrErr;
1273 if (SecI == Obj->section_end())
1276 uint8_t SymbolType = ELF::STT_NOTYPE;
1278 SymbolType = getElfSymbolType(Obj, Symbol);
1280 AllSymbols[*SecI].emplace_back(Address, *Name, SymbolType);
1283 if (AllSymbols.empty() && Obj->isELF())
1284 addDynamicElfSymbols(Obj, AllSymbols);
1286 // Create a mapping from virtual address to section.
1287 std::vector<std::pair<uint64_t, SectionRef>> SectionAddresses;
1288 for (SectionRef Sec : Obj->sections())
1289 SectionAddresses.emplace_back(Sec.getAddress(), Sec);
1290 array_pod_sort(SectionAddresses.begin(), SectionAddresses.end());
1292 // Linked executables (.exe and .dll files) typically don't include a real
1293 // symbol table but they might contain an export table.
1294 if (const auto *COFFObj = dyn_cast<COFFObjectFile>(Obj)) {
1295 for (const auto &ExportEntry : COFFObj->export_directories()) {
1297 error(ExportEntry.getSymbolName(Name));
1301 error(ExportEntry.getExportRVA(RVA));
1303 uint64_t VA = COFFObj->getImageBase() + RVA;
1304 auto Sec = std::upper_bound(
1305 SectionAddresses.begin(), SectionAddresses.end(), VA,
1306 [](uint64_t LHS, const std::pair<uint64_t, SectionRef> &RHS) {
1307 return LHS < RHS.first;
1309 if (Sec != SectionAddresses.begin())
1312 Sec = SectionAddresses.end();
1314 if (Sec != SectionAddresses.end())
1315 AllSymbols[Sec->second].emplace_back(VA, Name, ELF::STT_NOTYPE);
1319 // Sort all the symbols, this allows us to use a simple binary search to find
1320 // a symbol near an address.
1321 for (std::pair<const SectionRef, SectionSymbolsTy> &SecSyms : AllSymbols)
1322 array_pod_sort(SecSyms.second.begin(), SecSyms.second.end());
1324 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1325 if (!DisassembleAll && (!Section.isText() || Section.isVirtual()))
1328 uint64_t SectionAddr = Section.getAddress();
1329 uint64_t SectSize = Section.getSize();
1333 // Get the list of all the symbols in this section.
1334 SectionSymbolsTy &Symbols = AllSymbols[Section];
1335 std::vector<uint64_t> DataMappingSymsAddr;
1336 std::vector<uint64_t> TextMappingSymsAddr;
1337 if (isArmElf(Obj)) {
1338 for (const auto &Symb : Symbols) {
1339 uint64_t Address = std::get<0>(Symb);
1340 StringRef Name = std::get<1>(Symb);
1341 if (Name.startswith("$d"))
1342 DataMappingSymsAddr.push_back(Address - SectionAddr);
1343 if (Name.startswith("$x"))
1344 TextMappingSymsAddr.push_back(Address - SectionAddr);
1345 if (Name.startswith("$a"))
1346 TextMappingSymsAddr.push_back(Address - SectionAddr);
1347 if (Name.startswith("$t"))
1348 TextMappingSymsAddr.push_back(Address - SectionAddr);
1352 std::sort(DataMappingSymsAddr.begin(), DataMappingSymsAddr.end());
1353 std::sort(TextMappingSymsAddr.begin(), TextMappingSymsAddr.end());
1355 if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
1356 // AMDGPU disassembler uses symbolizer for printing labels
1357 std::unique_ptr<MCRelocationInfo> RelInfo(
1358 TheTarget->createMCRelocationInfo(TripleName, Ctx));
1360 std::unique_ptr<MCSymbolizer> Symbolizer(
1361 TheTarget->createMCSymbolizer(
1362 TripleName, nullptr, nullptr, &Symbols, &Ctx, std::move(RelInfo)));
1363 DisAsm->setSymbolizer(std::move(Symbolizer));
1367 // Make a list of all the relocations for this section.
1368 std::vector<RelocationRef> Rels;
1370 for (const SectionRef &RelocSec : SectionRelocMap[Section]) {
1371 for (const RelocationRef &Reloc : RelocSec.relocations()) {
1372 Rels.push_back(Reloc);
1377 // Sort relocations by address.
1378 std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
1380 StringRef SegmentName = "";
1381 if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
1382 DataRefImpl DR = Section.getRawDataRefImpl();
1383 SegmentName = MachO->getSectionFinalSegmentName(DR);
1386 error(Section.getName(name));
1388 if ((SectionAddr <= StopAddress) &&
1389 (SectionAddr + SectSize) >= StartAddress) {
1390 outs() << "Disassembly of section ";
1391 if (!SegmentName.empty())
1392 outs() << SegmentName << ",";
1393 outs() << name << ':';
1396 // If the section has no symbol at the start, just insert a dummy one.
1397 if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) {
1398 Symbols.insert(Symbols.begin(),
1399 std::make_tuple(SectionAddr, name, Section.isText()
1401 : ELF::STT_OBJECT));
1404 SmallString<40> Comments;
1405 raw_svector_ostream CommentStream(Comments);
1408 error(Section.getContents(BytesStr));
1409 ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(BytesStr.data()),
1415 std::vector<RelocationRef>::const_iterator rel_cur = Rels.begin();
1416 std::vector<RelocationRef>::const_iterator rel_end = Rels.end();
1417 // Disassemble symbol by symbol.
1418 for (unsigned si = 0, se = Symbols.size(); si != se; ++si) {
1419 uint64_t Start = std::get<0>(Symbols[si]) - SectionAddr;
1420 // The end is either the section end or the beginning of the next
1423 (si == se - 1) ? SectSize : std::get<0>(Symbols[si + 1]) - SectionAddr;
1424 // Don't try to disassemble beyond the end of section contents.
1427 // If this symbol has the same address as the next symbol, then skip it.
1431 // Check if we need to skip symbol
1432 // Skip if the symbol's data is not between StartAddress and StopAddress
1433 if (End + SectionAddr < StartAddress ||
1434 Start + SectionAddr > StopAddress) {
1438 // Stop disassembly at the stop address specified
1439 if (End + SectionAddr > StopAddress)
1440 End = StopAddress - SectionAddr;
1442 if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
1443 // make size 4 bytes folded
1444 End = Start + ((End - Start) & ~0x3ull);
1445 if (std::get<2>(Symbols[si]) == ELF::STT_AMDGPU_HSA_KERNEL) {
1446 // skip amd_kernel_code_t at the begining of kernel symbol (256 bytes)
1450 std::get<2>(Symbols[si + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) {
1451 // cut trailing zeroes at the end of kernel
1452 // cut up to 256 bytes
1453 const uint64_t EndAlign = 256;
1454 const auto Limit = End - (std::min)(EndAlign, End - Start);
1455 while (End > Limit &&
1456 *reinterpret_cast<const support::ulittle32_t*>(&Bytes[End - 4]) == 0)
1461 outs() << '\n' << std::get<1>(Symbols[si]) << ":\n";
1464 raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
1466 raw_ostream &DebugOut = nulls();
1469 for (Index = Start; Index < End; Index += Size) {
1472 if (Index + SectionAddr < StartAddress ||
1473 Index + SectionAddr > StopAddress) {
1474 // skip byte by byte till StartAddress is reached
1478 // AArch64 ELF binaries can interleave data and text in the
1479 // same section. We rely on the markers introduced to
1480 // understand what we need to dump. If the data marker is within a
1481 // function, it is denoted as a word/short etc
1482 if (isArmElf(Obj) && std::get<2>(Symbols[si]) != ELF::STT_OBJECT &&
1484 uint64_t Stride = 0;
1486 auto DAI = std::lower_bound(DataMappingSymsAddr.begin(),
1487 DataMappingSymsAddr.end(), Index);
1488 if (DAI != DataMappingSymsAddr.end() && *DAI == Index) {
1490 while (Index < End) {
1491 outs() << format("%8" PRIx64 ":", SectionAddr + Index);
1493 if (Index + 4 <= End) {
1495 dumpBytes(Bytes.slice(Index, 4), outs());
1496 outs() << "\t.word\t";
1498 if (Obj->isLittleEndian()) {
1500 reinterpret_cast<const support::ulittle32_t *>(
1501 Bytes.data() + Index);
1504 const auto Word = reinterpret_cast<const support::ubig32_t *>(
1505 Bytes.data() + Index);
1508 outs() << "0x" << format("%08" PRIx32, Data);
1509 } else if (Index + 2 <= End) {
1511 dumpBytes(Bytes.slice(Index, 2), outs());
1512 outs() << "\t\t.short\t";
1514 if (Obj->isLittleEndian()) {
1516 reinterpret_cast<const support::ulittle16_t *>(
1517 Bytes.data() + Index);
1521 reinterpret_cast<const support::ubig16_t *>(Bytes.data() +
1525 outs() << "0x" << format("%04" PRIx16, Data);
1528 dumpBytes(Bytes.slice(Index, 1), outs());
1529 outs() << "\t\t.byte\t";
1530 outs() << "0x" << format("%02" PRIx8, Bytes.slice(Index, 1)[0]);
1534 auto TAI = std::lower_bound(TextMappingSymsAddr.begin(),
1535 TextMappingSymsAddr.end(), Index);
1536 if (TAI != TextMappingSymsAddr.end() && *TAI == Index)
1542 // If there is a data symbol inside an ELF text section and we are only
1543 // disassembling text (applicable all architectures),
1544 // we are in a situation where we must print the data and not
1546 if (Obj->isELF() && std::get<2>(Symbols[si]) == ELF::STT_OBJECT &&
1547 !DisassembleAll && Section.isText()) {
1548 // print out data up to 8 bytes at a time in hex and ascii
1549 uint8_t AsciiData[9] = {'\0'};
1553 for (Index = Start; Index < End; Index += 1) {
1554 if (((SectionAddr + Index) < StartAddress) ||
1555 ((SectionAddr + Index) > StopAddress))
1557 if (NumBytes == 0) {
1558 outs() << format("%8" PRIx64 ":", SectionAddr + Index);
1561 Byte = Bytes.slice(Index)[0];
1562 outs() << format(" %02x", Byte);
1563 AsciiData[NumBytes] = isprint(Byte) ? Byte : '.';
1565 uint8_t IndentOffset = 0;
1567 if (Index == End - 1 || NumBytes > 8) {
1568 // Indent the space for less than 8 bytes data.
1569 // 2 spaces for byte and one for space between bytes
1570 IndentOffset = 3 * (8 - NumBytes);
1571 for (int Excess = 8 - NumBytes; Excess < 8; Excess++)
1572 AsciiData[Excess] = '\0';
1575 if (NumBytes == 8) {
1576 AsciiData[8] = '\0';
1577 outs() << std::string(IndentOffset, ' ') << " ";
1578 outs() << reinterpret_cast<char *>(AsciiData);
1587 // Disassemble a real instruction or a data when disassemble all is
1589 bool Disassembled = DisAsm->getInstruction(Inst, Size, Bytes.slice(Index),
1590 SectionAddr + Index, DebugOut,
1595 PIP.printInst(*IP, Disassembled ? &Inst : nullptr,
1596 Bytes.slice(Index, Size), SectionAddr + Index, outs(), "",
1598 outs() << CommentStream.str();
1601 // Try to resolve the target of a call, tail call, etc. to a specific
1603 if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) ||
1604 MIA->isConditionalBranch(Inst))) {
1606 if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) {
1607 // In a relocatable object, the target's section must reside in
1608 // the same section as the call instruction or it is accessed
1609 // through a relocation.
1611 // In a non-relocatable object, the target may be in any section.
1613 // N.B. We don't walk the relocations in the relocatable case yet.
1614 auto *TargetSectionSymbols = &Symbols;
1615 if (!Obj->isRelocatableObject()) {
1616 auto SectionAddress = std::upper_bound(
1617 SectionAddresses.begin(), SectionAddresses.end(), Target,
1619 const std::pair<uint64_t, SectionRef> &RHS) {
1620 return LHS < RHS.first;
1622 if (SectionAddress != SectionAddresses.begin()) {
1624 TargetSectionSymbols = &AllSymbols[SectionAddress->second];
1626 TargetSectionSymbols = nullptr;
1630 // Find the first symbol in the section whose offset is less than
1631 // or equal to the target.
1632 if (TargetSectionSymbols) {
1633 auto TargetSym = std::upper_bound(
1634 TargetSectionSymbols->begin(), TargetSectionSymbols->end(),
1635 Target, [](uint64_t LHS,
1636 const std::tuple<uint64_t, StringRef, uint8_t> &RHS) {
1637 return LHS < std::get<0>(RHS);
1639 if (TargetSym != TargetSectionSymbols->begin()) {
1641 uint64_t TargetAddress = std::get<0>(*TargetSym);
1642 StringRef TargetName = std::get<1>(*TargetSym);
1643 outs() << " <" << TargetName;
1644 uint64_t Disp = Target - TargetAddress;
1646 outs() << "+0x" << Twine::utohexstr(Disp);
1654 // Print relocation for instruction.
1655 while (rel_cur != rel_end) {
1656 bool hidden = getHidden(*rel_cur);
1657 uint64_t addr = rel_cur->getOffset();
1658 SmallString<16> name;
1659 SmallString<32> val;
1661 // If this relocation is hidden, skip it.
1662 if (hidden || ((SectionAddr + addr) < StartAddress)) {
1667 // Stop when rel_cur's address is past the current instruction.
1668 if (addr >= Index + Size) break;
1669 rel_cur->getTypeName(name);
1670 error(getRelocationValueString(*rel_cur, val));
1671 outs() << format(Fmt.data(), SectionAddr + addr) << name
1672 << "\t" << val << "\n";
1680 void llvm::PrintRelocations(const ObjectFile *Obj) {
1681 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
1683 // Regular objdump doesn't print relocations in non-relocatable object
1685 if (!Obj->isRelocatableObject())
1688 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1689 if (Section.relocation_begin() == Section.relocation_end())
1692 error(Section.getName(secname));
1693 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
1694 for (const RelocationRef &Reloc : Section.relocations()) {
1695 bool hidden = getHidden(Reloc);
1696 uint64_t address = Reloc.getOffset();
1697 SmallString<32> relocname;
1698 SmallString<32> valuestr;
1699 if (address < StartAddress || address > StopAddress || hidden)
1701 Reloc.getTypeName(relocname);
1702 error(getRelocationValueString(Reloc, valuestr));
1703 outs() << format(Fmt.data(), address) << " " << relocname << " "
1704 << valuestr << "\n";
1710 void llvm::PrintSectionHeaders(const ObjectFile *Obj) {
1711 outs() << "Sections:\n"
1712 "Idx Name Size Address Type\n";
1714 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1716 error(Section.getName(Name));
1717 uint64_t Address = Section.getAddress();
1718 uint64_t Size = Section.getSize();
1719 bool Text = Section.isText();
1720 bool Data = Section.isData();
1721 bool BSS = Section.isBSS();
1722 std::string Type = (std::string(Text ? "TEXT " : "") +
1723 (Data ? "DATA " : "") + (BSS ? "BSS" : ""));
1724 outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n", i,
1725 Name.str().c_str(), Size, Address, Type.c_str());
1730 void llvm::PrintSectionContents(const ObjectFile *Obj) {
1732 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1735 error(Section.getName(Name));
1736 uint64_t BaseAddr = Section.getAddress();
1737 uint64_t Size = Section.getSize();
1741 outs() << "Contents of section " << Name << ":\n";
1742 if (Section.isBSS()) {
1743 outs() << format("<skipping contents of bss section at [%04" PRIx64
1744 ", %04" PRIx64 ")>\n",
1745 BaseAddr, BaseAddr + Size);
1749 error(Section.getContents(Contents));
1751 // Dump out the content as hex and printable ascii characters.
1752 for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) {
1753 outs() << format(" %04" PRIx64 " ", BaseAddr + addr);
1754 // Dump line of hex.
1755 for (std::size_t i = 0; i < 16; ++i) {
1756 if (i != 0 && i % 4 == 0)
1759 outs() << hexdigit((Contents[addr + i] >> 4) & 0xF, true)
1760 << hexdigit(Contents[addr + i] & 0xF, true);
1766 for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
1767 if (std::isprint(static_cast<unsigned char>(Contents[addr + i]) & 0xFF))
1768 outs() << Contents[addr + i];
1777 void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName,
1778 StringRef ArchitectureName) {
1779 outs() << "SYMBOL TABLE:\n";
1781 if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o)) {
1782 printCOFFSymbolTable(coff);
1785 for (const SymbolRef &Symbol : o->symbols()) {
1786 Expected<uint64_t> AddressOrError = Symbol.getAddress();
1787 if (!AddressOrError)
1788 report_error(ArchiveName, o->getFileName(), AddressOrError.takeError(),
1790 uint64_t Address = *AddressOrError;
1791 if ((Address < StartAddress) || (Address > StopAddress))
1793 Expected<SymbolRef::Type> TypeOrError = Symbol.getType();
1795 report_error(ArchiveName, o->getFileName(), TypeOrError.takeError(),
1797 SymbolRef::Type Type = *TypeOrError;
1798 uint32_t Flags = Symbol.getFlags();
1799 Expected<section_iterator> SectionOrErr = Symbol.getSection();
1801 report_error(ArchiveName, o->getFileName(), SectionOrErr.takeError(),
1803 section_iterator Section = *SectionOrErr;
1805 if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
1806 Section->getName(Name);
1808 Expected<StringRef> NameOrErr = Symbol.getName();
1810 report_error(ArchiveName, o->getFileName(), NameOrErr.takeError(),
1815 bool Global = Flags & SymbolRef::SF_Global;
1816 bool Weak = Flags & SymbolRef::SF_Weak;
1817 bool Absolute = Flags & SymbolRef::SF_Absolute;
1818 bool Common = Flags & SymbolRef::SF_Common;
1819 bool Hidden = Flags & SymbolRef::SF_Hidden;
1822 if (Type != SymbolRef::ST_Unknown)
1823 GlobLoc = Global ? 'g' : 'l';
1824 char Debug = (Type == SymbolRef::ST_Debug || Type == SymbolRef::ST_File)
1826 char FileFunc = ' ';
1827 if (Type == SymbolRef::ST_File)
1829 else if (Type == SymbolRef::ST_Function)
1832 const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 :
1835 outs() << format(Fmt, Address) << " "
1836 << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' '
1837 << (Weak ? 'w' : ' ') // Weak?
1838 << ' ' // Constructor. Not supported yet.
1839 << ' ' // Warning. Not supported yet.
1840 << ' ' // Indirect reference to another symbol.
1841 << Debug // Debugging (d) or dynamic (D) symbol.
1842 << FileFunc // Name of function (F), file (f) or object (O).
1846 } else if (Common) {
1848 } else if (Section == o->section_end()) {
1851 if (const MachOObjectFile *MachO =
1852 dyn_cast<const MachOObjectFile>(o)) {
1853 DataRefImpl DR = Section->getRawDataRefImpl();
1854 StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
1855 outs() << SegmentName << ",";
1857 StringRef SectionName;
1858 error(Section->getName(SectionName));
1859 outs() << SectionName;
1863 if (Common || isa<ELFObjectFileBase>(o)) {
1865 Common ? Symbol.getAlignment() : ELFSymbolRef(Symbol).getSize();
1866 outs() << format("\t %08" PRIx64 " ", Val);
1870 outs() << ".hidden ";
1877 static void PrintUnwindInfo(const ObjectFile *o) {
1878 outs() << "Unwind info:\n\n";
1880 if (const COFFObjectFile *coff = dyn_cast<COFFObjectFile>(o)) {
1881 printCOFFUnwindInfo(coff);
1882 } else if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1883 printMachOUnwindInfo(MachO);
1885 // TODO: Extract DWARF dump tool to objdump.
1886 errs() << "This operation is only currently supported "
1887 "for COFF and MachO object files.\n";
1892 void llvm::printExportsTrie(const ObjectFile *o) {
1893 outs() << "Exports trie:\n";
1894 if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1895 printMachOExportsTrie(MachO);
1897 errs() << "This operation is only currently supported "
1898 "for Mach-O executable files.\n";
1903 void llvm::printRebaseTable(ObjectFile *o) {
1904 outs() << "Rebase table:\n";
1905 if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1906 printMachORebaseTable(MachO);
1908 errs() << "This operation is only currently supported "
1909 "for Mach-O executable files.\n";
1914 void llvm::printBindTable(ObjectFile *o) {
1915 outs() << "Bind table:\n";
1916 if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1917 printMachOBindTable(MachO);
1919 errs() << "This operation is only currently supported "
1920 "for Mach-O executable files.\n";
1925 void llvm::printLazyBindTable(ObjectFile *o) {
1926 outs() << "Lazy bind table:\n";
1927 if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1928 printMachOLazyBindTable(MachO);
1930 errs() << "This operation is only currently supported "
1931 "for Mach-O executable files.\n";
1936 void llvm::printWeakBindTable(ObjectFile *o) {
1937 outs() << "Weak bind table:\n";
1938 if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1939 printMachOWeakBindTable(MachO);
1941 errs() << "This operation is only currently supported "
1942 "for Mach-O executable files.\n";
1947 /// Dump the raw contents of the __clangast section so the output can be piped
1948 /// into llvm-bcanalyzer.
1949 void llvm::printRawClangAST(const ObjectFile *Obj) {
1950 if (outs().is_displayed()) {
1951 errs() << "The -raw-clang-ast option will dump the raw binary contents of "
1952 "the clang ast section.\n"
1953 "Please redirect the output to a file or another program such as "
1954 "llvm-bcanalyzer.\n";
1958 StringRef ClangASTSectionName("__clangast");
1959 if (isa<COFFObjectFile>(Obj)) {
1960 ClangASTSectionName = "clangast";
1963 Optional<object::SectionRef> ClangASTSection;
1964 for (auto Sec : ToolSectionFilter(*Obj)) {
1967 if (Name == ClangASTSectionName) {
1968 ClangASTSection = Sec;
1972 if (!ClangASTSection)
1975 StringRef ClangASTContents;
1976 error(ClangASTSection.getValue().getContents(ClangASTContents));
1977 outs().write(ClangASTContents.data(), ClangASTContents.size());
1980 static void printFaultMaps(const ObjectFile *Obj) {
1981 const char *FaultMapSectionName = nullptr;
1983 if (isa<ELFObjectFileBase>(Obj)) {
1984 FaultMapSectionName = ".llvm_faultmaps";
1985 } else if (isa<MachOObjectFile>(Obj)) {
1986 FaultMapSectionName = "__llvm_faultmaps";
1988 errs() << "This operation is only currently supported "
1989 "for ELF and Mach-O executable files.\n";
1993 Optional<object::SectionRef> FaultMapSection;
1995 for (auto Sec : ToolSectionFilter(*Obj)) {
1998 if (Name == FaultMapSectionName) {
1999 FaultMapSection = Sec;
2004 outs() << "FaultMap table:\n";
2006 if (!FaultMapSection.hasValue()) {
2007 outs() << "<not found>\n";
2011 StringRef FaultMapContents;
2012 error(FaultMapSection.getValue().getContents(FaultMapContents));
2014 FaultMapParser FMP(FaultMapContents.bytes_begin(),
2015 FaultMapContents.bytes_end());
2020 static void printPrivateFileHeaders(const ObjectFile *o, bool onlyFirst) {
2022 return printELFFileHeader(o);
2024 return printCOFFFileHeader(o);
2026 return printWasmFileHeader(o);
2028 printMachOFileHeader(o);
2030 printMachOLoadCommands(o);
2033 report_error(o->getFileName(), "Invalid/Unsupported object file format");
2036 static void DumpObject(ObjectFile *o, const Archive *a = nullptr) {
2037 StringRef ArchiveName = a != nullptr ? a->getFileName() : "";
2038 // Avoid other output when using a raw option.
2042 outs() << a->getFileName() << "(" << o->getFileName() << ")";
2044 outs() << o->getFileName();
2045 outs() << ":\tfile format " << o->getFileFormatName() << "\n\n";
2049 DisassembleObject(o, Relocations);
2050 if (Relocations && !Disassemble)
2051 PrintRelocations(o);
2053 PrintSectionHeaders(o);
2054 if (SectionContents)
2055 PrintSectionContents(o);
2057 PrintSymbolTable(o, ArchiveName);
2060 if (PrivateHeaders || FirstPrivateHeader)
2061 printPrivateFileHeaders(o, FirstPrivateHeader);
2063 printExportsTrie(o);
2065 printRebaseTable(o);
2069 printLazyBindTable(o);
2071 printWeakBindTable(o);
2073 printRawClangAST(o);
2076 if (DwarfDumpType != DIDT_Null) {
2077 std::unique_ptr<DIContext> DICtx = DWARFContext::create(*o);
2078 // Dump the complete DWARF structure.
2079 DIDumpOptions DumpOpts;
2080 DumpOpts.DumpType = DwarfDumpType;
2081 DICtx->dump(outs(), DumpOpts);
2085 static void DumpObject(const COFFImportFile *I, const Archive *A) {
2086 StringRef ArchiveName = A ? A->getFileName() : "";
2088 // Avoid other output when using a raw option.
2091 << ArchiveName << "(" << I->getFileName() << ")"
2092 << ":\tfile format COFF-import-file"
2096 printCOFFSymbolTable(I);
2099 /// @brief Dump each object file in \a a;
2100 static void DumpArchive(const Archive *a) {
2101 Error Err = Error::success();
2102 for (auto &C : a->children(Err)) {
2103 Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
2105 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
2106 report_error(a->getFileName(), C, std::move(E));
2109 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
2111 else if (COFFImportFile *I = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
2114 report_error(a->getFileName(), object_error::invalid_file_type);
2117 report_error(a->getFileName(), std::move(Err));
2120 /// @brief Open file and figure out how to dump it.
2121 static void DumpInput(StringRef file) {
2123 // If we are using the Mach-O specific object file parser, then let it parse
2124 // the file and process the command line options. So the -arch flags can
2125 // be used to select specific slices, etc.
2127 ParseInputMachO(file);
2131 // Attempt to open the binary.
2132 Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
2134 report_error(file, BinaryOrErr.takeError());
2135 Binary &Binary = *BinaryOrErr.get().getBinary();
2137 if (Archive *a = dyn_cast<Archive>(&Binary))
2139 else if (ObjectFile *o = dyn_cast<ObjectFile>(&Binary))
2142 report_error(file, object_error::invalid_file_type);
2145 int main(int argc, char **argv) {
2146 // Print a stack trace if we signal out.
2147 sys::PrintStackTraceOnErrorSignal(argv[0]);
2148 PrettyStackTraceProgram X(argc, argv);
2149 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
2151 // Initialize targets and assembly printers/parsers.
2152 llvm::InitializeAllTargetInfos();
2153 llvm::InitializeAllTargetMCs();
2154 llvm::InitializeAllDisassemblers();
2156 // Register the target printer for --version.
2157 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
2159 cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n");
2160 TripleName = Triple::normalize(TripleName);
2164 // Defaults to a.out if no filenames specified.
2165 if (InputFilenames.size() == 0)
2166 InputFilenames.push_back("a.out");
2168 if (DisassembleAll || PrintSource || PrintLines)
2177 && !FirstPrivateHeader
2184 && !(UniversalHeaders && MachOOpt)
2185 && !(ArchiveHeaders && MachOOpt)
2186 && !(IndirectSymbols && MachOOpt)
2187 && !(DataInCode && MachOOpt)
2188 && !(LinkOptHints && MachOOpt)
2189 && !(InfoPlist && MachOOpt)
2190 && !(DylibsUsed && MachOOpt)
2191 && !(DylibId && MachOOpt)
2192 && !(ObjcMetaData && MachOOpt)
2193 && !(FilterSections.size() != 0 && MachOOpt)
2195 && DwarfDumpType == DIDT_Null) {
2196 cl::PrintHelpMessage();
2200 llvm::for_each(InputFilenames, DumpInput);
2202 return EXIT_SUCCESS;