[lld] [lld][COFF] Emit coffgrp debug record (PR #205630)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 4 08:37:03 PDT 2026


================
@@ -3113,3 +3123,64 @@ void Writer::printSummary() {
 
   Msg(ctx) << buffer;
 }
+
+size_t COFFDebugRecordChunk::getSize() const {
+  size_t size = sizeof(uint32_t);
+  llvm::for_each(records, [&](auto &r) { size += r.size(); });
+  return size;
+}
+
+void COFFDebugRecordChunk::computeRecords() {
+  records.clear();
+  auto addRange = [](const auto &range, Chunk *end, StringRef name) {
+    bool hasData = false;
+    Chunk *last = nullptr;
+    for (auto *c : range) {
+      if (c == end)
+        break;
+      hasData |= c->getSize();
+      last = c;
+    }
+    return hasData ? COFFGrpRecord{*range.begin(), last, name}
+                   : COFFGrpRecord{nullptr, nullptr, ""};
+  };
+
+  for (OutputSection *os : ctx.outputSections) {
+    for (auto *sec : os->contribSections) {
+      COFFGrpRecord rec = addRange(sec->chunks, nullptr, sec->name);
+      if (!rec.first)
+        continue;
+      records.push_back(rec);
+    }
+    Chunk *lastChunk = records.empty() ? nullptr : records.back().last;
+    COFFGrpRecord lastRec =
+        addRange(llvm::reverse(os->chunks), lastChunk, os->name);
+    if (lastRec.first) {
+      std::swap(lastRec.first, lastRec.last);
+      records.push_back(lastRec);
+    }
+  }
+}
+
+void COFFDebugRecordChunk::writeTo(uint8_t *b) const {
+  bool is_pgo = llvm::any_of(records, [](auto &r) {
----------------
aganea wrote:

I think this part should be expanded and include all the other possible signatures. PGI, PGU and LTCG. Also I cannot seem to find in the wild any examples for a PGO signature. MSVC nowadays generates either PGI or PGU. PGO is only the overall name of the feature.

In essence what I'am saying is that we should tie the signature based on provenance, for example:
(Thin)LTO mode (`ctx.bitcodeFileInstances` non empty) -> LTCG
Module flag like @rnk [suggests here](https://github.com/llvm/llvm-project/pull/114260#discussion_r1852769032) -> PGI / PGU

https://github.com/llvm/llvm-project/pull/205630


More information about the llvm-commits mailing list