Add the option, -non-verbose to llvm-objdump used with -macho to print things
authorKevin Enderby <enderby@apple.com>
Fri, 13 Mar 2015 17:56:32 +0000 (17:56 +0000)
committerKevin Enderby <enderby@apple.com>
Fri, 13 Mar 2015 17:56:32 +0000 (17:56 +0000)
using numeric values and not their symbolic constant names.

The routines that print Mach-O stuff already had a verbose parameter and this
change is just changing the passing true to passing !NonVerbose.  With just a
couple of fixes and a bunch of test case updates.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232182 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-objdump/ARM/macho-data-in-code.test
test/tools/llvm-objdump/X86/macho-cstring-dump.test
test/tools/llvm-objdump/X86/macho-indirect-symbols.test
test/tools/llvm-objdump/X86/macho-literal-pointers-i386.test
test/tools/llvm-objdump/X86/macho-literal-pointers-x86_64.test
test/tools/llvm-objdump/X86/macho-literals.test
test/tools/llvm-objdump/X86/macho-private-headers.test
test/tools/llvm-objdump/X86/macho-section.test
test/tools/llvm-objdump/X86/macho-universal-x86_64.i386.test
tools/llvm-objdump/MachODump.cpp
tools/llvm-objdump/llvm-objdump.h

index 1814dc02862aa7cd67892cc67758cadd71349b3b..c7a6da1d9504b7753fd5cd49efc4fc0593decfa6 100644 (file)
@@ -1,4 +1,5 @@
 RUN: llvm-objdump -m -data-in-code %p/Inputs/data-in-code.macho-arm | FileCheck %s
+RUN: llvm-objdump -m -data-in-code -non-verbose %p/Inputs/data-in-code.macho-arm | FileCheck %s -check-prefix=NON_VERBOSE
 
 CHECK: Data in code table (4 entries)
 CHECK: offset     length kind
@@ -6,3 +7,10 @@ CHECK: 0x00000000      4 DATA
 CHECK: 0x00000004      4 JUMP_TABLE32
 CHECK: 0x00000008      2 JUMP_TABLE16
 CHECK: 0x0000000a      1 JUMP_TABLE8
+
+NON_VERBOSE: Data in code table (4 entries)
+NON_VERBOSE: offset     length kind
+NON_VERBOSE: 0x00000000      4 0x0001
+NON_VERBOSE: 0x00000004      4 0x0004
+NON_VERBOSE: 0x00000008      2 0x0003
+NON_VERBOSE: 0x0000000a      1 0x0002
index 3dfa4e34b262e6f4307fd5aade912cf68eaf7e12..a45690dbd7d95c8492674e7ff38cf46dcc4827f0 100644 (file)
@@ -1,4 +1,8 @@
 RUN: llvm-objdump -m -section __TEXT,__cstring %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
+RUN: llvm-objdump -m -section __TEXT,__cstring -non-verbose %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s -check-prefix=NON_VERBOSE
 
 CHECK: Contents of (__TEXT,__cstring) section
 CHECK: 000000000000003b  Hello world\n
+
+NON_VERBOSE: Contents of (__TEXT,__cstring) section
+NON_VERBOSE: 000000000000003b  48 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 
index 4f3af181c062edda30f3dba8c52fec0c512950c7..fdc465ad54258ba6bbf68cb68330e3f3cae9b455 100644 (file)
@@ -1,4 +1,5 @@
 RUN: llvm-objdump -macho -indirect-symbols %p/Inputs/hello.exe.macho-x86_64 | FileCheck %s
+RUN: llvm-objdump -macho -indirect-symbols -non-verbose %p/Inputs/hello.exe.macho-x86_64 | FileCheck %s -check-prefix=NON_VERBOSE
 
 CHECK: Indirect symbols for (__TEXT,__stubs) 1 entries
 CHECK: address            index name
@@ -10,3 +11,14 @@ CHECK: 0x0000000100001008 ABSOLUTE
 CHECK: Indirect symbols for (__DATA,__la_symbol_ptr) 1 entries
 CHECK: address            index name
 CHECK: 0x0000000100001010     2 _printf
