[llvm] r264778 - Fix some bugs in the posix output of llvm-nm. Which is documented on

Kevin Enderby via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 13:18:07 PDT 2016


Author: enderby
Date: Tue Mar 29 15:18:07 2016
New Revision: 264778

URL: http://llvm.org/viewvc/llvm-project?rev=264778&view=rev
Log:
Fix some bugs in the posix output of llvm-nm.  Which is documented on
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/nm.html .

1) For Mach-O files the code was not printing the values in hex as is the default.
2) The values printed had leading zeros which they should not have.
3) The address for undefined symbols was printed as spaces instead of 0.
4) With the -A option with posix output for an archive did not use square
brackets around the archive member name.

rdar://25311883 and rdar://25299678

Added:
    llvm/trunk/test/tools/llvm-nm/X86/Inputs/libExample.a.macho-x86_64   (with props)
    llvm/trunk/test/tools/llvm-nm/X86/posixArchiveMachO.test
Modified:
    llvm/trunk/test/tools/llvm-nm/X86/posixELF.test
    llvm/trunk/test/tools/llvm-nm/X86/posixMachO.test
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Added: llvm/trunk/test/tools/llvm-nm/X86/Inputs/libExample.a.macho-x86_64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/Inputs/libExample.a.macho-x86_64?rev=264778&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-nm/X86/Inputs/libExample.a.macho-x86_64
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/tools/llvm-nm/X86/posixArchiveMachO.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/posixArchiveMachO.test?rev=264778&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/X86/posixArchiveMachO.test (added)
+++ llvm/trunk/test/tools/llvm-nm/X86/posixArchiveMachO.test Tue Mar 29 15:18:07 2016
@@ -0,0 +1,5 @@
+# RUN: llvm-nm -P -A %p/Inputs/libExample.a.macho-x86_64 | FileCheck %s
+
+# CHECK: libExample.a.macho-x86_64[example.o]: EH_frame0 s 30 0
+# CHECK: libExample.a.macho-x86_64[example.o]: _f T 0 0
+# CHECK: libExample.a.macho-x86_64[example.o]: _f.eh S 48 0

Modified: llvm/trunk/test/tools/llvm-nm/X86/posixELF.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/posixELF.test?rev=264778&r1=264777&r2=264778&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/X86/posixELF.test (original)
+++ llvm/trunk/test/tools/llvm-nm/X86/posixELF.test Tue Mar 29 15:18:07 2016
@@ -1,4 +1,4 @@
 # RUN: llvm-nm -P %p/Inputs/hello.obj.elf-x86_64 | FileCheck %s
 
-CHECK: main T 0000000000000000 0000000000000000
-CHECK: puts U                  0000000000000000
+CHECK: main T 0 0
+CHECK: puts U 0 0

Modified: llvm/trunk/test/tools/llvm-nm/X86/posixMachO.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/posixMachO.test?rev=264778&r1=264777&r2=264778&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/X86/posixMachO.test (original)
+++ llvm/trunk/test/tools/llvm-nm/X86/posixMachO.test Tue Mar 29 15:18:07 2016
@@ -1,7 +1,7 @@
 # RUN: llvm-nm -P %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
 
-# CHECK: EH_frame0 s 104 0
-# CHECK: L_.str s 59 0
+# CHECK: EH_frame0 s 68 0
+# CHECK: L_.str s 3b 0
 # CHECK: _main T 0 0
-# CHECK: _main.eh S 128 0
+# CHECK: _main.eh S 80 0
 # CHECK: _printf U 0 0

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=264778&r1=264777&r2=264778&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Tue Mar 29 15:18:07 2016
@@ -583,26 +583,26 @@ static void sortAndPrintSymbolList(Symbo
     printDashes = "----------------";
     switch (AddressRadix) {
     case Radix::o:
-      printFormat = "%016" PRIo64;
+      printFormat = OutputFormat == posix ? "%" PRIo64 : "%016" PRIo64;
       break;
     case Radix::x:
-      printFormat = "%016" PRIx64;
+      printFormat = OutputFormat == posix ? "%" PRIx64 : "%016" PRIx64;
       break;
     default:
-      printFormat = "%016" PRId64;
+      printFormat = OutputFormat == posix ? "%" PRId64 : "%016" PRId64;
     }
   } else {
     printBlanks = "        ";
     printDashes = "--------";
     switch (AddressRadix) {
     case Radix::o:
-      printFormat = "%08" PRIo64;
+      printFormat = OutputFormat == posix ? "%" PRIo64 : "%08" PRIo64;
       break;
     case Radix::x:
-      printFormat = "%08" PRIx64;
+      printFormat = OutputFormat == posix ? "%" PRIx64 : "%08" PRIx64;
       break;
     default:
-      printFormat = "%08" PRId64;
+      printFormat = OutputFormat == posix ? "%" PRId64 : "%08" PRId64;
     }
   }
 
@@ -617,9 +617,13 @@ static void sortAndPrintSymbolList(Symbo
     if (PrintFileName) {
       if (!ArchitectureName.empty())
         outs() << "(for architecture " << ArchitectureName << "):";
-      if (!ArchiveName.empty())
-        outs() << ArchiveName << ":";
-      outs() << CurrentFilename << ": ";
+      if (OutputFormat == posix && !ArchiveName.empty())
+        outs() << ArchiveName << "[" << CurrentFilename << "]: ";
+      else {
+        if (!ArchiveName.empty())
+          outs() << ArchiveName << ":";
+        outs() << CurrentFilename << ": ";
+      }
     }
     if ((JustSymbolName || (UndefinedOnly && isa<MachOObjectFile>(Obj) &&
                             OutputFormat != darwin)) && OutputFormat != posix) {
@@ -630,8 +634,13 @@ static void sortAndPrintSymbolList(Symbo
     char SymbolAddrStr[18] = "";
     char SymbolSizeStr[18] = "";
 
-    if (OutputFormat == sysv || I->TypeChar == 'U')
-      strcpy(SymbolAddrStr, printBlanks);
+    if (OutputFormat == sysv || I->TypeChar == 'U') {
+      if (OutputFormat == posix)
+        format(printFormat, I->Address)
+          .print(SymbolAddrStr, sizeof(SymbolAddrStr));
+      else
+        strcpy(SymbolAddrStr, printBlanks);
+    }
     if (OutputFormat == sysv)
       strcpy(SymbolSizeStr, printBlanks);
 
@@ -656,7 +665,7 @@ static void sortAndPrintSymbolList(Symbo
     } else if (OutputFormat == posix) {
       outs() << I->Name << " " << I->TypeChar << " ";
       if (MachO)
-        outs() << I->Address << " " << "0" /* SymbolSizeStr */ << "\n";
+        outs() << SymbolAddrStr << " " << "0" /* SymbolSizeStr */ << "\n";
       else
         outs() << SymbolAddrStr << " " << SymbolSizeStr << "\n";
     } else if (OutputFormat == bsd || (OutputFormat == darwin && !MachO)) {




More information about the llvm-commits mailing list