[llvm] [pdb] Provide a better error message when overflowing the public/global symbol record stream (PR #140884)

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 05:08:22 PDT 2025


https://github.com/zmodem updated https://github.com/llvm/llvm-project/pull/140884

>From 37914e798385c81bc4a426b9ae842af823918e2f Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Wed, 21 May 2025 13:58:01 +0200
Subject: [PATCH 1/2] [pdb] Provide a better error message when overflowing the
 public/global symbol record stream

Before:

  lld-link: error: Stream Error: The stream is too short to perform the requested operation.
  lld-link: error: failed to write PDB file ./unit_tests.exe.pdb

After:

  lld-link: error: the public (2127832912 bytes) and global (2200532960 bytes) symbols are too large to fit in a PDB file.
  lld-link: error: failed to write PDB file ./unit_tests.exe.pdb
---
 llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
index c195754c0c679..0289a7543205a 100644
--- a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
@@ -25,6 +25,7 @@
 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
 #include "llvm/Support/BinaryItemStream.h"
 #include "llvm/Support/BinaryStreamWriter.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Parallel.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
@@ -39,7 +40,7 @@ using namespace llvm::codeview;
 // Helper class for building the public and global PDB hash table buckets.
 struct llvm::pdb::GSIHashStreamBuilder {
   // Sum of the size of all public or global records.
-  uint32_t RecordByteSize = 0;
+  uint64_t RecordByteSize = 0;
 
   std::vector<PSHashRecord> HashRecords;
 
@@ -319,7 +320,11 @@ Error GSIStreamBuilder::finalizeMsfLayout() {
     return Idx.takeError();
   PublicsStreamIndex = *Idx;
 
-  uint32_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
+  uint64_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
+  if (RecordBytes > UINT32_MAX)
+    return make_error<StringError>(formatv("the public ({0} bytes) and global "
+          "({1} bytes) symbols are too large to fit in a PDB file.",
+          PSH->RecordByteSize, GSH->RecordByteSize), inconvertibleErrorCode());
 
   Idx = Msf.addStream(RecordBytes);
   if (!Idx)

>From a16712c6b24e501b4e97fc035051c5f7a277f342 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Wed, 21 May 2025 14:07:11 +0200
Subject: [PATCH 2/2] format

---
 llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
index 0289a7543205a..92b521e31d482 100644
--- a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
@@ -322,9 +322,11 @@ Error GSIStreamBuilder::finalizeMsfLayout() {
 
   uint64_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
   if (RecordBytes > UINT32_MAX)
-    return make_error<StringError>(formatv("the public ({0} bytes) and global "
-          "({1} bytes) symbols are too large to fit in a PDB file.",
-          PSH->RecordByteSize, GSH->RecordByteSize), inconvertibleErrorCode());
+    return make_error<StringError>(
+        formatv("the public ({0} bytes) and global ({1} bytes) "
+                "symbols are too large to fit in a PDB file.",
+                PSH->RecordByteSize, GSH->RecordByteSize),
+        inconvertibleErrorCode());
 
   Idx = Msf.addStream(RecordBytes);
   if (!Idx)



More information about the llvm-commits mailing list