Change the output of llvm-nm and llvm-size for Mach-O universal files (aka
authorKevin Enderby <enderby@apple.com>
Thu, 19 Jun 2014 22:03:18 +0000 (22:03 +0000)
committerKevin Enderby <enderby@apple.com>
Thu, 19 Jun 2014 22:03:18 +0000 (22:03 +0000)
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)".

llvm-svn: 211316

llvm/include/llvm/Object/MachOUniversal.h
llvm/lib/Object/MachOUniversal.cpp
llvm/test/Object/nm-universal-binary.test
llvm/test/Object/size-trivial-macho.test
llvm/tools/llvm-nm/llvm-nm.cpp
llvm/tools/llvm-size/llvm-size.cpp

index 47e93c2..74448f9 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/Archive.h"
+#include "llvm/Object/MachO.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/MachO.h"
 
@@ -52,6 +53,9 @@ public:
 
     ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
     uint32_t getCPUType() const { return Header.cputype; }
+    std::string getArchTypeName() const {
+      return Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
+    }
 
     std::error_code getAsObjectFile(std::unique_ptr<ObjectFile> &Result) const;
 
index 05729ef..887e2bd 100644 (file)
@@ -72,9 +72,7 @@ std::error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile(
   if (Parent) {
     StringRef ParentData = Parent->getData();
     StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
-    std::string ObjectName =
-        Parent->getFileName().str() + ":" +
-        Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
+    std::string ObjectName = Parent->getFileName().str();
     MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
         ObjectData, ObjectName, false);
     ErrorOr<ObjectFile *> Obj = ObjectFile::createMachOObjectFile(ObjBuffer);
@@ -91,9 +89,7 @@ std::error_code MachOUniversalBinary::ObjectForArch::getAsArchive(
   if (Parent) {
     StringRef ParentData = Parent->getData();
     StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
-    std::string ObjectName =
-        Parent->getFileName().str() + ":" +
-        Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
+    std::string ObjectName = Parent->getFileName().str();
     MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
         ObjectData, ObjectName, false);
     ErrorOr<Archive *> Obj = Archive::create(ObjBuffer);
index c20c733..5278126 100644 (file)
@@ -3,17 +3,17 @@ RUN:         | FileCheck %s -check-prefix CHECK-OBJ
 RUN: llvm-nm %p/Inputs/macho-universal-archive.x86_64.i386 \
 RUN:         | FileCheck %s -check-prefix CHECK-AR
 
-CHECK-OBJ: macho-universal.x86_64.i386:x86_64
+CHECK-OBJ: macho-universal.x86_64.i386 (for architecture x86_64):
 CHECK-OBJ: 0000000100000f60 T _main
-CHECK-OBJ: macho-universal.x86_64.i386:i386
+CHECK-OBJ: macho-universal.x86_64.i386 (for architecture i386):
 CHECK-OBJ: 00001fa0 T _main
 
-CHECK-AR: macho-universal-archive.x86_64.i386:x86_64:hello.o:
+CHECK-AR: macho-universal-archive.x86_64.i386(hello.o) (for architecture x86_64):
 CHECK-AR: 0000000000000068 s EH_frame0
 CHECK-AR: 000000000000003b s L_.str
 CHECK-AR: 0000000000000000 T _main
 CHECK-AR: 0000000000000080 S _main.eh
 CHECK-AR:                  U _printf
-CHECK-AR: macho-universal-archive.x86_64.i386:i386:foo.o:
+CHECK-AR: macho-universal-archive.x86_64.i386(foo.o) (for architecture i386):
 CHECK-AR: 00000008 S _bar
 CHECK-AR: 00000000 T _foo
index 1ed611b..6602d56 100644 (file)
@@ -71,9 +71,9 @@ mxl: Segment __LINKEDIT: 0x1000 (vmaddr 0x100002000 fileoff 8192)
 mxl: total 0x100003000
 
 u: __TEXT      __DATA  __OBJC  others  dec     hex
-u: 4096        0       0       4294971392      4294975488      100002000       {{.*}}/macho-universal.x86_64.i386:x86_64
-u: 4096        0       0       8192    12288   3000    {{.*}}/macho-universal.x86_64.i386:i386
+u: 4096        0       0       4294971392      4294975488      100002000       {{.*}}/macho-universal.x86_64.i386 (for architecture x86_64)
+u: 4096        0       0       8192    12288   3000    {{.*}}/macho-universal.x86_64.i386 (for architecture i386)
 
 uAR: __TEXT    __DATA  __OBJC  others  dec     hex
-uAR: 136       0       0       32      168     a8      {{.*}}/macho-universal-archive.x86_64.i386:x86_64(hello.o)
-uAR: 5 4       0       0       9       9       {{.*}}/macho-universal-archive.x86_64.i386:i386(foo.o)
+uAR: 136       0       0       32      168     a8      {{.*}}/macho-universal-archive.x86_64.i386(hello.o) (for architecture x86_64)
+uAR: 5 4       0       0       9       9       {{.*}}/macho-universal-archive.x86_64.i386(foo.o) (for architecture i386)
index e605e6e..c6b80d1 100644 (file)
@@ -752,20 +752,28 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
       if (ChildOrErr.getError())
         continue;
       if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
-        outs() << O->getFileName() << ":\n";
+        if (isa<MachOObjectFile>(O)) {
+          outs() << Filename << "(" << O->getFileName() << ")";
+        } else
+          outs() << O->getFileName();
+        outs() << ":\n";
         dumpSymbolNamesFromObject(O);
       }
     }
     return;
   }
   if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(Bin.get())) {
+    bool moreThanOneArch = UB->getNumberOfObjects() > 1;
     for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
                                                E = UB->end_objects();
          I != E; ++I) {
       std::unique_ptr<ObjectFile> Obj;
       std::unique_ptr<Archive> A;
       if (!I->getAsObjectFile(Obj)) {
-        outs() << Obj->getFileName() << ":\n";
+        outs() << Obj->getFileName();
+        if (isa<MachOObjectFile>(Obj.get()) && moreThanOneArch)
+          outs() << " (for architecture " << I->getArchTypeName() << ")";
+        outs() << ":\n";
         dumpSymbolNamesFromObject(Obj.get());
       }
       else if (!I->getAsArchive(A)) {
@@ -776,8 +784,14 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
           if (ChildOrErr.getError())
             continue;
           if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
-            outs() << A->getFileName() << ":";
-            outs() << O->getFileName() << ":\n";
+            outs() << A->getFileName();
+            if (isa<MachOObjectFile>(O)) {
+              outs() << "(" << O->getFileName() << ")";
+              if (moreThanOneArch)
+                outs() << " (for architecture " << I->getArchTypeName() << ")";
+            } else
+              outs() << ":" << O->getFileName();
+            outs() << ":\n";
             dumpSymbolNamesFromObject(O);
           }
         }
