[lld] r185308 - [PECOFF][Writer] Do not emit the empty section as Windows loader rejects such executable.
Rui Ueyama
ruiu at google.com
Mon Jul 1 00:32:13 PDT 2013
Author: ruiu
Date: Mon Jul 1 02:32:12 2013
New Revision: 185308
URL: http://llvm.org/viewvc/llvm-project?rev=185308&view=rev
Log:
[PECOFF][Writer] Do not emit the empty section as Windows loader rejects such executable.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/hello.test
lld/trunk/test/pecoff/trivial.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=185308&r1=185307&r2=185308&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Mon Jul 1 02:32:12 2013
@@ -438,6 +438,11 @@ void SectionHeaderTableChunk::write(uint
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);
@@ -525,8 +530,12 @@ private:
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);
}
}
Modified: lld/trunk/test/pecoff/hello.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/hello.test?rev=185308&r1=185307&r2=185308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/hello.test (original)
+++ lld/trunk/test/pecoff/hello.test Mon Jul 1 02:32:12 2013
@@ -25,22 +25,6 @@ CHECK: ]
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
Modified: lld/trunk/test/pecoff/trivial.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/trivial.test?rev=185308&r1=185307&r2=185308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/trivial.test (original)
+++ lld/trunk/test/pecoff/trivial.test Mon Jul 1 02:32:12 2013
@@ -10,7 +10,7 @@ FILE: Arch: i386
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
@@ -78,37 +78,4 @@ SECTIONS: IMAGE_SCN_MEM_EXECUTE (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: ]
More information about the llvm-commits
mailing list