Bug Summary

File:include/llvm/Object/ObjectFile.h
Warning:line 417, column 10
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name COFFDumper.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/llvm-readobj -I /build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/llvm-readobj -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-07-29-043837-17923-1 -x c++ /build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp -faddrsig

/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp

1//===-- COFFDumper.cpp - COFF-specific dumper -------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// This file implements the COFF-specific dumper for llvm-readobj.
12///
13//===----------------------------------------------------------------------===//
14
15#include "ARMWinEHPrinter.h"
16#include "Error.h"
17#include "ObjDumper.h"
18#include "StackMapPrinter.h"
19#include "Win64EHDumper.h"
20#include "llvm-readobj.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/SmallString.h"
23#include "llvm/ADT/StringExtras.h"
24#include "llvm/BinaryFormat/COFF.h"
25#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
26#include "llvm/DebugInfo/CodeView/CodeView.h"
27#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
28#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
29#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
30#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
31#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
32#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
33#include "llvm/DebugInfo/CodeView/Line.h"
34#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
35#include "llvm/DebugInfo/CodeView/RecordSerialization.h"
36#include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h"
37#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
38#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
39#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
40#include "llvm/DebugInfo/CodeView/TypeHashing.h"
41#include "llvm/DebugInfo/CodeView/TypeIndex.h"
42#include "llvm/DebugInfo/CodeView/TypeRecord.h"
43#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
44#include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
45#include "llvm/Object/COFF.h"
46#include "llvm/Object/ObjectFile.h"
47#include "llvm/Support/BinaryStreamReader.h"
48#include "llvm/Support/Casting.h"
49#include "llvm/Support/Compiler.h"
50#include "llvm/Support/ConvertUTF.h"
51#include "llvm/Support/FormatVariadic.h"
52#include "llvm/Support/ScopedPrinter.h"
53#include "llvm/Support/Win64EH.h"
54#include "llvm/Support/raw_ostream.h"
55
56using namespace llvm;
57using namespace llvm::object;
58using namespace llvm::codeview;
59using namespace llvm::support;
60using namespace llvm::Win64EH;
61
62namespace {
63
64struct LoadConfigTables {
65 uint64_t SEHTableVA = 0;
66 uint64_t SEHTableCount = 0;
67 uint32_t GuardFlags = 0;
68 uint64_t GuardFidTableVA = 0;
69 uint64_t GuardFidTableCount = 0;
70 uint64_t GuardLJmpTableVA = 0;
71 uint64_t GuardLJmpTableCount = 0;
72};
73
74class COFFDumper : public ObjDumper {
75public:
76 friend class COFFObjectDumpDelegate;
77 COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer)
78 : ObjDumper(Writer), Obj(Obj), Writer(Writer), Types(100) {}
79
80 void printFileHeaders() override;
81 void printSections() override;
82 void printRelocations() override;
83 void printSymbols() override;
84 void printDynamicSymbols() override;
85 void printUnwindInfo() override;
86
87 void printNeededLibraries() override;
88
89 void printCOFFImports() override;
90 void printCOFFExports() override;
91 void printCOFFDirectives() override;
92 void printCOFFBaseReloc() override;
93 void printCOFFDebugDirectory() override;
94 void printCOFFResources() override;
95 void printCOFFLoadConfig() override;
96 void printCodeViewDebugInfo() override;
97 void
98 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
99 llvm::codeview::MergingTypeTableBuilder &CVTypes) override;
100 void printStackMap() const override;
101private:
102 void printSymbol(const SymbolRef &Sym);
103 void printRelocation(const SectionRef &Section, const RelocationRef &Reloc,
104 uint64_t Bias = 0);
105 void printDataDirectory(uint32_t Index, const std::string &FieldName);
106
107 void printDOSHeader(const dos_header *DH);
108 template <class PEHeader> void printPEHeader(const PEHeader *Hdr);
109 void printBaseOfDataField(const pe32_header *Hdr);
110 void printBaseOfDataField(const pe32plus_header *Hdr);
111 template <typename T>
112 void printCOFFLoadConfig(const T *Conf, LoadConfigTables &Tables);
113 typedef void (*PrintExtraCB)(raw_ostream &, const uint8_t *);
114 void printRVATable(uint64_t TableVA, uint64_t Count, uint64_t EntrySize,
115 PrintExtraCB PrintExtra = 0);
116
117 void printCodeViewSymbolSection(StringRef SectionName, const SectionRef &Section);
118 void printCodeViewTypeSection(StringRef SectionName, const SectionRef &Section);
119 StringRef getTypeName(TypeIndex Ty);
120 StringRef getFileNameForFileOffset(uint32_t FileOffset);
121 void printFileNameForOffset(StringRef Label, uint32_t FileOffset);
122 void printTypeIndex(StringRef FieldName, TypeIndex TI) {
123 // Forward to CVTypeDumper for simplicity.
124 codeview::printTypeIndex(Writer, FieldName, TI, Types);
125 }
126
127 void printCodeViewSymbolsSubsection(StringRef Subsection,
128 const SectionRef &Section,
129 StringRef SectionContents);
130
131 void printCodeViewFileChecksums(StringRef Subsection);
132
133 void printCodeViewInlineeLines(StringRef Subsection);
134
135 void printRelocatedField(StringRef Label, const coff_section *Sec,
136 uint32_t RelocOffset, uint32_t Offset,
137 StringRef *RelocSym = nullptr);
138
139 uint32_t countTotalTableEntries(ResourceSectionRef RSF,
140 const coff_resource_dir_table &Table,
141 StringRef Level);
142
143 void printResourceDirectoryTable(ResourceSectionRef RSF,
144 const coff_resource_dir_table &Table,
145 StringRef Level);
146
147 void printBinaryBlockWithRelocs(StringRef Label, const SectionRef &Sec,
148 StringRef SectionContents, StringRef Block);
149
150 /// Given a .debug$S section, find the string table and file checksum table.
151 void initializeFileAndStringTables(BinaryStreamReader &Reader);
152
153 void cacheRelocations();
154
155 std::error_code resolveSymbol(const coff_section *Section, uint64_t Offset,
156 SymbolRef &Sym);
157 std::error_code resolveSymbolName(const coff_section *Section,
158 uint64_t Offset, StringRef &Name);
159 std::error_code resolveSymbolName(const coff_section *Section,
160 StringRef SectionContents,
161 const void *RelocPtr, StringRef &Name);
162 void printImportedSymbols(iterator_range<imported_symbol_iterator> Range);
163 void printDelayImportedSymbols(
164 const DelayImportDirectoryEntryRef &I,
165 iterator_range<imported_symbol_iterator> Range);
166 ErrorOr<const coff_resource_dir_entry &>
167 getResourceDirectoryTableEntry(const coff_resource_dir_table &Table,
168 uint32_t Index);
169
170 typedef DenseMap<const coff_section*, std::vector<RelocationRef> > RelocMapTy;
171
172 const llvm::object::COFFObjectFile *Obj;
173 bool RelocCached = false;
174 RelocMapTy RelocMap;
175
176 DebugChecksumsSubsectionRef CVFileChecksumTable;
177
178 DebugStringTableSubsectionRef CVStringTable;
179
180 ScopedPrinter &Writer;
181 BinaryByteStream TypeContents;
182 LazyRandomTypeCollection Types;
183};
184
185class COFFObjectDumpDelegate : public SymbolDumpDelegate {
186public:
187 COFFObjectDumpDelegate(COFFDumper &CD, const SectionRef &SR,
188 const COFFObjectFile *Obj, StringRef SectionContents)
189 : CD(CD), SR(SR), SectionContents(SectionContents) {
190 Sec = Obj->getCOFFSection(SR);
191 }
192
193 uint32_t getRecordOffset(BinaryStreamReader Reader) override {
194 ArrayRef<uint8_t> Data;
195 if (auto EC = Reader.readLongestContiguousChunk(Data)) {
196 llvm::consumeError(std::move(EC));
197 return 0;
198 }
199 return Data.data() - SectionContents.bytes_begin();
200 }
201
202 void printRelocatedField(StringRef Label, uint32_t RelocOffset,
203 uint32_t Offset, StringRef *RelocSym) override {
204 CD.printRelocatedField(Label, Sec, RelocOffset, Offset, RelocSym);
205 }
206
207 void printBinaryBlockWithRelocs(StringRef Label,
208 ArrayRef<uint8_t> Block) override {
209 StringRef SBlock(reinterpret_cast<const char *>(Block.data()),
210 Block.size());
211 if (opts::CodeViewSubsectionBytes)
212 CD.printBinaryBlockWithRelocs(Label, SR, SectionContents, SBlock);
213 }
214
215 StringRef getFileNameForFileOffset(uint32_t FileOffset) override {
216 return CD.getFileNameForFileOffset(FileOffset);
217 }
218
219 DebugStringTableSubsectionRef getStringTable() override {
220 return CD.CVStringTable;
221 }
222
223private:
224 COFFDumper &CD;
225 const SectionRef &SR;
226 const coff_section *Sec;
227 StringRef SectionContents;
228};
229
230} // end namespace
231
232namespace llvm {
233
234std::error_code createCOFFDumper(const object::ObjectFile *Obj,
235 ScopedPrinter &Writer,
236 std::unique_ptr<ObjDumper> &Result) {
237 const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(Obj);
238 if (!COFFObj)
239 return readobj_error::unsupported_obj_file_format;
240
241 Result.reset(new COFFDumper(COFFObj, Writer));
242 return readobj_error::success;
243}
244
245} // namespace llvm
246
247// Given a section and an offset into this section the function returns the
248// symbol used for the relocation at the offset.
249std::error_code COFFDumper::resolveSymbol(const coff_section *Section,
250 uint64_t Offset, SymbolRef &Sym) {
251 cacheRelocations();
252 const auto &Relocations = RelocMap[Section];
253 auto SymI = Obj->symbol_end();
254 for (const auto &Relocation : Relocations) {
255 uint64_t RelocationOffset = Relocation.getOffset();
256
257 if (RelocationOffset == Offset) {
258 SymI = Relocation.getSymbol();
259 break;
260 }
261 }
262 if (SymI == Obj->symbol_end())
263 return readobj_error::unknown_symbol;
264 Sym = *SymI;
265 return readobj_error::success;
266}
267
268// Given a section and an offset into this section the function returns the name
269// of the symbol used for the relocation at the offset.
270std::error_code COFFDumper::resolveSymbolName(const coff_section *Section,
271 uint64_t Offset,
272 StringRef &Name) {
273 SymbolRef Symbol;
274 if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
275 return EC;
276 Expected<StringRef> NameOrErr = Symbol.getName();
277 if (!NameOrErr)
278 return errorToErrorCode(NameOrErr.takeError());
279 Name = *NameOrErr;
280 return std::error_code();
281}
282
283// Helper for when you have a pointer to real data and you want to know about
284// relocations against it.
285std::error_code COFFDumper::resolveSymbolName(const coff_section *Section,
286 StringRef SectionContents,
287 const void *RelocPtr,
288 StringRef &Name) {
289 assert(SectionContents.data() < RelocPtr &&(static_cast <bool> (SectionContents.data() < RelocPtr
&& RelocPtr < SectionContents.data() + SectionContents
.size() && "pointer to relocated object is not in section"
) ? void (0) : __assert_fail ("SectionContents.data() < RelocPtr && RelocPtr < SectionContents.data() + SectionContents.size() && \"pointer to relocated object is not in section\""
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp"
, 291, __extension__ __PRETTY_FUNCTION__))
290 RelocPtr < SectionContents.data() + SectionContents.size() &&(static_cast <bool> (SectionContents.data() < RelocPtr
&& RelocPtr < SectionContents.data() + SectionContents
.size() && "pointer to relocated object is not in section"
) ? void (0) : __assert_fail ("SectionContents.data() < RelocPtr && RelocPtr < SectionContents.data() + SectionContents.size() && \"pointer to relocated object is not in section\""
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp"
, 291, __extension__ __PRETTY_FUNCTION__))
291 "pointer to relocated object is not in section")(static_cast <bool> (SectionContents.data() < RelocPtr
&& RelocPtr < SectionContents.data() + SectionContents
.size() && "pointer to relocated object is not in section"
) ? void (0) : __assert_fail ("SectionContents.data() < RelocPtr && RelocPtr < SectionContents.data() + SectionContents.size() && \"pointer to relocated object is not in section\""
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp"
, 291, __extension__ __PRETTY_FUNCTION__))
;
292 uint64_t Offset = ptrdiff_t(reinterpret_cast<const char *>(RelocPtr) -
293 SectionContents.data());
294 return resolveSymbolName(Section, Offset, Name);
295}
296
297void COFFDumper::printRelocatedField(StringRef Label, const coff_section *Sec,
298 uint32_t RelocOffset, uint32_t Offset,
299 StringRef *RelocSym) {
300 StringRef SymStorage;
301 StringRef &Symbol = RelocSym ? *RelocSym : SymStorage;
302 if (!resolveSymbolName(Sec, RelocOffset, Symbol))
303 W.printSymbolOffset(Label, Symbol, Offset);
304 else
305 W.printHex(Label, RelocOffset);
306}
307
308void COFFDumper::printBinaryBlockWithRelocs(StringRef Label,
309 const SectionRef &Sec,
310 StringRef SectionContents,
311 StringRef Block) {
312 W.printBinaryBlock(Label, Block);
313
314 assert(SectionContents.begin() < Block.begin() &&(static_cast <bool> (SectionContents.begin() < Block
.begin() && SectionContents.end() >= Block.end() &&
"Block is not contained in SectionContents") ? void (0) : __assert_fail
("SectionContents.begin() < Block.begin() && SectionContents.end() >= Block.end() && \"Block is not contained in SectionContents\""
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp"
, 316, __extension__ __PRETTY_FUNCTION__))
315 SectionContents.end() >= Block.end() &&(static_cast <bool> (SectionContents.begin() < Block
.begin() && SectionContents.end() >= Block.end() &&
"Block is not contained in SectionContents") ? void (0) : __assert_fail
("SectionContents.begin() < Block.begin() && SectionContents.end() >= Block.end() && \"Block is not contained in SectionContents\""
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp"
, 316, __extension__ __PRETTY_FUNCTION__))
316 "Block is not contained in SectionContents")(static_cast <bool> (SectionContents.begin() < Block
.begin() && SectionContents.end() >= Block.end() &&
"Block is not contained in SectionContents") ? void (0) : __assert_fail
("SectionContents.begin() < Block.begin() && SectionContents.end() >= Block.end() && \"Block is not contained in SectionContents\""
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/llvm-readobj/COFFDumper.cpp"
, 316, __extension__ __PRETTY_FUNCTION__))
;
317 uint64_t OffsetStart = Block.data() - SectionContents.data();
318 uint64_t OffsetEnd = OffsetStart + Block.size();
319
320 W.flush();
321 cacheRelocations();
322 ListScope D(W, "BlockRelocations");
323 const coff_section *Section = Obj->getCOFFSection(Sec);
324 const auto &Relocations = RelocMap[Section];
325 for (const auto &Relocation : Relocations) {
326 uint64_t RelocationOffset = Relocation.getOffset();
327 if (OffsetStart <= RelocationOffset && RelocationOffset < OffsetEnd)
328 printRelocation(Sec, Relocation, OffsetStart);
329 }
330}
331
332static const EnumEntry<COFF::MachineTypes> ImageFileMachineType[] = {
333 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_UNKNOWN ){ "IMAGE_FILE_MACHINE_UNKNOWN", COFF::IMAGE_FILE_MACHINE_UNKNOWN
}
,
334 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_AM33 ){ "IMAGE_FILE_MACHINE_AM33", COFF::IMAGE_FILE_MACHINE_AM33 },
335 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_AMD64 ){ "IMAGE_FILE_MACHINE_AMD64", COFF::IMAGE_FILE_MACHINE_AMD64 },
336 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_ARM ){ "IMAGE_FILE_MACHINE_ARM", COFF::IMAGE_FILE_MACHINE_ARM },
337 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_ARM64 ){ "IMAGE_FILE_MACHINE_ARM64", COFF::IMAGE_FILE_MACHINE_ARM64 },
338 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_ARMNT ){ "IMAGE_FILE_MACHINE_ARMNT", COFF::IMAGE_FILE_MACHINE_ARMNT },
339 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_EBC ){ "IMAGE_FILE_MACHINE_EBC", COFF::IMAGE_FILE_MACHINE_EBC },
340 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_I386 ){ "IMAGE_FILE_MACHINE_I386", COFF::IMAGE_FILE_MACHINE_I386 },
341 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_IA64 ){ "IMAGE_FILE_MACHINE_IA64", COFF::IMAGE_FILE_MACHINE_IA64 },
342 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_M32R ){ "IMAGE_FILE_MACHINE_M32R", COFF::IMAGE_FILE_MACHINE_M32R },
343 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_MIPS16 ){ "IMAGE_FILE_MACHINE_MIPS16", COFF::IMAGE_FILE_MACHINE_MIPS16
}
,
344 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_MIPSFPU ){ "IMAGE_FILE_MACHINE_MIPSFPU", COFF::IMAGE_FILE_MACHINE_MIPSFPU
}
,
345 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_MIPSFPU16){ "IMAGE_FILE_MACHINE_MIPSFPU16", COFF::IMAGE_FILE_MACHINE_MIPSFPU16
}
,
346 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_POWERPC ){ "IMAGE_FILE_MACHINE_POWERPC", COFF::IMAGE_FILE_MACHINE_POWERPC
}
,
347 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_POWERPCFP){ "IMAGE_FILE_MACHINE_POWERPCFP", COFF::IMAGE_FILE_MACHINE_POWERPCFP
}
,
348 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_R4000 ){ "IMAGE_FILE_MACHINE_R4000", COFF::IMAGE_FILE_MACHINE_R4000 },
349 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH3 ){ "IMAGE_FILE_MACHINE_SH3", COFF::IMAGE_FILE_MACHINE_SH3 },
350 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH3DSP ){ "IMAGE_FILE_MACHINE_SH3DSP", COFF::IMAGE_FILE_MACHINE_SH3DSP
}
,
351 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH4 ){ "IMAGE_FILE_MACHINE_SH4", COFF::IMAGE_FILE_MACHINE_SH4 },
352 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH5 ){ "IMAGE_FILE_MACHINE_SH5", COFF::IMAGE_FILE_MACHINE_SH5 },
353 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_THUMB ){ "IMAGE_FILE_MACHINE_THUMB", COFF::IMAGE_FILE_MACHINE_THUMB },
354 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_WCEMIPSV2){ "IMAGE_FILE_MACHINE_WCEMIPSV2", COFF::IMAGE_FILE_MACHINE_WCEMIPSV2
}
355};
356
357static const EnumEntry<COFF::Characteristics> ImageFileCharacteristics[] = {
358 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_RELOCS_STRIPPED ){ "IMAGE_FILE_RELOCS_STRIPPED", COFF::IMAGE_FILE_RELOCS_STRIPPED
}
,
359 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_EXECUTABLE_IMAGE ){ "IMAGE_FILE_EXECUTABLE_IMAGE", COFF::IMAGE_FILE_EXECUTABLE_IMAGE
}
,
360 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LINE_NUMS_STRIPPED ){ "IMAGE_FILE_LINE_NUMS_STRIPPED", COFF::IMAGE_FILE_LINE_NUMS_STRIPPED
}
,
361 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LOCAL_SYMS_STRIPPED ){ "IMAGE_FILE_LOCAL_SYMS_STRIPPED", COFF::IMAGE_FILE_LOCAL_SYMS_STRIPPED
}
,
362 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_AGGRESSIVE_WS_TRIM ){ "IMAGE_FILE_AGGRESSIVE_WS_TRIM", COFF::IMAGE_FILE_AGGRESSIVE_WS_TRIM
}
,
363 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LARGE_ADDRESS_AWARE ){ "IMAGE_FILE_LARGE_ADDRESS_AWARE", COFF::IMAGE_FILE_LARGE_ADDRESS_AWARE
}
,
364 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_BYTES_REVERSED_LO ){ "IMAGE_FILE_BYTES_REVERSED_LO", COFF::IMAGE_FILE_BYTES_REVERSED_LO
}
,
365 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_32BIT_MACHINE ){ "IMAGE_FILE_32BIT_MACHINE", COFF::IMAGE_FILE_32BIT_MACHINE },
366 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_DEBUG_STRIPPED ){ "IMAGE_FILE_DEBUG_STRIPPED", COFF::IMAGE_FILE_DEBUG_STRIPPED
}
,
367 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP){ "IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP", COFF::IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
}
,
368 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_NET_RUN_FROM_SWAP ){ "IMAGE_FILE_NET_RUN_FROM_SWAP", COFF::IMAGE_FILE_NET_RUN_FROM_SWAP
}
,
369 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_SYSTEM ){ "IMAGE_FILE_SYSTEM", COFF::IMAGE_FILE_SYSTEM },
370 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_DLL ){ "IMAGE_FILE_DLL", COFF::IMAGE_FILE_DLL },
371 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_UP_SYSTEM_ONLY ){ "IMAGE_FILE_UP_SYSTEM_ONLY", COFF::IMAGE_FILE_UP_SYSTEM_ONLY
}
,
372 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_BYTES_REVERSED_HI ){ "IMAGE_FILE_BYTES_REVERSED_HI", COFF::IMAGE_FILE_BYTES_REVERSED_HI
}
373};
374
375static const EnumEntry<COFF::WindowsSubsystem> PEWindowsSubsystem[] = {
376 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_UNKNOWN ){ "IMAGE_SUBSYSTEM_UNKNOWN", COFF::IMAGE_SUBSYSTEM_UNKNOWN },
377 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_NATIVE ){ "IMAGE_SUBSYSTEM_NATIVE", COFF::IMAGE_SUBSYSTEM_NATIVE },
378 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_GUI ){ "IMAGE_SUBSYSTEM_WINDOWS_GUI", COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI
}
,
379 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_CUI ){ "IMAGE_SUBSYSTEM_WINDOWS_CUI", COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI
}
,
380 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_POSIX_CUI ){ "IMAGE_SUBSYSTEM_POSIX_CUI", COFF::IMAGE_SUBSYSTEM_POSIX_CUI
}
,
381 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_CE_GUI ){ "IMAGE_SUBSYSTEM_WINDOWS_CE_GUI", COFF::IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
}
,
382 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_APPLICATION ){ "IMAGE_SUBSYSTEM_EFI_APPLICATION", COFF::IMAGE_SUBSYSTEM_EFI_APPLICATION
}
,
383 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER){ "IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER", COFF::IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
}
,
384 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER ){ "IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER", COFF::IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
}
,
385 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_ROM ){ "IMAGE_SUBSYSTEM_EFI_ROM", COFF::IMAGE_SUBSYSTEM_EFI_ROM },
386 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_XBOX ){ "IMAGE_SUBSYSTEM_XBOX", COFF::IMAGE_SUBSYSTEM_XBOX },
387};
388
389static const EnumEntry<COFF::DLLCharacteristics> PEDLLCharacteristics[] = {
390 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA ){ "IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA", COFF::IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
}
,
391 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE ){ "IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE", COFF::IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
}
,
392 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY ){ "IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY", COFF::IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY
}
,
393 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT ){ "IMAGE_DLL_CHARACTERISTICS_NX_COMPAT", COFF::IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
}
,
394 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION ){ "IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION", COFF::IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
}
,
395 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NO_SEH ){ "IMAGE_DLL_CHARACTERISTICS_NO_SEH", COFF::IMAGE_DLL_CHARACTERISTICS_NO_SEH
}
,
396 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NO_BIND ){ "IMAGE_DLL_CHARACTERISTICS_NO_BIND", COFF::IMAGE_DLL_CHARACTERISTICS_NO_BIND
}
,
397 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_APPCONTAINER ){ "IMAGE_DLL_CHARACTERISTICS_APPCONTAINER", COFF::IMAGE_DLL_CHARACTERISTICS_APPCONTAINER
}
,
398 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER ){ "IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER", COFF::IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER
}
,
399 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_GUARD_CF ){ "IMAGE_DLL_CHARACTERISTICS_GUARD_CF", COFF::IMAGE_DLL_CHARACTERISTICS_GUARD_CF
}
,
400 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE){ "IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE", COFF::IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE
}
,
401};
402
403static const EnumEntry<COFF::SectionCharacteristics>
404ImageSectionCharacteristics[] = {
405 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NOLOAD ){ "IMAGE_SCN_TYPE_NOLOAD", COFF::IMAGE_SCN_TYPE_NOLOAD },
406 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NO_PAD ){ "IMAGE_SCN_TYPE_NO_PAD", COFF::IMAGE_SCN_TYPE_NO_PAD },
407 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_CNT_CODE ){ "IMAGE_SCN_CNT_CODE", COFF::IMAGE_SCN_CNT_CODE },
408 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_CNT_INITIALIZED_DATA ){ "IMAGE_SCN_CNT_INITIALIZED_DATA", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
}
,
409 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_CNT_UNINITIALIZED_DATA){ "IMAGE_SCN_CNT_UNINITIALIZED_DATA", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
}
,
410 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_OTHER ){ "IMAGE_SCN_LNK_OTHER", COFF::IMAGE_SCN_LNK_OTHER },
411 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_INFO ){ "IMAGE_SCN_LNK_INFO", COFF::IMAGE_SCN_LNK_INFO },
412 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_REMOVE ){ "IMAGE_SCN_LNK_REMOVE", COFF::IMAGE_SCN_LNK_REMOVE },
413 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_COMDAT ){ "IMAGE_SCN_LNK_COMDAT", COFF::IMAGE_SCN_LNK_COMDAT },
414 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_GPREL ){ "IMAGE_SCN_GPREL", COFF::IMAGE_SCN_GPREL },
415 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_PURGEABLE ){ "IMAGE_SCN_MEM_PURGEABLE", COFF::IMAGE_SCN_MEM_PURGEABLE },
416 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_16BIT ){ "IMAGE_SCN_MEM_16BIT", COFF::IMAGE_SCN_MEM_16BIT },
417 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_LOCKED ){ "IMAGE_SCN_MEM_LOCKED", COFF::IMAGE_SCN_MEM_LOCKED },
418 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_PRELOAD ){ "IMAGE_SCN_MEM_PRELOAD", COFF::IMAGE_SCN_MEM_PRELOAD },
419 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_1BYTES ){ "IMAGE_SCN_ALIGN_1BYTES", COFF::IMAGE_SCN_ALIGN_1BYTES },
420 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_2BYTES ){ "IMAGE_SCN_ALIGN_2BYTES", COFF::IMAGE_SCN_ALIGN_2BYTES },
421 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_4BYTES ){ "IMAGE_SCN_ALIGN_4BYTES", COFF::IMAGE_SCN_ALIGN_4BYTES },
422 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_8BYTES ){ "IMAGE_SCN_ALIGN_8BYTES", COFF::IMAGE_SCN_ALIGN_8BYTES },
423 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_16BYTES ){ "IMAGE_SCN_ALIGN_16BYTES", COFF::IMAGE_SCN_ALIGN_16BYTES },
424 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_32BYTES ){ "IMAGE_SCN_ALIGN_32BYTES", COFF::IMAGE_SCN_ALIGN_32BYTES },
425 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_64BYTES ){ "IMAGE_SCN_ALIGN_64BYTES", COFF::IMAGE_SCN_ALIGN_64BYTES },
426 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_128BYTES ){ "IMAGE_SCN_ALIGN_128BYTES", COFF::IMAGE_SCN_ALIGN_128BYTES },
427 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_256BYTES ){ "IMAGE_SCN_ALIGN_256BYTES", COFF::IMAGE_SCN_ALIGN_256BYTES },
428 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_512BYTES ){ "IMAGE_SCN_ALIGN_512BYTES", COFF::IMAGE_SCN_ALIGN_512BYTES },
429 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_1024BYTES ){ "IMAGE_SCN_ALIGN_1024BYTES", COFF::IMAGE_SCN_ALIGN_1024BYTES
}
,
430 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_2048BYTES ){ "IMAGE_SCN_ALIGN_2048BYTES", COFF::IMAGE_SCN_ALIGN_2048BYTES
}
,
431 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_4096BYTES ){ "IMAGE_SCN_ALIGN_4096BYTES", COFF::IMAGE_SCN_ALIGN_4096BYTES
}
,
432 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_8192BYTES ){ "IMAGE_SCN_ALIGN_8192BYTES", COFF::IMAGE_SCN_ALIGN_8192BYTES
}
,
433 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_NRELOC_OVFL ){ "IMAGE_SCN_LNK_NRELOC_OVFL", COFF::IMAGE_SCN_LNK_NRELOC_OVFL
}
,
434 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_DISCARDABLE ){ "IMAGE_SCN_MEM_DISCARDABLE", COFF::IMAGE_SCN_MEM_DISCARDABLE
}
,
435 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_NOT_CACHED ){ "IMAGE_SCN_MEM_NOT_CACHED", COFF::IMAGE_SCN_MEM_NOT_CACHED },
436 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_NOT_PAGED ){ "IMAGE_SCN_MEM_NOT_PAGED", COFF::IMAGE_SCN_MEM_NOT_PAGED },
437 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_SHARED ){ "IMAGE_SCN_MEM_SHARED", COFF::IMAGE_SCN_MEM_SHARED },
438 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_EXECUTE ){ "IMAGE_SCN_MEM_EXECUTE", COFF::IMAGE_SCN_MEM_EXECUTE },
439 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_READ ){ "IMAGE_SCN_MEM_READ", COFF::IMAGE_SCN_MEM_READ },
440 LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_WRITE ){ "IMAGE_SCN_MEM_WRITE", COFF::IMAGE_SCN_MEM_WRITE }
441};
442
443static const EnumEntry<COFF::SymbolBaseType> ImageSymType[] = {
444 { "Null" , COFF::IMAGE_SYM_TYPE_NULL },
445 { "Void" , COFF::IMAGE_SYM_TYPE_VOID },
446 { "Char" , COFF::IMAGE_SYM_TYPE_CHAR },
447 { "Short" , COFF::IMAGE_SYM_TYPE_SHORT },
448 { "Int" , COFF::IMAGE_SYM_TYPE_INT },
449 { "Long" , COFF::IMAGE_SYM_TYPE_LONG },
450 { "Float" , COFF::IMAGE_SYM_TYPE_FLOAT },
451 { "Double", COFF::IMAGE_SYM_TYPE_DOUBLE },
452 { "Struct", COFF::IMAGE_SYM_TYPE_STRUCT },
453 { "Union" , COFF::IMAGE_SYM_TYPE_UNION },
454 { "Enum" , COFF::IMAGE_SYM_TYPE_ENUM },
455 { "MOE" , COFF::IMAGE_SYM_TYPE_MOE },
456 { "Byte" , COFF::IMAGE_SYM_TYPE_BYTE },
457 { "Word" , COFF::IMAGE_SYM_TYPE_WORD },
458 { "UInt" , COFF::IMAGE_SYM_TYPE_UINT },
459 { "DWord" , COFF::IMAGE_SYM_TYPE_DWORD }
460};
461
462static const EnumEntry<COFF::SymbolComplexType> ImageSymDType[] = {
463 { "Null" , COFF::IMAGE_SYM_DTYPE_NULL },
464 { "Pointer" , COFF::IMAGE_SYM_DTYPE_POINTER },
465 { "Function", COFF::IMAGE_SYM_DTYPE_FUNCTION },
466 { "Array" , COFF::IMAGE_SYM_DTYPE_ARRAY }
467};
468
469static const EnumEntry<COFF::SymbolStorageClass> ImageSymClass[] = {
470 { "EndOfFunction" , COFF::IMAGE_SYM_CLASS_END_OF_FUNCTION },
471 { "Null" , COFF::IMAGE_SYM_CLASS_NULL },
472 { "Automatic" , COFF::IMAGE_SYM_CLASS_AUTOMATIC },
473 { "External" , COFF::IMAGE_SYM_CLASS_EXTERNAL },
474 { "Static" , COFF::IMAGE_SYM_CLASS_STATIC },
475 { "Register" , COFF::IMAGE_SYM_CLASS_REGISTER },
476 { "ExternalDef" , COFF::IMAGE_SYM_CLASS_EXTERNAL_DEF },
477 { "Label" , COFF::IMAGE_SYM_CLASS_LABEL },
478 { "UndefinedLabel" , COFF::IMAGE_SYM_CLASS_UNDEFINED_LABEL },
479 { "MemberOfStruct" , COFF::IMAGE_SYM_CLASS_MEMBER_OF_STRUCT },
480 { "Argument" , COFF::IMAGE_SYM_CLASS_ARGUMENT },
481 { "StructTag" , COFF::IMAGE_SYM_CLASS_STRUCT_TAG },
482 { "MemberOfUnion" , COFF::IMAGE_SYM_CLASS_MEMBER_OF_UNION },
483 { "UnionTag" , COFF::IMAGE_SYM_CLASS_UNION_TAG },
484 { "TypeDefinition" , COFF::IMAGE_SYM_CLASS_TYPE_DEFINITION },
485 { "UndefinedStatic", COFF::IMAGE_SYM_CLASS_UNDEFINED_STATIC },
486 { "EnumTag" , COFF::IMAGE_SYM_CLASS_ENUM_TAG },
487 { "MemberOfEnum" , COFF::IMAGE_SYM_CLASS_MEMBER_OF_ENUM },
488 { "RegisterParam" , COFF::IMAGE_SYM_CLASS_REGISTER_PARAM },
489 { "BitField" , COFF::IMAGE_SYM_CLASS_BIT_FIELD },
490 { "Block" , COFF::IMAGE_SYM_CLASS_BLOCK },
491 { "Function" , COFF::IMAGE_SYM_CLASS_FUNCTION },
492 { "EndOfStruct" , COFF::IMAGE_SYM_CLASS_END_OF_STRUCT },
493 { "File" , COFF::IMAGE_SYM_CLASS_FILE },
494 { "Section" , COFF::IMAGE_SYM_CLASS_SECTION },
495 { "WeakExternal" , COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL },
496 { "CLRToken" , COFF::IMAGE_SYM_CLASS_CLR_TOKEN }
497};
498
499static const EnumEntry<COFF::COMDATType> ImageCOMDATSelect[] = {
500 { "NoDuplicates", COFF::IMAGE_COMDAT_SELECT_NODUPLICATES },
501 { "Any" , COFF::IMAGE_COMDAT_SELECT_ANY },
502 { "SameSize" , COFF::IMAGE_COMDAT_SELECT_SAME_SIZE },
503 { "ExactMatch" , COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH },
504 { "Associative" , COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE },
505 { "Largest" , COFF::IMAGE_COMDAT_SELECT_LARGEST },
506 { "Newest" , COFF::IMAGE_COMDAT_SELECT_NEWEST }
507};
508
509static const EnumEntry<COFF::DebugType> ImageDebugType[] = {
510 { "Unknown" , COFF::IMAGE_DEBUG_TYPE_UNKNOWN },
511 { "COFF" , COFF::IMAGE_DEBUG_TYPE_COFF },
512 { "CodeView" , COFF::IMAGE_DEBUG_TYPE_CODEVIEW },
513 { "FPO" , COFF::IMAGE_DEBUG_TYPE_FPO },
514 { "Misc" , COFF::IMAGE_DEBUG_TYPE_MISC },
515 { "Exception" , COFF::IMAGE_DEBUG_TYPE_EXCEPTION },
516 { "Fixup" , COFF::IMAGE_DEBUG_TYPE_FIXUP },
517 { "OmapToSrc" , COFF::IMAGE_DEBUG_TYPE_OMAP_TO_SRC },
518 { "OmapFromSrc", COFF::IMAGE_DEBUG_TYPE_OMAP_FROM_SRC },
519 { "Borland" , COFF::IMAGE_DEBUG_TYPE_BORLAND },
520 { "Reserved10" , COFF::IMAGE_DEBUG_TYPE_RESERVED10 },
521 { "CLSID" , COFF::IMAGE_DEBUG_TYPE_CLSID },
522 { "VCFeature" , COFF::IMAGE_DEBUG_TYPE_VC_FEATURE },
523 { "POGO" , COFF::IMAGE_DEBUG_TYPE_POGO },
524 { "ILTCG" , COFF::IMAGE_DEBUG_TYPE_ILTCG },
525 { "MPX" , COFF::IMAGE_DEBUG_TYPE_MPX },
526 { "Repro" , COFF::IMAGE_DEBUG_TYPE_REPRO },
527};
528
529static const EnumEntry<COFF::WeakExternalCharacteristics>
530WeakExternalCharacteristics[] = {
531 { "NoLibrary", COFF::IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY },
532 { "Library" , COFF::IMAGE_WEAK_EXTERN_SEARCH_LIBRARY },
533 { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS }
534};
535
536static const EnumEntry<uint32_t> SubSectionTypes[] = {
537 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, Symbols){ "Symbols", std::underlying_type<DebugSubsectionKind>::
type(DebugSubsectionKind::Symbols) }
,
538 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, Lines){ "Lines", std::underlying_type<DebugSubsectionKind>::type
(DebugSubsectionKind::Lines) }
,
539 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, StringTable){ "StringTable", std::underlying_type<DebugSubsectionKind>
::type(DebugSubsectionKind::StringTable) }
,
540 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, FileChecksums){ "FileChecksums", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::FileChecksums) }
,
541 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, FrameData){ "FrameData", std::underlying_type<DebugSubsectionKind>
::type(DebugSubsectionKind::FrameData) }
,
542 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, InlineeLines){ "InlineeLines", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::InlineeLines) }
,
543 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, CrossScopeImports){ "CrossScopeImports", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::CrossScopeImports) }
,
544 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, CrossScopeExports){ "CrossScopeExports", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::CrossScopeExports) }
,
545 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, ILLines){ "ILLines", std::underlying_type<DebugSubsectionKind>::
type(DebugSubsectionKind::ILLines) }
,
546 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, FuncMDTokenMap){ "FuncMDTokenMap", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::FuncMDTokenMap) }
,
547 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, TypeMDTokenMap){ "TypeMDTokenMap", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::TypeMDTokenMap) }
,
548 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, MergedAssemblyInput){ "MergedAssemblyInput", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::MergedAssemblyInput) }
,
549 LLVM_READOBJ_ENUM_CLASS_ENT(DebugSubsectionKind, CoffSymbolRVA){ "CoffSymbolRVA", std::underlying_type<DebugSubsectionKind
>::type(DebugSubsectionKind::CoffSymbolRVA) }
,
550};
551
552static const EnumEntry<uint32_t> FrameDataFlags[] = {
553 LLVM_READOBJ_ENUM_ENT(FrameData, HasSEH){ "HasSEH", FrameData::HasSEH },
554 LLVM_READOBJ_ENUM_ENT(FrameData, HasEH){ "HasEH", FrameData::HasEH },
555 LLVM_READOBJ_ENUM_ENT(FrameData, IsFunctionStart){ "IsFunctionStart", FrameData::IsFunctionStart },
556};
557
558static const EnumEntry<uint8_t> FileChecksumKindNames[] = {
559 LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, None){ "None", std::underlying_type<FileChecksumKind>::type(
FileChecksumKind::None) }
,
560 LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, MD5){ "MD5", std::underlying_type<FileChecksumKind>::type(FileChecksumKind
::MD5) }
,
561 LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA1){ "SHA1", std::underlying_type<FileChecksumKind>::type(
FileChecksumKind::SHA1) }
,
562 LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA256){ "SHA256", std::underlying_type<FileChecksumKind>::type
(FileChecksumKind::SHA256) }
,
563};
564
565static const EnumEntry<COFF::ResourceTypeID> ResourceTypeNames[]{
566 {"kRT_CURSOR (ID 1)", COFF::RID_Cursor},
567 {"kRT_BITMAP (ID 2)", COFF::RID_Bitmap},
568 {"kRT_ICON (ID 3)", COFF::RID_Icon},
569 {"kRT_MENU (ID 4)", COFF::RID_Menu},
570 {"kRT_DIALOG (ID 5)", COFF::RID_Dialog},
571 {"kRT_STRING (ID 6)", COFF::RID_String},
572 {"kRT_FONTDIR (ID 7)", COFF::RID_FontDir},
573 {"kRT_FONT (ID 8)", COFF::RID_Font},
574 {"kRT_ACCELERATOR (ID 9)", COFF::RID_Accelerator},
575 {"kRT_RCDATA (ID 10)", COFF::RID_RCData},
576 {"kRT_MESSAGETABLE (ID 11)", COFF::RID_MessageTable},
577 {"kRT_GROUP_CURSOR (ID 12)", COFF::RID_Group_Cursor},
578 {"kRT_GROUP_ICON (ID 14)", COFF::RID_Group_Icon},
579 {"kRT_VERSION (ID 16)", COFF::RID_Version},
580 {"kRT_DLGINCLUDE (ID 17)", COFF::RID_DLGInclude},
581 {"kRT_PLUGPLAY (ID 19)", COFF::RID_PlugPlay},
582 {"kRT_VXD (ID 20)", COFF::RID_VXD},
583 {"kRT_ANICURSOR (ID 21)", COFF::RID_AniCursor},
584 {"kRT_ANIICON (ID 22)", COFF::RID_AniIcon},
585 {"kRT_HTML (ID 23)", COFF::RID_HTML},
586 {"kRT_MANIFEST (ID 24)", COFF::RID_Manifest}};
587
588template <typename T>
589static std::error_code getSymbolAuxData(const COFFObjectFile *Obj,
590 COFFSymbolRef Symbol,
591 uint8_t AuxSymbolIdx, const T *&Aux) {
592 ArrayRef<uint8_t> AuxData = Obj->getSymbolAuxData(Symbol);
593 AuxData = AuxData.slice(AuxSymbolIdx * Obj->getSymbolTableEntrySize());
594 Aux = reinterpret_cast<const T*>(AuxData.data());
595 return readobj_error::success;
596}
597
598void COFFDumper::cacheRelocations() {
599 if (RelocCached)
600 return;
601 RelocCached = true;
602
603 for (const SectionRef &S : Obj->sections()) {
604 const coff_section *Section = Obj->getCOFFSection(S);
605
606 for (const RelocationRef &Reloc : S.relocations())
607 RelocMap[Section].push_back(Reloc);
608
609 // Sort relocations by address.
610 llvm::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
611 relocAddressLess);
612 }
613}
614
615void COFFDumper::printDataDirectory(uint32_t Index, const std::string &FieldName) {
616 const data_directory *Data;
617 if (Obj->getDataDirectory(Index, Data))
618 return;
619 W.printHex(FieldName + "RVA", Data->RelativeVirtualAddress);
620 W.printHex(FieldName + "Size", Data->Size);
621}
622
623void COFFDumper::printFileHeaders() {
624 time_t TDS = Obj->getTimeDateStamp();
625 char FormattedTime[20] = { };
626 strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS));
627
628 {
629 DictScope D(W, "ImageFileHeader");
630 W.printEnum ("Machine", Obj->getMachine(),
631 makeArrayRef(ImageFileMachineType));
632 W.printNumber("SectionCount", Obj->getNumberOfSections());
633 W.printHex ("TimeDateStamp", FormattedTime, Obj->getTimeDateStamp());
634 W.printHex ("PointerToSymbolTable", Obj->getPointerToSymbolTable());
635 W.printNumber("SymbolCount", Obj->getNumberOfSymbols());
636 W.printNumber("OptionalHeaderSize", Obj->getSizeOfOptionalHeader());
637 W.printFlags ("Characteristics", Obj->getCharacteristics(),
638 makeArrayRef(ImageFileCharacteristics));
639 }
640
641 // Print PE header. This header does not exist if this is an object file and
642 // not an executable.
643 const pe32_header *PEHeader = nullptr;
644 error(Obj->getPE32Header(PEHeader));
645 if (PEHeader)
646 printPEHeader<pe32_header>(PEHeader);
647
648 const pe32plus_header *PEPlusHeader = nullptr;
649 error(Obj->getPE32PlusHeader(PEPlusHeader));
650 if (PEPlusHeader)
651 printPEHeader<pe32plus_header>(PEPlusHeader);
652
653 if (const dos_header *DH = Obj->getDOSHeader())
654 printDOSHeader(DH);
655}
656
657void COFFDumper::printDOSHeader(const dos_header *DH) {
658 DictScope D(W, "DOSHeader");
659 W.printString("Magic", StringRef(DH->Magic, sizeof(DH->Magic)));
660 W.printNumber("UsedBytesInTheLastPage", DH->UsedBytesInTheLastPage);
661 W.printNumber("FileSizeInPages", DH->FileSizeInPages);
662 W.printNumber("NumberOfRelocationItems", DH->NumberOfRelocationItems);
663 W.printNumber("HeaderSizeInParagraphs", DH->HeaderSizeInParagraphs);
664 W.printNumber("MinimumExtraParagraphs", DH->MinimumExtraParagraphs);
665 W.printNumber("MaximumExtraParagraphs", DH->MaximumExtraParagraphs);
666 W.printNumber("InitialRelativeSS", DH->InitialRelativeSS);
667 W.printNumber("InitialSP", DH->InitialSP);
668 W.printNumber("Checksum", DH->Checksum);
669 W.printNumber("InitialIP", DH->InitialIP);
670 W.printNumber("InitialRelativeCS", DH->InitialRelativeCS);
671 W.printNumber("AddressOfRelocationTable", DH->AddressOfRelocationTable);
672 W.printNumber("OverlayNumber", DH->OverlayNumber);
673 W.printNumber("OEMid", DH->OEMid);
674 W.printNumber("OEMinfo", DH->OEMinfo);
675 W.printNumber("AddressOfNewExeHeader", DH->AddressOfNewExeHeader);
676}
677
678template <class PEHeader>
679void COFFDumper::printPEHeader(const PEHeader *Hdr) {
680 DictScope D(W, "ImageOptionalHeader");
681 W.printHex ("Magic", Hdr->Magic);
682 W.printNumber("MajorLinkerVersion", Hdr->MajorLinkerVersion);
683 W.printNumber("MinorLinkerVersion", Hdr->MinorLinkerVersion);
684 W.printNumber("SizeOfCode", Hdr->SizeOfCode);
685 W.printNumber("SizeOfInitializedData", Hdr->SizeOfInitializedData);
686 W.printNumber("SizeOfUninitializedData", Hdr->SizeOfUninitializedData);
687 W.printHex ("AddressOfEntryPoint", Hdr->AddressOfEntryPoint);
688 W.printHex ("BaseOfCode", Hdr->BaseOfCode);
689 printBaseOfDataField(Hdr);
690 W.printHex ("ImageBase", Hdr->ImageBase);
691 W.printNumber("SectionAlignment", Hdr->SectionAlignment);
692 W.printNumber("FileAlignment", Hdr->FileAlignment);
693 W.printNumber("MajorOperatingSystemVersion",
694 Hdr->MajorOperatingSystemVersion);
695 W.printNumber("MinorOperatingSystemVersion",
696 Hdr->MinorOperatingSystemVersion);
697 W.printNumber("MajorImageVersion", Hdr->MajorImageVersion);
698 W.printNumber("MinorImageVersion", Hdr->MinorImageVersion);
699 W.printNumber("MajorSubsystemVersion", Hdr->MajorSubsystemVersion);
700 W.printNumber("MinorSubsystemVersion", Hdr->MinorSubsystemVersion);
701 W.printNumber("SizeOfImage", Hdr->SizeOfImage);
702 W.printNumber("SizeOfHeaders", Hdr->SizeOfHeaders);
703 W.printEnum ("Subsystem", Hdr->Subsystem, makeArrayRef(PEWindowsSubsystem));
704 W.printFlags ("Characteristics", Hdr->DLLCharacteristics,
705 makeArrayRef(PEDLLCharacteristics));
706 W.printNumber("SizeOfStackReserve", Hdr->SizeOfStackReserve);
707 W.printNumber("SizeOfStackCommit", Hdr->SizeOfStackCommit);
708 W.printNumber("SizeOfHeapReserve", Hdr->SizeOfHeapReserve);
709 W.printNumber("SizeOfHeapCommit", Hdr->SizeOfHeapCommit);
710 W.printNumber("NumberOfRvaAndSize", Hdr->NumberOfRvaAndSize);
711
712 if (Hdr->NumberOfRvaAndSize > 0) {
713 DictScope D(W, "DataDirectory");
714 static const char * const directory[] = {
715 "ExportTable", "ImportTable", "ResourceTable", "ExceptionTable",
716 "CertificateTable", "BaseRelocationTable", "Debug", "Architecture",
717 "GlobalPtr", "TLSTable", "LoadConfigTable", "BoundImport", "IAT",
718 "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"
719 };
720
721 for (uint32_t i = 0; i < Hdr->NumberOfRvaAndSize; ++i)
722 printDataDirectory(i, directory[i]);
723 }
724}
725
726void COFFDumper::printCOFFDebugDirectory() {
727 ListScope LS(W, "DebugDirectory");
728 for (const debug_directory &D : Obj->debug_directories()) {
729 char FormattedTime[20] = {};
730 time_t TDS = D.TimeDateStamp;
731 strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS));
732 DictScope S(W, "DebugEntry");
733 W.printHex("Characteristics", D.Characteristics);
734 W.printHex("TimeDateStamp", FormattedTime, D.TimeDateStamp);
735 W.printHex("MajorVersion", D.MajorVersion);
736 W.printHex("MinorVersion", D.MinorVersion);
737 W.printEnum("Type", D.Type, makeArrayRef(ImageDebugType));
738 W.printHex("SizeOfData", D.SizeOfData);
739 W.printHex("AddressOfRawData", D.AddressOfRawData);
740 W.printHex("PointerToRawData", D.PointerToRawData);
741 if (D.Type == COFF::IMAGE_DEBUG_TYPE_CODEVIEW) {
742 const codeview::DebugInfo *DebugInfo;
743 StringRef PDBFileName;
744 error(Obj->getDebugPDBInfo(&D, DebugInfo, PDBFileName));
745 DictScope PDBScope(W, "PDBInfo");
746 W.printHex("PDBSignature", DebugInfo->Signature.CVSignature);
747 if (DebugInfo->Signature.CVSignature == OMF::Signature::PDB70) {
748 W.printBinary("PDBGUID", makeArrayRef(DebugInfo->PDB70.Signature));
749 W.printNumber("PDBAge", DebugInfo->PDB70.Age);
750 W.printString("PDBFileName", PDBFileName);
751 }
752 } else {
753 // FIXME: Type values of 12 and 13 are commonly observed but are not in
754 // the documented type enum. Figure out what they mean.
755 ArrayRef<uint8_t> RawData;
756 error(
757 Obj->getRvaAndSizeAsBytes(D.AddressOfRawData, D.SizeOfData, RawData));
758 W.printBinaryBlock("RawData", RawData);
759 }
760 }
761}
762
763void COFFDumper::printRVATable(uint64_t TableVA, uint64_t Count,
764 uint64_t EntrySize, PrintExtraCB PrintExtra) {
765 uintptr_t TableStart, TableEnd;
766 error(Obj->getVaPtr(TableVA, TableStart));
767 error(Obj->getVaPtr(TableVA + Count * EntrySize - 1, TableEnd));
768 TableEnd++;
769 for (uintptr_t I = TableStart; I < TableEnd; I += EntrySize) {
770 uint32_t RVA = *reinterpret_cast<const ulittle32_t *>(I);
771 raw_ostream &OS = W.startLine();
772 OS << W.hex(Obj->getImageBase() + RVA);
773 if (PrintExtra)
774 PrintExtra(OS, reinterpret_cast<const uint8_t *>(I));
775 OS << '\n';
776 }
777}
778
779void COFFDumper::printCOFFLoadConfig() {
780 LoadConfigTables Tables;
781 if (Obj->is64())
782 printCOFFLoadConfig(Obj->getLoadConfig64(), Tables);
783 else
784 printCOFFLoadConfig(Obj->getLoadConfig32(), Tables);
785
786 if (Tables.SEHTableVA) {
787 ListScope LS(W, "SEHTable");
788 printRVATable(Tables.SEHTableVA, Tables.SEHTableCount, 4);
789 }
790
791 if (Tables.GuardFidTableVA) {
792 ListScope LS(W, "GuardFidTable");
793 if (Tables.GuardFlags & uint32_t(coff_guard_flags::FidTableHasFlags)) {
794 auto PrintGuardFlags = [](raw_ostream &OS, const uint8_t *Entry) {
795 uint8_t Flags = *reinterpret_cast<const uint8_t *>(Entry + 4);
796 if (Flags)
797 OS << " flags " << utohexstr(Flags);
798 };
799 printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, 5,
800 PrintGuardFlags);
801 } else {
802 printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, 4);
803 }
804 }
805
806 if (Tables.GuardLJmpTableVA) {
807 ListScope LS(W, "GuardLJmpTable");
808 printRVATable(Tables.GuardLJmpTableVA, Tables.GuardLJmpTableCount, 4);
809 }
810}
811
812template <typename T>
813void COFFDumper::printCOFFLoadConfig(const T *Conf, LoadConfigTables &Tables) {
814 if (!Conf)
815 return;
816
817 ListScope LS(W, "LoadConfig");
818 char FormattedTime[20] = {};
819 time_t TDS = Conf->TimeDateStamp;
820 strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS));
821 W.printHex("Size", Conf->Size);
822
823 // Print everything before SecurityCookie. The vast majority of images today
824 // have all these fields.
825 if (Conf->Size < offsetof(T, SEHandlerTable)__builtin_offsetof(T, SEHandlerTable))
826 return;
827 W.printHex("TimeDateStamp", FormattedTime, TDS);
828 W.printHex("MajorVersion", Conf->MajorVersion);
829 W.printHex("MinorVersion", Conf->MinorVersion);
830 W.printHex("GlobalFlagsClear", Conf->GlobalFlagsClear);
831 W.printHex("GlobalFlagsSet", Conf->GlobalFlagsSet);
832 W.printHex("CriticalSectionDefaultTimeout",
833 Conf->CriticalSectionDefaultTimeout);
834 W.printHex("DeCommitFreeBlockThreshold", Conf->DeCommitFreeBlockThreshold);
835 W.printHex("DeCommitTotalFreeThreshold", Conf->DeCommitTotalFreeThreshold);
836 W.printHex("LockPrefixTable", Conf->LockPrefixTable);
837 W.printHex("MaximumAllocationSize", Conf->MaximumAllocationSize);
838 W.printHex("VirtualMemoryThreshold", Conf->VirtualMemoryThreshold);
839 W.printHex("ProcessHeapFlags", Conf->ProcessHeapFlags);
840 W.printHex("ProcessAffinityMask", Conf->ProcessAffinityMask);
841 W.printHex("CSDVersion", Conf->CSDVersion);
842 W.printHex("DependentLoadFlags", Conf->DependentLoadFlags);
843 W.printHex("EditList", Conf->EditList);
844 W.printHex("SecurityCookie", Conf->SecurityCookie);
845
846 // Print the safe SEH table if present.
847 if (Conf->Size < offsetof(coff_load_configuration32, GuardCFCheckFunction)__builtin_offsetof(coff_load_configuration32, GuardCFCheckFunction
)
)
848 return;
849 W.printHex("SEHandlerTable", Conf->SEHandlerTable);
850 W.printNumber("SEHandlerCount", Conf->SEHandlerCount);
851
852 Tables.SEHTableVA = Conf->SEHandlerTable;
853 Tables.SEHTableCount = Conf->SEHandlerCount;
854
855 // Print everything before CodeIntegrity. (2015)
856 if (Conf->Size < offsetof(T, CodeIntegrity)__builtin_offsetof(T, CodeIntegrity))
857 return;
858 W.printHex("GuardCFCheckFunction", Conf->GuardCFCheckFunction);
859 W.printHex("GuardCFCheckDispatch", Conf->GuardCFCheckDispatch);
860 W.printHex("GuardCFFunctionTable", Conf->GuardCFFunctionTable);
861 W.printNumber("GuardCFFunctionCount", Conf->GuardCFFunctionCount);
862 W.printHex("GuardFlags", Conf->GuardFlags);
863
864 Tables.GuardFidTableVA = Conf->GuardCFFunctionTable;
865 Tables.GuardFidTableCount = Conf->GuardCFFunctionCount;
866 Tables.GuardFlags = Conf->GuardFlags;
867
868 // Print the rest. (2017)
869 if (Conf->Size < sizeof(T))
870 return;
871 W.printHex("GuardAddressTakenIatEntryTable",
872 Conf->GuardAddressTakenIatEntryTable);
873 W.printNumber("GuardAddressTakenIatEntryCount",
874 Conf->GuardAddressTakenIatEntryCount);
875 W.printHex("GuardLongJumpTargetTable", Conf->GuardLongJumpTargetTable);
876 W.printNumber("GuardLongJumpTargetCount", Conf->GuardLongJumpTargetCount);
877 W.printHex("DynamicValueRelocTable", Conf->DynamicValueRelocTable);
878 W.printHex("CHPEMetadataPointer", Conf->CHPEMetadataPointer);
879 W.printHex("GuardRFFailureRoutine", Conf->GuardRFFailureRoutine);
880 W.printHex("GuardRFFailureRoutineFunctionPointer",
881 Conf->GuardRFFailureRoutineFunctionPointer);
882 W.printHex("DynamicValueRelocTableOffset",
883 Conf->DynamicValueRelocTableOffset);
884 W.printNumber("DynamicValueRelocTableSection",
885 Conf->DynamicValueRelocTableSection);
886 W.printHex("GuardRFVerifyStackPointerFunctionPointer",
887 Conf->GuardRFVerifyStackPointerFunctionPointer);
888 W.printHex("HotPatchTableOffset", Conf->HotPatchTableOffset);
889
890 Tables.GuardLJmpTableVA = Conf->GuardLongJumpTargetTable;
891 Tables.GuardLJmpTableCount = Conf->GuardLongJumpTargetCount;
892}
893
894void COFFDumper::printBaseOfDataField(const pe32_header *Hdr) {
895 W.printHex("BaseOfData", Hdr->BaseOfData);
896}
897
898void COFFDumper::printBaseOfDataField(const pe32plus_header *) {}
899
900void COFFDumper::printCodeViewDebugInfo() {
901 // Print types first to build CVUDTNames, then print symbols.
902 for (const SectionRef &S : Obj->sections()) {
903 StringRef SectionName;
904 error(S.getName(SectionName));
905 // .debug$T is a standard CodeView type section, while .debug$P is the same
906 // format but used for MSVC precompiled header object files.
907 if (SectionName == ".debug$T" || SectionName == ".debug$P")
908 printCodeViewTypeSection(SectionName, S);
909 }
910 for (const SectionRef &S : Obj->sections()) {
911 StringRef SectionName;
912 error(S.getName(SectionName));
913 if (SectionName == ".debug$S")
914 printCodeViewSymbolSection(SectionName, S);
915 }
916}
917
918void COFFDumper::initializeFileAndStringTables(BinaryStreamReader &Reader) {
919 while (Reader.bytesRemaining() > 0 &&
920 (!CVFileChecksumTable.valid() || !CVStringTable.valid())) {
921 // The section consists of a number of subsection in the following format:
922 // |SubSectionType|SubSectionSize|Contents...|
923 uint32_t SubType, SubSectionSize;
924 error(Reader.readInteger(SubType));
925 error(Reader.readInteger(SubSectionSize));
926
927 StringRef Contents;
928 error(Reader.readFixedString(Contents, SubSectionSize));
929
930 BinaryStreamRef ST(Contents, support::little);
931 switch (DebugSubsectionKind(SubType)) {
932 case DebugSubsectionKind::FileChecksums:
933 error(CVFileChecksumTable.initialize(ST));
934 break;
935 case DebugSubsectionKind::StringTable:
936 error(CVStringTable.initialize(ST));
937 break;
938 default:
939 break;
940 }
941
942 uint32_t PaddedSize = alignTo(SubSectionSize, 4);
943 error(Reader.skip(PaddedSize - SubSectionSize));
944 }
945}
946
947void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
948 const SectionRef &Section) {
949 StringRef SectionContents;
950 error(Section.getContents(SectionContents));
951 StringRef Data = SectionContents;
952
953 SmallVector<StringRef, 10> FunctionNames;
954 StringMap<StringRef> FunctionLineTables;
955
956 ListScope D(W, "CodeViewDebugInfo");
957 // Print the section to allow correlation with printSections.
958 W.printNumber("Section", SectionName, Obj->getSectionID(Section));
959
960 uint32_t Magic;
961 error(consume(Data, Magic));
962 W.printHex("Magic", Magic);
963 if (Magic != COFF::DEBUG_SECTION_MAGIC)
964 return error(object_error::parse_failed);
965
966 BinaryStreamReader FSReader(Data, support::little);
967 initializeFileAndStringTables(FSReader);
968
969 // TODO: Convert this over to using ModuleSubstreamVisitor.
970 while (!Data.empty()) {
971 // The section consists of a number of subsection in the following format:
972 // |SubSectionType|SubSectionSize|Contents...|
973 uint32_t SubType, SubSectionSize;
974 error(consume(Data, SubType));
975 error(consume(Data, SubSectionSize));
976
977 ListScope S(W, "Subsection");
978 W.printEnum("SubSectionType", SubType, makeArrayRef(SubSectionTypes));
979 W.printHex("SubSectionSize", SubSectionSize);
980
981 // Get the contents of the subsection.
982 if (SubSectionSize > Data.size())
983 return error(object_error::parse_failed);
984 StringRef Contents = Data.substr(0, SubSectionSize);
985
986 // Add SubSectionSize to the current offset and align that offset to find
987 // the next subsection.
988 size_t SectionOffset = Data.data() - SectionContents.data();
989 size_t NextOffset = SectionOffset + SubSectionSize;
990 NextOffset = alignTo(NextOffset, 4);
991 if (NextOffset > SectionContents.size())
992 return error(object_error::parse_failed);
993 Data = SectionContents.drop_front(NextOffset);
994
995 // Optionally print the subsection bytes in case our parsing gets confused
996 // later.
997 if (opts::CodeViewSubsectionBytes)
998 printBinaryBlockWithRelocs("SubSectionContents", Section, SectionContents,
999 Contents);
1000
1001 switch (DebugSubsectionKind(SubType)) {
1002 case DebugSubsectionKind::Symbols:
1003 printCodeViewSymbolsSubsection(Contents, Section, SectionContents);
1004 break;
1005
1006 case DebugSubsectionKind::InlineeLines:
1007 printCodeViewInlineeLines(Contents);
1008 break;
1009
1010 case DebugSubsectionKind::FileChecksums:
1011 printCodeViewFileChecksums(Contents);
1012 break;
1013
1014 case DebugSubsectionKind::Lines: {
1015 // Holds a PC to file:line table. Some data to parse this subsection is
1016 // stored in the other subsections, so just check sanity and store the
1017 // pointers for deferred processing.
1018
1019 if (SubSectionSize < 12) {
1020 // There should be at least three words to store two function
1021 // relocations and size of the code.
1022 error(object_error::parse_failed);
1023 return;
1024 }
1025
1026 StringRef LinkageName;
1027 error(resolveSymbolName(Obj->getCOFFSection(Section), SectionOffset,
1028 LinkageName));
1029 W.printString("LinkageName", LinkageName);
1030 if (FunctionLineTables.count(LinkageName) != 0) {
1031 // Saw debug info for this function already?
1032 error(object_error::parse_failed);
1033 return;
1034 }
1035
1036 FunctionLineTables[LinkageName] = Contents;
1037 FunctionNames.push_back(LinkageName);
1038 break;
1039 }
1040 case DebugSubsectionKind::FrameData: {
1041 // First four bytes is a relocation against the function.
1042 BinaryStreamReader SR(Contents, llvm::support::little);
1043
1044 DebugFrameDataSubsectionRef FrameData;
1045 error(FrameData.initialize(SR));
1046
1047 StringRef LinkageName;
1048 error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents,
1049 FrameData.getRelocPtr(), LinkageName));
1050 W.printString("LinkageName", LinkageName);
1051
1052 // To find the active frame description, search this array for the
1053 // smallest PC range that includes the current PC.
1054 for (const auto &FD : FrameData) {
1055 StringRef FrameFunc = error(CVStringTable.getString(FD.FrameFunc));
1056
1057 DictScope S(W, "FrameData");
1058 W.printHex("RvaStart", FD.RvaStart);
1059 W.printHex("CodeSize", FD.CodeSize);
1060 W.printHex("LocalSize", FD.LocalSize);
1061 W.printHex("ParamsSize", FD.ParamsSize);
1062 W.printHex("MaxStackSize", FD.MaxStackSize);
1063 W.printString("FrameFunc", FrameFunc);
1064 W.printHex("PrologSize", FD.PrologSize);
1065 W.printHex("SavedRegsSize", FD.SavedRegsSize);
1066 W.printFlags("Flags", FD.Flags, makeArrayRef(FrameDataFlags));
1067 }
1068 break;
1069 }
1070
1071 // Do nothing for unrecognized subsections.
1072 default:
1073 break;
1074 }
1075 W.flush();
1076 }
1077
1078 // Dump the line tables now that we've read all the subsections and know all
1079 // the required information.
1080 for (unsigned I = 0, E = FunctionNames.size(); I != E; ++I) {
1081 StringRef Name = FunctionNames[I];
1082 ListScope S(W, "FunctionLineTable");
1083 W.printString("LinkageName", Name);
1084
1085 BinaryStreamReader Reader(FunctionLineTables[Name], support::little);
1086
1087 DebugLinesSubsectionRef LineInfo;
1088 error(LineInfo.initialize(Reader));
1089
1090 W.printHex("Flags", LineInfo.header()->Flags);
1091 W.printHex("CodeSize", LineInfo.header()->CodeSize);
1092 for (const auto &Entry : LineInfo) {
1093
1094 ListScope S(W, "FilenameSegment");
1095 printFileNameForOffset("Filename", Entry.NameIndex);
1096 uint32_t ColumnIndex = 0;
1097 for (const auto &Line : Entry.LineNumbers) {
1098 if (Line.Offset >= LineInfo.header()->CodeSize) {
1099 error(object_error::parse_failed);
1100 return;
1101 }
1102
1103 std::string PC = formatv("+{0:X}", uint32_t(Line.Offset));
1104 ListScope PCScope(W, PC);
1105 codeview::LineInfo LI(Line.Flags);
1106
1107 if (LI.isAlwaysStepInto())
1108 W.printString("StepInto", StringRef("Always"));
1109 else if (LI.isNeverStepInto())
1110 W.printString("StepInto", StringRef("Never"));
1111 else
1112 W.printNumber("LineNumberStart", LI.getStartLine());
1113 W.printNumber("LineNumberEndDelta", LI.getLineDelta());
1114 W.printBoolean("IsStatement", LI.isStatement());
1115 if (LineInfo.hasColumnInfo()) {
1116 W.printNumber("ColStart", Entry.Columns[ColumnIndex].StartColumn);
1117 W.printNumber("ColEnd", Entry.Columns[ColumnIndex].EndColumn);
1118 ++ColumnIndex;
1119 }
1120 }
1121 }
1122 }
1123}
1124
1125void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
1126 const SectionRef &Section,
1127 StringRef SectionContents) {
1128 ArrayRef<uint8_t> BinaryData(Subsection.bytes_begin(),
1129 Subsection.bytes_end());
1130 auto CODD = llvm::make_unique<COFFObjectDumpDelegate>(*this, Section, Obj,
1131 SectionContents);
1132 CVSymbolDumper CVSD(W, Types, CodeViewContainer::ObjectFile, std::move(CODD),
1133 opts::CodeViewSubsectionBytes);
1134 CVSymbolArray Symbols;
1135 BinaryStreamReader Reader(BinaryData, llvm::support::little);
1136 if (auto EC = Reader.readArray(Symbols, Reader.getLength())) {
1137 consumeError(std::move(EC));
1138 W.flush();
1139 error(object_error::parse_failed);
1140 }
1141
1142 if (auto EC = CVSD.dump(Symbols)) {
1143 W.flush();
1144 error(std::move(EC));
1145 }
1146 W.flush();
1147}
1148
1149void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) {
1150 BinaryStreamRef Stream(Subsection, llvm::support::little);
1151 DebugChecksumsSubsectionRef Checksums;
1152 error(Checksums.initialize(Stream));
1153
1154 for (auto &FC : Checksums) {
1155 DictScope S(W, "FileChecksum");
1156
1157 StringRef Filename = error(CVStringTable.getString(FC.FileNameOffset));
1158 W.printHex("Filename", Filename, FC.FileNameOffset);
1159 W.printHex("ChecksumSize", FC.Checksum.size());
1160 W.printEnum("ChecksumKind", uint8_t(FC.Kind),
1161 makeArrayRef(FileChecksumKindNames));
1162
1163 W.printBinary("ChecksumBytes", FC.Checksum);
1164 }
1165}
1166
1167void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) {
1168 BinaryStreamReader SR(Subsection, llvm::support::little);
1169 DebugInlineeLinesSubsectionRef Lines;
1170 error(Lines.initialize(SR));
1171
1172 for (auto &Line : Lines) {
1173 DictScope S(W, "InlineeSourceLine");
1174 printTypeIndex("Inlinee", Line.Header->Inlinee);
1175 printFileNameForOffset("FileID", Line.Header->FileID);
1176 W.printNumber("SourceLineNum", Line.Header->SourceLineNum);
1177
1178 if (Lines.hasExtraFiles()) {
1179 W.printNumber("ExtraFileCount", Line.ExtraFiles.size());
1180 ListScope ExtraFiles(W, "ExtraFiles");
1181 for (const auto &FID : Line.ExtraFiles) {
1182 printFileNameForOffset("FileID", FID);
1183 }
1184 }
1185 }
1186}
1187
1188StringRef COFFDumper::getFileNameForFileOffset(uint32_t FileOffset) {
1189 // The file checksum subsection should precede all references to it.
1190 if (!CVFileChecksumTable.valid() || !CVStringTable.valid())
1191 error(object_error::parse_failed);
1192
1193 auto Iter = CVFileChecksumTable.getArray().at(FileOffset);
1194
1195 // Check if the file checksum table offset is valid.
1196 if (Iter == CVFileChecksumTable.end())
1197 error(object_error::parse_failed);
1198
1199 return error(CVStringTable.getString(Iter->FileNameOffset));
1200}
1201
1202void COFFDumper::printFileNameForOffset(StringRef Label, uint32_t FileOffset) {
1203 W.printHex(Label, getFileNameForFileOffset(FileOffset), FileOffset);
1204}
1205
1206void COFFDumper::mergeCodeViewTypes(MergingTypeTableBuilder &CVIDs,
1207 MergingTypeTableBuilder &CVTypes) {
1208 for (const SectionRef &S : Obj->sections()) {
1209 StringRef SectionName;
1210 error(S.getName(SectionName));
1211 if (SectionName == ".debug$T") {
1212 StringRef Data;
1213 error(S.getContents(Data));
1214 uint32_t Magic;
1215 error(consume(Data, Magic));
1216 if (Magic != 4)
1217 error(object_error::parse_failed);
1218
1219 CVTypeArray Types;
1220 BinaryStreamReader Reader(Data, llvm::support::little);
1221 if (auto EC = Reader.readArray(Types, Reader.getLength())) {
1222 consumeError(std::move(EC));
1223 W.flush();
1224 error(object_error::parse_failed);
1225 }
1226 SmallVector<TypeIndex, 128> SourceToDest;
1227 if (auto EC = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types))
1228 return error(std::move(EC));
1229 }
1230 }
1231}
1232
1233void COFFDumper::printCodeViewTypeSection(StringRef SectionName,
1234 const SectionRef &Section) {
1235 ListScope D(W, "CodeViewTypes");
1236 W.printNumber("Section", SectionName, Obj->getSectionID(Section));
1237
1238 StringRef Data;
1239 error(Section.getContents(Data));
1240 if (opts::CodeViewSubsectionBytes)
1241 W.printBinaryBlock("Data", Data);
1242
1243 uint32_t Magic;
1244 error(consume(Data, Magic));
1245 W.printHex("Magic", Magic);
1246 if (Magic != COFF::DEBUG_SECTION_MAGIC)
1247 return error(object_error::parse_failed);
1248
1249 Types.reset(Data, 100);
1250
1251 TypeDumpVisitor TDV(Types, &W, opts::CodeViewSubsectionBytes);
1252 error(codeview::visitTypeStream(Types, TDV));
1253 W.flush();
1254}
1255
1256void COFFDumper::printSections() {
1257 ListScope SectionsD(W, "Sections");
1258 int SectionNumber = 0;
1259 for (const SectionRef &Sec : Obj->sections()) {
1260 ++SectionNumber;
1261 const coff_section *Section = Obj->getCOFFSection(Sec);
1262
1263 StringRef Name;
1264 error(Sec.getName(Name));
1265
1266 DictScope D(W, "Section");
1267 W.printNumber("Number", SectionNumber);
1268 W.printBinary("Name", Name, Section->Name);
1269 W.printHex ("VirtualSize", Section->VirtualSize);
1270 W.printHex ("VirtualAddress", Section->VirtualAddress);
1271 W.printNumber("RawDataSize", Section->SizeOfRawData);
1272 W.printHex ("PointerToRawData", Section->PointerToRawData);
1273 W.printHex ("PointerToRelocations", Section->PointerToRelocations);
1274 W.printHex ("PointerToLineNumbers", Section->PointerToLinenumbers);
1275 W.printNumber("RelocationCount", Section->NumberOfRelocations);
1276 W.printNumber("LineNumberCount", Section->NumberOfLinenumbers);
1277 W.printFlags ("Characteristics", Section->Characteristics,
1278 makeArrayRef(ImageSectionCharacteristics),
1279 COFF::SectionCharacteristics(0x00F00000));
1280
1281 if (opts::SectionRelocations) {
1282 ListScope D(W, "Relocations");
1283 for (const RelocationRef &Reloc : Sec.relocations())
1284 printRelocation(Sec, Reloc);
1285 }
1286
1287 if (opts::SectionSymbols) {
1288 ListScope D(W, "Symbols");
1289 for (const SymbolRef &Symbol : Obj->symbols()) {
1290 if (!Sec.containsSymbol(Symbol))
1291 continue;
1292
1293 printSymbol(Symbol);
1294 }
1295 }
1296
1297 if (opts::SectionData &&
1298 !(Section->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)) {
1299 StringRef Data;
1300 error(Sec.getContents(Data));
1301
1302 W.printBinaryBlock("SectionData", Data);
1303 }
1304 }
1305}
1306
1307void COFFDumper::printRelocations() {
1308 ListScope D(W, "Relocations");
1309
1310 int SectionNumber = 0;
1311 for (const SectionRef &Section : Obj->sections()) {
1312 ++SectionNumber;
1313 StringRef Name;
1314 error(Section.getName(Name));
1315
1316 bool PrintedGroup = false;
1317 for (const RelocationRef &Reloc : Section.relocations()) {
1318 if (!PrintedGroup) {
1319 W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
1320 W.indent();
1321 PrintedGroup = true;
1322 }
1323
1324 printRelocation(Section, Reloc);
1325 }
1326
1327 if (PrintedGroup) {
1328 W.unindent();
1329 W.startLine() << "}\n";
1330 }
1331 }
1332}
1333
1334void COFFDumper::printRelocation(const SectionRef &Section,
1335 const RelocationRef &Reloc, uint64_t Bias) {
1336 uint64_t Offset = Reloc.getOffset() - Bias;
1337 uint64_t RelocType = Reloc.getType();
1338 SmallString<32> RelocName;
1339 StringRef SymbolName;
1340 Reloc.getTypeName(RelocName);
1341 symbol_iterator Symbol = Reloc.getSymbol();
1342 if (Symbol != Obj->symbol_end()) {
1343 Expected<StringRef> SymbolNameOrErr = Symbol->getName();
1344 error(errorToErrorCode(SymbolNameOrErr.takeError()));
1345 SymbolName = *SymbolNameOrErr;
1346 }
1347
1348 if (opts::ExpandRelocs) {
1349 DictScope Group(W, "Relocation");
1350 W.printHex("Offset", Offset);
1351 W.printNumber("Type", RelocName, RelocType);
1352 W.printString("Symbol", SymbolName.empty() ? "-" : SymbolName);
1353 } else {
1354 raw_ostream& OS = W.startLine();
1355 OS << W.hex(Offset)
1356 << " " << RelocName
1357 << " " << (SymbolName.empty() ? "-" : SymbolName)
1358 << "\n";
1359 }
1360}
1361
1362void COFFDumper::printSymbols() {
1363 ListScope Group(W, "Symbols");
1364
1365 for (const SymbolRef &Symbol : Obj->symbols())
1366 printSymbol(Symbol);
1367}
1368
1369void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); }
1370
1371static ErrorOr<StringRef>
1372getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber,
1373 const coff_section *Section) {
1374 if (Section) {
1375 StringRef SectionName;
1376 if (std::error_code EC = Obj->getSectionName(Section, SectionName))
1377 return EC;
1378 return SectionName;
1379 }
1380 if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
1381 return StringRef("IMAGE_SYM_DEBUG");
1382 if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE)
1383 return StringRef("IMAGE_SYM_ABSOLUTE");
1384 if (SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED)
1385 return StringRef("IMAGE_SYM_UNDEFINED");
1386 return StringRef("");
1387}
1388
1389void COFFDumper::printSymbol(const SymbolRef &Sym) {
1390 DictScope D(W, "Symbol");
1391
1392 COFFSymbolRef Symbol = Obj->getCOFFSymbol(Sym);
1393 const coff_section *Section;
1394 if (std::error_code EC = Obj->getSection(Symbol.getSectionNumber(), Section)) {
1395 W.startLine() << "Invalid section number: " << EC.message() << "\n";
1396 W.flush();
1397 return;
1398 }
1399
1400 StringRef SymbolName;
1401 if (Obj->getSymbolName(Symbol, SymbolName))
1402 SymbolName = "";
1403
1404 StringRef SectionName = "";
1405 ErrorOr<StringRef> Res =
1406 getSectionName(Obj, Symbol.getSectionNumber(), Section);
1407 if (Res)
1408 SectionName = *Res;
1409
1410 W.printString("Name", SymbolName);
1411 W.printNumber("Value", Symbol.getValue());
1412 W.printNumber("Section", SectionName, Symbol.getSectionNumber());
1413 W.printEnum ("BaseType", Symbol.getBaseType(), makeArrayRef(ImageSymType));
1414 W.printEnum ("ComplexType", Symbol.getComplexType(),
1415 makeArrayRef(ImageSymDType));
1416 W.printEnum ("StorageClass", Symbol.getStorageClass(),
1417 makeArrayRef(ImageSymClass));
1418 W.printNumber("AuxSymbolCount", Symbol.getNumberOfAuxSymbols());
1419
1420 for (uint8_t I = 0; I < Symbol.getNumberOfAuxSymbols(); ++I) {
1421 if (Symbol.isFunctionDefinition()) {
1422 const coff_aux_function_definition *Aux;
1423 error(getSymbolAuxData(Obj, Symbol, I, Aux));
1424
1425 DictScope AS(W, "AuxFunctionDef");
1426 W.printNumber("TagIndex", Aux->TagIndex);
1427 W.printNumber("TotalSize", Aux->TotalSize);
1428 W.printHex("PointerToLineNumber", Aux->PointerToLinenumber);
1429 W.printHex("PointerToNextFunction", Aux->PointerToNextFunction);
1430
1431 } else if (Symbol.isAnyUndefined()) {
1432 const coff_aux_weak_external *Aux;
1433 error(getSymbolAuxData(Obj, Symbol, I, Aux));
1434
1435 Expected<COFFSymbolRef> Linked = Obj->getSymbol(Aux->TagIndex);
1436 StringRef LinkedName;
1437 std::error_code EC = errorToErrorCode(Linked.takeError());
1438 if (EC || (EC = Obj->getSymbolName(*Linked, LinkedName))) {
1439 LinkedName = "";
1440 error(EC);
1441 }
1442
1443 DictScope AS(W, "AuxWeakExternal");
1444 W.printNumber("Linked", LinkedName, Aux->TagIndex);
1445 W.printEnum ("Search", Aux->Characteristics,
1446 makeArrayRef(WeakExternalCharacteristics));
1447
1448 } else if (Symbol.isFileRecord()) {
1449 const char *FileName;
1450 error(getSymbolAuxData(Obj, Symbol, I, FileName));
1451
1452 DictScope AS(W, "AuxFileRecord");
1453
1454 StringRef Name(FileName, Symbol.getNumberOfAuxSymbols() *
1455 Obj->getSymbolTableEntrySize());
1456 W.printString("FileName", Name.rtrim(StringRef("\0", 1)));
1457 break;
1458 } else if (Symbol.isSectionDefinition()) {
1459 const coff_aux_section_definition *Aux;
1460 error(getSymbolAuxData(Obj, Symbol, I, Aux));
1461
1462 int32_t AuxNumber = Aux->getNumber(Symbol.isBigObj());
1463
1464 DictScope AS(W, "AuxSectionDef");
1465 W.printNumber("Length", Aux->Length);
1466 W.printNumber("RelocationCount", Aux->NumberOfRelocations);
1467 W.printNumber("LineNumberCount", Aux->NumberOfLinenumbers);
1468 W.printHex("Checksum", Aux->CheckSum);
1469 W.printNumber("Number", AuxNumber);
1470 W.printEnum("Selection", Aux->Selection, makeArrayRef(ImageCOMDATSelect));
1471
1472 if (Section && Section->Characteristics & COFF::IMAGE_SCN_LNK_COMDAT
1473 && Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
1474 const coff_section *Assoc;
1475 StringRef AssocName = "";
1476 std::error_code EC = Obj->getSection(AuxNumber, Assoc);
1477 ErrorOr<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc);
1478 if (Res)
1479 AssocName = *Res;
1480 if (!EC)
1481 EC = Res.getError();
1482 if (EC) {
1483 AssocName = "";
1484 error(EC);
1485 }
1486
1487 W.printNumber("AssocSection", AssocName, AuxNumber);
1488 }
1489 } else if (Symbol.isCLRToken()) {
1490 const coff_aux_clr_token *Aux;
1491 error(getSymbolAuxData(Obj, Symbol, I, Aux));
1492
1493 Expected<COFFSymbolRef> ReferredSym =
1494 Obj->getSymbol(Aux->SymbolTableIndex);
1495 StringRef ReferredName;
1496 std::error_code EC = errorToErrorCode(ReferredSym.takeError());
1497 if (EC || (EC = Obj->getSymbolName(*ReferredSym, ReferredName))) {
1498 ReferredName = "";
1499 error(EC);
1500 }
1501
1502 DictScope AS(W, "AuxCLRToken");
1503 W.printNumber("AuxType", Aux->AuxType);
1504 W.printNumber("Reserved", Aux->Reserved);
1505 W.printNumber("SymbolTableIndex", ReferredName, Aux->SymbolTableIndex);
1506
1507 } else {
1508 W.startLine() << "<unhandled auxiliary record>\n";
1509 }
1510 }
1511}
1512
1513void COFFDumper::printUnwindInfo() {
1514 ListScope D(W, "UnwindInformation");
1515 switch (Obj->getMachine()) {
1516 case COFF::IMAGE_FILE_MACHINE_AMD64: {
1517 Win64EH::Dumper Dumper(W);
1518 Win64EH::Dumper::SymbolResolver
1519 Resolver = [](const object::coff_section *Section, uint64_t Offset,
1520 SymbolRef &Symbol, void *user_data) -> std::error_code {
1521 COFFDumper *Dumper = reinterpret_cast<COFFDumper *>(user_data);
1522 return Dumper->resolveSymbol(Section, Offset, Symbol);
1523 };
1524 Win64EH::Dumper::Context Ctx(*Obj, Resolver, this);
1525 Dumper.printData(Ctx);
1526 break;
1527 }
1528 case COFF::IMAGE_FILE_MACHINE_ARMNT: {
1529 ARM::WinEH::Decoder Decoder(W);
1530 Decoder.dumpProcedureData(*Obj);
1531 break;
1532 }
1533 default:
1534 W.printEnum("unsupported Image Machine", Obj->getMachine(),
1535 makeArrayRef(ImageFileMachineType));
1536 break;
1537 }
1538}
1539
1540void COFFDumper::printNeededLibraries() {
1541 ListScope D(W, "NeededLibraries");
1542
1543 using LibsTy = std::vector<StringRef>;
1544 LibsTy Libs;
1545
1546 for (const ImportDirectoryEntryRef &DirRef : Obj->import_directories()) {
1547 StringRef Name;
1548 if (!DirRef.getName(Name))
1549 Libs.push_back(Name);
1550 }
1551
1552 std::stable_sort(Libs.begin(), Libs.end());
1553
1554 for (const auto &L : Libs) {
1555 outs() << " " << L << "\n";
1556 }
1557}
1558
1559void COFFDumper::printImportedSymbols(
1560 iterator_range<imported_symbol_iterator> Range) {
1561 for (const ImportedSymbolRef &I : Range) {
1562 StringRef Sym;
1563 error(I.getSymbolName(Sym));
1564 uint16_t Ordinal;
1565 error(I.getOrdinal(Ordinal));
1566 W.printNumber("Symbol", Sym, Ordinal);
1567 }
1568}
1569
1570void COFFDumper::printDelayImportedSymbols(
1571 const DelayImportDirectoryEntryRef &I,
1572 iterator_range<imported_symbol_iterator> Range) {
1573 int Index = 0;
1574 for (const ImportedSymbolRef &S : Range) {
1575 DictScope Import(W, "Import");
1576 StringRef Sym;
1577 error(S.getSymbolName(Sym));
1578 uint16_t Ordinal;
1579 error(S.getOrdinal(Ordinal));
1580 W.printNumber("Symbol", Sym, Ordinal);
1581 uint64_t Addr;
1582 error(I.getImportAddress(Index++, Addr));
1583 W.printHex("Address", Addr);
1584 }
1585}
1586
1587void COFFDumper::printCOFFImports() {
1588 // Regular imports
1589 for (const ImportDirectoryEntryRef &I : Obj->import_directories()) {
1590 DictScope Import(W, "Import");
1591 StringRef Name;
1592 error(I.getName(Name));
1593 W.printString("Name", Name);
1594 uint32_t ILTAddr;
1595 error(I.getImportLookupTableRVA(ILTAddr));
1596 W.printHex("ImportLookupTableRVA", ILTAddr);
1597 uint32_t IATAddr;
1598 error(I.getImportAddressTableRVA(IATAddr));
1599 W.printHex("ImportAddressTableRVA", IATAddr);
1600 // The import lookup table can be missing with certain older linkers, so
1601 // fall back to the import address table in that case.
1602 if (ILTAddr)
1603 printImportedSymbols(I.lookup_table_symbols());
1604 else
1605 printImportedSymbols(I.imported_symbols());
1606 }
1607
1608 // Delay imports
1609 for (const DelayImportDirectoryEntryRef &I : Obj->delay_import_directories()) {
1610 DictScope Import(W, "DelayImport");
1611 StringRef Name;
1612 error(I.getName(Name));
1613 W.printString("Name", Name);
1614 const delay_import_directory_table_entry *Table;
1615 error(I.getDelayImportTable(Table));
1616 W.printHex("Attributes", Table->Attributes);
1617 W.printHex("ModuleHandle", Table->ModuleHandle);
1618 W.printHex("ImportAddressTable", Table->DelayImportAddressTable);
1619 W.printHex("ImportNameTable", Table->DelayImportNameTable);
1620 W.printHex("BoundDelayImportTable", Table->BoundDelayImportTable);
1621 W.printHex("UnloadDelayImportTable", Table->UnloadDelayImportTable);
1622 printDelayImportedSymbols(I, I.imported_symbols());
1623 }
1624}
1625
1626void COFFDumper::printCOFFExports() {
1627 for (const ExportDirectoryEntryRef &E : Obj->export_directories()) {
1628 DictScope Export(W, "Export");
1629
1630 StringRef Name;
1631 uint32_t Ordinal, RVA;
1632
1633 error(E.getSymbolName(Name));
1634 error(E.getOrdinal(Ordinal));
1635 error(E.getExportRVA(RVA));
1636
1637 W.printNumber("Ordinal", Ordinal);
1638 W.printString("Name", Name);
1639 W.printHex("RVA", RVA);
1640 }
1641}
1642
1643void COFFDumper::printCOFFDirectives() {
1644 for (const SectionRef &Section : Obj->sections()) {
1645 StringRef Contents;
1646 StringRef Name;
1647
1648 error(Section.getName(Name));
1649 if (Name != ".drectve")
1650 continue;
1651
1652 error(Section.getContents(Contents));
1653
1654 W.printString("Directive(s)", Contents);
1655 }
1656}
1657
1658static std::string getBaseRelocTypeName(uint8_t Type) {
1659 switch (Type) {
1660 case COFF::IMAGE_REL_BASED_ABSOLUTE: return "ABSOLUTE";
1661 case COFF::IMAGE_REL_BASED_HIGH: return "HIGH";
1662 case COFF::IMAGE_REL_BASED_LOW: return "LOW";
1663 case COFF::IMAGE_REL_BASED_HIGHLOW: return "HIGHLOW";
1664 case COFF::IMAGE_REL_BASED_HIGHADJ: return "HIGHADJ";
1665 case COFF::IMAGE_REL_BASED_ARM_MOV32T: return "ARM_MOV32(T)";
1666 case COFF::IMAGE_REL_BASED_DIR64: return "DIR64";
1667 default: return "unknown (" + llvm::utostr(Type) + ")";
1668 }
1669}
1670
1671void COFFDumper::printCOFFBaseReloc() {
1672 ListScope D(W, "BaseReloc");
1673 for (const BaseRelocRef &I : Obj->base_relocs()) {
1674 uint8_t Type;
1675 uint32_t RVA;
1676 error(I.getRVA(RVA));
1677 error(I.getType(Type));
1678 DictScope Import(W, "Entry");
1679 W.printString("Type", getBaseRelocTypeName(Type));
1680 W.printHex("Address", RVA);
1681 }
1682}
1683
1684void COFFDumper::printCOFFResources() {
1685 ListScope ResourcesD(W, "Resources");
1686 for (const SectionRef &S : Obj->sections()) {
1687 StringRef Name;
1688 error(S.getName(Name));
1689 if (!Name.startswith(".rsrc"))
1690 continue;
1691
1692 StringRef Ref;
1693 error(S.getContents(Ref));
1694
1695 if ((Name == ".rsrc") || (Name == ".rsrc$01")) {
1696 ResourceSectionRef RSF(Ref);
1697 auto &BaseTable = unwrapOrError(RSF.getBaseTable());
1698 W.printNumber("Total Number of Resources",
1699 countTotalTableEntries(RSF, BaseTable, "Type"));
1700 W.printHex("Base Table Address",
1701 Obj->getCOFFSection(S)->PointerToRawData);
1702 W.startLine() << "\n";
1703 printResourceDirectoryTable(RSF, BaseTable, "Type");
1704 }
1705 if (opts::SectionData)
1706 W.printBinaryBlock(Name.str() + " Data", Ref);
1707 }
1708}
1709
1710uint32_t
1711COFFDumper::countTotalTableEntries(ResourceSectionRef RSF,
1712 const coff_resource_dir_table &Table,
1713 StringRef Level) {
1714 uint32_t TotalEntries = 0;
1715 for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries;
1716 i++) {
1717 auto Entry = unwrapOrError(getResourceDirectoryTableEntry(Table, i));
1718 if (Entry.Offset.isSubDir()) {
1719 StringRef NextLevel;
1720 if (Level == "Name")
1721 NextLevel = "Language";
1722 else
1723 NextLevel = "Name";
1724 auto &NextTable = unwrapOrError(RSF.getEntrySubDir(Entry));
1725 TotalEntries += countTotalTableEntries(RSF, NextTable, NextLevel);
1726 } else {
1727 TotalEntries += 1;
1728 }
1729 }
1730 return TotalEntries;
1731}
1732
1733void COFFDumper::printResourceDirectoryTable(
1734 ResourceSectionRef RSF, const coff_resource_dir_table &Table,
1735 StringRef Level) {
1736
1737 W.printNumber("Number of String Entries", Table.NumberOfNameEntries);
1738 W.printNumber("Number of ID Entries", Table.NumberOfIDEntries);
1739
1740 // Iterate through level in resource directory tree.
1741 for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries;
1742 i++) {
1743 auto Entry = unwrapOrError(getResourceDirectoryTableEntry(Table, i));
1744 StringRef Name;
1745 SmallString<20> IDStr;
1746 raw_svector_ostream OS(IDStr);
1747 if (i < Table.NumberOfNameEntries) {
1748 ArrayRef<UTF16> RawEntryNameString = unwrapOrError(RSF.getEntryNameString(Entry));
1749 std::vector<UTF16> EndianCorrectedNameString;
1750 if (llvm::sys::IsBigEndianHost) {
1751 EndianCorrectedNameString.resize(RawEntryNameString.size() + 1);
1752 std::copy(RawEntryNameString.begin(), RawEntryNameString.end(),
1753 EndianCorrectedNameString.begin() + 1);
1754 EndianCorrectedNameString[0] = UNI_UTF16_BYTE_ORDER_MARK_SWAPPED0xFFFE;
1755 RawEntryNameString = makeArrayRef(EndianCorrectedNameString);
1756 }
1757 std::string EntryNameString;
1758 if (!llvm::convertUTF16ToUTF8String(RawEntryNameString, EntryNameString))
1759 error(object_error::parse_failed);
1760 OS << ": ";
1761 OS << EntryNameString;
1762 } else {
1763 if (Level == "Type") {
1764 ScopedPrinter Printer(OS);
1765 Printer.printEnum("", Entry.Identifier.ID,
1766 makeArrayRef(ResourceTypeNames));
1767 IDStr = IDStr.slice(0, IDStr.find_first_of(")", 0) + 1);
1768 } else {
1769 OS << ": (ID " << Entry.Identifier.ID << ")";
1770 }
1771 }
1772 Name = StringRef(IDStr);
1773 ListScope ResourceType(W, Level.str() + Name.str());
1774 if (Entry.Offset.isSubDir()) {
1775 W.printHex("Table Offset", Entry.Offset.value());
1776 StringRef NextLevel;
1777 if (Level == "Name")
1778 NextLevel = "Language";
1779 else
1780 NextLevel = "Name";
1781 auto &NextTable = unwrapOrError(RSF.getEntrySubDir(Entry));
1782 printResourceDirectoryTable(RSF, NextTable, NextLevel);
1783 } else {
1784 W.printHex("Entry Offset", Entry.Offset.value());
1785 char FormattedTime[20] = {};
1786 time_t TDS = time_t(Table.TimeDateStamp);
1787 strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS));
1788 W.printHex("Time/Date Stamp", FormattedTime, Table.TimeDateStamp);
1789 W.printNumber("Major Version", Table.MajorVersion);
1790 W.printNumber("Minor Version", Table.MinorVersion);
1791 W.printNumber("Characteristics", Table.Characteristics);
1792 }
1793 }
1794}
1795
1796ErrorOr<const coff_resource_dir_entry &>
1797COFFDumper::getResourceDirectoryTableEntry(const coff_resource_dir_table &Table,
1798 uint32_t Index) {
1799 if (Index >= (uint32_t)(Table.NumberOfNameEntries + Table.NumberOfIDEntries))
1800 return object_error::parse_failed;
1801 auto TablePtr = reinterpret_cast<const coff_resource_dir_entry *>(&Table + 1);
1802 return TablePtr[Index];
1803}
1804
1805void COFFDumper::printStackMap() const {
1806 object::SectionRef StackMapSection;
1
Calling defaulted default constructor for 'SectionRef'
3
Returning from default constructor for 'SectionRef'
1807 for (auto Sec : Obj->sections()) {
1808 StringRef Name;
1809 Sec.getName(Name);
1810 if (Name == ".llvm_stackmaps") {
1811 StackMapSection = Sec;
1812 break;
1813 }
1814 }
1815
1816 if (StackMapSection == object::SectionRef())
4
Taking false branch
1817 return;
1818
1819 StringRef StackMapContents;
1820 StackMapSection.getContents(StackMapContents);
5
Calling 'SectionRef::getContents'
1821 ArrayRef<uint8_t> StackMapContentsArray(
1822 reinterpret_cast<const uint8_t*>(StackMapContents.data()),
1823 StackMapContents.size());
1824
1825 if (Obj->isLittleEndian())
1826 prettyPrintStackMap(
1827 W, StackMapV2Parser<support::little>(StackMapContentsArray));
1828 else
1829 prettyPrintStackMap(W,
1830 StackMapV2Parser<support::big>(StackMapContentsArray));
1831}
1832
1833void llvm::dumpCodeViewMergedTypes(
1834 ScopedPrinter &Writer, llvm::codeview::MergingTypeTableBuilder &IDTable,
1835 llvm::codeview::MergingTypeTableBuilder &CVTypes) {
1836 // Flatten it first, then run our dumper on it.
1837 SmallString<0> TypeBuf;
1838 CVTypes.ForEachRecord([&](TypeIndex TI, const CVType &Record) {
1839 TypeBuf.append(Record.RecordData.begin(), Record.RecordData.end());
1840 });
1841
1842 TypeTableCollection TpiTypes(CVTypes.records());
1843 {
1844 ListScope S(Writer, "MergedTypeStream");
1845 TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes);
1846 error(codeview::visitTypeStream(TpiTypes, TDV));
1847 Writer.flush();
1848 }
1849
1850 // Flatten the id stream and print it next. The ID stream refers to names from
1851 // the type stream.
1852 TypeTableCollection IpiTypes(IDTable.records());
1853 {
1854 ListScope S(Writer, "MergedIDStream");
1855 TypeDumpVisitor TDV(TpiTypes, &Writer, opts::CodeViewSubsectionBytes);
1856 TDV.setIpiTypes(IpiTypes);
1857 error(codeview::visitTypeStream(IpiTypes, TDV));
1858 Writer.flush();
1859 }
1860}

