llvm.org GIT mirror llvm / 9d13594
Revert "COFFDumper: Dump data directory entries." Because it broke s390x and ppc64-linux buildbots. This reverts commit r186623. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186627 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 7 years ago
5 changed file(s) with 48 addition(s) and 118 deletion(s). Raw diff Collapse all Expand all
197197 private:
198198 const coff_file_header *COFFHeader;
199199 const pe32_header *PE32Header;
200 const data_directory *DataDirectory;
201200 const coff_section *SectionTable;
202201 const coff_symbol *SymbolTable;
203202 const char *StringTable;
283282 error_code getHeader(const coff_file_header *&Res) const;
284283 error_code getCOFFHeader(const coff_file_header *&Res) const;
285284 error_code getPE32Header(const pe32_header *&Res) const;
286 error_code getDataDirectory(uint32_t index, const data_directory *&Res) const;
287285 error_code getSection(int32_t index, const coff_section *&Res) const;
288286 error_code getSymbol(uint32_t index, const coff_symbol *&Res) const;
289287 template
3636 return true;
3737 }
3838
39 // Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.
40 // Returns unexpected_eof if error.
41 template
42 error_code getObject(const T *&Obj, const MemoryBuffer *M, const uint8_t *Ptr,
43 const size_t Size = sizeof(T)) {
44 uintptr_t Addr = uintptr_t(Ptr);
45 if (Addr + Size < Addr ||
46 Addr + Size < Size ||
47 Addr + Size > uintptr_t(M->getBufferEnd())) {
48 return object_error::unexpected_eof;
49 }
50 Obj = reinterpret_cast(Addr);
51 return object_error::success;
39 // Returns false if any bytes in [addr, addr + size) fall outsize of m.
40 bool checkAddr(const MemoryBuffer *m,
41 error_code &ec,
42 uintptr_t addr,
43 uint64_t size) {
44 if (addr + size < addr ||
45 addr + size < size ||
46 addr + size > uintptr_t(m->getBufferEnd())) {
47 ec = object_error::unexpected_eof;
48 return false;
49 }
50 return true;
5251 }
5352 }
5453
432431 : ObjectFile(Binary::ID_COFF, Object)
433432 , COFFHeader(0)
434433 , PE32Header(0)
435 , DataDirectory(0)
436434 , SectionTable(0)
437435 , SymbolTable(0)
438436 , StringTable(0)
462460 hasPEHeader = true;
463461 }
464462
465 if ((ec = getObject(COFFHeader, Data, base() + CurPtr)))
463 COFFHeader = reinterpret_cast(base() + CurPtr);
464 if (!checkAddr(Data, ec, uintptr_t(COFFHeader), sizeof(coff_file_header)))
466465 return;
467466 CurPtr += sizeof(coff_file_header);
468467
469468 if (hasPEHeader) {
470 if ((ec = getObject(PE32Header, Data, base() + CurPtr)))
469 PE32Header = reinterpret_cast(base() + CurPtr);
470 if (!checkAddr(Data, ec, uintptr_t(PE32Header), sizeof(pe32_header)))
471471 return;
472 if (PE32Header->Magic != 0x10b) {
473 // We only support PE32. If this is PE32 (not PE32+), the magic byte
474 // should be 0x10b. If this is not PE32, continue as if there's no PE
475 // header in this file.
472 // We only support PE32. If this is PE32 (not PE32+), the magic byte
473 // should be 0x10b. If this is not PE32, continue as if there's no PE
474 // header in this file.
475 if (PE32Header->Magic != 0x10b)
476476 PE32Header = 0;
477 } else if (PE32Header->NumberOfRvaAndSize > 0) {
478 const uint8_t *addr = base() + CurPtr + sizeof(pe32_header);
479 uint64_t size = sizeof(data_directory) * PE32Header->NumberOfRvaAndSize;
480 if ((ec = getObject(DataDirectory, Data, addr, size)))
481 return;
482 }
477 // There may be optional data directory after PE header. Skip them.
483478 CurPtr += COFFHeader->SizeOfOptionalHeader;
484479 }
485480
486 if ((ec = getObject(SectionTable, Data, base() + CurPtr,
487 COFFHeader->NumberOfSections * sizeof(coff_section))))
481 SectionTable =
482 reinterpret_cast(base() + CurPtr);
483 if (!checkAddr(Data, ec, uintptr_t(SectionTable),
484 COFFHeader->NumberOfSections * sizeof(coff_section)))
488485 return;
489486
490487 if (COFFHeader->PointerToSymbolTable != 0) {
491 if ((ec = getObject(SymbolTable, Data,
492 base() + COFFHeader->PointerToSymbolTable,
493 COFFHeader->NumberOfSymbols * sizeof(coff_symbol))))
488 SymbolTable =
489 reinterpret_cast(base()
490 + COFFHeader->PointerToSymbolTable);
491 if (!checkAddr(Data, ec, uintptr_t(SymbolTable),
492 COFFHeader->NumberOfSymbols * sizeof(coff_symbol)))
494493 return;
495494
496495 // Find string table.
497 const uint8_t *StringTableAddr = base() + COFFHeader->PointerToSymbolTable
498 + COFFHeader->NumberOfSymbols * sizeof(coff_symbol);
499 const uint32_t *StringTableSizePtr;
500 if ((ec = getObject(StringTableSizePtr, Data, StringTableAddr)))
496 StringTable = reinterpret_cast(base())
497 + COFFHeader->PointerToSymbolTable
498 + COFFHeader->NumberOfSymbols * sizeof(coff_symbol);
499 if (!checkAddr(Data, ec, uintptr_t(StringTable), sizeof(ulittle32_t)))
501500 return;
502 StringTableSize = *StringTableSizePtr;
503 if ((ec = getObject(StringTable, Data, StringTableAddr, StringTableSize)))
501
502 StringTableSize = *reinterpret_cast(StringTable);
503 if (!checkAddr(Data, ec, uintptr_t(StringTable), StringTableSize))
504504 return;
505
506505 // Check that the string table is null terminated if has any in it.
507506 if (StringTableSize < 4
508507 || (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) {
604603
605604 error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const {
606605 Res = PE32Header;
607 return object_error::success;
608 }
609
610 error_code COFFObjectFile::getDataDirectory(uint32_t index,
611 const data_directory *&Res) const {
612 // Error if if there's no data directory or the index is out of range.
613 if (!DataDirectory || index > PE32Header->NumberOfRvaAndSize)
614 return object_error::parse_failed;
615 Res = &DataDirectory[index];
616606 return object_error::success;
617607 }
618608
106106 PE32-NEXT: AddressSize: 32bit
107107 PE32-NEXT: ImageFileHeader {
108108 PE32-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
109 PE32-NEXT: SectionCount: 3
110 PE32-NEXT: TimeDateStamp: 2013-07-16 00:39:15 (0x51E49633)
109 PE32-NEXT: SectionCount: 1
110 PE32-NEXT: TimeDateStamp: 2013-05-24 21:24:34 (0x519FDA92)
111111 PE32-NEXT: PointerToSymbolTable: 0x0
112112 PE32-NEXT: SymbolCount: 0
113113 PE32-NEXT: OptionalHeaderSize: 224
117117 PE32-NEXT: ]
118118 PE32-NEXT: }
119119 PE32-NEXT: ImageOptionalHeader {
120 PE32-NEXT: MajorLinkerVersion: 11
120 PE32-NEXT: MajorLinkerVersion: 10
121121 PE32-NEXT: MinorLinkerVersion: 0
122122 PE32-NEXT: SizeOfCode: 512
123 PE32-NEXT: SizeOfInitializedData: 1024
123 PE32-NEXT: SizeOfInitializedData: 0
124124 PE32-NEXT: SizeOfUninitializedData: 0
125125 PE32-NEXT: AddressOfEntryPoint: 0x1000
126126 PE32-NEXT: BaseOfCode: 0x1000
128128 PE32-NEXT: ImageBase: 0x400000
129129 PE32-NEXT: SectionAlignment: 4096
130130 PE32-NEXT: FileAlignment: 512
131 PE32-NEXT: MajorOperatingSystemVersion: 6
132 PE32-NEXT: MinorOperatingSystemVersion: 0
131 PE32-NEXT: MajorOperatingSystemVersion: 5
132 PE32-NEXT: MinorOperatingSystemVersion: 1
133133 PE32-NEXT: MajorImageVersion: 0
134134 PE32-NEXT: MinorImageVersion: 0
135 PE32-NEXT: MajorSubsystemVersion: 6
136 PE32-NEXT: MinorSubsystemVersion: 0
137 PE32-NEXT: SizeOfImage: 16384
138 PE32-NEXT: SizeOfHeaders: 1024
139 PE32-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
135 PE32-NEXT: MajorSubsystemVersion: 5
136 PE32-NEXT: MinorSubsystemVersion: 1
137 PE32-NEXT: SizeOfImage: 8192
138 PE32-NEXT: SizeOfHeaders: 512
139 PE32-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI (0x2)
140140 PE32-NEXT: Subsystem [ (0x8140)
141141 PE32-NEXT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40)
142142 PE32-NEXT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100)
147147 PE32-NEXT: SizeOfHeapReserve: 1048576
148148 PE32-NEXT: SizeOfHeapCommit: 4096
149149 PE32-NEXT: NumberOfRvaAndSize: 16
150 PE32-NEXT: DataDirectory {
151 PE32-NEXT: ExportTableRVA: 0x0
152 PE32-NEXT: ExportTableSize: 0x0
153 PE32-NEXT: ImportTableRVA: 0x0
154 PE32-NEXT: ImportTableSize: 0x0
155 PE32-NEXT: ResourceTableRVA: 0x0
156 PE32-NEXT: ResourceTableSize: 0x0
157 PE32-NEXT: ExceptionTableRVA: 0x0
158 PE32-NEXT: ExceptionTableSize: 0x0
159 PE32-NEXT: CertificateTableRVA: 0x0
160 PE32-NEXT: CertificateTableSize: 0x0
161 PE32-NEXT: BaseRelocationTableRVA: 0x3000
162 PE32-NEXT: BaseRelocationTableSize: 0xC
163 PE32-NEXT: DebugRVA: 0x0
164 PE32-NEXT: DebugSize: 0x0
165 PE32-NEXT: ArchitectureRVA: 0x0
166 PE32-NEXT: ArchitectureSize: 0x0
167 PE32-NEXT: GlobalPtrRVA: 0x0
168 PE32-NEXT: GlobalPtrSize: 0x0
169 PE32-NEXT: TLSTableRVA: 0x0
170 PE32-NEXT: TLSTableSize: 0x0
171 PE32-NEXT: LoadConfigTableRVA: 0x0
172 PE32-NEXT: LoadConfigTableSize: 0x0
173 PE32-NEXT: BoundImportRVA: 0x0
174 PE32-NEXT: BoundImportSize: 0x0
175 PE32-NEXT: IATRVA: 0x0
176 PE32-NEXT: IATSize: 0x0
177 PE32-NEXT: DelayImportDescriptorRVA: 0x0
178 PE32-NEXT: DelayImportDescriptorSize: 0x0
179 PE32-NEXT: CLRRuntimeHeaderRVA: 0x0
180 PE32-NEXT: CLRRuntimeHeaderSize: 0x0
181 PE32-NEXT: ReservedRVA: 0x0
182 PE32-NEXT: ReservedSize: 0x0
183 PE32-NEXT: }
184150 PE32-NEXT: }
5858 void printSymbol(symbol_iterator SymI);
5959
6060 void printRelocation(section_iterator SecI, relocation_iterator RelI);
61
62 void printDataDirectory(uint32_t Index, const std::string &FieldName);
6361
6462 void printX64UnwindInfo();
6563
561559 }
562560 }
563561
564 void COFFDumper::printDataDirectory(uint32_t Index, const std::string &FieldName) {
565 const data_directory *Data;
566 if (Obj->getDataDirectory(Index, Data))
567 return;
568 W.printHex(FieldName + "RVA", Data->RelativeVirtualAddress);
569 W.printHex(FieldName + "Size", Data->Size);
570 }
571
572562 void COFFDumper::printFileHeaders() {
573563 // Print COFF header
574564 const coff_file_header *COFFHeader = 0;
630620 W.printNumber("SizeOfHeapReserve", PEHeader->SizeOfHeapReserve);
631621 W.printNumber("SizeOfHeapCommit", PEHeader->SizeOfHeapCommit);
632622 W.printNumber("NumberOfRvaAndSize", PEHeader->NumberOfRvaAndSize);
633
634 if (PEHeader->NumberOfRvaAndSize > 0) {
635 DictScope D(W, "DataDirectory");
636 static const char * const directory[] = {
637 "ExportTable", "ImportTable", "ResourceTable", "ExceptionTable",
638 "CertificateTable", "BaseRelocationTable", "Debug", "Architecture",
639 "GlobalPtr", "TLSTable", "LoadConfigTable", "BoundImport", "IAT",
640 "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved"
641 };
642
643 for (uint32_t i = 0; i < PEHeader->NumberOfRvaAndSize; ++i) {
644 printDataDirectory(i, directory[i]);
645 }
646 }
647623 }
648624 }
649625