1 //===-- ObjDumper.h ---------------------------------------------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
10 #define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
13 #include <system_error>
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Object/ObjectFile.h"
17 #include "llvm/Support/CommandLine.h"
19 #include <unordered_set>
26 class XCOFFObjectFile
;
27 class ELFObjectFileBase
;
30 class GlobalTypeTableBuilder
;
31 class MergingTypeTableBuilder
;
32 } // namespace codeview
38 ObjDumper(ScopedPrinter
&Writer
, StringRef ObjName
);
41 virtual bool canDumpContent() { return true; }
43 virtual void printFileSummary(StringRef FileStr
, object::ObjectFile
&Obj
,
44 ArrayRef
<std::string
> InputFilenames
,
45 const object::Archive
*A
);
46 virtual void printFileHeaders() = 0;
47 virtual void printSectionHeaders() = 0;
48 virtual void printRelocations() = 0;
49 virtual void printSymbols(bool PrintSymbols
, bool PrintDynamicSymbols
) {
52 if (PrintDynamicSymbols
)
53 printDynamicSymbols();
55 virtual void printProgramHeaders(bool PrintProgramHeaders
,
56 cl::boolOrDefault PrintSectionMapping
) {
57 if (PrintProgramHeaders
)
58 printProgramHeaders();
59 if (PrintSectionMapping
== cl::BOU_TRUE
)
60 printSectionMapping();
63 virtual void printUnwindInfo() = 0;
65 // Only implemented for ELF at this time.
66 virtual void printDependentLibs() {}
67 virtual void printDynamicRelocations() { }
68 virtual void printDynamicTable() { }
69 virtual void printNeededLibraries() { }
70 virtual void printSectionAsHex(StringRef SectionName
) {}
71 virtual void printHashTable() { }
72 virtual void printGnuHashTable() {}
73 virtual void printHashSymbols() {}
74 virtual void printLoadName() {}
75 virtual void printVersionInfo() {}
76 virtual void printGroupSections() {}
77 virtual void printHashHistograms() {}
78 virtual void printCGProfile() {}
79 virtual void printBBAddrMaps() {}
80 virtual void printAddrsig() {}
81 virtual void printNotes() {}
82 virtual void printELFLinkerOptions() {}
83 virtual void printStackSizes() {}
84 virtual void printSectionDetails() {}
85 virtual void printArchSpecificInfo() {}
87 // Only implemented for PE/COFF.
88 virtual void printCOFFImports() { }
89 virtual void printCOFFExports() { }
90 virtual void printCOFFDirectives() { }
91 virtual void printCOFFBaseReloc() { }
92 virtual void printCOFFDebugDirectory() { }
93 virtual void printCOFFTLSDirectory() {}
94 virtual void printCOFFResources() {}
95 virtual void printCOFFLoadConfig() { }
96 virtual void printCodeViewDebugInfo() { }
98 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder
&CVIDs
,
99 llvm::codeview::MergingTypeTableBuilder
&CVTypes
,
100 llvm::codeview::GlobalTypeTableBuilder
&GlobalCVIDs
,
101 llvm::codeview::GlobalTypeTableBuilder
&GlobalCVTypes
,
104 // Only implement for XCOFF
105 virtual void printAuxiliaryHeader() {}
107 // Only implemented for MachO.
108 virtual void printMachODataInCode() { }
109 virtual void printMachOVersionMin() { }
110 virtual void printMachODysymtab() { }
111 virtual void printMachOSegment() { }
112 virtual void printMachOIndirectSymbols() { }
113 virtual void printMachOLinkerOptions() { }
115 // Currently only implemented for XCOFF.
116 virtual void printStringTable() { }
118 virtual void printStackMap() const = 0;
120 void printAsStringList(StringRef StringContent
, size_t StringDataOffset
= 0);
122 void printSectionsAsString(const object::ObjectFile
&Obj
,
123 ArrayRef
<std::string
> Sections
);
124 void printSectionsAsHex(const object::ObjectFile
&Obj
,
125 ArrayRef
<std::string
> Sections
);
127 std::function
<Error(const Twine
&Msg
)> WarningHandler
;
128 void reportUniqueWarning(Error Err
) const;
129 void reportUniqueWarning(const Twine
&Msg
) const;
135 virtual void printSymbols() {}
136 virtual void printDynamicSymbols() {}
137 virtual void printProgramHeaders() {}
138 virtual void printSectionMapping() {}
140 std::unordered_set
<std::string
> Warnings
;
143 std::unique_ptr
<ObjDumper
> createCOFFDumper(const object::COFFObjectFile
&Obj
,
144 ScopedPrinter
&Writer
);
146 std::unique_ptr
<ObjDumper
> createELFDumper(const object::ELFObjectFileBase
&Obj
,
147 ScopedPrinter
&Writer
);
149 std::unique_ptr
<ObjDumper
> createMachODumper(const object::MachOObjectFile
&Obj
,
150 ScopedPrinter
&Writer
);
152 std::unique_ptr
<ObjDumper
> createWasmDumper(const object::WasmObjectFile
&Obj
,
153 ScopedPrinter
&Writer
);
155 std::unique_ptr
<ObjDumper
> createXCOFFDumper(const object::XCOFFObjectFile
&Obj
,
156 ScopedPrinter
&Writer
);
158 void dumpCOFFImportFile(const object::COFFImportFile
*File
,
159 ScopedPrinter
&Writer
);
161 void dumpCodeViewMergedTypes(ScopedPrinter
&Writer
,
162 ArrayRef
<ArrayRef
<uint8_t>> IpiRecords
,
163 ArrayRef
<ArrayRef
<uint8_t>> TpiRecords
);