diff options
author | Kevin Enderby <enderby@apple.com> | 2014-06-18 22:04:40 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2014-06-18 22:04:40 +0000 |
commit | fb2b9fb894b6c9be8a290bdf69c29f0f5511ba3c (patch) | |
tree | 870821c76b4ffa05d6db078eaac6d52aae75bd9c /tools | |
parent | ce09bda96ee00a1024952faf85e3fa01e0d6bc72 (diff) | |
download | llvm-fb2b9fb894b6c9be8a290bdf69c29f0f5511ba3c.tar.gz llvm-fb2b9fb894b6c9be8a290bdf69c29f0f5511ba3c.tar.bz2 llvm-fb2b9fb894b6c9be8a290bdf69c29f0f5511ba3c.tar.xz |
Teach llvm-size to know about Mach-O universal files (aka fat files) and
fat files containing archives.
Also fix a bug in MachOUniversalBinary::ObjectForArch::ObjectForArch()
where it needed a >= when comparing the Index with the number of
objects in a fat file. As the index starts at 0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211230 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-size/llvm-size.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp index 5e4e4aa932..b3aaac8d27 100644 --- a/tools/llvm-size/llvm-size.cpp +++ b/tools/llvm-size/llvm-size.cpp @@ -17,6 +17,7 @@ #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Object/MachO.h" +#include "llvm/Object/MachOUniversal.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -456,6 +457,57 @@ static void PrintFileSectionSizes(StringRef file) { } } } + } else if (MachOUniversalBinary *UB = + dyn_cast<MachOUniversalBinary>(binary.get())) { + // This is a Mach-O universal binary. Iterate over each object and + // display its sizes. + bool moreThanOneArch = UB->getNumberOfObjects() > 1; + for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), + E = UB->end_objects(); + I != E; ++I) { + std::unique_ptr<ObjectFile> UO; + std::unique_ptr<Archive> UA; + if (!I->getAsObjectFile(UO)) { + if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) { + if (OutputFormat == sysv) + outs() << o->getFileName() << " :\n"; + PrintObjectSectionSizes(o); + if (OutputFormat == berkeley) { + MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); + if (!MachO || moreThanOneFile || moreThanOneArch) + outs() << o->getFileName(); + outs() << "\n"; + } + } + } + else if (!I->getAsArchive(UA)) { + // This is an archive. Iterate over each member and display its sizes. + for (object::Archive::child_iterator i = UA->child_begin(), + e = UA->child_end(); i != e; ++i) { + ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary(); + if (std::error_code EC = ChildOrErr.getError()) { + errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; + continue; + } + if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { + MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); + if (OutputFormat == sysv) + outs() << o->getFileName() << " (ex " << UA->getFileName() + << "):\n"; + else if(MachO && OutputFormat == darwin) + outs() << UA->getFileName() << "(" << o->getFileName() << "):\n"; + PrintObjectSectionSizes(o); + if (OutputFormat == berkeley) { + if (MachO) + outs() << UA->getFileName() << "(" << o->getFileName() << ")\n"; + else + outs() << o->getFileName() << " (ex " << UA->getFileName() + << ")\n"; + } + } + } + } + } } else if (ObjectFile *o = dyn_cast<ObjectFile>(binary.get())) { if (OutputFormat == sysv) outs() << o->getFileName() << " :\n"; |