[llvm] 4aa4a6d - [PDB] Correctly read/write the named stream map's niMac value (#225729)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 04:21:52 PDT 2026


Author: Hans Wennborg
Date: 2026-09-24T13:21:45+02:00
New Revision: 4aa4a6d9e82dcef3e6a1c9ae249a144e60384f52

URL: https://github.com/llvm/llvm-project/commit/4aa4a6d9e82dcef3e6a1c9ae249a144e60384f52
DIFF: https://github.com/llvm/llvm-project/commit/4aa4a6d9e82dcef3e6a1c9ae249a144e60384f52.diff

LOG: [PDB] Correctly read/write the named stream map's niMac value (#225729)

The serialization of a PDB stream's named stream map ends with an
integer value, NMTNI::niMac in the microsoft-pdb code.

Since 05d5e6136f5a3f5de28ae64077200bbdc2cacfb4, LLVM was writing this
out as an undocumented zero between the named streams map and feature
codes, and reading it as an unknown/ignored feature code.

The actual value doesn't seem particularly important, but it's better to
read/write these explicitly, and it should not be read as a feature
code.

This fixes one of the issues in
https://github.com/llvm/llvm-project/issues/206120

Added: 
    

Modified: 
    llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
    llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
    llvm/test/DebugInfo/PDB/pdbdump-raw-bytes.test
    llvm/test/tools/llvm-pdbutil/explain-pdb-stream.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
index fa77ded0db7ff0..d5fa0776ed26c5 100644
--- a/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
@@ -47,7 +47,7 @@ void InfoStreamBuilder::setGuid(GUID G) { Guid = G; }
 Error InfoStreamBuilder::finalizeMsfLayout() {
   uint32_t Length = sizeof(InfoStreamHeader) +
                     NamedStreams.calculateSerializedLength() +
-                    (Features.size() + 1) * sizeof(uint32_t);
+                    Features.size() * sizeof(uint32_t);
   if (auto EC = Msf.setStreamSize(StreamPDB, Length))
     return EC;
   return Error::success();
@@ -70,8 +70,6 @@ Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout,
 
   if (auto EC = NamedStreams.commit(Writer))
     return EC;
-  if (auto EC = Writer.writeInteger(0))
-    return EC;
   for (auto E : Features) {
     if (auto EC = Writer.writeEnum(E))
       return EC;

diff  --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
index f5bed785b02b9c..900fbea943ac4d 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
@@ -56,7 +56,11 @@ Error NamedStreamMap::load(BinaryStreamReader &Stream) {
     return EC;
   NamesBuffer.assign(Buffer.begin(), Buffer.end());
 
-  return OffsetIndexMap.load(Stream);
+  if (auto EC = OffsetIndexMap.load(Stream))
+    return EC;
+
+  uint32_t NiMac;
+  return Stream.readInteger(NiMac);
 }
 
 Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const {
@@ -69,17 +73,22 @@ Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const {
   if (auto EC = Writer.writeFixedString(Data))
     return EC;
 
-  // And finally the Offset Index map.
+  // Followed by the Offset Index map.
   if (auto EC = OffsetIndexMap.commit(Writer))
     return EC;
 
+  // And finally the NMTNI::niMac value.
+  if (auto EC = Writer.writeInteger<uint32_t>(0))
+    return EC;
+
   return Error::success();
 }
 
 uint32_t NamedStreamMap::calculateSerializedLength() const {
-  return sizeof(uint32_t)                              // String data size
-         + NamesBuffer.size()                          // String data
-         + OffsetIndexMap.calculateSerializedLength(); // Offset Index Map
+  return sizeof(uint32_t)                             // String data size
+         + NamesBuffer.size()                         // String data
+         + OffsetIndexMap.calculateSerializedLength() // Offset Index Map
+         + sizeof(uint32_t);                          // NMTNI::niMac.
 }
 
 uint32_t NamedStreamMap::size() const { return OffsetIndexMap.size(); }

diff  --git a/llvm/test/DebugInfo/PDB/pdbdump-raw-bytes.test b/llvm/test/DebugInfo/PDB/pdbdump-raw-bytes.test
index 2cf6850221d5f5..647faf1cea245e 100644
--- a/llvm/test/DebugInfo/PDB/pdbdump-raw-bytes.test
+++ b/llvm/test/DebugInfo/PDB/pdbdump-raw-bytes.test
@@ -21,5 +21,5 @@ NAME-MAP-NEXT: ============================================================
 NAME-MAP-NEXT:   Named Stream Map (
 NAME-MAP-NEXT:     1301C: 22000000 2F4C696E 6B496E66 6F002F6E 616D6573 002F7372 632F6865 61646572  |".../LinkInfo./names./src/header|
 NAME-MAP-NEXT:     1303C: 626C6F63 6B000300 00000600 00000100 00001A00 00000000 00001100 00000900  |block...........................|
-NAME-MAP-NEXT:     1305C: 00000A00 00000D00 00000000 00000500 0000                                 |..................|
+NAME-MAP-NEXT:     1305C: 00000A00 00000D00 00000000 00000500 00000000 0000                        |......................|
 NAME-MAP-NEXT:   )

diff  --git a/llvm/test/tools/llvm-pdbutil/explain-pdb-stream.test b/llvm/test/tools/llvm-pdbutil/explain-pdb-stream.test
index a55382105a7371..a2aa108ae27252 100644
--- a/llvm/test/tools/llvm-pdbutil/explain-pdb-stream.test
+++ b/llvm/test/tools/llvm-pdbutil/explain-pdb-stream.test
@@ -45,4 +45,4 @@ CHECK:      Block:Offset = 11:001C.
 CHECK-NEXT: Address is in block 17 (allocated).
 CHECK-NEXT:   Address is at offset 28/202 of Stream 1 (PDB Stream).
 CHECK-NEXT:   Within the PDB stream:
-CHECK-NEXT:     address is at offset 0/166 of the Named Stream Map.
+CHECK-NEXT:     address is at offset 0/170 of the Named Stream Map.


        


More information about the llvm-commits mailing list