index b3aaac8..408bb4a 100644 (file)
@@ -469,13 +469,20 @@ static void PrintFileSectionSizes(StringRef file) {
       std::unique_ptr<Archive> UA;
       if (!I->getAsObjectFile(UO)) {
         if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
+          MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
           if (OutputFormat == sysv)
             outs() << o->getFileName() << "  :\n";
+          else if(MachO && OutputFormat == darwin) {
+            if (moreThanOneFile || moreThanOneArch)
+              outs() << o->getFileName() << " (for architecture "
+                     << I->getArchTypeName() << "):";
+            outs() << "\n";
+          }
           PrintObjectSectionSizes(o);
           if (OutputFormat == berkeley) {
-            MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
             if (!MachO || moreThanOneFile || moreThanOneArch)
-              outs() << o->getFileName();
+              outs() << o->getFileName() << " (for architecture "
+                     << I->getArchTypeName() << ")";
             outs() << "\n";
           }
         }
@@ -495,11 +502,15 @@ static void PrintFileSectionSizes(StringRef file) {
               outs() << o->getFileName() << "   (ex " << UA->getFileName()
                      << "):\n";
             else if(MachO && OutputFormat == darwin)
-              outs() << UA->getFileName() << "(" << o->getFileName() << "):\n";
+              outs() << UA->getFileName() << "(" << o->getFileName() << ")"
+                     << " (for architecture " << I->getArchTypeName()
+                     << "):\n";
             PrintObjectSectionSizes(o);
             if (OutputFormat == berkeley) {
               if (MachO)
-                outs() << UA->getFileName() << "(" << o->getFileName() << ")\n";
+                outs() << UA->getFileName() << "(" << o->getFileName() << ")"
+                       << " (for architecture " << I->getArchTypeName()
+                       << ")\n";
               else
                 outs() << o->getFileName() << " (ex " << UA->getFileName()
                        << ")\n";