/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/Object/ObjectFile.h

1//===- ObjectFile.h - File format independent object file -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares a file format independent ObjectFile class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_OBJECT_OBJECTFILE_H
15#define LLVM_OBJECT_OBJECTFILE_H
16
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/Triple.h"
19#include "llvm/ADT/iterator_range.h"
20#include "llvm/BinaryFormat/Magic.h"
21#include "llvm/MC/SubtargetFeature.h"
22#include "llvm/Object/Binary.h"
23#include "llvm/Object/Error.h"
24#include "llvm/Object/SymbolicFile.h"
25#include "llvm/Support/Casting.h"
26#include "llvm/Support/Error.h"
27#include "llvm/Support/FileSystem.h"
28#include "llvm/Support/MemoryBuffer.h"
29#include <cassert>
30#include <cstdint>
31#include <memory>
32#include <system_error>
33
34namespace llvm {
35
36class ARMAttributeParser;
37
38namespace object {
39
40class COFFObjectFile;
41class MachOObjectFile;
42class ObjectFile;
43class SectionRef;
44class SymbolRef;
45class symbol_iterator;
46class WasmObjectFile;
47
48using section_iterator = content_iterator<SectionRef>;
49
50/// This is a value type class that represents a single relocation in the list
51/// of relocations in the object file.
52class RelocationRef {
53 DataRefImpl RelocationPimpl;
54 const ObjectFile *OwningObject = nullptr;
55
56public:
57 RelocationRef() = default;
58 RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
59
60 bool operator==(const RelocationRef &Other) const;
61
62 void moveNext();
63
64 uint64_t getOffset() const;
65 symbol_iterator getSymbol() const;
66 uint64_t getType() const;
67
68 /// Get a string that represents the type of this relocation.
69 ///
70 /// This is for display purposes only.
71 void getTypeName(SmallVectorImpl<char> &Result) const;
72
73 DataRefImpl getRawDataRefImpl() const;
74 const ObjectFile *getObject() const;
75};
76
77using relocation_iterator = content_iterator<RelocationRef>;
78
79/// This is a value type class that represents a single section in the list of
80/// sections in the object file.
81class SectionRef {
82 friend class SymbolRef;
83
84 DataRefImpl SectionPimpl;
85 const ObjectFile *OwningObject = nullptr;
2
Null pointer value stored to 'StackMapSection.OwningObject'
86
87public:
88 SectionRef() = default;
89 SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
90
91 bool operator==(const SectionRef &Other) const;
92 bool operator!=(const SectionRef &Other) const;
93 bool operator<(const SectionRef &Other) const;
94
95 void moveNext();
96
97 std::error_code getName(StringRef &Result) const;
98 uint64_t getAddress() const;
99 uint64_t getIndex() const;
100 uint64_t getSize() const;
101 std::error_code getContents(StringRef &Result) const;
102
103 /// Get the alignment of this section as the actual value (not log 2).
104 uint64_t getAlignment() const;
105
106 bool isCompressed() const;
107 bool isText() const;
108 bool isData() const;
109 bool isBSS() const;
110 bool isVirtual() const;
111 bool isBitcode() const;
112 bool isStripped() const;
113
114 bool containsSymbol(SymbolRef S) const;
115
116 relocation_iterator relocation_begin() const;
117 relocation_iterator relocation_end() const;
118 iterator_range<relocation_iterator> relocations() const {
119 return make_range(relocation_begin(), relocation_end());
120 }
121 section_iterator getRelocatedSection() const;
122
123 DataRefImpl getRawDataRefImpl() const;
124 const ObjectFile *getObject() const;
125};
126
127/// This is a value type class that represents a single symbol in the list of
128/// symbols in the object file.
129class SymbolRef : public BasicSymbolRef {
130 friend class SectionRef;
131
132public:
133 enum Type {
134 ST_Unknown, // Type not specified
135 ST_Data,
136 ST_Debug,
137 ST_File,
138 ST_Function,
139 ST_Other
140 };
141
142 SymbolRef() = default;
143 SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
144 SymbolRef(const BasicSymbolRef &B) : BasicSymbolRef(B) {
145 assert(isa<ObjectFile>(BasicSymbolRef::getObject()))(static_cast <bool> (isa<ObjectFile>(BasicSymbolRef
::getObject())) ? void (0) : __assert_fail ("isa<ObjectFile>(BasicSymbolRef::getObject())"
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/Object/ObjectFile.h"
, 145, __extension__ __PRETTY_FUNCTION__))
;
146 }
147
148 Expected<StringRef> getName() const;
149 /// Returns the symbol virtual address (i.e. address at which it will be
150 /// mapped).
151 Expected<uint64_t> getAddress() const;
152
153 /// Return the value of the symbol depending on the object this can be an
154 /// offset or a virtual address.
155 uint64_t getValue() const;
156
157 /// Get the alignment of this symbol as the actual value (not log 2).
158 uint32_t getAlignment() const;
159 uint64_t getCommonSize() const;
160 Expected<SymbolRef::Type> getType() const;
161
162 /// Get section this symbol is defined in reference to. Result is
163 /// end_sections() if it is undefined or is an absolute symbol.
164 Expected<section_iterator> getSection() const;
165
166 const ObjectFile *getObject() const;
167};
168
169class symbol_iterator : public basic_symbol_iterator {
170public:
171 symbol_iterator(SymbolRef Sym) : basic_symbol_iterator(Sym) {}
172 symbol_iterator(const basic_symbol_iterator &B)
173 : basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
174 cast<ObjectFile>(B->getObject()))) {}
175
176 const SymbolRef *operator->() const {
177 const BasicSymbolRef &P = basic_symbol_iterator::operator *();
178 return static_cast<const SymbolRef*>(&P);
179 }
180
181 const SymbolRef &operator*() const {
182 const BasicSymbolRef &P = basic_symbol_iterator::operator *();
183 return static_cast<const SymbolRef&>(P);
184 }
185};
186
187/// This class is the base class for all object file types. Concrete instances
188/// of this object are created by createObjectFile, which figures out which type
189/// to create.
190class ObjectFile : public SymbolicFile {
191 virtual void anchor();
192
193protected:
194 ObjectFile(unsigned int Type, MemoryBufferRef Source);
195
196 const uint8_t *base() const {
197 return reinterpret_cast<const uint8_t *>(Data.getBufferStart());
198 }
199
200 // These functions are for SymbolRef to call internally. The main goal of
201 // this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
202 // entry in the memory mapped object file. SymbolPimpl cannot contain any
203 // virtual functions because then it could not point into the memory mapped
204 // file.
205 //
206 // Implementations assume that the DataRefImpl is valid and has not been
207 // modified externally. It's UB otherwise.
208 friend class SymbolRef;
209
210 virtual Expected<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
211 std::error_code printSymbolName(raw_ostream &OS,
212 DataRefImpl Symb) const override;
213 virtual Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
214 virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
215 virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
216 virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
217 virtual Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const = 0;
218 virtual Expected<section_iterator>
219 getSymbolSection(DataRefImpl Symb) const = 0;
220
221 // Same as above for SectionRef.
222 friend class SectionRef;
223
224 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
225 virtual std::error_code getSectionName(DataRefImpl Sec,
226 StringRef &Res) const = 0;
227 virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
228 virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;
229 virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
230 virtual std::error_code getSectionContents(DataRefImpl Sec,
231 StringRef &Res) const = 0;
232 virtual uint64_t getSectionAlignment(DataRefImpl Sec) const = 0;
233 virtual bool isSectionCompressed(DataRefImpl Sec) const = 0;
234 virtual bool isSectionText(DataRefImpl Sec) const = 0;
235 virtual bool isSectionData(DataRefImpl Sec) const = 0;
236 virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
237 // A section is 'virtual' if its contents aren't present in the object image.
238 virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
239 virtual bool isSectionBitcode(DataRefImpl Sec) const;
240 virtual bool isSectionStripped(DataRefImpl Sec) const;
241 virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
242 virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
243 virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
244
245 // Same as above for RelocationRef.
246 friend class RelocationRef;
247 virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
248 virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
249 virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
250 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
251 virtual void getRelocationTypeName(DataRefImpl Rel,
252 SmallVectorImpl<char> &Result) const = 0;
253
254 uint64_t getSymbolValue(DataRefImpl Symb) const;
255
256public:
257 ObjectFile() = delete;
258 ObjectFile(const ObjectFile &other) = delete;
259
260 uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
261 assert(getSymbolFlags(Symb) & SymbolRef::SF_Common)(static_cast <bool> (getSymbolFlags(Symb) & SymbolRef
::SF_Common) ? void (0) : __assert_fail ("getSymbolFlags(Symb) & SymbolRef::SF_Common"
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/Object/ObjectFile.h"
, 261, __extension__ __PRETTY_FUNCTION__))
;
262 return getCommonSymbolSizeImpl(Symb);
263 }
264
265 virtual std::vector<SectionRef> dynamic_relocation_sections() const {
266 return std::vector<SectionRef>();
267 }
268
269 using symbol_iterator_range = iterator_range<symbol_iterator>;
270 symbol_iterator_range symbols() const {
271 return symbol_iterator_range(symbol_begin(), symbol_end());
272 }
273
274 virtual section_iterator section_begin() const = 0;
275 virtual section_iterator section_end() const = 0;
276
277 using section_iterator_range = iterator_range<section_iterator>;
278 section_iterator_range sections() const {
279 return section_iterator_range(section_begin(), section_end());
280 }
281
282 /// The number of bytes used to represent an address in this object
283 /// file format.
284 virtual uint8_t getBytesInAddress() const = 0;
285
286 virtual StringRef getFileFormatName() const = 0;
287 virtual Triple::ArchType getArch() const = 0;
288 virtual SubtargetFeatures getFeatures() const = 0;
289 virtual void setARMSubArch(Triple &TheTriple) const { }
290 virtual Expected<uint64_t> getStartAddress() const {
291 return errorCodeToError(object_error::parse_failed);
292 };
293
294 /// Create a triple from the data in this object file.
295 Triple makeTriple() const;
296
297 virtual std::error_code
298 getBuildAttributes(ARMAttributeParser &Attributes) const {
299 return std::error_code();
300 }
301
302 /// Maps a debug section name to a standard DWARF section name.
303 virtual StringRef mapDebugSectionName(StringRef Name) const { return Name; }
304
305 /// True if this is a relocatable object (.o/.obj).
306 virtual bool isRelocatableObject() const = 0;
307
308 /// @returns Pointer to ObjectFile subclass to handle this type of object.
309 /// @param ObjectPath The path to the object file. ObjectPath.isObject must
310 /// return true.
311 /// Create ObjectFile from path.
312 static Expected<OwningBinary<ObjectFile>>
313 createObjectFile(StringRef ObjectPath);
314
315 static Expected<std::unique_ptr<ObjectFile>>
316 createObjectFile(MemoryBufferRef Object, llvm::file_magic Type);
317 static Expected<std::unique_ptr<ObjectFile>>
318 createObjectFile(MemoryBufferRef Object) {
319 return createObjectFile(Object, llvm::file_magic::unknown);
320 }
321
322 static bool classof(const Binary *v) {
323 return v->isObject();
324 }
325
326 static Expected<std::unique_ptr<COFFObjectFile>>
327 createCOFFObjectFile(MemoryBufferRef Object);
328
329 static Expected<std::unique_ptr<ObjectFile>>
330 createELFObjectFile(MemoryBufferRef Object);
331
332 static Expected<std::unique_ptr<MachOObjectFile>>
333 createMachOObjectFile(MemoryBufferRef Object,
334 uint32_t UniversalCputype = 0,
335 uint32_t UniversalIndex = 0);
336
337 static Expected<std::unique_ptr<WasmObjectFile>>
338 createWasmObjectFile(MemoryBufferRef Object);
339};
340
341// Inline function definitions.
342inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
343 : BasicSymbolRef(SymbolP, Owner) {}
344
345inline Expected<StringRef> SymbolRef::getName() const {
346 return getObject()->getSymbolName(getRawDataRefImpl());
347}
348
349inline Expected<uint64_t> SymbolRef::getAddress() const {
350 return getObject()->getSymbolAddress(getRawDataRefImpl());
351}
352
353inline uint64_t SymbolRef::getValue() const {
354 return getObject()->getSymbolValue(getRawDataRefImpl());
355}
356
357inline uint32_t SymbolRef::getAlignment() const {
358 return getObject()->getSymbolAlignment(getRawDataRefImpl());
359}
360
361inline uint64_t SymbolRef::getCommonSize() const {
362 return getObject()->getCommonSymbolSize(getRawDataRefImpl());
363}
364
365inline Expected<section_iterator> SymbolRef::getSection() const {
366 return getObject()->getSymbolSection(getRawDataRefImpl());
367}
368
369inline Expected<SymbolRef::Type> SymbolRef::getType() const {
370 return getObject()->getSymbolType(getRawDataRefImpl());
371}
372
373inline const ObjectFile *SymbolRef::getObject() const {
374 const SymbolicFile *O = BasicSymbolRef::getObject();
375 return cast<ObjectFile>(O);
376}
377
378/// SectionRef
379inline SectionRef::SectionRef(DataRefImpl SectionP,
380 const ObjectFile *Owner)
381 : SectionPimpl(SectionP)
382 , OwningObject(Owner) {}
383
384inline bool SectionRef::operator==(const SectionRef &Other) const {
385 return SectionPimpl == Other.SectionPimpl;
386}
387
388inline bool SectionRef::operator!=(const SectionRef &Other) const {
389 return SectionPimpl != Other.SectionPimpl;
390}
391
392inline bool SectionRef::operator<(const SectionRef &Other) const {
393 return SectionPimpl < Other.SectionPimpl;
394}
395
396inline void SectionRef::moveNext() {
397 return OwningObject->moveSectionNext(SectionPimpl);
398}
399
400inline std::error_code SectionRef::getName(StringRef &Result) const {
401 return OwningObject->getSectionName(SectionPimpl, Result);
402}
403
404inline uint64_t SectionRef::getAddress() const {
405 return OwningObject->getSectionAddress(SectionPimpl);
406}
407
408inline uint64_t SectionRef::getIndex() const {
409 return OwningObject->getSectionIndex(SectionPimpl);
410}
411
412inline uint64_t SectionRef::getSize() const {
413 return OwningObject->getSectionSize(SectionPimpl);
414}
415
416inline std::error_code SectionRef::getContents(StringRef &Result) const {
417 return OwningObject->getSectionContents(SectionPimpl, Result);
6
Called C++ object pointer is null
418}
419
420inline uint64_t SectionRef::getAlignment() const {
421 return OwningObject->getSectionAlignment(SectionPimpl);
422}
423
424inline bool SectionRef::isCompressed() const {
425 return OwningObject->isSectionCompressed(SectionPimpl);
426}
427
428inline bool SectionRef::isText() const {
429 return OwningObject->isSectionText(SectionPimpl);
430}
431
432inline bool SectionRef::isData() const {
433 return OwningObject->isSectionData(SectionPimpl);
434}
435
436inline bool SectionRef::isBSS() const {
437 return OwningObject->isSectionBSS(SectionPimpl);
438}
439
440inline bool SectionRef::isVirtual() const {
441 return OwningObject->isSectionVirtual(SectionPimpl);
442}
443
444inline bool SectionRef::isBitcode() const {
445 return OwningObject->isSectionBitcode(SectionPimpl);
446}
447
448inline bool SectionRef::isStripped() const {
449 return OwningObject->isSectionStripped(SectionPimpl);
450}
451
452inline relocation_iterator SectionRef::relocation_begin() const {
453 return OwningObject->section_rel_begin(SectionPimpl);
454}
455
456inline relocation_iterator SectionRef::relocation_end() const {
457 return OwningObject->section_rel_end(SectionPimpl);
458}
459
460inline section_iterator SectionRef::getRelocatedSection() const {
461 return OwningObject->getRelocatedSection(SectionPimpl);
462}
463
464inline DataRefImpl SectionRef::getRawDataRefImpl() const {
465 return SectionPimpl;
466}
467
468inline const ObjectFile *SectionRef::getObject() const {
469 return OwningObject;
470}
471
472/// RelocationRef
473inline RelocationRef::RelocationRef(DataRefImpl RelocationP,
474 const ObjectFile *Owner)
475 : RelocationPimpl(RelocationP)
476 , OwningObject(Owner) {}
477
478inline bool RelocationRef::operator==(const RelocationRef &Other) const {
479 return RelocationPimpl == Other.RelocationPimpl;
480}
481
482inline void RelocationRef::moveNext() {
483 return OwningObject->moveRelocationNext(RelocationPimpl);
484}
485
486inline uint64_t RelocationRef::getOffset() const {
487 return OwningObject->getRelocationOffset(RelocationPimpl);
488}
489
490inline symbol_iterator RelocationRef::getSymbol() const {
491 return OwningObject->getRelocationSymbol(RelocationPimpl);
492}
493
494inline uint64_t RelocationRef::getType() const {
495 return OwningObject->getRelocationType(RelocationPimpl);
496}
497
498inline void RelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
499 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
500}
501
502inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
503 return RelocationPimpl;
504}
505
506inline const ObjectFile *RelocationRef::getObject() const {
507 return OwningObject;
508}
509
510} // end namespace object
511
512} // end namespace llvm
513
514#endif // LLVM_OBJECT_OBJECTFILE_H