Run clang-format on llvm-size.cpp to tidy things up. No functional changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212141 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kevin Enderby
2014-07-01 22:26:31 +00:00
parent f26039734c
commit 9c23bd0943

View File

@@ -33,59 +33,55 @@
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
enum OutputFormatTy {berkeley, sysv, darwin}; enum OutputFormatTy { berkeley, sysv, darwin };
static cl::opt<OutputFormatTy> static cl::opt<OutputFormatTy>
OutputFormat("format", OutputFormat("format", cl::desc("Specify output format"),
cl::desc("Specify output format"), cl::values(clEnumVal(sysv, "System V format"),
cl::values(clEnumVal(sysv, "System V format"), clEnumVal(berkeley, "Berkeley format"),
clEnumVal(berkeley, "Berkeley format"), clEnumVal(darwin, "Darwin -m format"), clEnumValEnd),
clEnumVal(darwin, "Darwin -m format"), clEnumValEnd), cl::init(berkeley));
cl::init(berkeley));
static cl::opt<OutputFormatTy> static cl::opt<OutputFormatTy> OutputFormatShort(
OutputFormatShort(cl::desc("Specify output format"), cl::desc("Specify output format"),
cl::values(clEnumValN(sysv, "A", "System V format"), cl::values(clEnumValN(sysv, "A", "System V format"),
clEnumValN(berkeley, "B", "Berkeley format"), clEnumValN(berkeley, "B", "Berkeley format"),
clEnumValN(darwin, "m", "Darwin -m format"), clEnumValN(darwin, "m", "Darwin -m format"), clEnumValEnd),
clEnumValEnd), cl::init(berkeley));
cl::init(berkeley));
static bool berkeleyHeaderPrinted = false; static bool berkeleyHeaderPrinted = false;
static bool moreThanOneFile = false; static bool moreThanOneFile = false;
cl::opt<bool> DarwinLongFormat("l", cl::opt<bool>
cl::desc("When format is darwin, use long format " DarwinLongFormat("l", cl::desc("When format is darwin, use long format "
"to include addresses and offsets.")); "to include addresses and offsets."));
static cl::list<std::string> static cl::list<std::string>
ArchFlags("arch", ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
cl::desc("architecture(s) from a Mach-O file to dump"), cl::ZeroOrMore);
cl::ZeroOrMore);
bool ArchAll = false; bool ArchAll = false;
enum RadixTy {octal = 8, decimal = 10, hexadecimal = 16}; enum RadixTy { octal = 8, decimal = 10, hexadecimal = 16 };
static cl::opt<unsigned int> static cl::opt<unsigned int>
Radix("-radix", Radix("-radix", cl::desc("Print size in radix. Only 8, 10, and 16 are valid"),
cl::desc("Print size in radix. Only 8, 10, and 16 are valid"), cl::init(decimal));
cl::init(decimal));
static cl::opt<RadixTy> static cl::opt<RadixTy>
RadixShort(cl::desc("Print size in radix:"), RadixShort(cl::desc("Print size in radix:"),
cl::values(clEnumValN(octal, "o", "Print size in octal"), cl::values(clEnumValN(octal, "o", "Print size in octal"),
clEnumValN(decimal, "d", "Print size in decimal"), clEnumValN(decimal, "d", "Print size in decimal"),
clEnumValN(hexadecimal, "x", "Print size in hexadecimal"), clEnumValN(hexadecimal, "x", "Print size in hexadecimal"),
clEnumValEnd), clEnumValEnd),
cl::init(decimal)); cl::init(decimal));
static cl::list<std::string> static cl::list<std::string>
InputFilenames(cl::Positional, cl::desc("<input files>"), InputFilenames(cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
cl::ZeroOrMore);
static std::string ToolName; static std::string ToolName;
/// @brief If ec is not success, print the error and return true. /// @brief If ec is not success, print the error and return true.
static bool error(std::error_code ec) { static bool error(std::error_code ec) {
if (!ec) return false; if (!ec)
return false;
outs() << ToolName << ": error reading file: " << ec.message() << ".\n"; outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
outs().flush(); outs().flush();
@@ -102,7 +98,7 @@ static size_t getNumLengthAsString(uint64_t num) {
} }
/// @brief Return the the printing format for the Radix. /// @brief Return the the printing format for the Radix.
static const char * getRadixFmt(void) { static const char *getRadixFmt(void) {
switch (Radix) { switch (Radix) {
case octal: case octal:
return PRIo64; return PRIo64;
@@ -131,14 +127,14 @@ static void PrintDarwinSectionSizes(MachOObjectFile *MachO) {
MachOObjectFile::LoadCommandInfo Load = MachO->getFirstLoadCommandInfo(); MachOObjectFile::LoadCommandInfo Load = MachO->getFirstLoadCommandInfo();
uint64_t total = 0; uint64_t total = 0;
for (unsigned I = 0; ; ++I) { for (unsigned I = 0;; ++I) {
if (Load.C.cmd == MachO::LC_SEGMENT_64) { if (Load.C.cmd == MachO::LC_SEGMENT_64) {
MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load); MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
outs() << "Segment " << Seg.segname << ": " outs() << "Segment " << Seg.segname << ": "
<< format(fmt.str().c_str(), Seg.vmsize); << format(fmt.str().c_str(), Seg.vmsize);
if (DarwinLongFormat) if (DarwinLongFormat)
outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) << " fileoff "
<< " fileoff " << Seg.fileoff << ")"; << Seg.fileoff << ")";
outs() << "\n"; outs() << "\n";
total += Seg.vmsize; total += Seg.vmsize;
uint64_t sec_total = 0; uint64_t sec_total = 0;
@@ -151,21 +147,20 @@ static void PrintDarwinSectionSizes(MachOObjectFile *MachO) {
outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": "; outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
outs() << format(fmt.str().c_str(), Sec.size); outs() << format(fmt.str().c_str(), Sec.size);
if (DarwinLongFormat) if (DarwinLongFormat)
outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) << " offset "
<< " offset " << Sec.offset << ")"; << Sec.offset << ")";
outs() << "\n"; outs() << "\n";
sec_total += Sec.size; sec_total += Sec.size;
} }
if (Seg.nsects != 0) if (Seg.nsects != 0)
outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n"; outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
} } else if (Load.C.cmd == MachO::LC_SEGMENT) {
else if (Load.C.cmd == MachO::LC_SEGMENT) {
MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load); MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
outs() << "Segment " << Seg.segname << ": " outs() << "Segment " << Seg.segname << ": "
<< format(fmt.str().c_str(), Seg.vmsize); << format(fmt.str().c_str(), Seg.vmsize);
if (DarwinLongFormat) if (DarwinLongFormat)
outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) << " fileoff "
<< " fileoff " << Seg.fileoff << ")"; << Seg.fileoff << ")";
outs() << "\n"; outs() << "\n";
total += Seg.vmsize; total += Seg.vmsize;
uint64_t sec_total = 0; uint64_t sec_total = 0;
@@ -178,8 +173,8 @@ static void PrintDarwinSectionSizes(MachOObjectFile *MachO) {
outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": "; outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
outs() << format(fmt.str().c_str(), Sec.size); outs() << format(fmt.str().c_str(), Sec.size);
if (DarwinLongFormat) if (DarwinLongFormat)
outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) << " offset "
<< " offset " << Sec.offset << ")"; << Sec.offset << ")";
outs() << "\n"; outs() << "\n";
sec_total += Sec.size; sec_total += Sec.size;
} }
@@ -206,7 +201,7 @@ static void PrintDarwinSegmentSizes(MachOObjectFile *MachO) {
uint64_t total_data = 0; uint64_t total_data = 0;
uint64_t total_objc = 0; uint64_t total_objc = 0;
uint64_t total_others = 0; uint64_t total_others = 0;
for (unsigned I = 0; ; ++I) { for (unsigned I = 0;; ++I) {
if (Load.C.cmd == MachO::LC_SEGMENT_64) { if (Load.C.cmd == MachO::LC_SEGMENT_64) {
MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load); MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
if (MachO->getHeader().filetype == MachO::MH_OBJECT) { if (MachO->getHeader().filetype == MachO::MH_OBJECT) {
@@ -221,7 +216,7 @@ static void PrintDarwinSegmentSizes(MachOObjectFile *MachO) {
total_objc += Sec.size; total_objc += Sec.size;
else else
total_others += Sec.size; total_others += Sec.size;
} }
} else { } else {
StringRef SegmentName = StringRef(Seg.segname); StringRef SegmentName = StringRef(Seg.segname);
if (SegmentName == "__TEXT") if (SegmentName == "__TEXT")
@@ -233,8 +228,7 @@ static void PrintDarwinSegmentSizes(MachOObjectFile *MachO) {
else else
total_others += Seg.vmsize; total_others += Seg.vmsize;
} }
} } else if (Load.C.cmd == MachO::LC_SEGMENT) {
else if (Load.C.cmd == MachO::LC_SEGMENT) {
MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load); MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
if (MachO->getHeader().filetype == MachO::MH_OBJECT) { if (MachO->getHeader().filetype == MachO::MH_OBJECT) {
for (unsigned J = 0; J < Seg.nsects; ++J) { for (unsigned J = 0; J < Seg.nsects; ++J) {
@@ -248,7 +242,7 @@ static void PrintDarwinSegmentSizes(MachOObjectFile *MachO) {
total_objc += Sec.size; total_objc += Sec.size;
else else
total_others += Sec.size; total_others += Sec.size;
} }
} else { } else {
StringRef SegmentName = StringRef(Seg.segname); StringRef SegmentName = StringRef(Seg.segname);
if (SegmentName == "__TEXT") if (SegmentName == "__TEXT")
@@ -330,10 +324,9 @@ static void PrintObjectSectionSizes(ObjectFile *Obj) {
<< "%" << max_addr_len << "s\n"; << "%" << max_addr_len << "s\n";
// Print header // Print header
outs() << format(fmt.str().c_str(), outs() << format(fmt.str().c_str(), static_cast<const char *>("section"),
static_cast<const char*>("section"), static_cast<const char *>("size"),
static_cast<const char*>("size"), static_cast<const char *>("addr"));
static_cast<const char*>("addr"));
fmtbuf.clear(); fmtbuf.clear();
// Setup per section format. // Setup per section format.
@@ -361,8 +354,7 @@ static void PrintObjectSectionSizes(ObjectFile *Obj) {
fmtbuf.clear(); fmtbuf.clear();
fmt << "%-" << max_name_len << "s " fmt << "%-" << max_name_len << "s "
<< "%#" << max_size_len << radix_fmt << "\n"; << "%#" << max_size_len << radix_fmt << "\n";
outs() << format(fmt.str().c_str(), outs() << format(fmt.str().c_str(), static_cast<const char *>("Total"),
static_cast<const char*>("Total"),
total); total);
} else { } else {
// The Berkeley format does not display individual section sizes. It // The Berkeley format does not display individual section sizes. It
@@ -397,8 +389,7 @@ static void PrintObjectSectionSizes(ObjectFile *Obj) {
if (!berkeleyHeaderPrinted) { if (!berkeleyHeaderPrinted) {
outs() << " text data bss " outs() << " text data bss "
<< (Radix == octal ? "oct" : "dec") << (Radix == octal ? "oct" : "dec") << " hex filename\n";
<< " hex filename\n";
berkeleyHeaderPrinted = true; berkeleyHeaderPrinted = true;
} }
@@ -406,16 +397,11 @@ static void PrintObjectSectionSizes(ObjectFile *Obj) {
fmt << "%#7" << radix_fmt << " " fmt << "%#7" << radix_fmt << " "
<< "%#7" << radix_fmt << " " << "%#7" << radix_fmt << " "
<< "%#7" << radix_fmt << " "; << "%#7" << radix_fmt << " ";
outs() << format(fmt.str().c_str(), outs() << format(fmt.str().c_str(), total_text, total_data, total_bss);
total_text,
total_data,
total_bss);
fmtbuf.clear(); fmtbuf.clear();
fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << " " fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << " "
<< "%7" PRIx64 " "; << "%7" PRIx64 " ";
outs() << format(fmt.str().c_str(), outs() << format(fmt.str().c_str(), total, total);
total,
total);
} }
} }
@@ -439,7 +425,7 @@ static bool checkMachOAndArchFlags(ObjectFile *o, StringRef file) {
T = MachOObjectFile::getArch(H.cputype, H.cpusubtype); T = MachOObjectFile::getArch(H.cputype, H.cpusubtype);
} }
unsigned i; unsigned i;
for (i = 0; i < ArchFlags.size(); ++i){ for (i = 0; i < ArchFlags.size(); ++i) {
if (ArchFlags[i] == T.getArchName()) if (ArchFlags[i] == T.getArchName())
ArchFound = true; ArchFound = true;
break; break;
@@ -460,7 +446,8 @@ static void PrintFileSectionSizes(StringRef file) {
if (file != "-") { if (file != "-") {
bool exists; bool exists;
if (sys::fs::exists(file, exists) || !exists) { if (sys::fs::exists(file, exists) || !exists) {
errs() << ToolName << ": '" << file << "': " << "No such file\n"; errs() << ToolName << ": '" << file << "': "
<< "No such file\n";
return; return;
} }
} }
@@ -476,7 +463,8 @@ static void PrintFileSectionSizes(StringRef file) {
if (Archive *a = dyn_cast<Archive>(binary.get())) { if (Archive *a = dyn_cast<Archive>(binary.get())) {
// This is an archive. Iterate over each member and display its sizes. // This is an archive. Iterate over each member and display its sizes.
for (object::Archive::child_iterator i = a->child_begin(), for (object::Archive::child_iterator i = a->child_begin(),
e = a->child_end(); i != e; ++i) { e = a->child_end();
i != e; ++i) {
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary(); ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) { if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
@@ -487,10 +475,9 @@ static void PrintFileSectionSizes(StringRef file) {
if (!checkMachOAndArchFlags(o, file)) if (!checkMachOAndArchFlags(o, file))
return; return;
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " (ex " << a->getFileName() outs() << o->getFileName() << " (ex " << a->getFileName() << "):\n";
<< "):\n"; else if (MachO && OutputFormat == darwin)
else if(MachO && OutputFormat == darwin) outs() << a->getFileName() << "(" << o->getFileName() << "):\n";
outs() << a->getFileName() << "(" << o->getFileName() << "):\n";
PrintObjectSectionSizes(o); PrintObjectSectionSizes(o);
if (OutputFormat == berkeley) { if (OutputFormat == berkeley) {
if (MachO) if (MachO)
@@ -501,17 +488,17 @@ static void PrintFileSectionSizes(StringRef file) {
} }
} }
} else if (MachOUniversalBinary *UB = } else if (MachOUniversalBinary *UB =
dyn_cast<MachOUniversalBinary>(binary.get())) { dyn_cast<MachOUniversalBinary>(binary.get())) {
// If we have a list of architecture flags specified dump only those. // If we have a list of architecture flags specified dump only those.
if (!ArchAll && ArchFlags.size() != 0) { if (!ArchAll && ArchFlags.size() != 0) {
// Look for a slice in the universal binary that matches each ArchFlag. // Look for a slice in the universal binary that matches each ArchFlag.
bool ArchFound; bool ArchFound;
for (unsigned i = 0; i < ArchFlags.size(); ++i){ for (unsigned i = 0; i < ArchFlags.size(); ++i) {
ArchFound = false; ArchFound = false;
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
E = UB->end_objects(); E = UB->end_objects();
I != E; ++I) { I != E; ++I) {
if (ArchFlags[i] == I->getArchTypeName()){ if (ArchFlags[i] == I->getArchTypeName()) {
ArchFound = true; ArchFound = true;
ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile(); ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
std::unique_ptr<Archive> UA; std::unique_ptr<Archive> UA;
@@ -520,7 +507,7 @@ static void PrintFileSectionSizes(StringRef file) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " :\n"; outs() << o->getFileName() << " :\n";
else if(MachO && OutputFormat == darwin) { else if (MachO && OutputFormat == darwin) {
if (moreThanOneFile || ArchFlags.size() > 1) if (moreThanOneFile || ArchFlags.size() > 1)
outs() << o->getFileName() << " (for architecture " outs() << o->getFileName() << " (for architecture "
<< I->getArchTypeName() << "): \n"; << I->getArchTypeName() << "): \n";
@@ -533,13 +520,12 @@ static void PrintFileSectionSizes(StringRef file) {
outs() << "\n"; outs() << "\n";
} }
} }
} } else if (!I->getAsArchive(UA)) {
else if (!I->getAsArchive(UA)) {
// This is an archive. Iterate over each member and display its // This is an archive. Iterate over each member and display its
//sizes. // sizes.
for (object::Archive::child_iterator i = UA->child_begin(), for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end(); e = UA->child_end();
i != e; ++i) { i != e; ++i) {
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary(); ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) { if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() errs() << ToolName << ": " << file << ": " << EC.message()
@@ -551,21 +537,21 @@ static void PrintFileSectionSizes(StringRef file) {
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " (ex " << UA->getFileName() outs() << o->getFileName() << " (ex " << UA->getFileName()
<< "):\n"; << "):\n";
else if(MachO && OutputFormat == darwin) else if (MachO && OutputFormat == darwin)
outs() << UA->getFileName() << "(" << o->getFileName() outs() << UA->getFileName() << "(" << o->getFileName()
<< ")" << " (for architecture " << ")"
<< I->getArchTypeName() << "):\n"; << " (for architecture " << I->getArchTypeName()
<< "):\n";
PrintObjectSectionSizes(o); PrintObjectSectionSizes(o);
if (OutputFormat == berkeley) { if (OutputFormat == berkeley) {
if (MachO) { if (MachO) {
outs() << UA->getFileName() << "(" << o->getFileName() outs() << UA->getFileName() << "(" << o->getFileName()
<< ")"; << ")";
if (ArchFlags.size() > 1) if (ArchFlags.size() > 1)
outs() << " (for architecture " outs() << " (for architecture " << I->getArchTypeName()
<< I->getArchTypeName() << ")"; << ")";
outs() << "\n"; outs() << "\n";
} } else
else
outs() << o->getFileName() << " (ex " << UA->getFileName() outs() << o->getFileName() << " (ex " << UA->getFileName()
<< ")\n"; << ")\n";
} }
@@ -585,12 +571,11 @@ static void PrintFileSectionSizes(StringRef file) {
// No architecture flags were specified so if this contains a slice that // No architecture flags were specified so if this contains a slice that
// matches the host architecture dump only that. // matches the host architecture dump only that.
if (!ArchAll) { if (!ArchAll) {
StringRef HostArchName = StringRef HostArchName = MachOObjectFile::getHostArch().getArchName();
MachOObjectFile::getHostArch().getArchName();
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
E = UB->end_objects(); E = UB->end_objects();
I != E; ++I) { I != E; ++I) {
if (HostArchName == I->getArchTypeName()){ if (HostArchName == I->getArchTypeName()) {
ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile(); ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
std::unique_ptr<Archive> UA; std::unique_ptr<Archive> UA;
if (UO) { if (UO) {
@@ -598,7 +583,7 @@ static void PrintFileSectionSizes(StringRef file) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " :\n"; outs() << o->getFileName() << " :\n";
else if(MachO && OutputFormat == darwin) { else if (MachO && OutputFormat == darwin) {
if (moreThanOneFile) if (moreThanOneFile)
outs() << o->getFileName() << " (for architecture " outs() << o->getFileName() << " (for architecture "
<< I->getArchTypeName() << "):\n"; << I->getArchTypeName() << "):\n";
@@ -611,13 +596,12 @@ static void PrintFileSectionSizes(StringRef file) {
outs() << "\n"; outs() << "\n";
} }
} }
} } else if (!I->getAsArchive(UA)) {
else if (!I->getAsArchive(UA)) {
// This is an archive. Iterate over each member and display its // This is an archive. Iterate over each member and display its
// sizes. // sizes.
for (object::Archive::child_iterator i = UA->child_begin(), for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end(); e = UA->child_end();
i != e; ++i) { i != e; ++i) {
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary(); ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) { if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() errs() << ToolName << ": " << file << ": " << EC.message()
@@ -629,7 +613,7 @@ static void PrintFileSectionSizes(StringRef file) {
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " (ex " << UA->getFileName() outs() << o->getFileName() << " (ex " << UA->getFileName()
<< "):\n"; << "):\n";
else if(MachO && OutputFormat == darwin) else if (MachO && OutputFormat == darwin)
outs() << UA->getFileName() << "(" << o->getFileName() << ")" outs() << UA->getFileName() << "(" << o->getFileName() << ")"
<< " (for architecture " << I->getArchTypeName() << " (for architecture " << I->getArchTypeName()
<< "):\n"; << "):\n";
@@ -662,7 +646,7 @@ static void PrintFileSectionSizes(StringRef file) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " :\n"; outs() << o->getFileName() << " :\n";
else if(MachO && OutputFormat == darwin) { else if (MachO && OutputFormat == darwin) {
if (moreThanOneFile || moreThanOneArch) if (moreThanOneFile || moreThanOneArch)
outs() << o->getFileName() << " (for architecture " outs() << o->getFileName() << " (for architecture "
<< I->getArchTypeName() << "):"; << I->getArchTypeName() << "):";
@@ -676,11 +660,11 @@ static void PrintFileSectionSizes(StringRef file) {
outs() << "\n"; outs() << "\n";
} }
} }
} } else if (!I->getAsArchive(UA)) {
else if (!I->getAsArchive(UA)) {
// This is an archive. Iterate over each member and display its sizes. // This is an archive. Iterate over each member and display its sizes.
for (object::Archive::child_iterator i = UA->child_begin(), for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end(); i != e; ++i) { e = UA->child_end();
i != e; ++i) {
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary(); ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) { if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
@@ -691,10 +675,9 @@ static void PrintFileSectionSizes(StringRef file) {
if (OutputFormat == sysv) if (OutputFormat == sysv)
outs() << o->getFileName() << " (ex " << UA->getFileName() outs() << o->getFileName() << " (ex " << UA->getFileName()
<< "):\n"; << "):\n";
else if(MachO && OutputFormat == darwin) else if (MachO && OutputFormat == darwin)
outs() << UA->getFileName() << "(" << o->getFileName() << ")" outs() << UA->getFileName() << "(" << o->getFileName() << ")"
<< " (for architecture " << I->getArchTypeName() << " (for architecture " << I->getArchTypeName() << "):\n";
<< "):\n";
PrintObjectSectionSizes(o); PrintObjectSectionSizes(o);
if (OutputFormat == berkeley) { if (OutputFormat == berkeley) {
if (MachO) if (MachO)
@@ -722,7 +705,8 @@ static void PrintFileSectionSizes(StringRef file) {
outs() << "\n"; outs() << "\n";
} }
} else { } else {
errs() << ToolName << ": " << file << ": " << "Unrecognized file type.\n"; errs() << ToolName << ": " << file << ": "
<< "Unrecognized file type.\n";
} }
// System V adds an extra newline at the end of each file. // System V adds an extra newline at the end of each file.
if (OutputFormat == sysv) if (OutputFormat == sysv)
@@ -734,7 +718,7 @@ int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal(); sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv); PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n"); cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");
ToolName = argv[0]; ToolName = argv[0];
@@ -743,13 +727,12 @@ int main(int argc, char **argv) {
if (RadixShort.getNumOccurrences()) if (RadixShort.getNumOccurrences())
Radix = RadixShort; Radix = RadixShort;
for (unsigned i = 0; i < ArchFlags.size(); ++i){ for (unsigned i = 0; i < ArchFlags.size(); ++i) {
if (ArchFlags[i] == "all") { if (ArchFlags[i] == "all") {
ArchAll = true; ArchAll = true;
} } else {
else {
Triple T = MachOObjectFile::getArch(ArchFlags[i]); Triple T = MachOObjectFile::getArch(ArchFlags[i]);
if (T.getArch() == Triple::UnknownArch){ if (T.getArch() == Triple::UnknownArch) {
outs() << ToolName << ": for the -arch option: Unknown architecture " outs() << ToolName << ": for the -arch option: Unknown architecture "
<< "named '" << ArchFlags[i] << "'"; << "named '" << ArchFlags[i] << "'";
return 1; return 1;