Skip to content

Commit ac2226b

Browse files
committed
[PDB] Improve error handling when writes fail
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%) Differential Revision: https://reviews.llvm.org/D102713
1 parent f9ea3eb commit ac2226b

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

lld/COFF/PDB.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,13 @@ void PDBLinker::addSections(ArrayRef<OutputSection *> outputSections,
16481648
}
16491649

16501650
void PDBLinker::commit(codeview::GUID *guid) {
1651-
ExitOnError exitOnErr((config->pdbPath + ": ").str());
1652-
// Write to a file.
1653-
exitOnErr(builder.commit(config->pdbPath, guid));
1651+
// Print an error and continue if PDB writing fails. This is done mainly so
1652+
// the user can see the output of /time and /summary, which is very helpful
1653+
// when trying to figure out why a PDB file is too large.
1654+
if (Error e = builder.commit(config->pdbPath, guid)) {
1655+
checkError(std::move(e));
1656+
error("failed to write PDB file " + Twine(config->pdbPath));
1657+
}
16541658
}
16551659

16561660
static uint32_t getSecrelReloc() {

llvm/include/llvm/DebugInfo/MSF/MSFError.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace msf {
1818
enum class msf_error_code {
1919
unspecified = 1,
2020
insufficient_buffer,
21+
size_overflow,
2122
not_writable,
2223
no_stream,
2324
invalid_format,

llvm/lib/DebugInfo/MSF/MSFBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Support/Endian.h"
1616
#include "llvm/Support/Error.h"
1717
#include "llvm/Support/FileOutputBuffer.h"
18+
#include "llvm/Support/FormatVariadic.h"
1819
#include <algorithm>
1920
#include <cassert>
2021
#include <cstdint>
@@ -348,8 +349,9 @@ Expected<FileBufferByteStream> MSFBuilder::commit(StringRef Path,
348349
// block-based and as long as each stream is small enough, PDBs larger than
349350
// 4 GiB might work. Check if tools can handle these large PDBs, and if so
350351
// add support for writing them.
351-
return make_error<MSFError>(msf_error_code::invalid_format,
352-
"Output larger than 4 GiB");
352+
return make_error<MSFError>(
353+
msf_error_code::size_overflow,
354+
formatv("File size would have been {0,1:N}", FileSize));
353355
}
354356

355357
auto OutFileOrError = FileOutputBuffer::create(Path, FileSize);

llvm/lib/DebugInfo/MSF/MSFError.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class MSFErrorCategory : public std::error_category {
2727
case msf_error_code::insufficient_buffer:
2828
return "The buffer is not large enough to read the requested number of "
2929
"bytes.";
30+
case msf_error_code::size_overflow:
31+
return "Output data is larger than 4 GiB.";
3032
case msf_error_code::not_writable:
3133
return "The specified stream is not writable.";
3234
case msf_error_code::no_stream:

0 commit comments

Comments
 (0)