Fix printing of common symbols.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 6 Jul 2015 18:18:44 +0000 (18:18 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 6 Jul 2015 18:18:44 +0000 (18:18 +0000)
Printing the symbol size matches the behavior or both gnu nm and freebsd nm.

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

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

index b833601969c2fddf1c7767bbc5eff2feea066ad2..4aed80257eae67d57321148581c8154fc45e663b 100644 (file)
@@ -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
index cf6746109954de9db4c712851c3161047db5c24e..4edb4efa8d086dcea21ac493d9bfa06b6872eebd 100644 (file)
@@ -901,10 +901,15 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
         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)))