OSDN Git Service

[llvm-nm] Fix for BZ41711 - Class character for a symbol with undefined
authorChris Jackson <snortotter@gmail.com>
Thu, 27 Jun 2019 16:27:53 +0000 (16:27 +0000)
committerChris Jackson <snortotter@gmail.com>
Thu, 27 Jun 2019 16:27:53 +0000 (16:27 +0000)
          binding does not match class assigned by GNU nm

 Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=41711

 Differential Revision: https://reviews.llvm.org/D63340

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

test/tools/llvm-nm/format-sysv-binding.test
tools/llvm-nm/llvm-nm.cpp

index 557df3d..2960c72 100644 (file)
@@ -1,9 +1,4 @@
-# XFAIL: *
-# For a symbol in a text section the class character for an unrecognised binding
-# value is '?' in gnu-nm but llvm-nm prints 'T'. Filed as:
-# https://bugs.llvm.org/show_bug.cgi?id=41711
-
-# RUN: yaml2obj %s > %t.o
+# RUN: yaml2obj %s -o %t.o
 # RUN: llvm-nm %t.o --format=sysv | FileCheck %s
 
 !ELF
@@ -17,28 +12,33 @@ Sections:
     Type:  SHT_PROGBITS
     Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
 Symbols:
-  - Name:    symbol_local
+  - Name:    local_binding
     Binding: STB_LOCAL
     Section: .text
-    Value:   0x101
-    Size:    8
-  - Name:    symbol_weak
+    Value:   0xbeef
+  - Name:    global_binding
+    Binding: STB_GLOBAL
+    Section: .text
+  - Name:    weak_binding
     Binding: STB_WEAK
     Section: .text
-    Value:   0x102
-    Size:    4
-  - Name:    symbol_undefined_binding
+  - Name:    unrecognised_binding
     Binding: 5
     Section: .text
-    Value:   0x1004
-    Size:    32
-  - Name:    symbol_global
-    Binding: STB_GLOBAL
+  - Name:    gnu_unique_binding
+    Binding: 10
+    Section: .text
+  - Name:    os_binding
+    Binding: 11
+    Section: .text
+  - Name:    proc_binding
+    Binding: 14
     Section: .text
-    Value:   0x103
-    Size:    16
 
-# CHECK:      symbol_global {{.*}}|   T  |
-# CHECK-NEXT: symbol_local  {{.*}}|   t  |
-# CHECK-NEXT: symbol_unrecognised_binding {{.*}}| ? |
-# CHECK-NEXT: symbol_weak {{.*}}|   W  |
+# CHECK:      global_binding      {{.*}}|   T  |
+# CHECK-NEXT: gnu_unique_binding  {{.*}}|   u  |
+# CHECK-NEXT: local_binding       {{.*}}|   t  |
+# CHECK-NEXT: os_binding          {{.*}}|   ?  |
+# CHECK-NEXT: proc_binding        {{.*}}|   ?  |
+# CHECK-NEXT: unrecognised_binding{{.*}}|   ?  |
+# CHECK-NEXT: weak_binding        {{.*}}|   W  |
index ae9bf60..aa62e6f 100644 (file)
@@ -894,9 +894,14 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
     return '?';
   }
 
-  if (SymI->getBinding() == ELF::STB_GNU_UNIQUE)
+  uint8_t Binding = SymI->getBinding();
+  if (Binding == ELF::STB_GNU_UNIQUE)
     return 'u';
 
+  assert(Binding != ELF::STB_WEAK && "STB_WEAK not tested in calling function");
+  if (Binding != ELF::STB_GLOBAL && Binding != ELF::STB_LOCAL)
+    return '?';
+
   elf_section_iterator SecI = *SecIOrErr;
   if (SecI != Obj.section_end()) {
     uint32_t Type = SecI->getType();