[llvm] r360339 - [llvm-nm] Fix handling of symbol types 't' 'd' 'r'
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 05:43:37 PDT 2019
Author: maskray
Date: Thu May 9 05:43:37 2019
New Revision: 360339
URL: http://llvm.org/viewvc/llvm-project?rev=360339&view=rev
Log:
[llvm-nm] Fix handling of symbol types 't' 'd' 'r'
This restores part of r359311 that was reverted by r359830.
Rewrite the symbol types to fix several issues.
Notable difference is that the type of __init_array_start changes from
't' to 'd'.
GNU nm used to mark ELF symbols relative to .init_array as 't'
https://sourceware.org/bugzilla/show_bug.cgi?id=24505 (before 2.33)
because ".init" is the prefix. The bug was copied by r287803.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D61551
Added:
llvm/trunk/test/tools/llvm-nm/data.test
llvm/trunk/test/tools/llvm-nm/linker-synthesized.test
llvm/trunk/test/tools/llvm-nm/nobits.test
llvm/trunk/test/tools/llvm-nm/nonalloc.test
llvm/trunk/test/tools/llvm-nm/readonly.test
Removed:
llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64
llvm/trunk/test/tools/llvm-nm/X86/init-fini.test
Modified:
llvm/trunk/test/ThinLTO/X86/strong_non_prevailing.ll
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
Modified: llvm/trunk/test/ThinLTO/X86/strong_non_prevailing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/strong_non_prevailing.ll?rev=360339&r1=360338&r2=360339&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/strong_non_prevailing.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/strong_non_prevailing.ll Thu May 9 05:43:37 2019
@@ -12,5 +12,5 @@ $__llvm_profile_filename = comdat any
@__llvm_profile_filename = constant [19 x i8] c"default_%m.profraw\00", comdat
-; EXPORTED: N __llvm_profile_filename
-; NOT_EXPORTED-NOT: N __llvm_profile_filename
+; EXPORTED: R __llvm_profile_filename
+; NOT_EXPORTED-NOT: R __llvm_profile_filename
Removed: llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/Inputs/init-fini.out.elf-x86_64?rev=360338&view=auto
==============================================================================
Binary file - no diff available.
Removed: llvm/trunk/test/tools/llvm-nm/X86/init-fini.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/init-fini.test?rev=360338&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/X86/init-fini.test (original)
+++ llvm/trunk/test/tools/llvm-nm/X86/init-fini.test (removed)
@@ -1,8 +0,0 @@
-# RUN: llvm-nm -B -S %p/Inputs/init-fini.out.elf-x86_64 | FileCheck --match-full-lines %s
-
-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
Added: llvm/trunk/test/tools/llvm-nm/data.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/data.test?rev=360339&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/data.test (added)
+++ llvm/trunk/test/tools/llvm-nm/data.test Thu May 9 05:43:37 2019
@@ -0,0 +1,43 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+
+# CHECK: b mybss_local
+# CHECK-NEXT: d mydata_local
+# CHECK-NEXT: d mytdata_local
+# CHECK-NEXT: B mybss_global
+# CHECK-NEXT: D mydata_global
+# CHECK-NEXT: D mytdata_global
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: mybss
+ Type: SHT_NOBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ - Name: mydata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ - Name: mytdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE, SHF_TLS ]
+Symbols:
+ - Name: mybss_local
+ Section: mybss
+ - Name: mydata_local
+ Section: mydata
+ - Name: mytdata_local
+ Section: mytdata
+
+ - Name: mybss_global
+ Binding: STB_GLOBAL
+ Section: mybss
+ - Name: mydata_global
+ Binding: STB_GLOBAL
+ Section: mydata
+ - Name: mytdata_global
+ Binding: STB_GLOBAL
+ Section: mytdata
Added: llvm/trunk/test/tools/llvm-nm/linker-synthesized.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/linker-synthesized.test?rev=360339&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/linker-synthesized.test (added)
+++ llvm/trunk/test/tools/llvm-nm/linker-synthesized.test Thu May 9 05:43:37 2019
@@ -0,0 +1,57 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+
+## We used to be wrong with some linker synthesized symbols.
+
+## We mark __init_array_start as 'd', as consistent with GNU nm >= 2.33 (older GNU
+## nm marks it as 't'). See https://sourceware.org/bugzilla/show_bug.cgi?id=24511
+
+# CHECK: d __fini_array_start
+# CHECK: d __init_array_start
+# CHECK: d __preinit_array_start
+# CHECK: B __bss_start
+# CHECK: D _edata
+# CHECK: B _end
+
+!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: .fini_array
+ Type: SHT_FINI_ARRAY
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ - 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: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+Symbols:
+ - Name: __fini_array_start
+ Section: .fini_array
+ - Name: __init_array_start
+ Section: .init_array
+ - Name: __preinit_array_start
+ Section: .preinit_array
+
+ - Name: __bss_start
+ Section: .bss
+ Binding: STB_GLOBAL
+ - Name: _edata
+ Section: .data
+ Binding: STB_GLOBAL
+ - Name: _end
+ Section: .bss
+ Binding: STB_GLOBAL
Added: llvm/trunk/test/tools/llvm-nm/nobits.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/nobits.test?rev=360339&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/nobits.test (added)
+++ llvm/trunk/test/tools/llvm-nm/nobits.test Thu May 9 05:43:37 2019
@@ -0,0 +1,35 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+
+# CHECK: b mybss_local
+# CHECK: b mytbss_local
+# CHECK: B mybss_global
+# CHECK: B mytbss_global
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: mybss
+ Type: SHT_NOBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ - Name: mytbss
+ Type: SHT_NOBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE, SHF_TLS ]
+Symbols:
+ - Name: mybss_local
+ Binding: STB_LOCAL
+ Section: mybss
+ - Name: mytbss_local
+ Binding: STB_LOCAL
+ Section: mytbss
+
+ - Name: mybss_global
+ Binding: STB_GLOBAL
+ Section: mybss
+ - Name: mytbss_global
+ Binding: STB_GLOBAL
+ Section: mytbss
Added: llvm/trunk/test/tools/llvm-nm/nonalloc.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/nonalloc.test?rev=360339&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/nonalloc.test (added)
+++ llvm/trunk/test/tools/llvm-nm/nonalloc.test Thu May 9 05:43:37 2019
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+
+# CHECK: n debug_info_main
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .debug_info
+ Type: SHT_PROGBITS
+Symbols:
+ - Name: debug_info_main
+ Section: .debug_info
Added: llvm/trunk/test/tools/llvm-nm/readonly.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/readonly.test?rev=360339&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/readonly.test (added)
+++ llvm/trunk/test/tools/llvm-nm/readonly.test Thu May 9 05:43:37 2019
@@ -0,0 +1,43 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+
+# CHECK: r myrodata0_local
+# CHECK-NEXT: r myrodata1_local
+# CHECK-NEXT: r myrodata2_local
+# CHECK-NEXT: R myrodata0_global
+# CHECK-NEXT: R myrodata1_global
+# CHECK-NEXT: R myrodata2_global
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: myrodata0
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ - Name: myrodata1
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_MERGE ]
+ - Name: myrodata2
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
+Symbols:
+ - Name: myrodata0_local
+ Section: myrodata0
+ - Name: myrodata1_local
+ Section: myrodata1
+ - Name: myrodata2_local
+ Section: myrodata2
+
+ - Name: myrodata0_global
+ Binding: STB_GLOBAL
+ Section: myrodata0
+ - Name: myrodata1_global
+ Binding: STB_GLOBAL
+ Section: myrodata1
+ - Name: myrodata2_global
+ Binding: STB_GLOBAL
+ Section: myrodata2
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=360339&r1=360338&r2=360339&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Thu May 9 05:43:37 2019
@@ -901,27 +901,14 @@ static char getSymbolNMTypeChar(ELFObjec
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:
- return 'b';
- case ELF::SHT_INIT_ARRAY:
- case ELF::SHT_FINI_ARRAY:
+ uint32_t Type = SecI->getType();
+ uint64_t Flags = SecI->getFlags();
+ if (Flags & ELF::SHF_EXECINSTR)
return 't';
- }
+ if (Type == ELF::SHT_NOBITS)
+ return 'b';
+ if (Flags & ELF::SHF_ALLOC)
+ return Flags & ELF::SHF_WRITE ? 'd' : 'r';
}
if (SymI->getELFType() == ELF::STT_SECTION) {
More information about the llvm-commits
mailing list