blob: 7b1b9c6f93ab9bd8e66b2917054f27fa9f54f7e4 [file] [log] [blame]
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001//===-- llvm-size.cpp - Print the size of each object section ---*- C++ -*-===//
Michael J. Spencerc4ad4662011-09-28 20:57:46 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This program is a utility that works like traditional Unix "size",
11// that is, it prints out the size of each section, and the total size of all
12// sections.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/ADT/APInt.h"
17#include "llvm/Object/Archive.h"
Kevin Enderby246a4602014-06-17 17:54:13 +000018#include "llvm/Object/MachO.h"
Kevin Enderby4b8fc282014-06-18 22:04:40 +000019#include "llvm/Object/MachOUniversal.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000020#include "llvm/Object/ObjectFile.h"
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000021#include "llvm/Support/Casting.h"
22#include "llvm/Support/CommandLine.h"
23#include "llvm/Support/FileSystem.h"
24#include "llvm/Support/Format.h"
25#include "llvm/Support/ManagedStatic.h"
26#include "llvm/Support/MemoryBuffer.h"
27#include "llvm/Support/PrettyStackTrace.h"
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000028#include "llvm/Support/Signals.h"
Chandler Carruth4d88a1c2012-12-04 10:44:52 +000029#include "llvm/Support/raw_ostream.h"
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000030#include <algorithm>
31#include <string>
Rafael Espindolaa6e9c3e2014-06-12 17:38:55 +000032#include <system_error>
Eugene Zelenkoffec81c2015-11-04 22:32:32 +000033
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000034using namespace llvm;
35using namespace object;
36
Kevin Enderby10769742014-07-01 22:26:31 +000037enum OutputFormatTy { berkeley, sysv, darwin };
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000038static cl::opt<OutputFormatTy>
Kevin Enderby10769742014-07-01 22:26:31 +000039OutputFormat("format", cl::desc("Specify output format"),
40 cl::values(clEnumVal(sysv, "System V format"),
41 clEnumVal(berkeley, "Berkeley format"),
42 clEnumVal(darwin, "Darwin -m format"), clEnumValEnd),
43 cl::init(berkeley));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000044
Kevin Enderby10769742014-07-01 22:26:31 +000045static cl::opt<OutputFormatTy> OutputFormatShort(
46 cl::desc("Specify output format"),
47 cl::values(clEnumValN(sysv, "A", "System V format"),
48 clEnumValN(berkeley, "B", "Berkeley format"),
49 clEnumValN(darwin, "m", "Darwin -m format"), clEnumValEnd),
50 cl::init(berkeley));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000051
Rafael Espindola1dc30a42016-02-09 21:35:14 +000052static bool BerkeleyHeaderPrinted = false;
53static bool MoreThanOneFile = false;
Kevin Enderby246a4602014-06-17 17:54:13 +000054
Kevin Enderby10769742014-07-01 22:26:31 +000055cl::opt<bool>
56DarwinLongFormat("l", cl::desc("When format is darwin, use long format "
57 "to include addresses and offsets."));
Kevin Enderby246a4602014-06-17 17:54:13 +000058
Kevin Enderbyafef4c92014-07-01 17:19:10 +000059static cl::list<std::string>
Kevin Enderby10769742014-07-01 22:26:31 +000060ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
61 cl::ZeroOrMore);
Kevin Enderbyafef4c92014-07-01 17:19:10 +000062bool ArchAll = false;
63
Kevin Enderby10769742014-07-01 22:26:31 +000064enum RadixTy { octal = 8, decimal = 10, hexadecimal = 16 };
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000065static cl::opt<unsigned int>
Kevin Enderby10769742014-07-01 22:26:31 +000066Radix("-radix", cl::desc("Print size in radix. Only 8, 10, and 16 are valid"),
67 cl::init(decimal));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000068
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000069static cl::opt<RadixTy>
Kevin Enderby10769742014-07-01 22:26:31 +000070RadixShort(cl::desc("Print size in radix:"),
71 cl::values(clEnumValN(octal, "o", "Print size in octal"),
72 clEnumValN(decimal, "d", "Print size in decimal"),
73 clEnumValN(hexadecimal, "x", "Print size in hexadecimal"),
74 clEnumValEnd),
75 cl::init(decimal));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000076
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000077static cl::list<std::string>
Kevin Enderby10769742014-07-01 22:26:31 +000078InputFilenames(cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000079
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000080static std::string ToolName;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000081
Rafael Espindola49a0e5e2016-02-09 21:32:56 +000082/// If ec is not success, print the error and return true.
Rafael Espindola4453e42942014-06-13 03:07:50 +000083static bool error(std::error_code ec) {
Kevin Enderby10769742014-07-01 22:26:31 +000084 if (!ec)
85 return false;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000086
Davide Italiano911eb312016-01-25 01:24:15 +000087 errs() << ToolName << ": error reading file: " << ec.message() << ".\n";
88 errs().flush();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000089 return true;
90}
91
Rafael Espindola49a0e5e2016-02-09 21:32:56 +000092/// Get the length of the string that represents @p num in Radix including the
93/// leading 0x or 0 for hexadecimal and octal respectively.
Andrew Trick7dc278d2011-09-29 01:22:31 +000094static size_t getNumLengthAsString(uint64_t num) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000095 APInt conv(64, num);
96 SmallString<32> result;
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000097 conv.toString(result, Radix, false, true);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000098 return result.size();
99}
100
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000101/// Return the printing format for the Radix.
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000102static const char *getRadixFmt() {
Kevin Enderby246a4602014-06-17 17:54:13 +0000103 switch (Radix) {
104 case octal:
105 return PRIo64;
106 case decimal:
107 return PRIu64;
108 case hexadecimal:
109 return PRIx64;
110 }
111 return nullptr;
112}
113
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000114/// Print the size of each Mach-O segment and section in @p MachO.
Kevin Enderby246a4602014-06-17 17:54:13 +0000115///
116/// This is when used when @c OutputFormat is darwin and produces the same
117/// output as darwin's size(1) -m output.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000118static void printDarwinSectionSizes(MachOObjectFile *MachO) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000119 std::string fmtbuf;
120 raw_string_ostream fmt(fmtbuf);
121 const char *radix_fmt = getRadixFmt();
122 if (Radix == hexadecimal)
123 fmt << "0x";
124 fmt << "%" << radix_fmt;
125
Kevin Enderby246a4602014-06-17 17:54:13 +0000126 uint32_t Filetype = MachO->getHeader().filetype;
Kevin Enderby246a4602014-06-17 17:54:13 +0000127
128 uint64_t total = 0;
Alexey Samsonovd319c4f2015-06-03 22:19:36 +0000129 for (const auto &Load : MachO->load_commands()) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000130 if (Load.C.cmd == MachO::LC_SEGMENT_64) {
131 MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
132 outs() << "Segment " << Seg.segname << ": "
133 << format(fmt.str().c_str(), Seg.vmsize);
134 if (DarwinLongFormat)
Kevin Enderby10769742014-07-01 22:26:31 +0000135 outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) << " fileoff "
136 << Seg.fileoff << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000137 outs() << "\n";
138 total += Seg.vmsize;
139 uint64_t sec_total = 0;
140 for (unsigned J = 0; J < Seg.nsects; ++J) {
141 MachO::section_64 Sec = MachO->getSection64(Load, J);
142 if (Filetype == MachO::MH_OBJECT)
143 outs() << "\tSection (" << format("%.16s", &Sec.segname) << ", "
144 << format("%.16s", &Sec.sectname) << "): ";
145 else
146 outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
147 outs() << format(fmt.str().c_str(), Sec.size);
148 if (DarwinLongFormat)
Kevin Enderby10769742014-07-01 22:26:31 +0000149 outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) << " offset "
150 << Sec.offset << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000151 outs() << "\n";
152 sec_total += Sec.size;
153 }
154 if (Seg.nsects != 0)
155 outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000156 } else if (Load.C.cmd == MachO::LC_SEGMENT) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000157 MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000158 uint64_t Seg_vmsize = Seg.vmsize;
Kevin Enderby246a4602014-06-17 17:54:13 +0000159 outs() << "Segment " << Seg.segname << ": "
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000160 << format(fmt.str().c_str(), Seg_vmsize);
Kevin Enderby246a4602014-06-17 17:54:13 +0000161 if (DarwinLongFormat)
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000162 outs() << " (vmaddr 0x" << format("%" PRIx32, Seg.vmaddr) << " fileoff "
Kevin Enderby10769742014-07-01 22:26:31 +0000163 << Seg.fileoff << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000164 outs() << "\n";
165 total += Seg.vmsize;
166 uint64_t sec_total = 0;
167 for (unsigned J = 0; J < Seg.nsects; ++J) {
168 MachO::section Sec = MachO->getSection(Load, J);
169 if (Filetype == MachO::MH_OBJECT)
170 outs() << "\tSection (" << format("%.16s", &Sec.segname) << ", "
171 << format("%.16s", &Sec.sectname) << "): ";
172 else
173 outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000174 uint64_t Sec_size = Sec.size;
175 outs() << format(fmt.str().c_str(), Sec_size);
Kevin Enderby246a4602014-06-17 17:54:13 +0000176 if (DarwinLongFormat)
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000177 outs() << " (addr 0x" << format("%" PRIx32, Sec.addr) << " offset "
Kevin Enderby10769742014-07-01 22:26:31 +0000178 << Sec.offset << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000179 outs() << "\n";
180 sec_total += Sec.size;
181 }
182 if (Seg.nsects != 0)
183 outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
184 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000185 }
186 outs() << "total " << format(fmt.str().c_str(), total) << "\n";
187}
188
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000189/// Print the summary sizes of the standard Mach-O segments in @p MachO.
Kevin Enderby246a4602014-06-17 17:54:13 +0000190///
191/// This is when used when @c OutputFormat is berkeley with a Mach-O file and
192/// produces the same output as darwin's size(1) default output.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000193static void printDarwinSegmentSizes(MachOObjectFile *MachO) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000194 uint64_t total_text = 0;
195 uint64_t total_data = 0;
196 uint64_t total_objc = 0;
197 uint64_t total_others = 0;
Alexey Samsonovd319c4f2015-06-03 22:19:36 +0000198 for (const auto &Load : MachO->load_commands()) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000199 if (Load.C.cmd == MachO::LC_SEGMENT_64) {
200 MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
201 if (MachO->getHeader().filetype == MachO::MH_OBJECT) {
202 for (unsigned J = 0; J < Seg.nsects; ++J) {
203 MachO::section_64 Sec = MachO->getSection64(Load, J);
204 StringRef SegmentName = StringRef(Sec.segname);
205 if (SegmentName == "__TEXT")
206 total_text += Sec.size;
207 else if (SegmentName == "__DATA")
208 total_data += Sec.size;
209 else if (SegmentName == "__OBJC")
210 total_objc += Sec.size;
211 else
212 total_others += Sec.size;
Kevin Enderby10769742014-07-01 22:26:31 +0000213 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000214 } else {
215 StringRef SegmentName = StringRef(Seg.segname);
216 if (SegmentName == "__TEXT")
217 total_text += Seg.vmsize;
218 else if (SegmentName == "__DATA")
219 total_data += Seg.vmsize;
220 else if (SegmentName == "__OBJC")
221 total_objc += Seg.vmsize;
222 else
223 total_others += Seg.vmsize;
224 }
Kevin Enderby10769742014-07-01 22:26:31 +0000225 } else if (Load.C.cmd == MachO::LC_SEGMENT) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000226 MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
227 if (MachO->getHeader().filetype == MachO::MH_OBJECT) {
228 for (unsigned J = 0; J < Seg.nsects; ++J) {
229 MachO::section Sec = MachO->getSection(Load, J);
230 StringRef SegmentName = StringRef(Sec.segname);
231 if (SegmentName == "__TEXT")
232 total_text += Sec.size;
233 else if (SegmentName == "__DATA")
234 total_data += Sec.size;
235 else if (SegmentName == "__OBJC")
236 total_objc += Sec.size;
237 else
238 total_others += Sec.size;
Kevin Enderby10769742014-07-01 22:26:31 +0000239 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000240 } else {
241 StringRef SegmentName = StringRef(Seg.segname);
242 if (SegmentName == "__TEXT")
243 total_text += Seg.vmsize;
244 else if (SegmentName == "__DATA")
245 total_data += Seg.vmsize;
246 else if (SegmentName == "__OBJC")
247 total_objc += Seg.vmsize;
248 else
249 total_others += Seg.vmsize;
250 }
251 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000252 }
253 uint64_t total = total_text + total_data + total_objc + total_others;
254
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000255 if (!BerkeleyHeaderPrinted) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000256 outs() << "__TEXT\t__DATA\t__OBJC\tothers\tdec\thex\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000257 BerkeleyHeaderPrinted = true;
Kevin Enderby246a4602014-06-17 17:54:13 +0000258 }
259 outs() << total_text << "\t" << total_data << "\t" << total_objc << "\t"
260 << total_others << "\t" << total << "\t" << format("%" PRIx64, total)
261 << "\t";
262}
263
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000264/// Print the size of each section in @p Obj.
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000265///
266/// The format used is determined by @c OutputFormat and @c Radix.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000267static void printObjectSectionSizes(ObjectFile *Obj) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000268 uint64_t total = 0;
269 std::string fmtbuf;
270 raw_string_ostream fmt(fmtbuf);
Kevin Enderby246a4602014-06-17 17:54:13 +0000271 const char *radix_fmt = getRadixFmt();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000272
Kevin Enderby246a4602014-06-17 17:54:13 +0000273 // If OutputFormat is darwin and we have a MachOObjectFile print as darwin's
274 // size(1) -m output, else if OutputFormat is darwin and not a Mach-O object
275 // let it fall through to OutputFormat berkeley.
276 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(Obj);
277 if (OutputFormat == darwin && MachO)
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000278 printDarwinSectionSizes(MachO);
Kevin Enderby246a4602014-06-17 17:54:13 +0000279 // If we have a MachOObjectFile and the OutputFormat is berkeley print as
280 // darwin's default berkeley format for Mach-O files.
281 else if (MachO && OutputFormat == berkeley)
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000282 printDarwinSegmentSizes(MachO);
Kevin Enderby246a4602014-06-17 17:54:13 +0000283 else if (OutputFormat == sysv) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000284 // Run two passes over all sections. The first gets the lengths needed for
285 // formatting the output. The second actually does the output.
286 std::size_t max_name_len = strlen("section");
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000287 std::size_t max_size_len = strlen("size");
288 std::size_t max_addr_len = strlen("addr");
Alexey Samsonov48803e52014-03-13 14:37:36 +0000289 for (const SectionRef &Section : Obj->sections()) {
Rafael Espindola80291272014-10-08 15:28:58 +0000290 uint64_t size = Section.getSize();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000291 total += size;
292
293 StringRef name;
Alexey Samsonov48803e52014-03-13 14:37:36 +0000294 if (error(Section.getName(name)))
295 return;
Rafael Espindola80291272014-10-08 15:28:58 +0000296 uint64_t addr = Section.getAddress();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000297 max_name_len = std::max(max_name_len, name.size());
Andrew Trick7dc278d2011-09-29 01:22:31 +0000298 max_size_len = std::max(max_size_len, getNumLengthAsString(size));
299 max_addr_len = std::max(max_addr_len, getNumLengthAsString(addr));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000300 }
301
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000302 // Add extra padding.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000303 max_name_len += 2;
304 max_size_len += 2;
305 max_addr_len += 2;
306
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000307 // Setup header format.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000308 fmt << "%-" << max_name_len << "s "
309 << "%" << max_size_len << "s "
310 << "%" << max_addr_len << "s\n";
311
312 // Print header
Kevin Enderby10769742014-07-01 22:26:31 +0000313 outs() << format(fmt.str().c_str(), static_cast<const char *>("section"),
314 static_cast<const char *>("size"),
315 static_cast<const char *>("addr"));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000316 fmtbuf.clear();
317
318 // Setup per section format.
319 fmt << "%-" << max_name_len << "s "
320 << "%#" << max_size_len << radix_fmt << " "
321 << "%#" << max_addr_len << radix_fmt << "\n";
322
323 // Print each section.
Alexey Samsonov48803e52014-03-13 14:37:36 +0000324 for (const SectionRef &Section : Obj->sections()) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000325 StringRef name;
Alexey Samsonov48803e52014-03-13 14:37:36 +0000326 if (error(Section.getName(name)))
327 return;
Rafael Espindola80291272014-10-08 15:28:58 +0000328 uint64_t size = Section.getSize();
329 uint64_t addr = Section.getAddress();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000330 std::string namestr = name;
331
Alexey Samsonov48803e52014-03-13 14:37:36 +0000332 outs() << format(fmt.str().c_str(), namestr.c_str(), size, addr);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000333 }
334
335 // Print total.
336 fmtbuf.clear();
337 fmt << "%-" << max_name_len << "s "
338 << "%#" << max_size_len << radix_fmt << "\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000339 outs() << format(fmt.str().c_str(), static_cast<const char *>("Total"),
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000340 total);
341 } else {
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000342 // The Berkeley format does not display individual section sizes. It
343 // displays the cumulative size for each section type.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000344 uint64_t total_text = 0;
345 uint64_t total_data = 0;
346 uint64_t total_bss = 0;
347
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000348 // Make one pass over the section table to calculate sizes.
Alexey Samsonov48803e52014-03-13 14:37:36 +0000349 for (const SectionRef &Section : Obj->sections()) {
Rafael Espindola80291272014-10-08 15:28:58 +0000350 uint64_t size = Section.getSize();
351 bool isText = Section.isText();
352 bool isData = Section.isData();
353 bool isBSS = Section.isBSS();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000354 if (isText)
355 total_text += size;
356 else if (isData)
357 total_data += size;
358 else if (isBSS)
359 total_bss += size;
360 }
361
362 total = total_text + total_data + total_bss;
363
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000364 if (!BerkeleyHeaderPrinted) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000365 outs() << " text data bss "
Kevin Enderby10769742014-07-01 22:26:31 +0000366 << (Radix == octal ? "oct" : "dec") << " hex filename\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000367 BerkeleyHeaderPrinted = true;
Kevin Enderby246a4602014-06-17 17:54:13 +0000368 }
369
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000370 // Print result.
371 fmt << "%#7" << radix_fmt << " "
372 << "%#7" << radix_fmt << " "
373 << "%#7" << radix_fmt << " ";
Kevin Enderby10769742014-07-01 22:26:31 +0000374 outs() << format(fmt.str().c_str(), total_text, total_data, total_bss);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000375 fmtbuf.clear();
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000376 fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << " "
377 << "%7" PRIx64 " ";
Kevin Enderby10769742014-07-01 22:26:31 +0000378 outs() << format(fmt.str().c_str(), total, total);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000379 }
380}
381
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000382/// Checks to see if the @p o ObjectFile is a Mach-O file and if it is and there
383/// is a list of architecture flags specified then check to make sure this
384/// Mach-O file is one of those architectures or all architectures was
385/// specificed. If not then an error is generated and this routine returns
386/// false. Else it returns true.
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000387static bool checkMachOAndArchFlags(ObjectFile *o, StringRef file) {
388 if (isa<MachOObjectFile>(o) && !ArchAll && ArchFlags.size() != 0) {
389 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
390 bool ArchFound = false;
391 MachO::mach_header H;
392 MachO::mach_header_64 H_64;
393 Triple T;
394 if (MachO->is64Bit()) {
395 H_64 = MachO->MachOObjectFile::getHeader64();
396 T = MachOObjectFile::getArch(H_64.cputype, H_64.cpusubtype);
397 } else {
398 H = MachO->MachOObjectFile::getHeader();
399 T = MachOObjectFile::getArch(H.cputype, H.cpusubtype);
400 }
401 unsigned i;
Kevin Enderby10769742014-07-01 22:26:31 +0000402 for (i = 0; i < ArchFlags.size(); ++i) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000403 if (ArchFlags[i] == T.getArchName())
404 ArchFound = true;
405 break;
406 }
407 if (!ArchFound) {
408 errs() << ToolName << ": file: " << file
409 << " does not contain architecture: " << ArchFlags[i] << ".\n";
410 return false;
411 }
412 }
413 return true;
414}
415
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000416/// Print the section sizes for @p file. If @p file is an archive, print the
417/// section sizes for each archive member.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000418static void printFileSectionSizes(StringRef file) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000419
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000420 // Attempt to open the binary.
Rafael Espindola48af1c22014-08-19 18:44:46 +0000421 ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
Rafael Espindola4453e42942014-06-13 03:07:50 +0000422 if (std::error_code EC = BinaryOrErr.getError()) {
Rafael Espindola63da2952014-01-15 19:37:43 +0000423 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000424 return;
425 }
Rafael Espindola48af1c22014-08-19 18:44:46 +0000426 Binary &Bin = *BinaryOrErr.get().getBinary();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000427
Rafael Espindola3f6481d2014-08-01 14:31:55 +0000428 if (Archive *a = dyn_cast<Archive>(&Bin)) {
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000429 // This is an archive. Iterate over each member and display its sizes.
Rafael Espindola23a97502014-01-21 16:09:45 +0000430 for (object::Archive::child_iterator i = a->child_begin(),
Kevin Enderby10769742014-07-01 22:26:31 +0000431 e = a->child_end();
432 i != e; ++i) {
Kevin Enderby7a969422015-11-05 19:24:56 +0000433 if (i->getError()) {
434 errs() << ToolName << ": " << file << ": " << i->getError().message()
435 << ".\n";
436 exit(1);
437 }
438 auto &c = i->get();
439 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
Rafael Espindolaae460022014-06-16 16:08:36 +0000440 if (std::error_code EC = ChildOrErr.getError()) {
441 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000442 continue;
443 }
Rafael Espindolaae460022014-06-16 16:08:36 +0000444 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000445 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000446 if (!checkMachOAndArchFlags(o, file))
447 return;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000448 if (OutputFormat == sysv)
Kevin Enderby10769742014-07-01 22:26:31 +0000449 outs() << o->getFileName() << " (ex " << a->getFileName() << "):\n";
450 else if (MachO && OutputFormat == darwin)
451 outs() << a->getFileName() << "(" << o->getFileName() << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000452 printObjectSectionSizes(o);
Kevin Enderby246a4602014-06-17 17:54:13 +0000453 if (OutputFormat == berkeley) {
454 if (MachO)
455 outs() << a->getFileName() << "(" << o->getFileName() << ")\n";
456 else
457 outs() << o->getFileName() << " (ex " << a->getFileName() << ")\n";
458 }
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000459 }
460 }
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000461 } else if (MachOUniversalBinary *UB =
Rafael Espindola3f6481d2014-08-01 14:31:55 +0000462 dyn_cast<MachOUniversalBinary>(&Bin)) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000463 // If we have a list of architecture flags specified dump only those.
464 if (!ArchAll && ArchFlags.size() != 0) {
465 // Look for a slice in the universal binary that matches each ArchFlag.
466 bool ArchFound;
Kevin Enderby10769742014-07-01 22:26:31 +0000467 for (unsigned i = 0; i < ArchFlags.size(); ++i) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000468 ArchFound = false;
469 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
470 E = UB->end_objects();
471 I != E; ++I) {
Kevin Enderby10769742014-07-01 22:26:31 +0000472 if (ArchFlags[i] == I->getArchTypeName()) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000473 ArchFound = true;
474 ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000475 if (UO) {
476 if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
477 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
478 if (OutputFormat == sysv)
479 outs() << o->getFileName() << " :\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000480 else if (MachO && OutputFormat == darwin) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000481 if (MoreThanOneFile || ArchFlags.size() > 1)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000482 outs() << o->getFileName() << " (for architecture "
483 << I->getArchTypeName() << "): \n";
484 }
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000485 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000486 if (OutputFormat == berkeley) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000487 if (!MachO || MoreThanOneFile || ArchFlags.size() > 1)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000488 outs() << o->getFileName() << " (for architecture "
489 << I->getArchTypeName() << ")";
490 outs() << "\n";
491 }
492 }
Rafael Espindola0bfe8282014-12-09 21:05:36 +0000493 } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
494 I->getAsArchive()) {
495 std::unique_ptr<Archive> &UA = *AOrErr;
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000496 // This is an archive. Iterate over each member and display its
Kevin Enderby10769742014-07-01 22:26:31 +0000497 // sizes.
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000498 for (object::Archive::child_iterator i = UA->child_begin(),
499 e = UA->child_end();
Kevin Enderby10769742014-07-01 22:26:31 +0000500 i != e; ++i) {
Kevin Enderby7a969422015-11-05 19:24:56 +0000501 if (std::error_code EC = i->getError()) {
502 errs() << ToolName << ": " << file << ": " << EC.message()
503 << ".\n";
504 exit(1);
505 }
506 auto &c = i->get();
507 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000508 if (std::error_code EC = ChildOrErr.getError()) {
509 errs() << ToolName << ": " << file << ": " << EC.message()
510 << ".\n";
511 continue;
512 }
513 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
514 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
515 if (OutputFormat == sysv)
516 outs() << o->getFileName() << " (ex " << UA->getFileName()
517 << "):\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000518 else if (MachO && OutputFormat == darwin)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000519 outs() << UA->getFileName() << "(" << o->getFileName()
Kevin Enderby10769742014-07-01 22:26:31 +0000520 << ")"
521 << " (for architecture " << I->getArchTypeName()
522 << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000523 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000524 if (OutputFormat == berkeley) {
525 if (MachO) {
526 outs() << UA->getFileName() << "(" << o->getFileName()
527 << ")";
528 if (ArchFlags.size() > 1)
Kevin Enderby10769742014-07-01 22:26:31 +0000529 outs() << " (for architecture " << I->getArchTypeName()
530 << ")";
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000531 outs() << "\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000532 } else
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000533 outs() << o->getFileName() << " (ex " << UA->getFileName()
534 << ")\n";
535 }
536 }
537 }
538 }
539 }
540 }
541 if (!ArchFound) {
542 errs() << ToolName << ": file: " << file
543 << " does not contain architecture" << ArchFlags[i] << ".\n";
544 return;
545 }
546 }
547 return;
548 }
549 // No architecture flags were specified so if this contains a slice that
550 // matches the host architecture dump only that.
551 if (!ArchAll) {
Kevin Enderby10769742014-07-01 22:26:31 +0000552 StringRef HostArchName = MachOObjectFile::getHostArch().getArchName();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000553 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
554 E = UB->end_objects();
555 I != E; ++I) {
Kevin Enderby10769742014-07-01 22:26:31 +0000556 if (HostArchName == I->getArchTypeName()) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000557 ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000558 if (UO) {
559 if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
560 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
561 if (OutputFormat == sysv)
562 outs() << o->getFileName() << " :\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000563 else if (MachO && OutputFormat == darwin) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000564 if (MoreThanOneFile)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000565 outs() << o->getFileName() << " (for architecture "
566 << I->getArchTypeName() << "):\n";
567 }
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000568 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000569 if (OutputFormat == berkeley) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000570 if (!MachO || MoreThanOneFile)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000571 outs() << o->getFileName() << " (for architecture "
572 << I->getArchTypeName() << ")";
573 outs() << "\n";
574 }
575 }
Rafael Espindola0bfe8282014-12-09 21:05:36 +0000576 } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
577 I->getAsArchive()) {
578 std::unique_ptr<Archive> &UA = *AOrErr;
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000579 // This is an archive. Iterate over each member and display its
580 // sizes.
581 for (object::Archive::child_iterator i = UA->child_begin(),
582 e = UA->child_end();
Kevin Enderby10769742014-07-01 22:26:31 +0000583 i != e; ++i) {
Kevin Enderby7a969422015-11-05 19:24:56 +0000584 if (std::error_code EC = i->getError()) {
585 errs() << ToolName << ": " << file << ": " << EC.message()
586 << ".\n";
587 exit(1);
588 }
589 auto &c = i->get();
590 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000591 if (std::error_code EC = ChildOrErr.getError()) {
592 errs() << ToolName << ": " << file << ": " << EC.message()
593 << ".\n";
594 continue;
595 }
596 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
597 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
598 if (OutputFormat == sysv)
599 outs() << o->getFileName() << " (ex " << UA->getFileName()
600 << "):\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000601 else if (MachO && OutputFormat == darwin)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000602 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
603 << " (for architecture " << I->getArchTypeName()
604 << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000605 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000606 if (OutputFormat == berkeley) {
607 if (MachO)
608 outs() << UA->getFileName() << "(" << o->getFileName()
609 << ")\n";
610 else
611 outs() << o->getFileName() << " (ex " << UA->getFileName()
612 << ")\n";
613 }
614 }
615 }
616 }
617 return;
618 }
619 }
620 }
621 // Either all architectures have been specified or none have been specified
622 // and this does not contain the host architecture so dump all the slices.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000623 bool MoreThanOneArch = UB->getNumberOfObjects() > 1;
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000624 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
625 E = UB->end_objects();
626 I != E; ++I) {
Rafael Espindola4f7932b2014-06-23 20:41:02 +0000627 ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
Rafael Espindola4f7932b2014-06-23 20:41:02 +0000628 if (UO) {
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000629 if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000630 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000631 if (OutputFormat == sysv)
632 outs() << o->getFileName() << " :\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000633 else if (MachO && OutputFormat == darwin) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000634 if (MoreThanOneFile || MoreThanOneArch)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000635 outs() << o->getFileName() << " (for architecture "
636 << I->getArchTypeName() << "):";
637 outs() << "\n";
638 }
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000639 printObjectSectionSizes(o);
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000640 if (OutputFormat == berkeley) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000641 if (!MachO || MoreThanOneFile || MoreThanOneArch)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000642 outs() << o->getFileName() << " (for architecture "
643 << I->getArchTypeName() << ")";
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000644 outs() << "\n";
645 }
646 }
Rafael Espindola0bfe8282014-12-09 21:05:36 +0000647 } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
648 I->getAsArchive()) {
649 std::unique_ptr<Archive> &UA = *AOrErr;
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000650 // This is an archive. Iterate over each member and display its sizes.
651 for (object::Archive::child_iterator i = UA->child_begin(),
Kevin Enderby10769742014-07-01 22:26:31 +0000652 e = UA->child_end();
653 i != e; ++i) {
Kevin Enderby7a969422015-11-05 19:24:56 +0000654 if (std::error_code EC = i->getError()) {
655 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
656 exit(1);
657 }
658 auto &c = i->get();
659 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000660 if (std::error_code EC = ChildOrErr.getError()) {
661 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
662 continue;
663 }
664 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
665 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
666 if (OutputFormat == sysv)
667 outs() << o->getFileName() << " (ex " << UA->getFileName()
668 << "):\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000669 else if (MachO && OutputFormat == darwin)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000670 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
Kevin Enderby10769742014-07-01 22:26:31 +0000671 << " (for architecture " << I->getArchTypeName() << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000672 printObjectSectionSizes(o);
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000673 if (OutputFormat == berkeley) {
674 if (MachO)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000675 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
676 << " (for architecture " << I->getArchTypeName()
677 << ")\n";
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000678 else
679 outs() << o->getFileName() << " (ex " << UA->getFileName()
680 << ")\n";
681 }
682 }
683 }
684 }
685 }
Rafael Espindola3f6481d2014-08-01 14:31:55 +0000686 } else if (ObjectFile *o = dyn_cast<ObjectFile>(&Bin)) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000687 if (!checkMachOAndArchFlags(o, file))
688 return;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000689 if (OutputFormat == sysv)
690 outs() << o->getFileName() << " :\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000691 printObjectSectionSizes(o);
Kevin Enderby246a4602014-06-17 17:54:13 +0000692 if (OutputFormat == berkeley) {
693 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000694 if (!MachO || MoreThanOneFile)
Kevin Enderby246a4602014-06-17 17:54:13 +0000695 outs() << o->getFileName();
696 outs() << "\n";
697 }
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000698 } else {
Kevin Enderby10769742014-07-01 22:26:31 +0000699 errs() << ToolName << ": " << file << ": "
700 << "Unrecognized file type.\n";
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000701 }
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000702 // System V adds an extra newline at the end of each file.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000703 if (OutputFormat == sysv)
704 outs() << "\n";
705}
706
707int main(int argc, char **argv) {
708 // Print a stack trace if we signal out.
709 sys::PrintStackTraceOnErrorSignal();
710 PrettyStackTraceProgram X(argc, argv);
711
Kevin Enderby10769742014-07-01 22:26:31 +0000712 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000713 cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");
714
715 ToolName = argv[0];
716 if (OutputFormatShort.getNumOccurrences())
Chris Bienemane71fb5c2015-01-22 01:49:59 +0000717 OutputFormat = static_cast<OutputFormatTy>(OutputFormatShort);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000718 if (RadixShort.getNumOccurrences())
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000719 Radix = RadixShort;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000720
Kevin Enderby10769742014-07-01 22:26:31 +0000721 for (unsigned i = 0; i < ArchFlags.size(); ++i) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000722 if (ArchFlags[i] == "all") {
723 ArchAll = true;
Kevin Enderby10769742014-07-01 22:26:31 +0000724 } else {
Rafael Espindola72318b42014-08-08 16:30:17 +0000725 if (!MachOObjectFile::isValidArch(ArchFlags[i])) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000726 outs() << ToolName << ": for the -arch option: Unknown architecture "
727 << "named '" << ArchFlags[i] << "'";
728 return 1;
729 }
730 }
731 }
732
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000733 if (InputFilenames.size() == 0)
734 InputFilenames.push_back("a.out");
735
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000736 MoreThanOneFile = InputFilenames.size() > 1;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000737 std::for_each(InputFilenames.begin(), InputFilenames.end(),
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000738 printFileSectionSizes);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000739
740 return 0;
741}