@@ -52,6 +52,10 @@ static cl::opt<OutputFormatTy> OutputFormatShort(
52
52
53
53
static bool BerkeleyHeaderPrinted = false ;
54
54
static bool MoreThanOneFile = false ;
55
+ static uint64_t TotalObjectText = 0 ;
56
+ static uint64_t TotalObjectData = 0 ;
57
+ static uint64_t TotalObjectBss = 0 ;
58
+ static uint64_t TotalObjectTotal = 0 ;
55
59
56
60
cl::opt<bool >
57
61
DarwinLongFormat (" l" , cl::desc(" When format is darwin, use long format "
@@ -81,6 +85,14 @@ RadixShort(cl::desc("Print size in radix:"),
81
85
clEnumValEnd),
82
86
cl::init(decimal));
83
87
88
+ static cl::opt<bool >
89
+ TotalSizes (" totals" ,
90
+ cl::desc (" Print totals of all objects - Berkeley format only" ),
91
+ cl::init(false ));
92
+
93
+ static cl::alias TotalSizesShort (" t" , cl::desc(" Short for --totals" ),
94
+ cl::aliasopt(TotalSizes));
95
+
84
96
static cl::list<std::string>
85
97
InputFilenames (cl::Positional, cl::desc(" <input files>" ), cl::ZeroOrMore);
86
98
@@ -108,7 +120,7 @@ static bool error(Twine Message) {
108
120
109
121
// This version of error() prints the archive name and member name, for example:
110
122
// "libx.a(foo.o)" after the ToolName before the error message. It sets
111
- // HadError but returns allowing the code to move on to other archive members.
123
+ // HadError but returns allowing the code to move on to other archive members.
112
124
static void error (llvm::Error E, StringRef FileName, const Archive::Child &C,
113
125
StringRef ArchitectureName = StringRef()) {
114
126
HadError = true ;
@@ -136,7 +148,7 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
136
148
137
149
// This version of error() prints the file name and which architecture slice it // is from, for example: "foo.o (for architecture i386)" after the ToolName
138
150
// before the error message. It sets HadError but returns allowing the code to
139
- // move on to other architecture slices.
151
+ // move on to other architecture slices.
140
152
static void error (llvm::Error E, StringRef FileName,
141
153
StringRef ArchitectureName = StringRef()) {
142
154
HadError = true ;
@@ -462,6 +474,13 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
462
474
463
475
total = total_text + total_data + total_bss;
464
476
477
+ if (TotalSizes) {
478
+ TotalObjectText += total_text;
479
+ TotalObjectData += total_data;
480
+ TotalObjectBss += total_bss;
481
+ TotalObjectTotal += total;
482
+ }
483
+
465
484
if (!BerkeleyHeaderPrinted) {
466
485
outs () << " text data bss "
467
486
<< (Radix == octal ? " oct" : " dec" ) << " hex filename\n " ;
@@ -821,6 +840,22 @@ static void printFileSectionSizes(StringRef file) {
821
840
outs () << " \n " ;
822
841
}
823
842
843
+ static void printBerkelyTotals () {
844
+ std::string fmtbuf;
845
+ raw_string_ostream fmt (fmtbuf);
846
+ const char *radix_fmt = getRadixFmt ();
847
+ fmt << " %#7" << radix_fmt << " "
848
+ << " %#7" << radix_fmt << " "
849
+ << " %#7" << radix_fmt << " " ;
850
+ outs () << format (fmt.str ().c_str (), TotalObjectText, TotalObjectData,
851
+ TotalObjectBss);
852
+ fmtbuf.clear ();
853
+ fmt << " %7" << (Radix == octal ? PRIo64 : PRIu64) << " "
854
+ << " %7" PRIx64 " " ;
855
+ outs () << format (fmt.str ().c_str (), TotalObjectTotal, TotalObjectTotal)
856
+ << " (TOTALS)\n " ;
857
+ }
858
+
824
859
int main (int argc, char **argv) {
825
860
// Print a stack trace if we signal out.
826
861
sys::PrintStackTraceOnErrorSignal (argv[0 ]);
@@ -853,6 +888,8 @@ int main(int argc, char **argv) {
853
888
MoreThanOneFile = InputFilenames.size () > 1 ;
854
889
std::for_each (InputFilenames.begin (), InputFilenames.end (),
855
890
printFileSectionSizes);
891
+ if (OutputFormat == berkeley && TotalSizes)
892
+ printBerkelyTotals ();
856
893
857
894
if (HadError)
858
895
return 1 ;
0 commit comments