+
+NON_VERBOSE: Indirect symbols for (__TEXT,__stubs) 1 entries
+NON_VERBOSE: address            index
+NON_VERBOSE: 0x0000000100000f6c     2 
+NON_VERBOSE: Indirect symbols for (__DATA,__nl_symbol_ptr) 2 entries
+NON_VERBOSE: address            index
+NON_VERBOSE: 0x0000000100001000     3 
+NON_VERBOSE: 0x0000000100001008 ABSOLUTE
+NON_VERBOSE: Indirect symbols for (__DATA,__la_symbol_ptr) 1 entries
+NON_VERBOSE: address            index
+NON_VERBOSE: 0x0000000100001010     2 
index 0069668c9909de4103fbedb2e5a494fff4abba43..62ed607c8ee54163ba009aa603b670bd20d10daf 100644 (file)
@@ -1,4 +1,5 @@
 # RUN: llvm-mc < %s -triple i386-apple-darwin -filetype=obj | llvm-objdump -m -section __DATA,__litp - | FileCheck %s
+# RUN: llvm-mc < %s -triple i386-apple-darwin -filetype=obj | llvm-objdump -m -section __DATA,__litp -non-verbose - | FileCheck %s -check-prefix=NON-VERBOSE
 
 .cstring
 L1: .asciz "Hello world\n"
@@ -32,3 +33,7 @@ L5: .asciz "const non-literal string"
 # CHECK: 00000054  __TEXT:__literal8:0x00000000 0x40200000
 # CHECK: 00000058  __TEXT:__literal16:0x10000016 0x20000016 0x30000016 0x40000016
 # CHECK: 0000005c  0x30 (not in a literal section)
+
+# NON-VERBOSE: Contents of (__DATA,__litp) section
+# NON-VERBOSE: 0000004c        00 00 00 00 10 00 00 00 18 00 00 00 20 00 00 00 
+# NON-VERBOSE: 0000005c        30 00 00 00 
index b403b8154de34ff502e6518a6db4065fa95dd7a1..f1912e8861cbe6f8cc3b8ba85fce82976eb6fb9d 100644 (file)
@@ -1,4 +1,5 @@
 # RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __DATA,__litp - | FileCheck %s
+# RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __DATA,__litp -non-verbose - | FileCheck %s -check-prefix=NON-VERBOSE
 
 .cstring
 L1: .asciz "Hello world\n"
@@ -32,3 +33,8 @@ L5: .asciz "const non-literal string"
 # CHECK: 0000000000000060  __TEXT:__literal8:0x00000000 0x40200000
 # CHECK: 0000000000000068  __TEXT:__literal16:0x10000016 0x20000016 0x30000016 0x40000016
 # CHECK: 0000000000000070  0x30 (not in a literal section)
+
+# NON-VERBOSE: Contents of (__DATA,__litp) section
+# NON-VERBOSE: 0000000000000050        00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 
+# NON-VERBOSE: 0000000000000060        18 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 
+# NON-VERBOSE: 0000000000000070        30 00 00 00 00 00 00 00 
index 4824453a9767dbed10865bc468e10a31c15e3bb5..d93ae679f348b2df7f248030f2b766631ede5d2f 100644 (file)
@@ -1,6 +1,9 @@
 # RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __TEXT,__literal4 - | FileCheck %s -check-prefix=CHECK-LIT4
+# RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __TEXT,__literal4 -non-verbose - | FileCheck %s -check-prefix=NON-VERBOSE-LIT4
 # RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __TEXT,__literal8 - | FileCheck %s -check-prefix=CHECK-LIT8
+# RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __TEXT,__literal8 -non-verbose - | FileCheck %s -check-prefix=NON-VERBOSE-LIT8
 # RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __TEXT,__literal16 - | FileCheck %s -check-prefix=CHECK-LIT16
+# RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __TEXT,__literal16 -non-verbose - | FileCheck %s -check-prefix=NON-VERBOSE-LIT16
 
 .literal4
 .float 2.5
 # CHECK-LIT4: 0000000000000010  0x7fc00000
 # CHECK-LIT4: 0000000000000014  0x7f800001
 
+# NON-VERBOSE-LIT4: Contents of (__TEXT,__literal4) section
+# NON-VERBOSE-LIT4: 0000000000000000   00 00 20 40 00 00 04 41 00 00 80 7f 00 00 80 ff 
+# NON-VERBOSE-LIT4: 0000000000000010   00 00 c0 7f 01 00 80 7f 
+
 .literal8
 .double 2.5
 .double 8.25
 # CHECK-LIT8: 0000000000000038  0x00000000 0x7ff80000
 # CHECK-LIT8: 0000000000000040  0x00000001 0x7ff00000
 
+# NON-VERBOSE-LIT8: Contents of (__TEXT,__literal8) section
+# NON-VERBOSE-LIT8: 0000000000000018   00 00 00 00 00 00 04 40 00 00 00 00 00 80 20 40 
+# NON-VERBOSE-LIT8: 0000000000000028   00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 ff 
+# NON-VERBOSE-LIT8: 0000000000000038   00 00 00 00 00 00 f8 7f 01 00 00 00 00 00 f0 7f 
+
 .literal16
 .long 1
 .long 2
