summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-02-19 03:53:11 +0000
committerRui Ueyama <ruiu@google.com>2014-02-19 03:53:11 +0000
commitb7e1ab795944263b663593085f7fee404f72475f (patch)
tree976a61779ab0ff43e9606c9d37db917397ee6825
parent3fd813ef423e23d7f57ed3784d423ca503cd3578 (diff)
downloadllvm-b7e1ab795944263b663593085f7fee404f72475f.tar.gz
llvm-b7e1ab795944263b663593085f7fee404f72475f.tar.bz2
llvm-b7e1ab795944263b663593085f7fee404f72475f.tar.xz
llvm-objdump/COFF: Print load configuration table.
Load Configuration Table may contain a pointer to SEH table. This patch is to print the offset to the table. Printing SEH table contents is a TODO. The layout of Layout Configuration Table is described in Microsoft PE/COFF Object File Format Spec, but the table's offset/size descriptions seems to be totally wrong, at least in revision 8.3 of the spec. I believe the table in this patch is the correct one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201638 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/COFF.h23
-rw-r--r--test/tools/llvm-objdump/Inputs/nop.exe.coff-i386bin7680 -> 6144 bytes
-rw-r--r--test/tools/llvm-objdump/coff-private-headers.test56
-rw-r--r--tools/llvm-objdump/COFFDump.cpp41
4 files changed, 116 insertions, 4 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index 264a851e85..6ce5490606 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -244,6 +244,29 @@ struct coff_aux_section_definition {
char Unused[3];
};
+struct coff_load_configuration32 {
+ support::ulittle32_t Characteristics;
+ support::ulittle32_t TimeDateStamp;
+ support::ulittle16_t MajorVersion;
+ support::ulittle16_t MinorVersion;
+ support::ulittle32_t GlobalFlagsClear;
+ support::ulittle32_t GlobalFlagsSet;
+ support::ulittle32_t CriticalSectionDefaultTimeout;
+ support::ulittle32_t DeCommitFreeBlockThreshold;
+ support::ulittle32_t DeCommitTotalFreeThreshold;
+ support::ulittle32_t LockPrefixTable;
+ support::ulittle32_t MaximumAllocationSize;
+ support::ulittle32_t VirtualMemoryThreshold;
+ support::ulittle32_t ProcessAffinityMask;
+ support::ulittle32_t ProcessHeapFlags;
+ support::ulittle16_t CSDVersion;
+ char Reserved[4];
+ support::ulittle32_t EditList;
+ support::ulittle32_t SecurityCookie;
+ support::ulittle32_t SEHandlerTable;
+ support::ulittle32_t SEHandlerCount;
+};
+
class COFFObjectFile : public ObjectFile {
private:
friend class ImportDirectoryEntryRef;
diff --git a/test/tools/llvm-objdump/Inputs/nop.exe.coff-i386 b/test/tools/llvm-objdump/Inputs/nop.exe.coff-i386
index 68c9d3db0f..2cda30ff3d 100644
--- a/test/tools/llvm-objdump/Inputs/nop.exe.coff-i386
+++ b/test/tools/llvm-objdump/Inputs/nop.exe.coff-i386
Binary files differ
diff --git a/test/tools/llvm-objdump/coff-private-headers.test b/test/tools/llvm-objdump/coff-private-headers.test
index de3de9001d..24d1b96cfc 100644
--- a/test/tools/llvm-objdump/coff-private-headers.test
+++ b/test/tools/llvm-objdump/coff-private-headers.test
@@ -1,11 +1,37 @@
// RUN: llvm-objdump -p %p/Inputs/nop.exe.coff-i386 | \
// RUN: FileCheck -check-prefix=IMPORT %s
-IMPORT: The Import Tables:
-IMPORT-NEXT: lookup 00005028 time 00000000 fwd 00000000 name 00005096 addr 00005058
-IMPORT: DLL Name: KERNEL32.dll
+IMPORT: The Import Tables:
+IMPORT: lookup 000021e4 time 00000000 fwd 00000000 name 0000234a addr 00002024
+IMPORT: DLL Name: MSVCR110.dll
IMPORT-NEXT: Hint/Ord Name
-IMPORT-NEXT: 365 ExitProcess
+IMPORT-NEXT: 767 _initterm_e
+IMPORT-NEXT: 766 _initterm
+IMPORT-NEXT: 437 __initenv
+IMPORT-NEXT: 660 _fmode
+IMPORT-NEXT: 571 _commode
+IMPORT-NEXT: 315 ?terminate@@YAXXZ
+IMPORT-NEXT: 424 __crtSetUnhandledExceptionFilter
+IMPORT-NEXT: 892 _lock
+IMPORT-NEXT: 1254 _unlock
+IMPORT-NEXT: 498 __setusermatherr
+IMPORT-NEXT: 428 __dllonexit
+IMPORT-NEXT: 1058 _onexit
+IMPORT-NEXT: 774 _invoke_watson
+IMPORT-NEXT: 575 _controlfp_s
+IMPORT-NEXT: 624 _except_handler4_common
+IMPORT-NEXT: 587 _crt_debugger_hook
+IMPORT-NEXT: 426 __crtUnhandledException
+IMPORT-NEXT: 425 __crtTerminateProcess
+IMPORT-NEXT: 572 _configthreadlocale
+IMPORT-NEXT: 556 _cexit
+IMPORT-NEXT: 633 _exit
+IMPORT-NEXT: 1484 exit
+IMPORT-NEXT: 496 __set_app_type
+IMPORT-NEXT: 436 __getmainargs
+IMPORT-NEXT: 533 _amsg_exit
+IMPORT-NEXT: 555 _calloc_crt
+IMPORT-NEXT: 367 _XcptFilter
// RUN: llvm-objdump -p %p/Inputs/export.dll.coff-i386 | \
// RUN: FileCheck -check-prefix=EXPORT %s
@@ -16,3 +42,25 @@ EXPORT-NEXT: Ordinal base: 5
EXPORT-NEXT: Ordinal RVA Name
EXPORT-NEXT: 5 0x2008
EXPORT-NEXT: 6 0x2010 exportfn2
+
+// RUN: llvm-objdump -p %p/Inputs/nop.exe.coff-i386 | \
+// RUN: FileCheck -check-prefix=LOADCFG %s
+
+LOADCFG: Load configuration:
+LOADCFG-NEXT: Timestamp: 0
+LOADCFG-NEXT: Major Version: 0
+LOADCFG-NEXT: Minor Version: 0
+LOADCFG-NEXT: GlobalFlags Clear: 0
+LOADCFG-NEXT: GlobalFlags Set: 0
+LOADCFG-NEXT: Critical Section Default Timeout: 0
+LOADCFG-NEXT: Decommit Free Block Threshold: 0
+LOADCFG-NEXT: Decommit Total Free Threshold: 0
+LOADCFG-NEXT: Lock Prefix Table: 0
+LOADCFG-NEXT: Maximum Allocation Size: 0
+LOADCFG-NEXT: Virtual Memory Threshold: 0
+LOADCFG-NEXT: Process Affinity Mask: 0
+LOADCFG-NEXT: Process Heap Flags: 0
+LOADCFG-NEXT: CSD Version: 0
+LOADCFG-NEXT: Security Cookie: 554696768
+LOADCFG-NEXT: SEH Table: 65600
+LOADCFG-NEXT: SEH Count: 0
diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp
index f6f0f15197..883786d4f6 100644
--- a/tools/llvm-objdump/COFFDump.cpp
+++ b/tools/llvm-objdump/COFFDump.cpp
@@ -233,6 +233,46 @@ static void printCOFFSymbolAddress(llvm::raw_ostream &Out,
Out << format(" + 0x%04x", Disp);
}
+static void printLoadConfiguration(const COFFObjectFile *Obj) {
+ const coff_file_header *Header;
+ if (error(Obj->getCOFFHeader(Header)))
+ return;
+ // Currently only x86 is supported
+ if (Header->Machine != COFF::IMAGE_FILE_MACHINE_I386)
+ return;
+
+ const data_directory *DataDir;
+ if (error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir)))
+ return;
+ uintptr_t IntPtr = 0;
+ if (DataDir->RelativeVirtualAddress == 0)
+ return;
+ if (error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr)))
+ return;
+ const coff_load_configuration32 *LoadConf =
+ reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
+
+ outs() << "Load configuration:"
+ << "\n Timestamp: " << LoadConf->TimeDateStamp
+ << "\n Major Version: " << LoadConf->MajorVersion
+ << "\n Minor Version: " << LoadConf->MinorVersion
+ << "\n GlobalFlags Clear: " << LoadConf->GlobalFlagsClear
+ << "\n GlobalFlags Set: " << LoadConf->GlobalFlagsSet
+ << "\n Critical Section Default Timeout: " << LoadConf->CriticalSectionDefaultTimeout
+ << "\n Decommit Free Block Threshold: " << LoadConf->DeCommitFreeBlockThreshold
+ << "\n Decommit Total Free Threshold: " << LoadConf->DeCommitTotalFreeThreshold
+ << "\n Lock Prefix Table: " << LoadConf->LockPrefixTable
+ << "\n Maximum Allocation Size: " << LoadConf->MaximumAllocationSize
+ << "\n Virtual Memory Threshold: " << LoadConf->VirtualMemoryThreshold
+ << "\n Process Affinity Mask: " << LoadConf->ProcessAffinityMask
+ << "\n Process Heap Flags: " << LoadConf->ProcessHeapFlags
+ << "\n CSD Version: " << LoadConf->CSDVersion
+ << "\n Security Cookie: " << LoadConf->SecurityCookie
+ << "\n SEH Table: " << LoadConf->SEHandlerTable
+ << "\n SEH Count: " << LoadConf->SEHandlerCount
+ << "\n\n";
+}
+
// Prints import tables. The import table is a table containing the list of
// DLL name and symbol names which will be linked by the loader.
static void printImportTables(const COFFObjectFile *Obj) {
@@ -431,6 +471,7 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) {
const COFFObjectFile *file = dyn_cast<const COFFObjectFile>(Obj);
+ printLoadConfiguration(file);
printImportTables(file);
printExportTable(file);
}