[llvm] 605a503 - [lld-link] emit an error when writing a PDB > 4 GiB

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 17 12:15:18 PDT 2021


Author: Nico Weber
Date: 2021-03-17T15:15:08-04:00
New Revision: 605a503f35063daf9ff264592caee713e85571e4

URL: https://github.com/llvm/llvm-project/commit/605a503f35063daf9ff264592caee713e85571e4
DIFF: https://github.com/llvm/llvm-project/commit/605a503f35063daf9ff264592caee713e85571e4.diff

LOG: [lld-link] emit an error when writing a PDB > 4 GiB

Maybe there's a way to make them work, but until I've investigated
if tools can consume large PDBs, erroring out is better than slowly
and silently consuming all available ram due to internal invariants
being violated.

(Patch to make writing larger files work at
https://bugs.chromium.org/p/chromium/issues/detail?id=1179085#c25
but I haven't had time to check if windbg & co can consume these
large PDBs. llvm-pdbutil can't, but we can fix that one at least :) )

Differential Revision: https://reviews.llvm.org/D98788

Added: 
    

Modified: 
    llvm/lib/DebugInfo/MSF/MSFBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/MSF/MSFBuilder.cpp b/llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
index f946dd4860ac..a02b9ea9e35b 100644
--- a/llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
+++ b/llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
@@ -341,7 +341,17 @@ Expected<FileBufferByteStream> MSFBuilder::commit(StringRef Path,
 
   Layout = std::move(*L);
 
-  uint64_t FileSize = Layout.SB->BlockSize * Layout.SB->NumBlocks;
+  uint64_t FileSize = uint64_t(Layout.SB->BlockSize) * Layout.SB->NumBlocks;
+  if (FileSize > UINT32_MAX) {
+    // FIXME: Changing the BinaryStream classes to use 64-bit numbers lets
+    // us create PDBs larger than 4 GiB successfully. The file format is
+    // block-based and as long as each stream is small enough, PDBs larger than
+    // 4 GiB might work. Check if tools can handle these large PDBs, and if so
+    // add support for writing them.
+    return make_error<MSFError>(msf_error_code::invalid_format,
+                                "Output larger than 4 GiB");
+  }
+
   auto OutFileOrError = FileOutputBuffer::create(Path, FileSize);
   if (auto EC = OutFileOrError.takeError())
     return std::move(EC);


        


More information about the llvm-commits mailing list