@@ -46,3 +58,6 @@
 
 # CHECK-LIT16: Contents of (__TEXT,__literal16) section
 # CHECK-LIT16: 0000000000000050  0x00000001 0x00000002 0x00000003 0x00000004
+
+# NON-VERBOSE-LIT16: Contents of (__TEXT,__literal16) section
+# NON-VERBOSE-LIT16: 0000000000000050  01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 
index c80bb083af3748a3e0a24472f6d45f4c10f1ec3f..ff45b1823fff28600900fb6e7aa11cfbb064c7c3 100644 (file)
@@ -19,6 +19,8 @@
 // RUN:     | FileCheck %s -check-prefix=THREAD
 // RUN: llvm-objdump -macho -p -arch i386 %p/Inputs/macho-universal.x86_64.i386 \
 // RUN:     | FileCheck %s -check-prefix=FATi386
+// RUN: llvm-objdump -p -non-verbose %p/Inputs/hello.obj.macho-x86_64 \
+// RUN:     | FileCheck %s -check-prefix=NON_VERBOSE
 
 CHECK: Mach header
 CHECK:       magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
@@ -443,3 +445,95 @@ THREAD:     gs  0x0000000000000000
 FATi386: Mach header
 FATi386:       magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 FATi386:    MH_MAGIC    I386        ALL  0x00     EXECUTE    16        716   NOUNDEFS DYLDLINK TWOLEVEL PIE MH_NO_HEAP_EXECUTION
+
+NON_VERBOSE: Mach header
+NON_VERBOSE:       magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
+NON_VERBOSE:  0xfeedfacf 16777223          3  0x00           1     3        496 0x00002000
+NON_VERBOSE: Load command 0
+NON_VERBOSE:       cmd LC_SEGMENT_64
+NON_VERBOSE:   cmdsize 392
+NON_VERBOSE:   segname 
+NON_VERBOSE:    vmaddr 0x0000000000000000
+NON_VERBOSE:    vmsize 0x00000000000000a8
+NON_VERBOSE:   fileoff 528
+NON_VERBOSE:  filesize 168
+NON_VERBOSE:   maxprot 0x00000007
+NON_VERBOSE:  initprot 0x00000007
+NON_VERBOSE:    nsects 4
+NON_VERBOSE:     flags 0x0
+NON_VERBOSE: Section
+NON_VERBOSE:   sectname __text
+NON_VERBOSE:    segname __TEXT
+NON_VERBOSE:       addr 0x0000000000000000
+NON_VERBOSE:       size 0x000000000000003b
+NON_VERBOSE:     offset 528
+NON_VERBOSE:      align 2^4 (16)
+NON_VERBOSE:     reloff 696
+NON_VERBOSE:     nreloc 2
+NON_VERBOSE:      flags 0x80000400
+NON_VERBOSE:  reserved1 0
+NON_VERBOSE:  reserved2 0
+NON_VERBOSE: Section
+NON_VERBOSE:   sectname __cstring
+NON_VERBOSE:    segname __TEXT
+NON_VERBOSE:       addr 0x000000000000003b
+NON_VERBOSE:       size 0x000000000000000d
+NON_VERBOSE:     offset 587
+NON_VERBOSE:      align 2^0 (1)
+NON_VERBOSE:     reloff 0
+NON_VERBOSE:     nreloc 0
+NON_VERBOSE:      flags 0x00000002
+NON_VERBOSE:  reserved1 0
+NON_VERBOSE:  reserved2 0
+NON_VERBOSE: Section
+NON_VERBOSE:   sectname __compact_unwind
+NON_VERBOSE:    segname __LD
+NON_VERBOSE:       addr 0x0000000000000048
+NON_VERBOSE:       size 0x0000000000000020
+NON_VERBOSE:     offset 600
+NON_VERBOSE:      align 2^3 (8)
+NON_VERBOSE:     reloff 712
+NON_VERBOSE:     nreloc 1
+NON_VERBOSE:      flags 0x02000000
+NON_VERBOSE:  reserved1 0
+NON_VERBOSE:  reserved2 0
+NON_VERBOSE: Section
+NON_VERBOSE:   sectname __eh_frame
+NON_VERBOSE:    segname __TEXT
+NON_VERBOSE:       addr 0x0000000000000068
+NON_VERBOSE:       size 0x0000000000000040
+NON_VERBOSE:     offset 632
+NON_VERBOSE:      align 2^3 (8)
+NON_VERBOSE:     reloff 0
+NON_VERBOSE:     nreloc 0
+NON_VERBOSE:      flags 0x6800000b
+NON_VERBOSE:  reserved1 0
+NON_VERBOSE:  reserved2 0
+NON_VERBOSE: Load command 1
+NON_VERBOSE:      cmd LC_SYMTAB
+NON_VERBOSE:  cmdsize 24
+NON_VERBOSE:   symoff 720
+NON_VERBOSE:    nsyms 5
+NON_VERBOSE:   stroff 800
+NON_VERBOSE:  strsize 44
+NON_VERBOSE: Load command 2
+NON_VERBOSE:             cmd LC_DYSYMTAB
+NON_VERBOSE:         cmdsize 80
+NON_VERBOSE:       ilocalsym 0
+NON_VERBOSE:       nlocalsym 2
+NON_VERBOSE:      iextdefsym 2
+NON_VERBOSE:      nextdefsym 2
+NON_VERBOSE:       iundefsym 4
+NON_VERBOSE:       nundefsym 1
+NON_VERBOSE:          tocoff 0
+NON_VERBOSE:            ntoc 0
+NON_VERBOSE:       modtaboff 0
+NON_VERBOSE:         nmodtab 0
+NON_VERBOSE:    extrefsymoff 0
+NON_VERBOSE:     nextrefsyms 0
+NON_VERBOSE:  indirectsymoff 0
+NON_VERBOSE:   nindirectsyms 0
+NON_VERBOSE:       extreloff 0
+NON_VERBOSE:         nextrel 0
+NON_VERBOSE:       locreloff 0
+NON_VERBOSE:         nlocrel 0
index 720b9a402e1a2c1dc051b0ee651964419d8159be..e4d7857f1414d02dabf7045971028eb9019301e3 100644 (file)
@@ -1,4 +1,8 @@
 // RUN: llvm-objdump -m -section __DATA,__mod_init_func %p/Inputs/dylibModInit.macho-x86_64 | FileCheck %s -check-prefix=MODINIT
