blob: 098f15298004c5f3428e4d75036925e7dc0519d8 [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"
Rafael Espindolaa0ff5562016-02-09 21:39:49 +000018#include "llvm/Object/ELFObjectFile.h"
Kevin Enderby246a4602014-06-17 17:54:13 +000019#include "llvm/Object/MachO.h"
Kevin Enderby4b8fc282014-06-18 22:04:40 +000020#include "llvm/Object/MachOUniversal.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000021#include "llvm/Object/ObjectFile.h"
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000022#include "llvm/Support/Casting.h"
23#include "llvm/Support/CommandLine.h"
24#include "llvm/Support/FileSystem.h"
25#include "llvm/Support/Format.h"
26#include "llvm/Support/ManagedStatic.h"
27#include "llvm/Support/MemoryBuffer.h"
28#include "llvm/Support/PrettyStackTrace.h"
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000029#include "llvm/Support/Signals.h"
Chandler Carruth4d88a1c2012-12-04 10:44:52 +000030#include "llvm/Support/raw_ostream.h"
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000031#include <algorithm>
32#include <string>
Rafael Espindolaa6e9c3e2014-06-12 17:38:55 +000033#include <system_error>
Eugene Zelenkoffec81c2015-11-04 22:32:32 +000034
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000035using namespace llvm;
36using namespace object;
37
Kevin Enderby10769742014-07-01 22:26:31 +000038enum OutputFormatTy { berkeley, sysv, darwin };
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000039static cl::opt<OutputFormatTy>
Kevin Enderby10769742014-07-01 22:26:31 +000040OutputFormat("format", cl::desc("Specify output format"),
41 cl::values(clEnumVal(sysv, "System V format"),
42 clEnumVal(berkeley, "Berkeley format"),
43 clEnumVal(darwin, "Darwin -m format"), clEnumValEnd),
44 cl::init(berkeley));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000045
Kevin Enderby10769742014-07-01 22:26:31 +000046static cl::opt<OutputFormatTy> OutputFormatShort(
47 cl::desc("Specify output format"),
48 cl::values(clEnumValN(sysv, "A", "System V format"),
49 clEnumValN(berkeley, "B", "Berkeley format"),
50 clEnumValN(darwin, "m", "Darwin -m format"), clEnumValEnd),
51 cl::init(berkeley));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000052
Rafael Espindola1dc30a42016-02-09 21:35:14 +000053static bool BerkeleyHeaderPrinted = false;
54static bool MoreThanOneFile = false;
Kevin Enderby246a4602014-06-17 17:54:13 +000055
Kevin Enderby10769742014-07-01 22:26:31 +000056cl::opt<bool>
57DarwinLongFormat("l", cl::desc("When format is darwin, use long format "
58 "to include addresses and offsets."));
Kevin Enderby246a4602014-06-17 17:54:13 +000059
Kevin Enderbyafef4c92014-07-01 17:19:10 +000060static cl::list<std::string>
Kevin Enderby10769742014-07-01 22:26:31 +000061ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
62 cl::ZeroOrMore);
Kevin Enderbyafef4c92014-07-01 17:19:10 +000063bool ArchAll = false;
64
Kevin Enderby10769742014-07-01 22:26:31 +000065enum RadixTy { octal = 8, decimal = 10, hexadecimal = 16 };
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000066static cl::opt<unsigned int>
Kevin Enderby10769742014-07-01 22:26:31 +000067Radix("-radix", cl::desc("Print size in radix. Only 8, 10, and 16 are valid"),
68 cl::init(decimal));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000069
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000070static cl::opt<RadixTy>
Kevin Enderby10769742014-07-01 22:26:31 +000071RadixShort(cl::desc("Print size in radix:"),
72 cl::values(clEnumValN(octal, "o", "Print size in octal"),
73 clEnumValN(decimal, "d", "Print size in decimal"),
74 clEnumValN(hexadecimal, "x", "Print size in hexadecimal"),
75 clEnumValEnd),
76 cl::init(decimal));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000077
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000078static cl::list<std::string>
Kevin Enderby10769742014-07-01 22:26:31 +000079InputFilenames(cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000080
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000081static std::string ToolName;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000082
Rafael Espindola49a0e5e2016-02-09 21:32:56 +000083/// If ec is not success, print the error and return true.
Rafael Espindola4453e42942014-06-13 03:07:50 +000084static bool error(std::error_code ec) {
Kevin Enderby10769742014-07-01 22:26:31 +000085 if (!ec)
86 return false;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000087
Davide Italiano911eb312016-01-25 01:24:15 +000088 errs() << ToolName << ": error reading file: " << ec.message() << ".\n";
89 errs().flush();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000090 return true;
91}
92
Rafael Espindola49a0e5e2016-02-09 21:32:56 +000093/// Get the length of the string that represents @p num in Radix including the
94/// leading 0x or 0 for hexadecimal and octal respectively.
Andrew Trick7dc278d2011-09-29 01:22:31 +000095static size_t getNumLengthAsString(uint64_t num) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000096 APInt conv(64, num);
97 SmallString<32> result;
Michael J. Spencercc5f8d42011-09-29 00:59:18 +000098 conv.toString(result, Radix, false, true);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +000099 return result.size();
100}
101
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000102/// Return the printing format for the Radix.
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000103static const char *getRadixFmt() {
Kevin Enderby246a4602014-06-17 17:54:13 +0000104 switch (Radix) {
105 case octal:
106 return PRIo64;
107 case decimal:
108 return PRIu64;
109 case hexadecimal:
110 return PRIx64;
111 }
112 return nullptr;
113}
114
Rafael Espindolaa0ff5562016-02-09 21:39:49 +0000115/// Remove unneeded ELF sections from calculation
116static bool considerForSize(ObjectFile *Obj, SectionRef Section) {
117 if (!Obj->isELF())
118 return true;
119 switch (static_cast<ELFSectionRef>(Section).getType()) {
120 case ELF::SHT_NULL:
121 case ELF::SHT_SYMTAB:
122 case ELF::SHT_STRTAB:
123 case ELF::SHT_REL:
124 case ELF::SHT_RELA:
125 return false;
126 }
127 return true;
128}
129
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000130/// Print the size of each Mach-O segment and section in @p MachO.
Kevin Enderby246a4602014-06-17 17:54:13 +0000131///
132/// This is when used when @c OutputFormat is darwin and produces the same
133/// output as darwin's size(1) -m output.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000134static void printDarwinSectionSizes(MachOObjectFile *MachO) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000135 std::string fmtbuf;
136 raw_string_ostream fmt(fmtbuf);
137 const char *radix_fmt = getRadixFmt();
138 if (Radix == hexadecimal)
139 fmt << "0x";
140 fmt << "%" << radix_fmt;
141
Kevin Enderby246a4602014-06-17 17:54:13 +0000142 uint32_t Filetype = MachO->getHeader().filetype;
Kevin Enderby246a4602014-06-17 17:54:13 +0000143
144 uint64_t total = 0;
Alexey Samsonovd319c4f2015-06-03 22:19:36 +0000145 for (const auto &Load : MachO->load_commands()) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000146 if (Load.C.cmd == MachO::LC_SEGMENT_64) {
147 MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
148 outs() << "Segment " << Seg.segname << ": "
149 << format(fmt.str().c_str(), Seg.vmsize);
150 if (DarwinLongFormat)
Kevin Enderby10769742014-07-01 22:26:31 +0000151 outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) << " fileoff "
152 << Seg.fileoff << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000153 outs() << "\n";
154 total += Seg.vmsize;
155 uint64_t sec_total = 0;
156 for (unsigned J = 0; J < Seg.nsects; ++J) {
157 MachO::section_64 Sec = MachO->getSection64(Load, J);
158 if (Filetype == MachO::MH_OBJECT)
159 outs() << "\tSection (" << format("%.16s", &Sec.segname) << ", "
160 << format("%.16s", &Sec.sectname) << "): ";
161 else
162 outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
163 outs() << format(fmt.str().c_str(), Sec.size);
164 if (DarwinLongFormat)
Kevin Enderby10769742014-07-01 22:26:31 +0000165 outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) << " offset "
166 << Sec.offset << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000167 outs() << "\n";
168 sec_total += Sec.size;
169 }
170 if (Seg.nsects != 0)
171 outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000172 } else if (Load.C.cmd == MachO::LC_SEGMENT) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000173 MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000174 uint64_t Seg_vmsize = Seg.vmsize;
Kevin Enderby246a4602014-06-17 17:54:13 +0000175 outs() << "Segment " << Seg.segname << ": "
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000176 << format(fmt.str().c_str(), Seg_vmsize);
Kevin Enderby246a4602014-06-17 17:54:13 +0000177 if (DarwinLongFormat)
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000178 outs() << " (vmaddr 0x" << format("%" PRIx32, Seg.vmaddr) << " fileoff "
Kevin Enderby10769742014-07-01 22:26:31 +0000179 << Seg.fileoff << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000180 outs() << "\n";
181 total += Seg.vmsize;
182 uint64_t sec_total = 0;
183 for (unsigned J = 0; J < Seg.nsects; ++J) {
184 MachO::section Sec = MachO->getSection(Load, J);
185 if (Filetype == MachO::MH_OBJECT)
186 outs() << "\tSection (" << format("%.16s", &Sec.segname) << ", "
187 << format("%.16s", &Sec.sectname) << "): ";
188 else
189 outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000190 uint64_t Sec_size = Sec.size;
191 outs() << format(fmt.str().c_str(), Sec_size);
Kevin Enderby246a4602014-06-17 17:54:13 +0000192 if (DarwinLongFormat)
Kevin Enderby2058e9d2016-02-09 18:33:15 +0000193 outs() << " (addr 0x" << format("%" PRIx32, Sec.addr) << " offset "
Kevin Enderby10769742014-07-01 22:26:31 +0000194 << Sec.offset << ")";
Kevin Enderby246a4602014-06-17 17:54:13 +0000195 outs() << "\n";
196 sec_total += Sec.size;
197 }
198 if (Seg.nsects != 0)
199 outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
200 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000201 }
202 outs() << "total " << format(fmt.str().c_str(), total) << "\n";
203}
204
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000205/// Print the summary sizes of the standard Mach-O segments in @p MachO.
Kevin Enderby246a4602014-06-17 17:54:13 +0000206///
207/// This is when used when @c OutputFormat is berkeley with a Mach-O file and
208/// produces the same output as darwin's size(1) default output.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000209static void printDarwinSegmentSizes(MachOObjectFile *MachO) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000210 uint64_t total_text = 0;
211 uint64_t total_data = 0;
212 uint64_t total_objc = 0;
213 uint64_t total_others = 0;
Alexey Samsonovd319c4f2015-06-03 22:19:36 +0000214 for (const auto &Load : MachO->load_commands()) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000215 if (Load.C.cmd == MachO::LC_SEGMENT_64) {
216 MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
217 if (MachO->getHeader().filetype == MachO::MH_OBJECT) {
218 for (unsigned J = 0; J < Seg.nsects; ++J) {
219 MachO::section_64 Sec = MachO->getSection64(Load, J);
220 StringRef SegmentName = StringRef(Sec.segname);
221 if (SegmentName == "__TEXT")
222 total_text += Sec.size;
223 else if (SegmentName == "__DATA")
224 total_data += Sec.size;
225 else if (SegmentName == "__OBJC")
226 total_objc += Sec.size;
227 else
228 total_others += Sec.size;
Kevin Enderby10769742014-07-01 22:26:31 +0000229 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000230 } else {
231 StringRef SegmentName = StringRef(Seg.segname);
232 if (SegmentName == "__TEXT")
233 total_text += Seg.vmsize;
234 else if (SegmentName == "__DATA")
235 total_data += Seg.vmsize;
236 else if (SegmentName == "__OBJC")
237 total_objc += Seg.vmsize;
238 else
239 total_others += Seg.vmsize;
240 }
Kevin Enderby10769742014-07-01 22:26:31 +0000241 } else if (Load.C.cmd == MachO::LC_SEGMENT) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000242 MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
243 if (MachO->getHeader().filetype == MachO::MH_OBJECT) {
244 for (unsigned J = 0; J < Seg.nsects; ++J) {
245 MachO::section Sec = MachO->getSection(Load, J);
246 StringRef SegmentName = StringRef(Sec.segname);
247 if (SegmentName == "__TEXT")
248 total_text += Sec.size;
249 else if (SegmentName == "__DATA")
250 total_data += Sec.size;
251 else if (SegmentName == "__OBJC")
252 total_objc += Sec.size;
253 else
254 total_others += Sec.size;
Kevin Enderby10769742014-07-01 22:26:31 +0000255 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000256 } else {
257 StringRef SegmentName = StringRef(Seg.segname);
258 if (SegmentName == "__TEXT")
259 total_text += Seg.vmsize;
260 else if (SegmentName == "__DATA")
261 total_data += Seg.vmsize;
262 else if (SegmentName == "__OBJC")
263 total_objc += Seg.vmsize;
264 else
265 total_others += Seg.vmsize;
266 }
267 }
Kevin Enderby246a4602014-06-17 17:54:13 +0000268 }
269 uint64_t total = total_text + total_data + total_objc + total_others;
270
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000271 if (!BerkeleyHeaderPrinted) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000272 outs() << "__TEXT\t__DATA\t__OBJC\tothers\tdec\thex\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000273 BerkeleyHeaderPrinted = true;
Kevin Enderby246a4602014-06-17 17:54:13 +0000274 }
275 outs() << total_text << "\t" << total_data << "\t" << total_objc << "\t"
276 << total_others << "\t" << total << "\t" << format("%" PRIx64, total)
277 << "\t";
278}
279
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000280/// Print the size of each section in @p Obj.
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000281///
282/// The format used is determined by @c OutputFormat and @c Radix.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000283static void printObjectSectionSizes(ObjectFile *Obj) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000284 uint64_t total = 0;
285 std::string fmtbuf;
286 raw_string_ostream fmt(fmtbuf);
Kevin Enderby246a4602014-06-17 17:54:13 +0000287 const char *radix_fmt = getRadixFmt();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000288
Kevin Enderby246a4602014-06-17 17:54:13 +0000289 // If OutputFormat is darwin and we have a MachOObjectFile print as darwin's
290 // size(1) -m output, else if OutputFormat is darwin and not a Mach-O object
291 // let it fall through to OutputFormat berkeley.
292 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(Obj);
293 if (OutputFormat == darwin && MachO)
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000294 printDarwinSectionSizes(MachO);
Kevin Enderby246a4602014-06-17 17:54:13 +0000295 // If we have a MachOObjectFile and the OutputFormat is berkeley print as
296 // darwin's default berkeley format for Mach-O files.
297 else if (MachO && OutputFormat == berkeley)
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000298 printDarwinSegmentSizes(MachO);
Kevin Enderby246a4602014-06-17 17:54:13 +0000299 else if (OutputFormat == sysv) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000300 // Run two passes over all sections. The first gets the lengths needed for
301 // formatting the output. The second actually does the output.
302 std::size_t max_name_len = strlen("section");
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000303 std::size_t max_size_len = strlen("size");
304 std::size_t max_addr_len = strlen("addr");
Alexey Samsonov48803e52014-03-13 14:37:36 +0000305 for (const SectionRef &Section : Obj->sections()) {
Rafael Espindolaa0ff5562016-02-09 21:39:49 +0000306 if (!considerForSize(Obj, Section))
307 continue;
Rafael Espindola80291272014-10-08 15:28:58 +0000308 uint64_t size = Section.getSize();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000309 total += size;
310
311 StringRef name;
Alexey Samsonov48803e52014-03-13 14:37:36 +0000312 if (error(Section.getName(name)))
313 return;
Rafael Espindola80291272014-10-08 15:28:58 +0000314 uint64_t addr = Section.getAddress();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000315 max_name_len = std::max(max_name_len, name.size());
Andrew Trick7dc278d2011-09-29 01:22:31 +0000316 max_size_len = std::max(max_size_len, getNumLengthAsString(size));
317 max_addr_len = std::max(max_addr_len, getNumLengthAsString(addr));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000318 }
319
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000320 // Add extra padding.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000321 max_name_len += 2;
322 max_size_len += 2;
323 max_addr_len += 2;
324
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000325 // Setup header format.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000326 fmt << "%-" << max_name_len << "s "
327 << "%" << max_size_len << "s "
328 << "%" << max_addr_len << "s\n";
329
330 // Print header
Kevin Enderby10769742014-07-01 22:26:31 +0000331 outs() << format(fmt.str().c_str(), static_cast<const char *>("section"),
332 static_cast<const char *>("size"),
333 static_cast<const char *>("addr"));
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000334 fmtbuf.clear();
335
336 // Setup per section format.
337 fmt << "%-" << max_name_len << "s "
338 << "%#" << max_size_len << radix_fmt << " "
339 << "%#" << max_addr_len << radix_fmt << "\n";
340
341 // Print each section.
Alexey Samsonov48803e52014-03-13 14:37:36 +0000342 for (const SectionRef &Section : Obj->sections()) {
Rafael Espindolaa0ff5562016-02-09 21:39:49 +0000343 if (!considerForSize(Obj, Section))
344 continue;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000345 StringRef name;
Alexey Samsonov48803e52014-03-13 14:37:36 +0000346 if (error(Section.getName(name)))
347 return;
Rafael Espindola80291272014-10-08 15:28:58 +0000348 uint64_t size = Section.getSize();
349 uint64_t addr = Section.getAddress();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000350 std::string namestr = name;
351
Alexey Samsonov48803e52014-03-13 14:37:36 +0000352 outs() << format(fmt.str().c_str(), namestr.c_str(), size, addr);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000353 }
354
355 // Print total.
356 fmtbuf.clear();
357 fmt << "%-" << max_name_len << "s "
358 << "%#" << max_size_len << radix_fmt << "\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000359 outs() << format(fmt.str().c_str(), static_cast<const char *>("Total"),
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000360 total);
361 } else {
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000362 // The Berkeley format does not display individual section sizes. It
363 // displays the cumulative size for each section type.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000364 uint64_t total_text = 0;
365 uint64_t total_data = 0;
366 uint64_t total_bss = 0;
367
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000368 // Make one pass over the section table to calculate sizes.
Alexey Samsonov48803e52014-03-13 14:37:36 +0000369 for (const SectionRef &Section : Obj->sections()) {
Rafael Espindola80291272014-10-08 15:28:58 +0000370 uint64_t size = Section.getSize();
371 bool isText = Section.isText();
372 bool isData = Section.isData();
373 bool isBSS = Section.isBSS();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000374 if (isText)
375 total_text += size;
376 else if (isData)
377 total_data += size;
378 else if (isBSS)
379 total_bss += size;
380 }
381
382 total = total_text + total_data + total_bss;
383
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000384 if (!BerkeleyHeaderPrinted) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000385 outs() << " text data bss "
Kevin Enderby10769742014-07-01 22:26:31 +0000386 << (Radix == octal ? "oct" : "dec") << " hex filename\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000387 BerkeleyHeaderPrinted = true;
Kevin Enderby246a4602014-06-17 17:54:13 +0000388 }
389
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000390 // Print result.
391 fmt << "%#7" << radix_fmt << " "
392 << "%#7" << radix_fmt << " "
393 << "%#7" << radix_fmt << " ";
Kevin Enderby10769742014-07-01 22:26:31 +0000394 outs() << format(fmt.str().c_str(), total_text, total_data, total_bss);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000395 fmtbuf.clear();
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000396 fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << " "
397 << "%7" PRIx64 " ";
Kevin Enderby10769742014-07-01 22:26:31 +0000398 outs() << format(fmt.str().c_str(), total, total);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000399 }
400}
401
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000402/// Checks to see if the @p o ObjectFile is a Mach-O file and if it is and there
403/// is a list of architecture flags specified then check to make sure this
404/// Mach-O file is one of those architectures or all architectures was
405/// specificed. If not then an error is generated and this routine returns
406/// false. Else it returns true.
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000407static bool checkMachOAndArchFlags(ObjectFile *o, StringRef file) {
408 if (isa<MachOObjectFile>(o) && !ArchAll && ArchFlags.size() != 0) {
409 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
410 bool ArchFound = false;
411 MachO::mach_header H;
412 MachO::mach_header_64 H_64;
413 Triple T;
414 if (MachO->is64Bit()) {
415 H_64 = MachO->MachOObjectFile::getHeader64();
416 T = MachOObjectFile::getArch(H_64.cputype, H_64.cpusubtype);
417 } else {
418 H = MachO->MachOObjectFile::getHeader();
419 T = MachOObjectFile::getArch(H.cputype, H.cpusubtype);
420 }
421 unsigned i;
Kevin Enderby10769742014-07-01 22:26:31 +0000422 for (i = 0; i < ArchFlags.size(); ++i) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000423 if (ArchFlags[i] == T.getArchName())
424 ArchFound = true;
425 break;
426 }
427 if (!ArchFound) {
428 errs() << ToolName << ": file: " << file
429 << " does not contain architecture: " << ArchFlags[i] << ".\n";
430 return false;
431 }
432 }
433 return true;
434}
435
Rafael Espindola49a0e5e2016-02-09 21:32:56 +0000436/// Print the section sizes for @p file. If @p file is an archive, print the
437/// section sizes for each archive member.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000438static void printFileSectionSizes(StringRef file) {
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000439
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000440 // Attempt to open the binary.
Rafael Espindola48af1c22014-08-19 18:44:46 +0000441 ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
Davide Italianoff11b902016-02-13 01:38:16 +0000442 if (error(BinaryOrErr.getError()))
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000443 return;
Rafael Espindola48af1c22014-08-19 18:44:46 +0000444 Binary &Bin = *BinaryOrErr.get().getBinary();
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000445
Rafael Espindola3f6481d2014-08-01 14:31:55 +0000446 if (Archive *a = dyn_cast<Archive>(&Bin)) {
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000447 // This is an archive. Iterate over each member and display its sizes.
Rafael Espindola23a97502014-01-21 16:09:45 +0000448 for (object::Archive::child_iterator i = a->child_begin(),
Kevin Enderby10769742014-07-01 22:26:31 +0000449 e = a->child_end();
450 i != e; ++i) {
Davide Italianoff11b902016-02-13 01:38:16 +0000451 if (error(i->getError()))
Kevin Enderby7a969422015-11-05 19:24:56 +0000452 exit(1);
Davide Italianoef34c992016-02-13 01:52:47 +0000453 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();
Davide Italianoff11b902016-02-13 01:38:16 +0000454 if (error(ChildOrErr.getError()))
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000455 continue;
Rafael Espindolaae460022014-06-16 16:08:36 +0000456 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
Kevin Enderby246a4602014-06-17 17:54:13 +0000457 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000458 if (!checkMachOAndArchFlags(o, file))
459 return;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000460 if (OutputFormat == sysv)
Kevin Enderby10769742014-07-01 22:26:31 +0000461 outs() << o->getFileName() << " (ex " << a->getFileName() << "):\n";
462 else if (MachO && OutputFormat == darwin)
463 outs() << a->getFileName() << "(" << o->getFileName() << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000464 printObjectSectionSizes(o);
Kevin Enderby246a4602014-06-17 17:54:13 +0000465 if (OutputFormat == berkeley) {
466 if (MachO)
467 outs() << a->getFileName() << "(" << o->getFileName() << ")\n";
468 else
469 outs() << o->getFileName() << " (ex " << a->getFileName() << ")\n";
470 }
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000471 }
472 }
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000473 } else if (MachOUniversalBinary *UB =
Rafael Espindola3f6481d2014-08-01 14:31:55 +0000474 dyn_cast<MachOUniversalBinary>(&Bin)) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000475 // If we have a list of architecture flags specified dump only those.
476 if (!ArchAll && ArchFlags.size() != 0) {
477 // Look for a slice in the universal binary that matches each ArchFlag.
478 bool ArchFound;
Kevin Enderby10769742014-07-01 22:26:31 +0000479 for (unsigned i = 0; i < ArchFlags.size(); ++i) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000480 ArchFound = false;
481 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
482 E = UB->end_objects();
483 I != E; ++I) {
Kevin Enderby10769742014-07-01 22:26:31 +0000484 if (ArchFlags[i] == I->getArchTypeName()) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000485 ArchFound = true;
486 ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000487 if (UO) {
488 if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
489 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
490 if (OutputFormat == sysv)
491 outs() << o->getFileName() << " :\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000492 else if (MachO && OutputFormat == darwin) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000493 if (MoreThanOneFile || ArchFlags.size() > 1)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000494 outs() << o->getFileName() << " (for architecture "
495 << I->getArchTypeName() << "): \n";
496 }
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000497 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000498 if (OutputFormat == berkeley) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000499 if (!MachO || MoreThanOneFile || ArchFlags.size() > 1)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000500 outs() << o->getFileName() << " (for architecture "
501 << I->getArchTypeName() << ")";
502 outs() << "\n";
503 }
504 }
Rafael Espindola0bfe8282014-12-09 21:05:36 +0000505 } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
506 I->getAsArchive()) {
507 std::unique_ptr<Archive> &UA = *AOrErr;
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000508 // This is an archive. Iterate over each member and display its
Kevin Enderby10769742014-07-01 22:26:31 +0000509 // sizes.
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000510 for (object::Archive::child_iterator i = UA->child_begin(),
511 e = UA->child_end();
Kevin Enderby10769742014-07-01 22:26:31 +0000512 i != e; ++i) {
Davide Italianoff11b902016-02-13 01:38:16 +0000513 if (error(i->getError()))
Kevin Enderby7a969422015-11-05 19:24:56 +0000514 exit(1);
Davide Italianoef34c992016-02-13 01:52:47 +0000515 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();
Davide Italianoff11b902016-02-13 01:38:16 +0000516 if (error(ChildOrErr.getError()))
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000517 continue;
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000518 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
519 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
520 if (OutputFormat == sysv)
521 outs() << o->getFileName() << " (ex " << UA->getFileName()
522 << "):\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000523 else if (MachO && OutputFormat == darwin)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000524 outs() << UA->getFileName() << "(" << o->getFileName()
Kevin Enderby10769742014-07-01 22:26:31 +0000525 << ")"
526 << " (for architecture " << I->getArchTypeName()
527 << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000528 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000529 if (OutputFormat == berkeley) {
530 if (MachO) {
531 outs() << UA->getFileName() << "(" << o->getFileName()
532 << ")";
533 if (ArchFlags.size() > 1)
Kevin Enderby10769742014-07-01 22:26:31 +0000534 outs() << " (for architecture " << I->getArchTypeName()
535 << ")";
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000536 outs() << "\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000537 } else
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000538 outs() << o->getFileName() << " (ex " << UA->getFileName()
539 << ")\n";
540 }
541 }
542 }
543 }
544 }
545 }
546 if (!ArchFound) {
547 errs() << ToolName << ": file: " << file
548 << " does not contain architecture" << ArchFlags[i] << ".\n";
549 return;
550 }
551 }
552 return;
553 }
554 // No architecture flags were specified so if this contains a slice that
555 // matches the host architecture dump only that.
556 if (!ArchAll) {
Kevin Enderby10769742014-07-01 22:26:31 +0000557 StringRef HostArchName = MachOObjectFile::getHostArch().getArchName();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000558 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
559 E = UB->end_objects();
560 I != E; ++I) {
Kevin Enderby10769742014-07-01 22:26:31 +0000561 if (HostArchName == I->getArchTypeName()) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000562 ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000563 if (UO) {
564 if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
565 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
566 if (OutputFormat == sysv)
567 outs() << o->getFileName() << " :\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000568 else if (MachO && OutputFormat == darwin) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000569 if (MoreThanOneFile)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000570 outs() << o->getFileName() << " (for architecture "
571 << I->getArchTypeName() << "):\n";
572 }
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000573 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000574 if (OutputFormat == berkeley) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000575 if (!MachO || MoreThanOneFile)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000576 outs() << o->getFileName() << " (for architecture "
577 << I->getArchTypeName() << ")";
578 outs() << "\n";
579 }
580 }
Rafael Espindola0bfe8282014-12-09 21:05:36 +0000581 } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
582 I->getAsArchive()) {
583 std::unique_ptr<Archive> &UA = *AOrErr;
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000584 // This is an archive. Iterate over each member and display its
585 // sizes.
586 for (object::Archive::child_iterator i = UA->child_begin(),
587 e = UA->child_end();
Kevin Enderby10769742014-07-01 22:26:31 +0000588 i != e; ++i) {
Davide Italianoff11b902016-02-13 01:38:16 +0000589 if (error(i->getError()))
Kevin Enderby7a969422015-11-05 19:24:56 +0000590 exit(1);
Davide Italianoef34c992016-02-13 01:52:47 +0000591 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();
Davide Italianoff11b902016-02-13 01:38:16 +0000592 if (error(ChildOrErr.getError()))
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000593 continue;
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000594 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
595 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
596 if (OutputFormat == sysv)
597 outs() << o->getFileName() << " (ex " << UA->getFileName()
598 << "):\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000599 else if (MachO && OutputFormat == darwin)
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000600 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
601 << " (for architecture " << I->getArchTypeName()
602 << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000603 printObjectSectionSizes(o);
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000604 if (OutputFormat == berkeley) {
605 if (MachO)
606 outs() << UA->getFileName() << "(" << o->getFileName()
607 << ")\n";
608 else
609 outs() << o->getFileName() << " (ex " << UA->getFileName()
610 << ")\n";
611 }
612 }
613 }
614 }
615 return;
616 }
617 }
618 }
619 // Either all architectures have been specified or none have been specified
620 // and this does not contain the host architecture so dump all the slices.
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000621 bool MoreThanOneArch = UB->getNumberOfObjects() > 1;
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000622 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
623 E = UB->end_objects();
624 I != E; ++I) {
Rafael Espindola4f7932b2014-06-23 20:41:02 +0000625 ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
Rafael Espindola4f7932b2014-06-23 20:41:02 +0000626 if (UO) {
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000627 if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000628 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000629 if (OutputFormat == sysv)
630 outs() << o->getFileName() << " :\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000631 else if (MachO && OutputFormat == darwin) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000632 if (MoreThanOneFile || MoreThanOneArch)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000633 outs() << o->getFileName() << " (for architecture "
634 << I->getArchTypeName() << "):";
635 outs() << "\n";
636 }
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000637 printObjectSectionSizes(o);
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000638 if (OutputFormat == berkeley) {
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000639 if (!MachO || MoreThanOneFile || MoreThanOneArch)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000640 outs() << o->getFileName() << " (for architecture "
641 << I->getArchTypeName() << ")";
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000642 outs() << "\n";
643 }
644 }
Rafael Espindola0bfe8282014-12-09 21:05:36 +0000645 } else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
646 I->getAsArchive()) {
647 std::unique_ptr<Archive> &UA = *AOrErr;
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000648 // This is an archive. Iterate over each member and display its sizes.
649 for (object::Archive::child_iterator i = UA->child_begin(),
Kevin Enderby10769742014-07-01 22:26:31 +0000650 e = UA->child_end();
651 i != e; ++i) {
Davide Italianoff11b902016-02-13 01:38:16 +0000652 if (error(i->getError()))
Kevin Enderby7a969422015-11-05 19:24:56 +0000653 exit(1);
Davide Italianoef34c992016-02-13 01:52:47 +0000654 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();
Davide Italianoff11b902016-02-13 01:38:16 +0000655 if (error(ChildOrErr.getError()))
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000656 continue;
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000657 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
658 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
659 if (OutputFormat == sysv)
660 outs() << o->getFileName() << " (ex " << UA->getFileName()
661 << "):\n";
Kevin Enderby10769742014-07-01 22:26:31 +0000662 else if (MachO && OutputFormat == darwin)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000663 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
Kevin Enderby10769742014-07-01 22:26:31 +0000664 << " (for architecture " << I->getArchTypeName() << "):\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000665 printObjectSectionSizes(o);
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000666 if (OutputFormat == berkeley) {
667 if (MachO)
Kevin Enderby1983fcf2014-06-19 22:03:18 +0000668 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
669 << " (for architecture " << I->getArchTypeName()
670 << ")\n";
Kevin Enderby4b8fc282014-06-18 22:04:40 +0000671 else
672 outs() << o->getFileName() << " (ex " << UA->getFileName()
673 << ")\n";
674 }
675 }
676 }
677 }
678 }
Rafael Espindola3f6481d2014-08-01 14:31:55 +0000679 } else if (ObjectFile *o = dyn_cast<ObjectFile>(&Bin)) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000680 if (!checkMachOAndArchFlags(o, file))
681 return;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000682 if (OutputFormat == sysv)
683 outs() << o->getFileName() << " :\n";
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000684 printObjectSectionSizes(o);
Kevin Enderby246a4602014-06-17 17:54:13 +0000685 if (OutputFormat == berkeley) {
686 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000687 if (!MachO || MoreThanOneFile)
Kevin Enderby246a4602014-06-17 17:54:13 +0000688 outs() << o->getFileName();
689 outs() << "\n";
690 }
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000691 } else {
Kevin Enderby10769742014-07-01 22:26:31 +0000692 errs() << ToolName << ": " << file << ": "
693 << "Unrecognized file type.\n";
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000694 }
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000695 // System V adds an extra newline at the end of each file.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000696 if (OutputFormat == sysv)
697 outs() << "\n";
698}
699
700int main(int argc, char **argv) {
701 // Print a stack trace if we signal out.
702 sys::PrintStackTraceOnErrorSignal();
703 PrettyStackTraceProgram X(argc, argv);
704
Kevin Enderby10769742014-07-01 22:26:31 +0000705 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000706 cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");
707
708 ToolName = argv[0];
709 if (OutputFormatShort.getNumOccurrences())
Chris Bienemane71fb5c2015-01-22 01:49:59 +0000710 OutputFormat = static_cast<OutputFormatTy>(OutputFormatShort);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000711 if (RadixShort.getNumOccurrences())
Michael J. Spencercc5f8d42011-09-29 00:59:18 +0000712 Radix = RadixShort;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000713
Kevin Enderby10769742014-07-01 22:26:31 +0000714 for (unsigned i = 0; i < ArchFlags.size(); ++i) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000715 if (ArchFlags[i] == "all") {
716 ArchAll = true;
Kevin Enderby10769742014-07-01 22:26:31 +0000717 } else {
Rafael Espindola72318b42014-08-08 16:30:17 +0000718 if (!MachOObjectFile::isValidArch(ArchFlags[i])) {
Kevin Enderbyafef4c92014-07-01 17:19:10 +0000719 outs() << ToolName << ": for the -arch option: Unknown architecture "
720 << "named '" << ArchFlags[i] << "'";
721 return 1;
722 }
723 }
724 }
725
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000726 if (InputFilenames.size() == 0)
727 InputFilenames.push_back("a.out");
728
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000729 MoreThanOneFile = InputFilenames.size() > 1;
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000730 std::for_each(InputFilenames.begin(), InputFilenames.end(),
Rafael Espindola1dc30a42016-02-09 21:35:14 +0000731 printFileSectionSizes);
Michael J. Spencerc4ad4662011-09-28 20:57:46 +0000732
733 return 0;
734}