[llvm] [PDB] Correctly read/write the named stream map's niMac value (PR #225729)
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 01:00:31 PDT 2026
https://github.com/zmodem updated https://github.com/llvm/llvm-project/pull/225729
>From fdfa1cee49192a26cd85d311a11e1d5bbd69d674 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Wed, 23 Sep 2026 12:56:46 +0200
Subject: [PATCH 1/3] [PDB] Correctly read/write the named stream map's niMac
value
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.
---
.../PDB/Native/InfoStreamBuilder.cpp | 4 +---
.../DebugInfo/PDB/Native/NamedStreamMap.cpp | 19 ++++++++++++++-----
.../test/DebugInfo/PDB/pdbdump-raw-bytes.test | 2 +-
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
index fa77ded0db7ff..d5fa0776ed26c 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 f5bed785b02b9..abac6772f7eff 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(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
+ + 4; // 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 2cf6850221d5f..647faf1cea245 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: )
>From 14b453a976fdfc52aecdde682a6fe51d988c6ae6 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Wed, 23 Sep 2026 13:42:15 +0200
Subject: [PATCH 2/3] sizeof(uint32_t)
---
llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
index abac6772f7eff..0fc29d783ec46 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
@@ -88,7 +88,7 @@ uint32_t NamedStreamMap::calculateSerializedLength() const {
return sizeof(uint32_t) // String data size
+ NamesBuffer.size() // String data
+ OffsetIndexMap.calculateSerializedLength() // Offset Index Map
- + 4; // NMTNI::niMac.
+ + sizeof(uint32_t); // NMTNI::niMac.
}
uint32_t NamedStreamMap::size() const { return OffsetIndexMap.size(); }
>From e1190fcc66d5c22269e18e957668d87a96e5bd75 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Thu, 24 Sep 2026 09:59:37 +0200
Subject: [PATCH 3/3] nits
---
llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
index 0fc29d783ec46..900fbea943ac4 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
@@ -59,8 +59,8 @@ Error NamedStreamMap::load(BinaryStreamReader &Stream) {
if (auto EC = OffsetIndexMap.load(Stream))
return EC;
- uint32_t niMac;
- return Stream.readInteger(niMac);
+ uint32_t NiMac;
+ return Stream.readInteger(NiMac);
}
Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const {
@@ -78,7 +78,7 @@ Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const {
return EC;
// And finally the NMTNI::niMac value.
- if (auto EC = Writer.writeInteger(0))
+ if (auto EC = Writer.writeInteger<uint32_t>(0))
return EC;
return Error::success();
More information about the llvm-commits
mailing list