+// RUN: llvm-objdump -m -section __DATA,__mod_init_func -non-verbose %p/Inputs/dylibModInit.macho-x86_64 | FileCheck %s -check-prefix=NON_VERBOSE
 
 MODINIT: Contents of (__DATA,__mod_init_func) section
 MODINIT: 0x0000000000001000 0x0000000000000f30 _libinit
+
+NON_VERBOSE: Contents of (__DATA,__mod_init_func) section
+NON_VERBOSE: 0000000000001000  30 0f 00 00 00 00 00 00 
index e4fd37a902c461bb22ce9b3f09e1be26ed78d6ff..260e9aa341e8c4b9955efa1aad1344048923d527 100644 (file)
@@ -4,6 +4,8 @@ RUN: llvm-objdump %p/Inputs/macho-universal-archive.x86_64.i386 -d -m -no-show-r
 RUN: | FileCheck %s -check-prefix UArchive-i386
 RUN: llvm-objdump %p/Inputs/macho-universal.x86_64.i386 -universal-headers -m \
 RUN: | FileCheck %s -check-prefix FAT
+RUN: llvm-objdump %p/Inputs/macho-universal.x86_64.i386 -universal-headers -m \
+RUN: -non-verbose | FileCheck %s -check-prefix NON-VERBOSE
 
 UEXE-all: macho-universal.x86_64.i386 (architecture x86_64):
 UEXE-all: (__TEXT,__text) section
@@ -42,3 +44,21 @@ FAT:     capabilities 0x0
 FAT:     offset 12288
 FAT:     size 4336
 FAT:     align 2^12 (4096)
+
+NON-VERBOSE: Fat headers
+NON-VERBOSE: fat_magic 0xcafebabe
+NON-VERBOSE: nfat_arch 2
+NON-VERBOSE: architecture 0
+NON-VERBOSE:     cputype 16777223
+NON-VERBOSE:     cpusubtype 3
+NON-VERBOSE:     capabilities 0x80
+NON-VERBOSE:     offset 4096
+NON-VERBOSE:     size 4360
+NON-VERBOSE:     align 2^12 (4096)
+NON-VERBOSE: architecture 1
+NON-VERBOSE:     cputype 7
+NON-VERBOSE:     cpusubtype 3
+NON-VERBOSE:     capabilities 0x0
+NON-VERBOSE:     offset 12288
+NON-VERBOSE:     size 4336
+NON-VERBOSE:     align 2^12 (4096)
index cf86d1c6812217e94b01af1632cebf9e4f4c0077..0e917e9ad5ca71c496564c2ebc0bc06f0fed8dd9 100644 (file)
@@ -101,6 +101,11 @@ cl::opt<bool>
                     cl::desc("Print the info plist section as strings for "
                              "Mach-O objects (requires -macho)"));
 
