[Objdump] Output information about common symbols in a way closer to GNU objdump.
authorColin LeMahieu <colinl@codeaurora.org>
Fri, 23 Jan 2015 20:06:24 +0000 (20:06 +0000)
committerColin LeMahieu <colinl@codeaurora.org>
Fri, 23 Jan 2015 20:06:24 +0000 (20:06 +0000)
llvm-svn: 226932

llvm/test/tools/llvm-objdump/Inputs/common-symbol-elf [new file with mode: 0644]
llvm/test/tools/llvm-objdump/common-symbol-elf.test [new file with mode: 0644]
llvm/tools/llvm-objdump/llvm-objdump.cpp

diff --git a/llvm/test/tools/llvm-objdump/Inputs/common-symbol-elf b/llvm/test/tools/llvm-objdump/Inputs/common-symbol-elf
new file mode 100644 (file)
index 0000000..9609edb
Binary files /dev/null and b/llvm/test/tools/llvm-objdump/Inputs/common-symbol-elf differ
diff --git a/llvm/test/tools/llvm-objdump/common-symbol-elf.test b/llvm/test/tools/llvm-objdump/common-symbol-elf.test
new file mode 100644 (file)
index 0000000..32df05a
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: llvm-objdump -t %p/Inputs/common-symbol-elf | FileCheck %s
+
+CHECK: 00000400 g       *COM*  00000008 common_symbol
index cd94a3a..1204a97 100644 (file)
@@ -642,7 +642,15 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
     bool Global = Flags & SymbolRef::SF_Global;
     bool Weak = Flags & SymbolRef::SF_Weak;
     bool Absolute = Flags & SymbolRef::SF_Absolute;
-
+    bool Common = Flags & SymbolRef::SF_Common;
+
+    if (Common) {
+      uint32_t Alignment;
+      if (error(Symbol.getAlignment(Alignment)))
+        Alignment = 0;
+      Address = Size;
+      Size = Alignment;
+    }
     if (Address == UnknownAddressOrSize)
       Address = 0;
     if (Size == UnknownAddressOrSize)
@@ -672,6 +680,8 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
            << ' ';
     if (Absolute) {
       outs() << "*ABS*";
+    } else if (Common) {
+      outs() << "*COM*";
     } else if (Section == o->section_end()) {
       outs() << "*UND*";
     } else {