diff --git a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp index c195754c0c67..8d684ab0aaf6 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 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( + 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)