[llvm] r241480 - Fix printing of common symbols.

Rafael Espindola rafael.espindola at gmail.com
Mon Jul 6 11:18:45 PDT 2015


Author: rafael
Date: Mon Jul  6 13:18:44 2015
New Revision: 241480

URL: http://llvm.org/viewvc/llvm-project?rev=241480&view=rev
Log:
Fix printing of common symbols.

Printing the symbol size matches the behavior or both gnu nm and freebsd nm.

Modified:
    llvm/trunk/test/Object/X86/nm-print-size.s
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Modified: llvm/trunk/test/Object/X86/nm-print-size.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/X86/nm-print-size.s?rev=241480&r1=241479&r2=241480&view=diff
==============================================================================
--- llvm/trunk/test/Object/X86/nm-print-size.s (original)
+++ llvm/trunk/test/Object/X86/nm-print-size.s Mon Jul  6 13:18:44 2015
@@ -3,6 +3,7 @@
 
 // CHECK: 0000000000000000 ffffffffffffffff n a
 // CHECK: 0000000000000000 0000000000000000 N b
+// CHECK: 0000000000000004 0000000000000004 C c
 
         .section foo
 a:
@@ -10,3 +11,5 @@ a:
 
         .global b
 b:
+
+        .comm c,4,8

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=241480&r1=241479&r2=241480&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Mon Jul  6 13:18:44 2015
@@ -901,10 +901,15 @@ static void dumpSymbolNamesFromObject(Sy
         S.Size = ELFSymbolRef(Sym).getSize();
     }
     if (PrintAddress && isa<ObjectFile>(Obj)) {
-      ErrorOr<uint64_t> AddressOrErr = SymbolRef(Sym).getAddress();
-      if (error(AddressOrErr.getError()))
-        break;
-      S.Address = *AddressOrErr;
+      SymbolRef SymRef(Sym);
+      if (SymFlags & SymbolRef::SF_Common) {
+        S.Address = SymRef.getCommonSize();
+      } else {
+        ErrorOr<uint64_t> AddressOrErr = SymRef.getAddress();
+        if (error(AddressOrErr.getError()))
+          break;
+        S.Address = *AddressOrErr;
+      }
     }
     S.TypeChar = getNMTypeChar(Obj, Sym);
     if (error(Sym.printName(OS)))





More information about the llvm-commits mailing list