[llvm] [llvm-size] Fix --totals option for Mach-O files (PR #157904)

Ryan Mansfield via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 06:36:45 PDT 2025


================
@@ -852,16 +866,25 @@ static void printBerkeleyTotals() {
   std::string fmtbuf;
   raw_string_ostream fmt(fmtbuf);
   const char *radix_fmt = getRadixFmt();
-  fmt << "%#7" << radix_fmt << "\t"
-      << "%#7" << radix_fmt << "\t"
-      << "%#7" << radix_fmt << "\t";
-  outs() << format(fmtbuf.c_str(), TotalObjectText, TotalObjectData,
-                   TotalObjectBss);
-  fmtbuf.clear();
-  fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << "\t"
-      << "%7" PRIx64 "\t";
-  outs() << format(fmtbuf.c_str(), TotalObjectTotal, TotalObjectTotal)
-         << "(TOTALS)\n";
+
+  if (HasMachOFiles) {
----------------
rjmansfield wrote:

Hm, what would be the expected output for that? I imagine the total format should match the header printed, which currently varies based on the format of the first input file. Or how were you thinking the mixed formatting should be displayed? e.g without the change

```
% bin/llvm-size --totals  elf macho               
   text	   data	    bss	    dec	    hex	filename
   1277	    600	      1	   1878	    756	elf
16384	0	0	4295000064	4295016448	10000c000	macho
   1277	    600	      1	   1878	    756	(TOTALS)
% bin/llvm-size --totals  macho elf
__TEXT	__DATA	__OBJC	others	dec	hex
16384	0	0	4295000064	4295016448	10000c000	macho
   1277	    600	      1	   1878	    756	elf
   1277	    600	      1	   1878	    756	(TOTALS)
```


https://github.com/llvm/llvm-project/pull/157904


More information about the llvm-commits mailing list