Skip to content

Commit 51a1418

Browse files
committed
Revert [llvm-nm] Fix handling of symbol types + [llvm-nm] Generalize symbol types
This reverts r359311 and r359312 (git commit 0bf06a8 and 5f184f1) llvm-svn: 359830
1 parent 81862f8 commit 51a1418

File tree

5 files changed

+41
-95
lines changed

5 files changed

+41
-95
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,8 @@
1-
# RUN: yaml2obj %s -o %t
2-
# RUN: llvm-nm -B -S %t | FileCheck %s
3-
!ELF
4-
FileHeader:
5-
Class: ELFCLASS64
6-
Data: ELFDATA2LSB
7-
Type: ET_EXEC
8-
Machine: EM_X86_64
9-
Sections:
10-
- Name: .text
11-
Type: SHT_PROGBITS
12-
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
13-
- Name: .init_array
14-
Type: SHT_INIT_ARRAY
15-
Flags: [ SHF_ALLOC, SHF_WRITE ]
16-
- Name: .preinit_array
17-
Type: SHT_PREINIT_ARRAY
18-
Flags: [ SHF_ALLOC, SHF_WRITE ]
19-
- Name: .fini_array
20-
Type: SHT_FINI_ARRAY
21-
Flags: [ SHF_ALLOC, SHF_WRITE ]
22-
- Name: .data
23-
Type: SHT_PROGBITS
24-
Flags: [ SHF_ALLOC, SHF_WRITE ]
25-
- Name: .bss
26-
Type: SHT_NOBITS
27-
Flags: [ SHF_ALLOC, SHF_WRITE ]
28-
Symbols:
29-
- Name: __init_array_start
30-
Section: .init_array
31-
- Name: __preinit_array_start
32-
Section: .preinit_array
33-
- Name: __fini_array_start
34-
Section: .fini_array
35-
- Name: __bss_start
36-
Section: .bss
37-
Binding: STB_GLOBAL
38-
- Name: _edata
39-
Section: .data
40-
Binding: STB_GLOBAL
41-
- Name: _end
42-
Section: .bss
43-
Binding: STB_GLOBAL
1+
# RUN: llvm-nm -B -S %p/Inputs/init-fini.out.elf-x86_64 | FileCheck --match-full-lines %s
442

45-
# CHECK: B __bss_start
46-
# CHECK: d __fini_array_start
47-
# CHECK: d __init_array_start
48-
# CHECK: d __preinit_array_start
49-
# CHECK: D _edata
50-
# CHECK: B _end
3+
CHECK: 00000000006000c2 0000000000000000 T __bss_start
4+
CHECK: 00000000006000c2 0000000000000000 t __init_array_end
5+
CHECK: 00000000006000ba 0000000000000000 t __init_array_start
6+
CHECK: 00000000006000c2 0000000000000000 T _edata
7+
CHECK: 00000000006000c8 0000000000000000 T _end
8+
CHECK: 00000000004000b0 0000000000000000 T _start

llvm/test/tools/llvm-nm/X86/weak.test

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
1-
# RUN: yaml2obj %s -o %t
2-
# RUN: llvm-nm -B -S %t | FileCheck --match-full-lines %s
3-
# RUN: llvm-nm -W -B -S %t | count 0
4-
!ELF
5-
FileHeader:
6-
Class: ELFCLASS64
7-
Data: ELFDATA2LSB
8-
Type: ET_REL
9-
Machine: EM_X86_64
10-
Sections:
11-
- Name: .text
12-
Type: SHT_PROGBITS
13-
- Name: .data
14-
Type: SHT_PROGBITS
15-
Symbols:
16-
- Name: weak_func
17-
Type: STT_FUNC
18-
Section: .text
19-
Binding: STB_WEAK
20-
Size: 17
21-
- Name: weak_var
22-
Type: STT_OBJECT
23-
Section: .data
24-
Binding: STB_WEAK
25-
Size: 4
26-
- Name: weak_extern_func
27-
Type: STT_FUNC
28-
Binding: STB_WEAK
29-
- Name: weak_extern_var
30-
Type: STT_OBJECT
31-
Binding: STB_WEAK
1+
# RUN: llvm-nm -B -S %p/Inputs/weak.obj.elf-x86_64 | FileCheck --match-full-lines %s
2+
# RUN: llvm-nm -W -B -S %p/Inputs/weak.obj.elf-x86_64 | count 0
323

33-
# CHECK: w weak_extern_func
34-
# CHECK: v weak_extern_var
35-
# CHECK: 0000000000000000 0000000000000011 W weak_func
36-
# CHECK: 0000000000000000 0000000000000004 V weak_var
4+
CHECK: w weak_extern_func
5+
CHECK: w weak_extern_var
6+
CHECK: 0000000000000000 0000000000000011 W weak_func
7+
CHECK: 0000000000000000 0000000000000004 V weak_var

llvm/tools/llvm-nm/llvm-nm.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -901,26 +901,43 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
901901

902902
elf_section_iterator SecI = *SecIOrErr;
903903
if (SecI != Obj.section_end()) {
904-
uint32_t Type = SecI->getType();
905-
uint64_t Flags = SecI->getFlags();
906-
if (Type == ELF::SHT_NOBITS)
904+
switch (SecI->getType()) {
905+
case ELF::SHT_PROGBITS:
906+
case ELF::SHT_DYNAMIC:
907+
switch (SecI->getFlags()) {
908+
case (ELF::SHF_ALLOC | ELF::SHF_EXECINSTR):
909+
return 't';
910+
case (ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE):
911+
case (ELF::SHF_ALLOC | ELF::SHF_WRITE):
912+
return 'd';
913+
case ELF::SHF_ALLOC:
914+
case (ELF::SHF_ALLOC | ELF::SHF_MERGE):
915+
case (ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS):
916+
return 'r';
917+
}
918+
break;
919+
case ELF::SHT_NOBITS:
907920
return 'b';
908-
if (Flags & ELF::SHF_EXECINSTR)
921+
case ELF::SHT_INIT_ARRAY:
922+
case ELF::SHT_FINI_ARRAY:
909923
return 't';
910-
if (Flags & ELF::SHF_ALLOC)
911-
return Flags & ELF::SHF_WRITE ? 'd' : 'r';
924+
}
925+
}
926+
927+
if (SymI->getELFType() == ELF::STT_SECTION) {
912928
Expected<StringRef> Name = SymI->getName();
913929
if (!Name) {
914930
consumeError(Name.takeError());
915931
return '?';
916932
}
917-
if (Name->startswith(".debug"))
918-
return 'N';
919-
if (!(Flags & ELF::SHF_WRITE))
920-
return 'n';
933+
return StringSwitch<char>(*Name)
934+
.StartsWith(".debug", 'N')
935+
.StartsWith(".note", 'n')
936+
.StartsWith(".comment", 'n')
937+
.Default('?');
921938
}
922939

923-
return '?';
940+
return 'n';
924941
}
925942

926943
static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {

0 commit comments

Comments
 (0)