Skip to content

Commit 7eb889a

Browse files
authored
[LLD][COFF] Display the size of all consumed inputs with /summary (#157279)
When `/summary` is used, we now also display the cumulative size of all input OBJ files, including those pulled from archives. Lazy OBJ files that were not pulled in are not accounted for. Also added separators between digit groups, to make the output more bearable. Example output: ``` > lld-link ... /summary Summary -------------------------------------------------------------------------------- 4,958 Input OBJ files (expanded from all cmd-line inputs) 46,715,790,512 Size of all consumed OBJ files (non-lazy), in bytes 42 PDB type server dependencies 0 Precomp OBJ dependencies 293,910,064 Input type records 16,931,361,928 Size of all input type records, in bytes 11,201,549 Merged TPI records 2,765,494 Merged IPI records 38,649 Output PDB strings 21,512,230 Global symbol records 82,380,837 Module symbol records 715,313 Public symbol records ``` We skip over the exact amounts for "Size of all consumed inputs (non-lazy)" in the unit tests, since the sizes of OBJ files can fluctuate between compilers.
1 parent 9da02e7 commit 7eb889a

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

lld/COFF/COFFLinkerContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class COFFLinkerContext : public CommonLinkerContext {
6161
std::vector<ObjFile *> objFileInstances;
6262
std::map<std::string, PDBInputFile *> pdbInputFileInstances;
6363
std::vector<ImportFile *> importFileInstances;
64+
std::int64_t consumedInputsSize = 0;
6465

6566
MergeChunk *mergeChunkInstances[Log2MaxSectionAlignment + 1] = {};
6667

lld/COFF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void LinkerDriver::addFile(InputFile *file) {
205205
else
206206
cast<ObjFile>(file)->parseLazy();
207207
} else {
208+
ctx.consumedInputsSize += file->mb.getBufferSize();
208209
file->parse();
209210
if (auto *f = dyn_cast<ObjFile>(file)) {
210211
ctx.objFileInstances.push_back(f);

lld/COFF/PDB.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Object/CVDebugRecord.h"
4545
#include "llvm/Support/CRC.h"
4646
#include "llvm/Support/Endian.h"
47+
#include "llvm/Support/FormatAdapters.h"
4748
#include "llvm/Support/FormatVariadic.h"
4849
#include "llvm/Support/Path.h"
4950
#include "llvm/Support/ScopedPrinter.h"
@@ -1247,15 +1248,19 @@ void PDBLinker::printStats() {
12471248
<< std::string(80, '-') << '\n';
12481249

12491250
auto print = [&](uint64_t v, StringRef s) {
1250-
stream << format_decimal(v, 15) << " " << s << '\n';
1251+
stream << formatv("{0}",
1252+
fmt_align(formatv("{0:N}", v), AlignStyle::Right, 20))
1253+
<< " " << s << '\n';
12511254
};
12521255

12531256
print(ctx.objFileInstances.size(),
12541257
"Input OBJ files (expanded from all cmd-line inputs)");
1258+
print(ctx.consumedInputsSize,
1259+
"Size of all consumed OBJ files (non-lazy), in bytes");
12551260
print(ctx.typeServerSourceMappings.size(), "PDB type server dependencies");
12561261
print(ctx.precompSourceMappings.size(), "Precomp OBJ dependencies");
12571262
print(nbTypeRecords, "Input type records");
1258-
print(nbTypeRecordsBytes, "Input type records bytes");
1263+
print(nbTypeRecordsBytes, "Size of all input type records, in bytes");
12591264
print(builder.getTpiBuilder().getRecordCount(), "Merged TPI records");
12601265
print(builder.getIpiBuilder().getRecordCount(), "Merged IPI records");
12611266
print(pdbStrTab.size(), "Output PDB strings");

lld/test/COFF/pdb-type-server-simple.test

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,18 @@ CHECK-LABEL: Mod 0002 | `* Linker *`:
106106

107107
SUMMARY: Summary
108108
SUMMARY-NEXT: --------------------------------------------------------------------------------
109-
SUMMARY-NEXT: 2 Input OBJ files (expanded from all cmd-line inputs)
110-
SUMMARY-NEXT: 1 PDB type server dependencies
111-
SUMMARY-NEXT: 0 Precomp OBJ dependencies
112-
SUMMARY-NEXT: 25 Input type records
113-
SUMMARY-NEXT: 868 Input type records bytes
114-
SUMMARY-NEXT: 9 Merged TPI records
115-
SUMMARY-NEXT: 16 Merged IPI records
116-
SUMMARY-NEXT: 3 Output PDB strings
117-
SUMMARY-NEXT: 4 Global symbol records
118-
SUMMARY-NEXT: 14 Module symbol records
119-
SUMMARY-NEXT: 2 Public symbol records
109+
SUMMARY-NEXT: 2 Input OBJ files (expanded from all cmd-line inputs)
110+
SUMMARY-NEXT: Size of all consumed OBJ files (non-lazy), in bytes
111+
SUMMARY-NEXT: 1 PDB type server dependencies
112+
SUMMARY-NEXT: 0 Precomp OBJ dependencies
113+
SUMMARY-NEXT: 25 Input type records
114+
SUMMARY-NEXT: 868 Size of all input type records, in bytes
115+
SUMMARY-NEXT: 9 Merged TPI records
116+
SUMMARY-NEXT: 16 Merged IPI records
117+
SUMMARY-NEXT: 3 Output PDB strings
118+
SUMMARY-NEXT: 4 Global symbol records
119+
SUMMARY-NEXT: 14 Module symbol records
120+
SUMMARY-NEXT: 2 Public symbol records
120121

121122
SUMMARY: Top 10 types responsible for the most TPI input:
122123
SUMMARY-NEXT: index total bytes count size

lld/test/COFF/precomp-link-samename.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ CHECK-NOT: LF_ENDPRECOMP
1212

1313
SUMMARY: Summary
1414
SUMMARY-NEXT: --------------------------------------------------------------------------------
15-
SUMMARY-NEXT: 4 Input OBJ files (expanded from all cmd-line inputs)
16-
SUMMARY-NEXT: 0 PDB type server dependencies
17-
SUMMARY-NEXT: 2 Precomp OBJ dependencies
15+
SUMMARY-NEXT: 4 Input OBJ files (expanded from all cmd-line inputs)
16+
SUMMARY-NEXT: Size of all consumed OBJ files (non-lazy), in bytes
17+
SUMMARY-NEXT: 0 PDB type server dependencies
18+
SUMMARY-NEXT: 2 Precomp OBJ dependencies
1819

1920
// precompa/precomp.cpp
2021
#include "precomp.h"

lld/test/COFF/precomp-link.test

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ CHECK-NOT: LF_ENDPRECOMP
5959

6060
SUMMARY: Summary
6161
SUMMARY-NEXT: --------------------------------------------------------------------------------
62-
SUMMARY-NEXT: 3 Input OBJ files (expanded from all cmd-line inputs)
63-
SUMMARY-NEXT: 0 PDB type server dependencies
64-
SUMMARY-NEXT: 1 Precomp OBJ dependencies
65-
SUMMARY-NEXT: 1066 Input type records
66-
SUMMARY-NEXT: 55968 Input type records bytes
67-
SUMMARY-NEXT: 874 Merged TPI records
68-
SUMMARY-NEXT: 170 Merged IPI records
69-
SUMMARY-NEXT: 5 Output PDB strings
70-
SUMMARY-NEXT: 167 Global symbol records
71-
SUMMARY-NEXT: 20 Module symbol records
72-
SUMMARY-NEXT: 3 Public symbol records
62+
SUMMARY-NEXT: 3 Input OBJ files (expanded from all cmd-line inputs)
63+
SUMMARY-NEXT: Size of all consumed OBJ files (non-lazy), in bytes
64+
SUMMARY-NEXT: 0 PDB type server dependencies
65+
SUMMARY-NEXT: 1 Precomp OBJ dependencies
66+
SUMMARY-NEXT: 1,066 Input type records
67+
SUMMARY-NEXT: 55,968 Size of all input type records, in bytes
68+
SUMMARY-NEXT: 874 Merged TPI records
69+
SUMMARY-NEXT: 170 Merged IPI records
70+
SUMMARY-NEXT: 5 Output PDB strings
71+
SUMMARY-NEXT: 167 Global symbol records
72+
SUMMARY-NEXT: 20 Module symbol records
73+
SUMMARY-NEXT: 3 Public symbol records
7374

7475
// precomp.h
7576
#pragma once

lld/test/COFF/precomp-summary-fail.test

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ RUN: /dll /out:%t.dll /debug /summary | FileCheck %s -check-prefix SUMMARY
1111

1212
SUMMARY: Summary
1313
SUMMARY-NEXT: --------------------------------------------------------------------------------
14-
SUMMARY-NEXT: 2 Input OBJ files (expanded from all cmd-line inputs)
15-
SUMMARY-NEXT: 0 PDB type server dependencies
16-
SUMMARY-NEXT: 1 Precomp OBJ dependencies
17-
SUMMARY-NEXT: 8 Input type records
18-
SUMMARY-NEXT: 232 Input type records bytes
19-
SUMMARY-NEXT: 3 Merged TPI records
20-
SUMMARY-NEXT: 2 Merged IPI records
21-
SUMMARY-NEXT: 1 Output PDB strings
22-
SUMMARY-NEXT: 0 Global symbol records
23-
SUMMARY-NEXT: 4 Module symbol records
24-
SUMMARY-NEXT: 0 Public symbol records
14+
SUMMARY-NEXT: 2 Input OBJ files (expanded from all cmd-line inputs)
15+
SUMMARY-NEXT: Size of all consumed OBJ files (non-lazy), in bytes
16+
SUMMARY-NEXT: 0 PDB type server dependencies
17+
SUMMARY-NEXT: 1 Precomp OBJ dependencies
18+
SUMMARY-NEXT: 8 Input type records
19+
SUMMARY-NEXT: 232 Size of all input type records, in bytes
20+
SUMMARY-NEXT: 3 Merged TPI records
21+
SUMMARY-NEXT: 2 Merged IPI records
22+
SUMMARY-NEXT: 1 Output PDB strings
23+
SUMMARY-NEXT: 0 Global symbol records
24+
SUMMARY-NEXT: 4 Module symbol records
25+
SUMMARY-NEXT: 0 Public symbol records

0 commit comments

Comments
 (0)