+cl::opt<bool>
+    llvm::NonVerbose("non-verbose",
+                     cl::desc("Print the info for Mach-O objects in "
+                              "non-verbose or numeric form (requires -macho)"));
+
 static cl::list<std::string>
     ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
               cl::ZeroOrMore);
@@ -328,15 +333,17 @@ static void PrintIndirectSymbolTable(MachOObjectFile *O, bool verbose,
       continue;
     }
     outs() << format("%5u ", indirect_symbol);
-    MachO::symtab_command Symtab = O->getSymtabLoadCommand();
-    if (indirect_symbol < Symtab.nsyms) {
-      symbol_iterator Sym = O->getSymbolByIndex(indirect_symbol);
-      SymbolRef Symbol = *Sym;
-      StringRef SymName;
-      Symbol.getName(SymName);
-      outs() << SymName;
-    } else {
-      outs() << "?";
+    if (verbose) {
+      MachO::symtab_command Symtab = O->getSymtabLoadCommand();
+      if (indirect_symbol < Symtab.nsyms) {
+        symbol_iterator Sym = O->getSymbolByIndex(indirect_symbol);
+        SymbolRef Symbol = *Sym;
+        StringRef SymName;
+        Symbol.getName(SymName);
+        outs() << SymName;
+      } else {
+        outs() << "?";
+      }
     }
     outs() << "\n";
   }
@@ -899,7 +906,7 @@ static void DumpRawSectionContents(MachOObjectFile *O, const char *sect,
       if (O->is64Bit())
         outs() << format("%016" PRIx64, addr) << "\t";
       else
-        outs() << format("%08" PRIx64, sect) << "\t";
+        outs() << format("%08" PRIx64, addr) << "\t";
       for (j = 0; j < 16 && i + j < size; j++) {
         uint8_t byte_word = *(sect + i + j);
         outs() << format("%02" PRIx32, (uint32_t)byte_word) << " ";
@@ -1111,9 +1118,9 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
   if (Disassemble)
     DisassembleMachO(Filename, MachOOF, "__TEXT", "__text");
   if (IndirectSymbols)
-    PrintIndirectSymbols(MachOOF, true);
+    PrintIndirectSymbols(MachOOF, !NonVerbose);
   if (DataInCode)
-    PrintDataInCodeTable(MachOOF, true);
+    PrintDataInCodeTable(MachOOF, !NonVerbose);
   if (LinkOptHints)
     PrintLinkOptHints(MachOOF);
   if (Relocations)
@@ -1123,7 +1130,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
   if (SectionContents)
     PrintSectionContents(MachOOF);
   if (DumpSections.size() != 0)
-    DumpSectionContents(Filename, MachOOF, true);
+    DumpSectionContents(Filename, MachOOF, !NonVerbose);
   if (InfoPlist)
     DumpInfoPlistSectionContents(Filename, MachOOF);
   if (SymbolTable)
@@ -1462,7 +1469,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
   }
   if (UniversalHeaders) {
     if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Bin))
-      printMachOUniversalHeaders(UB, true);
+      printMachOUniversalHeaders(UB, !NonVerbose);
   }
   if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Bin)) {
     // If we have a list of architecture flags specified dump only those.
@@ -5461,8 +5468,8 @@ void llvm::printMachOFileHeader(const object::ObjectFile *Obj) {
   uint32_t ncmds = 0;
   uint32_t filetype = 0;
   uint32_t cputype = 0;
-  getAndPrintMachHeader(file, ncmds, filetype, cputype, true);
-  PrintLoadCommands(file, ncmds, filetype, cputype, true);
+  getAndPrintMachHeader(file, ncmds, filetype, cputype, !NonVerbose);
+  PrintLoadCommands(file, ncmds, filetype, cputype, !NonVerbose);
 }
 
 //===----------------------------------------------------------------------===//
index 845b7ea26bb871a4079d392c144d0c3c98b8ea5c..434a10e677dabcf54430cadaae6a374e0780c2ae 100644 (file)
@@ -41,6 +41,7 @@ extern cl::opt<bool> IndirectSymbols;
 extern cl::opt<bool> DataInCode;
 extern cl::opt<bool> LinkOptHints;
 extern cl::opt<bool> InfoPlist;
+extern cl::opt<bool> NonVerbose;
 extern cl::opt<bool> Relocations;
 extern cl::opt<bool> SectionHeaders;
 extern cl::opt<bool> SectionContents;