summaryrefslogtreecommitdiff
path: root/tools/llvm-readobj
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-01-26 04:15:52 +0000
committerRui Ueyama <ruiu@google.com>2014-01-26 04:15:52 +0000
commit1e839eb2cd0e233db6225ea1db45411463654de6 (patch)
treeb638f5802f7e5dcbfd91cfa6f6491f9dc8d62c6b /tools/llvm-readobj
parent07f1de473f6ed6c42d9798c59cd90b61bac9c640 (diff)
llvm-readobj: add support for PE32+ (Windows 64 bit executable).
PE32+ supports 64 bit address space, but the file format remains 32 bit. So its file format is pretty similar to PE32 (32 bit executable). The differences compared to PE32 are (1) the lack of "BaseOfData" field and (2) some of its data members are 64 bit. In this patch, I added a new member function to get a PE32+ Header object to COFFObjectFile class and made llvm-readobj to use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200117 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r--tools/llvm-readobj/COFFDumper.cpp111
1 files changed, 63 insertions, 48 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index 1a6384afa00..493396f2e28 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -56,13 +56,14 @@ public:
private:
void printSymbol(symbol_iterator SymI);
-
void printRelocation(section_iterator SecI, relocation_iterator RelI);
-
void printDataDirectory(uint32_t Index, const std::string &FieldName);
-
void printX64UnwindInfo();
+ template <class PEHeader> void printPEHeader(const PEHeader *Hdr);
+ void printBaseOfDataField(const pe32_header *Hdr);
+ void printBaseOfDataField(const pe32plus_header *Hdr);
+
void printRuntimeFunction(
const RuntimeFunction& RTF,
uint64_t OffsetInSection,
@@ -599,56 +600,70 @@ void COFFDumper::printFileHeaders() {
const pe32_header *PEHeader = 0;
if (error(Obj->getPE32Header(PEHeader)))
return;
+ if (PEHeader)
+ printPEHeader<pe32_header>(PEHeader);
- if (PEHeader) {
- DictScope D(W, "ImageOptionalHeader");
- W.printNumber("MajorLinkerVersion", PEHeader->MajorLinkerVersion);
- W.printNumber("MinorLinkerVersion", PEHeader->MinorLinkerVersion);
- W.printNumber("SizeOfCode", PEHeader->SizeOfCode);
- W.printNumber("SizeOfInitializedData", PEHeader->SizeOfInitializedData);
- W.printNumber("SizeOfUninitializedData", PEHeader->SizeOfUninitializedData);
- W.printHex ("AddressOfEntryPoint", PEHeader->AddressOfEntryPoint);
- W.printHex ("BaseOfCode", PEHeader->BaseOfCode);
- W.printHex ("BaseOfData", PEHeader->BaseOfData);
- W.printHex ("ImageBase", PEHeader->ImageBase);
- W.printNumber("SectionAlignment", PEHeader->SectionAlignment);
- W.printNumber("FileAlignment", PEHeader->FileAlignment);
- W.printNumber("MajorOperatingSystemVersion",
- PEHeader->MajorOperatingSystemVersion);
- W.printNumber("MinorOperatingSystemVersion",
- PEHeader->MinorOperatingSystemVersion);
- W.printNumber("MajorImageVersion", PEHeader->MajorImageVersion);
- W.printNumber("MinorImageVersion", PEHeader->MinorImageVersion);
- W.printNumber("MajorSubsystemVersion", PEHeader->MajorSubsystemVersion);
- W.printNumber("MinorSubsystemVersion", PEHeader->MinorSubsystemVersion);
- W.printNumber("SizeOfImage", PEHeader->SizeOfImage);
- W.printNumber("SizeOfHeaders", PEHeader->SizeOfHeaders);
- W.printEnum ("Subsystem", PEHeader->Subsystem,
- makeArrayRef(PEWindowsSubsystem));
- W.printFlags ("Subsystem", PEHeader->DLLCharacteristics,
- makeArrayRef(PEDLLCharacteristics));
- W.printNumber("SizeOfStackReserve", PEHeader->SizeOfStackReserve);
- W.printNumber("SizeOfStackCommit", PEHeader->SizeOfStackCommit);
- W.printNumber("SizeOfHeapReserve", PEHeader->SizeOfHeapReserve);
- W.printNumber("SizeOfHeapCommit", PEHeader->SizeOfHeapCommit);
- W.printNumber("NumberOfRvaAndSize", PEHeader->NumberOfRvaAndSize);
-
- if (PEHeader->NumberOfRvaAndSize > 0) {
- DictScope D(W, "DataDirectory");
- static const char * const directory[] = {
- "ExportTable", "ImportTable", "ResourceTable", "ExceptionTable",
- "CertificateTable", "BaseRelocationTable", "Debug", "Architecture",
- "GlobalPtr", "TLSTable", "LoadConfigTable", "BoundImport", "IAT",
- "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"
- };
-
- for (uint32_t i = 0; i < PEHeader->NumberOfRvaAndSize; ++i) {
- printDataDirectory(i, directory[i]);
- }
+ const pe32plus_header *PEPlusHeader = 0;
+ if (error(Obj->getPE32PlusHeader(PEPlusHeader)))
+ return;
+ if (PEPlusHeader)
+ printPEHeader<pe32plus_header>(PEPlusHeader);
+}
+
+template <class PEHeader>
+void COFFDumper::printPEHeader(const PEHeader *Hdr) {
+ DictScope D(W, "ImageOptionalHeader");
+ W.printNumber("MajorLinkerVersion", Hdr->MajorLinkerVersion);
+ W.printNumber("MinorLinkerVersion", Hdr->MinorLinkerVersion);
+ W.printNumber("SizeOfCode", Hdr->SizeOfCode);
+ W.printNumber("SizeOfInitializedData", Hdr->SizeOfInitializedData);
+ W.printNumber("SizeOfUninitializedData", Hdr->SizeOfUninitializedData);
+ W.printHex ("AddressOfEntryPoint", Hdr->AddressOfEntryPoint);
+ W.printHex ("BaseOfCode", Hdr->BaseOfCode);
+ printBaseOfDataField(Hdr);
+ W.printHex ("ImageBase", Hdr->ImageBase);
+ W.printNumber("SectionAlignment", Hdr->SectionAlignment);
+ W.printNumber("FileAlignment", Hdr->FileAlignment);
+ W.printNumber("MajorOperatingSystemVersion",
+ Hdr->MajorOperatingSystemVersion);
+ W.printNumber("MinorOperatingSystemVersion",
+ Hdr->MinorOperatingSystemVersion);
+ W.printNumber("MajorImageVersion", Hdr->MajorImageVersion);
+ W.printNumber("MinorImageVersion", Hdr->MinorImageVersion);
+ W.printNumber("MajorSubsystemVersion", Hdr->MajorSubsystemVersion);
+ W.printNumber("MinorSubsystemVersion", Hdr->MinorSubsystemVersion);
+ W.printNumber("SizeOfImage", Hdr->SizeOfImage);
+ W.printNumber("SizeOfHeaders", Hdr->SizeOfHeaders);
+ W.printEnum ("Subsystem", Hdr->Subsystem, makeArrayRef(PEWindowsSubsystem));
+ W.printFlags ("Subsystem", Hdr->DLLCharacteristics,
+ makeArrayRef(PEDLLCharacteristics));
+ W.printNumber("SizeOfStackReserve", Hdr->SizeOfStackReserve);
+ W.printNumber("SizeOfStackCommit", Hdr->SizeOfStackCommit);
+ W.printNumber("SizeOfHeapReserve", Hdr->SizeOfHeapReserve);
+ W.printNumber("SizeOfHeapCommit", Hdr->SizeOfHeapCommit);
+ W.printNumber("NumberOfRvaAndSize", Hdr->NumberOfRvaAndSize);
+
+ if (Hdr->NumberOfRvaAndSize > 0) {
+ DictScope D(W, "DataDirectory");
+ static const char * const directory[] = {
+ "ExportTable", "ImportTable", "ResourceTable", "ExceptionTable",
+ "CertificateTable", "BaseRelocationTable", "Debug", "Architecture",
+ "GlobalPtr", "TLSTable", "LoadConfigTable", "BoundImport", "IAT",
+ "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"
+ };
+
+ for (uint32_t i = 0; i < Hdr->NumberOfRvaAndSize; ++i) {
+ printDataDirectory(i, directory[i]);
}
}
}
+void COFFDumper::printBaseOfDataField(const pe32_header *Hdr) {
+ W.printHex("BaseOfData", Hdr->BaseOfData);
+}
+
+void COFFDumper::printBaseOfDataField(const pe32plus_header *) {}
+
void COFFDumper::printCodeViewLineTables(section_iterator SecI) {
StringRef Data;
if (error(SecI->getContents(Data))) return;