llvm.org GIT mirror llvm / fb2b9fb
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 Kevin Enderby 5 years ago
3 changed file(s) with 65 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
5252 MachOUniversalBinary::ObjectForArch::ObjectForArch(
5353 const MachOUniversalBinary *Parent, uint32_t Index)
5454 : Parent(Parent), Index(Index) {
55 if (!Parent || Index > Parent->getNumberOfObjects()) {
55 if (!Parent || Index >= Parent->getNumberOfObjects()) {
5656 clear();
5757 } else {
5858 // Parse object header.
99 RUN: | FileCheck %s -check-prefix mAR
1010 RUN: llvm-size -format darwin -x -l %p/Inputs/hello-world.macho-x86_64 \
1111 RUN: | FileCheck %s -check-prefix mxl
12 RUN: llvm-size %p/Inputs/macho-universal.x86_64.i386 \
13 RUN: | FileCheck %s -check-prefix u
14 RUN: llvm-size %p/Inputs/macho-universal-archive.x86_64.i386 \
15 RUN: | FileCheck %s -check-prefix uAR
1216
1317 A: section size addr
1418 A: __text 12 0
6468 mxl: total 0x18
6569 mxl: Segment __LINKEDIT: 0x1000 (vmaddr 0x100002000 fileoff 8192)
6670 mxl: total 0x100003000
71
72 u: __TEXT __DATA __OBJC others dec hex
73 u: 4096 0 0 4294971392 4294975488 100002000 {{.*}}/macho-universal.x86_64.i386:x86_64
74 u: 4096 0 0 8192 12288 3000 {{.*}}/macho-universal.x86_64.i386:i386
75
76 uAR: __TEXT __DATA __OBJC others dec hex
77 uAR: 136 0 0 32 168 a8 {{.*}}/macho-universal-archive.x86_64.i386:x86_64(hello.o)
78 uAR: 5 4 0 0 9 9 {{.*}}/macho-universal-archive.x86_64.i386:i386(foo.o)
1616 #include "llvm/Object/Archive.h"
1717 #include "llvm/Object/ObjectFile.h"
1818 #include "llvm/Object/MachO.h"
19 #include "llvm/Object/MachOUniversal.h"
1920 #include "llvm/Support/Casting.h"
2021 #include "llvm/Support/CommandLine.h"
2122 #include "llvm/Support/FileSystem.h"
455456 }
456457 }
457458 }
459 } else if (MachOUniversalBinary *UB =
460 dyn_cast(binary.get())) {
461 // This is a Mach-O universal binary. Iterate over each object and
462 // display its sizes.
463 bool moreThanOneArch = UB->getNumberOfObjects() > 1;
464 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
465 E = UB->end_objects();
466 I != E; ++I) {
467 std::unique_ptr UO;
468 std::unique_ptr UA;
469 if (!I->getAsObjectFile(UO)) {
470 if (ObjectFile *o = dyn_cast(&*UO.get())) {
471 if (OutputFormat == sysv)
472 outs() << o->getFileName() << " :\n";
473 PrintObjectSectionSizes(o);
474 if (OutputFormat == berkeley) {
475 MachOObjectFile *MachO = dyn_cast(o);
476 if (!MachO || moreThanOneFile || moreThanOneArch)
477 outs() << o->getFileName();
478 outs() << "\n";
479 }
480 }
481 }
482 else if (!I->getAsArchive(UA)) {
483 // This is an archive. Iterate over each member and display its sizes.
484 for (object::Archive::child_iterator i = UA->child_begin(),
485 e = UA->child_end(); i != e; ++i) {
486 ErrorOr> ChildOrErr = i->getAsBinary();
487 if (std::error_code EC = ChildOrErr.getError()) {
488 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
489 continue;
490 }
491 if (ObjectFile *o = dyn_cast(&*ChildOrErr.get())) {
492 MachOObjectFile *MachO = dyn_cast(o);
493 if (OutputFormat == sysv)
494 outs() << o->getFileName() << " (ex " << UA->getFileName()
495 << "):\n";
496 else if(MachO && OutputFormat == darwin)
497 outs() << UA->getFileName() << "(" << o->getFileName() << "):\n";
498 PrintObjectSectionSizes(o);
499 if (OutputFormat == berkeley) {
500 if (MachO)
501 outs() << UA->getFileName() << "(" << o->getFileName() << ")\n";
502 else
503 outs() << o->getFileName() << " (ex " << UA->getFileName()
504 << ")\n";
505 }
506 }
507 }
508 }
509 }
458510 } else if (ObjectFile *o = dyn_cast(binary.get())) {
459511 if (OutputFormat == sysv)
460512 outs() << o->getFileName() << " :\n";