]> granicus.if.org Git - llvm/commitdiff
[llvm-nm] Fix handling of symbol types 't' 'd' 'r'
authorFangrui Song <maskray@google.com>
Fri, 26 Apr 2019 16:01:48 +0000 (16:01 +0000)
committerFangrui Song <maskray@google.com>
Fri, 26 Apr 2019 16:01:48 +0000 (16:01 +0000)
In addition, fix and convert the two tests to yaml2obj based. This
allows us to delete two executables.

X86/weak.test: 'v' was not tested
X86/init-fini.test: symbol types of __bss_start _edata _end were wrong
  GNU nm reports __init_array_start as 't', and __preinit_array_start as 'd'.
  __init_array_start is 't' just because its section ".init_array" starts with ".init"

  'd' makes more sense and allows us to drop the weird SHT_INIT_ARRAY rule.
  So, change __init_array_start to 'd' instead.

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

test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64 [deleted file]
test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64 [deleted file]
test/tools/llvm-nm/X86/init-fini.test
test/tools/llvm-nm/X86/weak.test
tools/llvm-nm/llvm-nm.cpp

diff --git a/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64 b/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64
deleted file mode 100755 (executable)
index b5c74f2..0000000
Binary files a/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64 and /dev/null differ
diff --git a/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64 b/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64
deleted file mode 100644 (file)
index 8aa41bf..0000000
Binary files a/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64 and /dev/null differ
index 86afc711c4ea468756cb94411a1a8b7cfa2e974f..80a81ba0d33f40806c45e55e02517cbedb01308e 100644 (file)
@@ -1,8 +1,50 @@
-# RUN: llvm-nm -B -S %p/Inputs/init-fini.out.elf-x86_64 | FileCheck --match-full-lines %s
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm -B -S %t | FileCheck %s
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
+Sections:
+  - Name: .text
+    Type: SHT_PROGBITS
+    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name: .init_array
+    Type: SHT_INIT_ARRAY
+    Flags: [ SHF_ALLOC, SHF_WRITE ]
+  - Name: .preinit_array
+    Type: SHT_PREINIT_ARRAY
+    Flags: [ SHF_ALLOC, SHF_WRITE ]
+  - Name: .fini_array
+    Type: SHT_FINI_ARRAY
+    Flags: [ SHF_ALLOC, SHF_WRITE ]
+  - Name: .data
+    Type: SHT_PROGBITS
+    Flags: [ SHF_ALLOC, SHF_WRITE ]
+  - Name: .bss
+    Type: SHT_NOBITS
+    Flags: [ SHF_ALLOC, SHF_WRITE ]
+Symbols:
+  - Name:    __init_array_start
+    Section: .init_array
+  - Name:    __preinit_array_start
+    Section: .preinit_array
+  - Name:    __fini_array_start
+    Section: .fini_array
+  - Name:    __bss_start
+    Section: .bss
+    Binding: STB_GLOBAL
+  - Name:    _edata
+    Section: .data
+    Binding: STB_GLOBAL
+  - Name:    _end
+    Section: .bss
+    Binding: STB_GLOBAL
 
-CHECK: 00000000006000c2 0000000000000000 T __bss_start
-CHECK: 00000000006000c2 0000000000000000 t __init_array_end
-CHECK: 00000000006000ba 0000000000000000 t __init_array_start
-CHECK: 00000000006000c2 0000000000000000 T _edata
-CHECK: 00000000006000c8 0000000000000000 T _end
-CHECK: 00000000004000b0 0000000000000000 T _start
+# CHECK: B __bss_start
+# CHECK: d __fini_array_start
+# CHECK: d __init_array_start
+# CHECK: d __preinit_array_start
+# CHECK: D _edata
+# CHECK: B _end
index 8d06f4fb029ea287a3b4ea4957d213bac89d6c28..4fc03eaffb90fc9626135fe6fefbf57b09e29e8b 100644 (file)
@@ -1,7 +1,36 @@
-# RUN: llvm-nm -B -S %p/Inputs/weak.obj.elf-x86_64 | FileCheck --match-full-lines %s
-# RUN: llvm-nm -W -B -S %p/Inputs/weak.obj.elf-x86_64 | count 0
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm -B -S %t | FileCheck --match-full-lines %s
+# RUN: llvm-nm -W -B -S %t | count 0
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name: .text
+    Type: SHT_PROGBITS
+  - Name: .data
+    Type: SHT_PROGBITS
+Symbols:
+  - Name:    weak_func
+    Type:    STT_FUNC
+    Section: .text
+    Binding: STB_WEAK
+    Size:    17
+  - Name:    weak_var
+    Type:    STT_OBJECT
+    Section: .data
+    Binding: STB_WEAK
+    Size:    4
+  - Name:    weak_extern_func
+    Type:    STT_FUNC
+    Binding: STB_WEAK
+  - Name:    weak_extern_var
+    Type:    STT_OBJECT
+    Binding: STB_WEAK
 
-CHECK:                  w weak_extern_func
-CHECK:                  w weak_extern_var
-CHECK: 0000000000000000 0000000000000011 W weak_func
-CHECK: 0000000000000000 0000000000000004 V weak_var
+CHECK:                  w weak_extern_func
+# CHECK:                  v weak_extern_var
+CHECK: 0000000000000000 0000000000000011 W weak_func
+CHECK: 0000000000000000 0000000000000004 V weak_var
index 139fcc3ea8754eaf16a041d74deb95bf7498d77d..8f4108d9d880d08161651790ebd127f1e112e8aa 100644 (file)
@@ -936,27 +936,14 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
 
   elf_section_iterator SecI = *SecIOrErr;
   if (SecI != Obj.section_end()) {
-    switch (SecI->getType()) {
-    case ELF::SHT_PROGBITS:
-    case ELF::SHT_DYNAMIC:
-      switch (SecI->getFlags()) {
-      case (ELF::SHF_ALLOC | ELF::SHF_EXECINSTR):
-        return 't';
-      case (ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE):
-      case (ELF::SHF_ALLOC | ELF::SHF_WRITE):
-        return 'd';
-      case ELF::SHF_ALLOC:
-      case (ELF::SHF_ALLOC | ELF::SHF_MERGE):
-      case (ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS):
-        return 'r';
-      }
-      break;
-    case ELF::SHT_NOBITS:
+    uint32_t Type = SecI->getType();
+    uint64_t Flags = SecI->getFlags();
+    if (Type == ELF::SHT_NOBITS)
       return 'b';
-    case ELF::SHT_INIT_ARRAY:
-    case ELF::SHT_FINI_ARRAY:
+    if (Flags & ELF::SHF_EXECINSTR)
       return 't';
-    }
+    if (Flags & ELF::SHF_ALLOC)
+      return Flags & ELF::SHF_WRITE ? 'd' : 'r';
   }
 
   if (SymI->getELFType() == ELF::STT_SECTION) {