[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
This commit is contained in:
Hans Wennborg
2025-05-22 09:31:35 +02:00
committed by GitHub
parent 1f5b6ae89f
commit 213d0d2233

View File

@@ -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,14 @@ 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; "
"the maximum total is {2} bytes.",
PSH->RecordByteSize, GSH->RecordByteSize, UINT32_MAX),
inconvertibleErrorCode());
Idx = Msf.addStream(RecordBytes);
if (!Idx)