Skip to content

Commit 213d0d2

Browse files
authored
[pdb] Provide a better error message when overflowing the public/global symbol record stream (#140884)
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; the maximum total is 4294967295 bytes. lld-link: error: failed to write PDB file ./unit_tests.exe.pdb
1 parent 1f5b6ae commit 213d0d2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
2626
#include "llvm/Support/BinaryItemStream.h"
2727
#include "llvm/Support/BinaryStreamWriter.h"
28+
#include "llvm/Support/FormatVariadic.h"
2829
#include "llvm/Support/Parallel.h"
2930
#include "llvm/Support/TimeProfiler.h"
3031
#include "llvm/Support/xxhash.h"
@@ -39,7 +40,7 @@ using namespace llvm::codeview;
3940
// Helper class for building the public and global PDB hash table buckets.
4041
struct llvm::pdb::GSIHashStreamBuilder {
4142
// Sum of the size of all public or global records.
42-
uint32_t RecordByteSize = 0;
43+
uint64_t RecordByteSize = 0;
4344

4445
std::vector<PSHashRecord> HashRecords;
4546

@@ -319,7 +320,14 @@ Error GSIStreamBuilder::finalizeMsfLayout() {
319320
return Idx.takeError();
320321
PublicsStreamIndex = *Idx;
321322

322-
uint32_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
323+
uint64_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
324+
if (RecordBytes > UINT32_MAX)
325+
return make_error<StringError>(
326+
formatv("the public ({0} bytes) and global ({1} bytes) "
327+
"symbols are too large to fit in a PDB file; "
328+
"the maximum total is {2} bytes.",
329+
PSH->RecordByteSize, GSH->RecordByteSize, UINT32_MAX),
330+
inconvertibleErrorCode());
323331

324332
Idx = Msf.addStream(RecordBytes);
325333
if (!Idx)

0 commit comments

Comments
 (0)