From 3f665d84f0785d4a961361bd0d0ddea41013be22 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Thu, 27 Jun 2019 16:27:53 +0000 Subject: [PATCH] [llvm-nm] Fix for BZ41711 - Class character for a symbol with undefined 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 | 46 ++++++++++----------- tools/llvm-nm/llvm-nm.cpp | 7 +++- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/test/tools/llvm-nm/format-sysv-binding.test b/test/tools/llvm-nm/format-sysv-binding.test index 557df3d6d0f..2960c72a85a 100644 --- a/test/tools/llvm-nm/format-sysv-binding.test +++ b/test/tools/llvm-nm/format-sysv-binding.test @@ -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 | diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index ae9bf60baeb..aa62e6f0209 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -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(); -- 2.50.1