uint64_t offset = 0;
fileBuffer += fileOffset();
for (const auto &chunk : _sections) {
+ // Skip the empty section. Windows loader does not like a section
+ // of size zero and rejects such executable.
+ if (chunk->size() == 0)
+ continue;
+
const llvm::object::coff_section &header = chunk->getSectionHeader();
std::memcpy(fileBuffer + offset, &header, sizeof(header));
offset += sizeof(header);
uint32_t va = offset;
for (auto &cp : _chunks) {
if (SectionChunk *chunk = dyn_cast<SectionChunk>(&*cp)) {
- numSections++;
chunk->setVirtualAddress(va);
+
+ // Skip the empty section.
+ if (chunk->size() == 0)
+ continue;
+ numSections++;
va = llvm::RoundUpToAlignment(va + chunk->size(), PAGE_SIZE);
}
}
CHECK: }
CHECK: Section {
CHECK: Number: 2
-CHECK: Name: .rdata (2E 72 64 61 74 61 00 00)
-CHECK: VirtualSize: 0x0
-CHECK: VirtualAddress: 0x2000
-CHECK: RawDataSize: 0
-CHECK: PointerToRawData: 0x400
-CHECK: PointerToRelocations: 0x0
-CHECK: PointerToLineNumbers: 0x0
-CHECK: RelocationCount: 0
-CHECK: LineNumberCount: 0
-CHECK: Characteristics [ (0x40000040)
-CHECK: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
-CHECK: IMAGE_SCN_MEM_READ (0x40000000)
-CHECK: ]
-CHECK: }
-CHECK: Section {
-CHECK: Number: 3
CHECK: Name: .data (2E 64 61 74 61 00 00 00)
CHECK: VirtualSize: 0x18
CHECK: VirtualAddress: 0x2000
FILE: AddressSize: 32bit
FILE: ImageFileHeader {
FILE: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
-FILE: SectionCount: 3
+FILE: SectionCount: 1
FILE: TimeDateStamp:
FILE: PointerToSymbolTable: 0x0
FILE: SymbolCount: 0
SECTIONS: IMAGE_SCN_MEM_READ (0x40000000)
SECTIONS: ]
SECTIONS: }
-SECTIONS: Section {
-SECTIONS: Number: 2
-SECTIONS: Name: .rdata (2E 72 64 61 74 61 00 00)
-SECTIONS: VirtualSize: 0x0
-SECTIONS: VirtualAddress: 0x2000
-SECTIONS: RawDataSize: 0
-SECTIONS: PointerToRawData: 0x400
-SECTIONS: PointerToRelocations: 0x0
-SECTIONS: PointerToLineNumbers: 0x0
-SECTIONS: RelocationCount: 0
-SECTIONS: LineNumberCount: 0
-SECTIONS: Characteristics [ (0x40000040)
-SECTIONS: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
-SECTIONS: IMAGE_SCN_MEM_READ (0x40000000)
-SECTIONS: ]
-SECTIONS: }
-SECTIONS: Section {
-SECTIONS: Number: 3
-SECTIONS: Name: .data (2E 64 61 74 61 00 00 00)
-SECTIONS: VirtualSize: 0x0
-SECTIONS: VirtualAddress: 0x2000
-SECTIONS: RawDataSize: 0
-SECTIONS: PointerToRawData: 0x400
-SECTIONS: PointerToRelocations: 0x0
-SECTIONS: PointerToLineNumbers: 0x0
-SECTIONS: RelocationCount: 0
-SECTIONS: LineNumberCount: 0
-SECTIONS: Characteristics [ (0xC0000040)
-SECTIONS: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
-SECTIONS: IMAGE_SCN_MEM_READ (0x40000000)
-SECTIONS: IMAGE_SCN_MEM_WRITE (0x80000000)
-SECTIONS: ]
-SECTIONS: }
SECTIONS: ]