[PECOFF] Do not emit a section if it's empty.

The PE32+ loader does not seem to like an executable with an empty section, so
we should not emit a section if it's empty.

llvm-svn: 200514
This commit is contained in:
Rui Ueyama 2014-01-31 05:15:42 +00:00
parent ec3da87f82
commit ebc13c47f2
3 changed files with 4 additions and 20 deletions

View File

@ -932,7 +932,8 @@ void PECOFFWriter::build(const File &linkedFile) {
StringRef sectionName = i.first; StringRef sectionName = i.first;
std::vector<const DefinedAtom *> &contents = i.second; std::vector<const DefinedAtom *> &contents = i.second;
auto *section = new AtomChunk(_ctx, sectionName, contents); auto *section = new AtomChunk(_ctx, sectionName, contents);
addSectionChunk(section, sectionTable); if (section->size() > 0)
addSectionChunk(section, sectionTable);
} }
// Now that we know the addresses of all defined atoms that needs to be // Now that we know the addresses of all defined atoms that needs to be

View File

@ -9,7 +9,7 @@ CHECK-NEXT: Arch: x86_64
CHECK-NEXT: AddressSize: 64bit CHECK-NEXT: AddressSize: 64bit
CHECK-NEXT: ImageFileHeader { CHECK-NEXT: ImageFileHeader {
CHECK-NEXT: Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664) CHECK-NEXT: Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664)
CHECK-NEXT: SectionCount: 3 CHECK-NEXT: SectionCount: 2
CHECK-NEXT: TimeDateStamp: CHECK-NEXT: TimeDateStamp:
CHECK-NEXT: PointerToSymbolTable: 0x0 CHECK-NEXT: PointerToSymbolTable: 0x0
CHECK-NEXT: SymbolCount: 0 CHECK-NEXT: SymbolCount: 0

View File

@ -17,7 +17,7 @@ FILE-NEXT: Arch: i386
FILE-NEXT: AddressSize: 32bit FILE-NEXT: AddressSize: 32bit
FILE-NEXT: ImageFileHeader { FILE-NEXT: ImageFileHeader {
FILE-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C) FILE-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
FILE-NEXT: SectionCount: 2 FILE-NEXT: SectionCount: 1
FILE-NEXT: TimeDateStamp: FILE-NEXT: TimeDateStamp:
FILE-NEXT: PointerToSymbolTable: 0x0 FILE-NEXT: PointerToSymbolTable: 0x0
FILE-NEXT: SymbolCount: 0 FILE-NEXT: SymbolCount: 0
@ -66,23 +66,6 @@ SECTIONS-NEXT: AddressSize: 32bit
SECTIONS-NEXT: Sections [ SECTIONS-NEXT: Sections [
SECTIONS-NEXT: Section { SECTIONS-NEXT: Section {
SECTIONS-NEXT: Number: 1 SECTIONS-NEXT: Number: 1
SECTIONS-NEXT: Name: .data (2E 64 61 74 61 00 00 00)
SECTIONS-NEXT: VirtualSize: 0x0
SECTIONS-NEXT: VirtualAddress: 0x1000
SECTIONS-NEXT: RawDataSize: 0
SECTIONS-NEXT: PointerToRawData: 0x200
SECTIONS-NEXT: PointerToRelocations: 0x0
SECTIONS-NEXT: PointerToLineNumbers: 0x0
SECTIONS-NEXT: RelocationCount: 0
SECTIONS-NEXT: LineNumberCount: 0
SECTIONS-NEXT: Characteristics [
SECTIONS-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
SECTIONS-NEXT: IMAGE_SCN_MEM_READ
SECTIONS-NEXT: IMAGE_SCN_MEM_WRITE
SECTIONS-NEXT: ]
SECTIONS-NEXT: }
SECTIONS-NEXT: Section {
SECTIONS-NEXT: Number: 2
SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00) SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00)
SECTIONS-NEXT: VirtualSize: 0x6 SECTIONS-NEXT: VirtualSize: 0x6
SECTIONS-NEXT: VirtualAddress: 0x1000 SECTIONS-NEXT: VirtualAddress: 0x1000