[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.

llvm-svn: 359311
This commit is contained in:
Fangrui Song 2019-04-26 16:01:48 +00:00
parent 51a4a0d68f
commit 0bf06a8f59
5 changed files with 90 additions and 32 deletions

View 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

View 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

View 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) {