[PATCH] D102713: [PDB] Improve error handling when writes fail

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 18 12:37:08 PDT 2021


rnk created this revision.
rnk added reviewers: thakis, hans, aganea.
Herald added a subscriber: hiraditya.
rnk requested review of this revision.
Herald added a project: LLVM.

Handle PDB writing errors like any other error in LLD: emit an error and
continue. This allows the linker to print timing data and summary data
after linking, which can be helpful for finding PDB size problems. Also
report how large the file would have been.

Example output:

lld-link: error: Output data is larger than 4 GiB. File size would have been 6,937,108,480
lld-link: error: failed to write PDB file ./chrome.dll.pdb

  Summary

--------------------------------------------------------------------------------

     33282 Input OBJ files (expanded from all cmd-line inputs)
         4 PDB type server dependencies
         0 Precomp OBJ dependencies
  33396931 Input type records

... snip ...

  Input File Reading:           59756 ms ( 45.5%)
  GC:                            7500 ms (  5.7%)
  ICF:                           3336 ms (  2.5%)
  Code Layout:                   6329 ms (  4.8%)
  PDB Emission (Cumulative):    46192 ms ( 35.2%)
    Add Objects:                27609 ms ( 21.0%)
      Type Merging:             16740 ms ( 12.8%)
      Symbol Merging:           10761 ms (  8.2%)
    Publics Stream Layout:       9383 ms (  7.1%)
    TPI Stream Layout:           1678 ms (  1.3%)
    Commit to Disk:              3461 ms (  2.6%)

--------------------------------------------------

Total Link Time:               131244 ms (100.0%)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102713

Files:
  lld/COFF/PDB.cpp
  llvm/include/llvm/DebugInfo/MSF/MSFError.h
  llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
  llvm/lib/DebugInfo/MSF/MSFError.cpp


Index: llvm/lib/DebugInfo/MSF/MSFError.cpp
===================================================================
--- llvm/lib/DebugInfo/MSF/MSFError.cpp
+++ llvm/lib/DebugInfo/MSF/MSFError.cpp
@@ -27,6 +27,8 @@
     case msf_error_code::insufficient_buffer:
       return "The buffer is not large enough to read the requested number of "
              "bytes.";
+    case msf_error_code::size_overflow:
+      return "Output data is larger than 4 GiB.";
     case msf_error_code::not_writable:
       return "The specified stream is not writable.";
     case msf_error_code::no_stream:
Index: llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
===================================================================
--- llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
+++ llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
+#include "llvm/Support/FormatVariadic.h"
 #include <algorithm>
 #include <cassert>
 #include <cstdint>
@@ -348,8 +349,9 @@
     // 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");
+    return make_error<MSFError>(
+        msf_error_code::size_overflow,
+        formatv("File size would have been {0,1:N}", FileSize));
   }
 
   auto OutFileOrError = FileOutputBuffer::create(Path, FileSize);
Index: llvm/include/llvm/DebugInfo/MSF/MSFError.h
===================================================================
--- llvm/include/llvm/DebugInfo/MSF/MSFError.h
+++ llvm/include/llvm/DebugInfo/MSF/MSFError.h
@@ -18,6 +18,7 @@
 enum class msf_error_code {
   unspecified = 1,
   insufficient_buffer,
+  size_overflow,
   not_writable,
   no_stream,
   invalid_format,
Index: lld/COFF/PDB.cpp
===================================================================
--- lld/COFF/PDB.cpp
+++ lld/COFF/PDB.cpp
@@ -1648,9 +1648,13 @@
 }
 
 void PDBLinker::commit(codeview::GUID *guid) {
-  ExitOnError exitOnErr((config->pdbPath + ": ").str());
-  // Write to a file.
-  exitOnErr(builder.commit(config->pdbPath, guid));
+  // Print an error and continue if PDB writing fails. This is done mainly so
+  // the user can see the output of /time and /summary, which is very helpful
+  // when trying to figure out why a PDB file is too large.
+  if (Error e = builder.commit(config->pdbPath, guid)) {
+    checkError(std::move(e));
+    error("failed to write PDB file " + Twine(config->pdbPath));
+  }
 }
 
 static uint32_t getSecrelReloc() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102713.346246.patch
Type: text/x-patch
Size: 2709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/f3ebdfa7/attachment.bin>


More information about the llvm-commits mailing list