Index: COFF/PDB.cpp =================================================================== --- COFF/PDB.cpp +++ COFF/PDB.cpp @@ -1085,6 +1085,21 @@ EBS, Allocator, CodeViewContainer::Pdb)); } +static void addLinkerModuleCoffGroup(const Chunk *firstChunk, + const Chunk *lastChunk, + pdb::DbiModuleDescriptorBuilder &Mod, + OutputSection &OS, + BumpPtrAllocator &Allocator) { + CoffGroupSym CGS(SymbolRecordKind::CoffGroupSym); + CGS.Name = firstChunk->getSectionName(); + CGS.Segment = OS.SectionIndex; + CGS.Offset = firstChunk->getRVA() - OS.getRVA(); + CGS.Size = lastChunk->getRVA() + lastChunk->getSize() - firstChunk->getRVA(); + CGS.Characteristics = firstChunk->getOutputCharacteristics(); + Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol( + CGS, Allocator, CodeViewContainer::Pdb)); +} + static void addLinkerModuleSectionSymbol(pdb::DbiModuleDescriptorBuilder &Mod, OutputSection &OS, BumpPtrAllocator &Allocator) { @@ -1097,6 +1112,39 @@ Sym.SectionNumber = OS.SectionIndex; Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol( Sym, Allocator, CodeViewContainer::Pdb)); + + // Output COFF groups for individual chunks of this section. + // There may be several chunks with the same name (e.g. .text$di), but we only + // want to output each unique chunk once. + Chunk *firstChunkInSubSection = nullptr; + Chunk *lastChunkInSubSection = nullptr; + + for (Chunk *C : OS.getChunks()) { + auto *SecChunk = dyn_cast(C); + + // If this chunk doesn't represent an unmerged input file chunk, or it + // didn't contribute to the final output file, skip it. + if (!SecChunk || !SecChunk->isLive()) + continue; + + if (!firstChunkInSubSection) { + firstChunkInSubSection = C; + } + + if (C->getSectionName() != firstChunkInSubSection->getSectionName()) { + addLinkerModuleCoffGroup(firstChunkInSubSection, lastChunkInSubSection, + Mod, OS, Allocator); + + firstChunkInSubSection = C; + } + + lastChunkInSubSection = C; + } + + if (firstChunkInSubSection && lastChunkInSubSection) { + addLinkerModuleCoffGroup(firstChunkInSubSection, lastChunkInSubSection, Mod, + OS, Allocator); + } } // Creates a PDB file.