[llvm] r355207 - [llvm-readobj] Display section names for STT_SECTION symbols.
Matt Davis via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 09:31:32 PST 2019
Author: mattd
Date: Fri Mar 1 09:31:32 2019
New Revision: 355207
URL: http://llvm.org/viewvc/llvm-project?rev=355207&view=rev
Log:
[llvm-readobj] Display section names for STT_SECTION symbols.
Summary:
This patch will obtain the section name for symbols that refer to a section. Prior to this patch the Name field for STT_SECTIONs was blank, now it is populated.
Before:
```
Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 SECTION LOCAL DEFAULT 1
2: 0000000000000000 0 SECTION LOCAL DEFAULT 3
3: 0000000000000000 0 SECTION LOCAL DEFAULT 4
4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _GLOBAL_OFFSET_TABLE_
5: 0000000000000000 0 TLS GLOBAL DEFAULT UND sym
```
With this patch:
```
Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text
2: 0000000000000000 0 SECTION LOCAL DEFAULT 3 .data
3: 0000000000000000 0 SECTION LOCAL DEFAULT 4 .bss
4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _GLOBAL_OFFSET_TABLE_
5: 0000000000000000 0 TLS GLOBAL DEFAULT UND sym
```
This fixes PR40788
Reviewers: jhenderson, rupprecht, espindola
Reviewed By: rupprecht
Subscribers: emaste, javed.absar, arichardson, MaskRay, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58796
Modified:
llvm/trunk/test/MC/ARM/arm-elf-symver.s
llvm/trunk/test/MC/ELF/alias.s
llvm/trunk/test/MC/ELF/many-sections-2.s
llvm/trunk/test/MC/ELF/section-sym.s
llvm/trunk/test/MC/ELF/symver.s
llvm/trunk/test/MC/ELF/weakref.s
llvm/trunk/test/Object/readobj-shared-object.test
llvm/trunk/test/tools/llvm-readobj/gnu-symbols.test
llvm/trunk/test/tools/llvm-readobj/sections-ext.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/test/MC/ARM/arm-elf-symver.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/arm-elf-symver.s?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/arm-elf-symver.s (original)
+++ llvm/trunk/test/MC/ARM/arm-elf-symver.s Fri Mar 1 09:31:32 2019
@@ -78,7 +78,7 @@ global1:
@ CHECK-NEXT: Section: .text
@ CHECK-NEXT: }
@ CHECK-NEXT: Symbol {
-@ CHECK-NEXT: Name: (0)
+@ CHECK-NEXT: Name: .text (0)
@ CHECK-NEXT: Value: 0x0
@ CHECK-NEXT: Size: 0
@ CHECK-NEXT: Binding: Local (0x0)
Modified: llvm/trunk/test/MC/ELF/alias.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/alias.s?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/alias.s (original)
+++ llvm/trunk/test/MC/ELF/alias.s Fri Mar 1 09:31:32 2019
@@ -107,7 +107,7 @@ leaq .Llocal1(%rip), %rdi
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: (0)
+// CHECK-NEXT: Name: .data (0)
// CHECK-NOT: Symbol {
// CHECK: }
// CHECK-NEXT: Symbol {
Modified: llvm/trunk/test/MC/ELF/many-sections-2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/many-sections-2.s?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/many-sections-2.s (original)
+++ llvm/trunk/test/MC/ELF/many-sections-2.s Fri Mar 1 09:31:32 2019
@@ -32,7 +32,7 @@
// Test that this file has one section too many.
-// SYMBOLS: Name: (0)
+// SYMBOLS: Name: dm (0)
// SYMBOLS: Value: 0x0
// SYMBOLS: Size: 0
// SYMBOLS: Binding: Local (0x0)
Modified: llvm/trunk/test/MC/ELF/section-sym.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-sym.s?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/section-sym.s (original)
+++ llvm/trunk/test/MC/ELF/section-sym.s Fri Mar 1 09:31:32 2019
@@ -82,7 +82,7 @@
// CHECK-NEXT: Section: .group
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: (0)
+// CHECK-NEXT: Name: foo (0)
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local (0x0)
Modified: llvm/trunk/test/MC/ELF/symver.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/symver.s?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/symver.s (original)
+++ llvm/trunk/test/MC/ELF/symver.s Fri Mar 1 09:31:32 2019
@@ -77,7 +77,7 @@ global1:
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: (0)
+// CHECK-NEXT: Name: .text (0)
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
Modified: llvm/trunk/test/MC/ELF/weakref.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/weakref.s?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/weakref.s (original)
+++ llvm/trunk/test/MC/ELF/weakref.s Fri Mar 1 09:31:32 2019
@@ -116,7 +116,7 @@ bar15:
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: (0)
+// CHECK-NEXT: Name: .text (0)
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
Modified: llvm/trunk/test/Object/readobj-shared-object.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/readobj-shared-object.test?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/Object/readobj-shared-object.test (original)
+++ llvm/trunk/test/Object/readobj-shared-object.test Fri Mar 1 09:31:32 2019
@@ -128,61 +128,61 @@ ELF: ]
ELF: Symbols [
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .hash (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .hash
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .dynsym (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .dynsym
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .dynstr (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .dynstr
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .text (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .text
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .eh_frame (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .eh_frame
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .tdata (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .tdata
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .dynamic (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .dynamic
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .got.plt (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .got.plt
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .data (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .data
ELF: }
ELF: Symbol {
-ELF: Name: (0)
+ELF: Name: .bss (0)
ELF: Binding: Local
ELF: Type: Section
ELF: Section: .bss
Modified: llvm/trunk/test/tools/llvm-readobj/gnu-symbols.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/gnu-symbols.test?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/gnu-symbols.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/gnu-symbols.test Fri Mar 1 09:31:32 2019
@@ -20,9 +20,9 @@ ELF32-NEXT: 4: 00000000 4 OBJEC
ELF64: Symbol table '.symtab' contains 6 entries:
ELF64-NEXT: Num: Value Size Type Bind Vis Ndx Name
ELF64-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
-ELF64-NEXT: 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1
-ELF64-NEXT: 2: 0000000000000000 0 SECTION LOCAL DEFAULT 3
-ELF64-NEXT: 3: 0000000000000000 0 SECTION LOCAL DEFAULT 4
+ELF64-NEXT: 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text
+ELF64-NEXT: 2: 0000000000000000 0 SECTION LOCAL DEFAULT 3 .data
+ELF64-NEXT: 3: 0000000000000000 0 SECTION LOCAL DEFAULT 4 .bss
ELF64-NEXT: 4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _GLOBAL_OFFSET_TABLE_
ELF64-NEXT: 5: 0000000000000000 0 TLS GLOBAL DEFAULT UND sym
@@ -42,11 +42,11 @@ NO-SYMTAB-NOT: Symbol table '.symtab'
SYMTAB: Symbol table '.symtab' contains 12 entries:
SYMTAB-NEXT: Num: Value Size Type Bind Vis Ndx Name
SYMTAB-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
-SYMTAB-NEXT: 1: 00000000000000e8 0 SECTION LOCAL DEFAULT 1
-SYMTAB-NEXT: 2: 0000000000000120 0 SECTION LOCAL DEFAULT 2
-SYMTAB-NEXT: 3: 0000000000000198 0 SECTION LOCAL DEFAULT 3
-SYMTAB-NEXT: 4: 00000000000001b8 0 SECTION LOCAL DEFAULT 4
-SYMTAB-NEXT: 5: 00000000002001b8 0 SECTION LOCAL DEFAULT 5
+SYMTAB-NEXT: 1: 00000000000000e8 0 SECTION LOCAL DEFAULT 1 .gnu.hash
+SYMTAB-NEXT: 2: 0000000000000120 0 SECTION LOCAL DEFAULT 2 .dynsym
+SYMTAB-NEXT: 3: 0000000000000198 0 SECTION LOCAL DEFAULT 3 .dynstr
+SYMTAB-NEXT: 4: 00000000000001b8 0 SECTION LOCAL DEFAULT 4 .eh_frame
+SYMTAB-NEXT: 5: 00000000002001b8 0 SECTION LOCAL DEFAULT 5 .dynamic
SYMTAB-NEXT: 6: 00000000002001b8 0 OBJECT LOCAL DEFAULT 5 _DYNAMIC
SYMTAB-NEXT: 7: 0000000000200268 0 OBJECT LOCAL DEFAULT 5 _GLOBAL_OFFSET_TABLE_
SYMTAB-NEXT: 8: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 __bss_start
Modified: llvm/trunk/test/tools/llvm-readobj/sections-ext.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/sections-ext.test?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/sections-ext.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/sections-ext.test Fri Mar 1 09:31:32 2019
@@ -124,7 +124,7 @@ ELF-NEXT: Relocations [
ELF-NEXT: ]
ELF-NEXT: Symbols [
ELF-NEXT: Symbol {
-ELF-NEXT: Name: (0)
+ELF-NEXT: Name: .text (0)
ELF-NEXT: Value: 0x0
ELF-NEXT: Size: 0
ELF-NEXT: Binding: Local (0x0)
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=355207&r1=355206&r2=355207&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Fri Mar 1 09:31:32 2019
@@ -814,6 +814,16 @@ std::string ELFDumper<ELFT>::getFullSymb
bool IsDynamic) const {
std::string SymbolName =
maybeDemangle(unwrapOrError(Symbol->getName(StrTable)));
+
+ if (SymbolName.empty() && Symbol->getType() == ELF::STT_SECTION) {
+ unsigned SectionIndex;
+ StringRef SectionName;
+ Elf_Sym_Range Syms =
+ unwrapOrError(ObjF->getELFFile()->symbols(DotSymtabSec));
+ getSectionNameIndex(Symbol, Syms.begin(), SectionName, SectionIndex);
+ return SectionName;
+ }
+
if (!IsDynamic)
return SymbolName;
More information about the llvm-commits
mailing list