Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -500,8 +500,8 @@ createExportTable(); mergeSections(); readRelocTargets(); - finalizeAddresses(); removeEmptySections(); + finalizeAddresses(); setSectionPermissions(); createSymbolAndStringTable(); @@ -885,7 +885,12 @@ // The Windows loader doesn't seem to like empty sections, // so we remove them if any. void Writer::removeEmptySections() { - auto IsEmpty = [](OutputSection *S) { return S->getVirtualSize() == 0; }; + auto IsEmpty = [](OutputSection *S) { + for (Chunk *C : S->Chunks) + if (C->getSize() > 0) + return false; + return true; + }; OutputSections.erase( std::remove_if(OutputSections.begin(), OutputSections.end(), IsEmpty), OutputSections.end());