llvm.org GIT mirror llvm / c28016e
Change the output of llvm-nm and llvm-size for Mach-O universal files (aka fat files) to print “ (for architecture XYZ)” for fat files with more than one architecture to be like what the darwin tools do for fat files. Also clean up the Mach-O printing of archive membernames in llvm-nm to use the darwin form of "libx.a(foo.o)". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211316 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 5 years ago
6 changed file(s) with 47 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/ADT/Triple.h"
1818 #include "llvm/Object/Binary.h"
1919 #include "llvm/Object/Archive.h"
20 #include "llvm/Object/MachO.h"
2021 #include "llvm/Support/ErrorOr.h"
2122 #include "llvm/Support/MachO.h"
2223
5152
5253 ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
5354 uint32_t getCPUType() const { return Header.cputype; }
55 std::string getArchTypeName() const {
56 return Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
57 }
5458
5559 std::error_code getAsObjectFile(std::unique_ptr &Result) const;
5660
7171 if (Parent) {
7272 StringRef ParentData = Parent->getData();
7373 StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
74 std::string ObjectName =
75 Parent->getFileName().str() + ":" +
76 Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
74 std::string ObjectName = Parent->getFileName().str();
7775 MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
7876 ObjectData, ObjectName, false);
7977 ErrorOr Obj = ObjectFile::createMachOObjectFile(ObjBuffer);
9088 if (Parent) {
9189 StringRef ParentData = Parent->getData();
9290 StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
93 std::string ObjectName =
94 Parent->getFileName().str() + ":" +
95 Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
91 std::string ObjectName = Parent->getFileName().str();
9692 MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
9793 ObjectData, ObjectName, false);
9894 ErrorOr Obj = Archive::create(ObjBuffer);
22 RUN: llvm-nm %p/Inputs/macho-universal-archive.x86_64.i386 \
33 RUN: | FileCheck %s -check-prefix CHECK-AR
44
5 CHECK-OBJ: macho-universal.x86_64.i386:x86_64
5 CHECK-OBJ: macho-universal.x86_64.i386 (for architecture x86_64):
66 CHECK-OBJ: 0000000100000f60 T _main
7 CHECK-OBJ: macho-universal.x86_64.i386:i386
7 CHECK-OBJ: macho-universal.x86_64.i386 (for architecture i386):
88 CHECK-OBJ: 00001fa0 T _main
99
10 CHECK-AR: macho-universal-archive.x86_64.i386:x86_64:hello.o:
10 CHECK-AR: macho-universal-archive.x86_64.i386(hello.o) (for architecture x86_64):
1111 CHECK-AR: 0000000000000068 s EH_frame0
1212 CHECK-AR: 000000000000003b s L_.str
1313 CHECK-AR: 0000000000000000 T _main
1414 CHECK-AR: 0000000000000080 S _main.eh
1515 CHECK-AR: U _printf
16 CHECK-AR: macho-universal-archive.x86_64.i386:i386:foo.o:
16 CHECK-AR: macho-universal-archive.x86_64.i386(foo.o) (for architecture i386):
1717 CHECK-AR: 00000008 S _bar
1818 CHECK-AR: 00000000 T _foo
7070 mxl: total 0x100003000
7171
7272 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
73 u: 4096 0 0 4294971392 4294975488 100002000 {{.*}}/macho-universal.x86_64.i386 (for architecture x86_64)
74 u: 4096 0 0 8192 12288 3000 {{.*}}/macho-universal.x86_64.i386 (for architecture i386)
7575
7676 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)
77 uAR: 136 0 0 32 168 a8 {{.*}}/macho-universal-archive.x86_64.i386(hello.o) (for architecture x86_64)
78 uAR: 5 4 0 0 9 9 {{.*}}/macho-universal-archive.x86_64.i386(foo.o) (for architecture i386)
751751 if (ChildOrErr.getError())
752752 continue;
753753 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
754 outs() << O->getFileName() << ":\n";
754 if (isa(O)) {
755 outs() << Filename << "(" << O->getFileName() << ")";
756 } else
757 outs() << O->getFileName();
758 outs() << ":\n";
755759 dumpSymbolNamesFromObject(O);
756760 }
757761 }
758762 return;
759763 }
760764 if (MachOUniversalBinary *UB = dyn_cast(Bin.get())) {
765 bool moreThanOneArch = UB->getNumberOfObjects() > 1;
761766 for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
762767 E = UB->end_objects();
763768 I != E; ++I) {
764769 std::unique_ptr Obj;
765770 std::unique_ptr A;
766771 if (!I->getAsObjectFile(Obj)) {
767 outs() << Obj->getFileName() << ":\n";
772 outs() << Obj->getFileName();
773 if (isa(Obj.get()) && moreThanOneArch)
774 outs() << " (for architecture " << I->getArchTypeName() << ")";
775 outs() << ":\n";
768776 dumpSymbolNamesFromObject(Obj.get());
769777 }
770778 else if (!I->getAsArchive(A)) {
775783 if (ChildOrErr.getError())
776784 continue;
777785 if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) {
778 outs() << A->getFileName() << ":";
779 outs() << O->getFileName() << ":\n";
786 outs() << A->getFileName();
787 if (isa(O)) {
788 outs() << "(" << O->getFileName() << ")";
789 if (moreThanOneArch)
790 outs() << " (for architecture " << I->getArchTypeName() << ")";
791 } else
792 outs() << ":" << O->getFileName();
793 outs() << ":\n";
780794 dumpSymbolNamesFromObject(O);
781795 }
782796 }
468468 std::unique_ptr UA;
469469 if (!I->getAsObjectFile(UO)) {
470470 if (ObjectFile *o = dyn_cast(&*UO.get())) {
471 MachOObjectFile *MachO = dyn_cast(o);
471472 if (OutputFormat == sysv)
472473 outs() << o->getFileName() << " :\n";
474 else if(MachO && OutputFormat == darwin) {
475 if (moreThanOneFile || moreThanOneArch)
476 outs() << o->getFileName() << " (for architecture "
477 << I->getArchTypeName() << "):";
478 outs() << "\n";
479 }
473480 PrintObjectSectionSizes(o);
474481 if (OutputFormat == berkeley) {
475 MachOObjectFile *MachO = dyn_cast(o);
476482 if (!MachO || moreThanOneFile || moreThanOneArch)
477 outs() << o->getFileName();
483 outs() << o->getFileName() << " (for architecture "
484 << I->getArchTypeName() << ")";
478485 outs() << "\n";
479486 }
480487 }
494501 outs() << o->getFileName() << " (ex " << UA->getFileName()
495502 << "):\n";
496503 else if(MachO && OutputFormat == darwin)
497 outs() << UA->getFileName() << "(" << o->getFileName() << "):\n";
504 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
505 << " (for architecture " << I->getArchTypeName()
506 << "):\n";
498507 PrintObjectSectionSizes(o);
499508 if (OutputFormat == berkeley) {
500509 if (MachO)
501 outs() << UA->getFileName() << "(" << o->getFileName() << ")\n";
510 outs() << UA->getFileName() << "(" << o->getFileName() << ")"
511 << " (for architecture " << I->getArchTypeName()
512 << ")\n";
502513 else
503514 outs() << o->getFileName() << " (ex " << UA->getFileName()
504515 << ")\n";