[PATCH] D49230: Add support for COFF groups in * Linker * compiland in PDB

Stefan Reinalter via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 18 03:20:10 PDT 2018


stefan_reinalter updated this revision to Diff 156035.
stefan_reinalter added a comment.

Updated diff to only contain formatted changes for new code.


https://reviews.llvm.org/D49230

Files:
  COFF/PDB.cpp


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<SectionChunk>(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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49230.156035.patch
Type: text/x-patch
Size: 2519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180718/d08233dc/attachment.bin>


More information about the llvm-commits mailing list