From: Fangrui Song Date: Fri, 26 Apr 2019 16:01:48 +0000 (+0000) Subject: [llvm-nm] Fix handling of symbol types 't' 'd' 'r' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=249f7ff6189f5f38eb27b85f7fb933af2edfa9f9;p=llvm [llvm-nm] Fix handling of symbol types 't' 'd' 'r' 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 --- 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 index b5c74f234c6..00000000000 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 index 8aa41bf4f37..00000000000 Binary files a/test/tools/llvm-nm/X86/Inputs/weak.obj.elf-x86_64 and /dev/null differ diff --git a/test/tools/llvm-nm/X86/init-fini.test b/test/tools/llvm-nm/X86/init-fini.test index 86afc711c4e..80a81ba0d33 100644 --- a/test/tools/llvm-nm/X86/init-fini.test +++ b/test/tools/llvm-nm/X86/init-fini.test @@ -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 diff --git a/test/tools/llvm-nm/X86/weak.test b/test/tools/llvm-nm/X86/weak.test index 8d06f4fb029..4fc03eaffb9 100644 --- a/test/tools/llvm-nm/X86/weak.test +++ b/test/tools/llvm-nm/X86/weak.test @@ -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 diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 139fcc3ea87..8f4108d9d88 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -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) {