Index: llvm/test/MC/ARM/arm-elf-symver.s =================================================================== --- llvm/test/MC/ARM/arm-elf-symver.s +++ llvm/test/MC/ARM/arm-elf-symver.s @@ -78,7 +78,7 @@ @ 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) Index: llvm/test/MC/ELF/alias.s =================================================================== --- llvm/test/MC/ELF/alias.s +++ llvm/test/MC/ELF/alias.s @@ -107,7 +107,7 @@ // 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 { Index: llvm/test/MC/ELF/many-sections-2.s =================================================================== --- llvm/test/MC/ELF/many-sections-2.s +++ llvm/test/MC/ELF/many-sections-2.s @@ -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) Index: llvm/test/MC/ELF/section-sym.s =================================================================== --- llvm/test/MC/ELF/section-sym.s +++ llvm/test/MC/ELF/section-sym.s @@ -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) Index: llvm/test/MC/ELF/symver.s =================================================================== --- llvm/test/MC/ELF/symver.s +++ llvm/test/MC/ELF/symver.s @@ -77,7 +77,7 @@ // 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 Index: llvm/test/MC/ELF/weakref.s =================================================================== --- llvm/test/MC/ELF/weakref.s +++ llvm/test/MC/ELF/weakref.s @@ -116,7 +116,7 @@ // 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 Index: llvm/test/Object/readobj-shared-object.test =================================================================== --- llvm/test/Object/readobj-shared-object.test +++ llvm/test/Object/readobj-shared-object.test @@ -128,61 +128,61 @@ 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 Index: llvm/test/tools/llvm-readobj/sections-ext.test =================================================================== --- llvm/test/tools/llvm-readobj/sections-ext.test +++ llvm/test/tools/llvm-readobj/sections-ext.test @@ -124,7 +124,7 @@ 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) Index: llvm/test/tools/llvm-readobj/symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/symbols.test +++ llvm/test/tools/llvm-readobj/symbols.test @@ -14,6 +14,10 @@ RUN: llvm-readelf -s -elf-output-style LLVM %p/Inputs/trivial.obj.elf-i386 > %t.lowers RUN: cmp %t.symbols %t.lowers +# Check the GNU presentation of the output. +RUN: llvm-readelf --symbols %p/Inputs/trivial.obj.elf-i386 \ +RUN: | FileCheck %s -check-prefix ELF-GNU + COFF: Symbols [ COFF-NEXT: Symbol { COFF-NEXT: Name: @comp.id @@ -127,3 +131,18 @@ WASM-NEXT: ElementIndex: 0x1 WASM-NEXT: } WASM-NEXT: ] + +ELF-GNU: Symbol table '.symtab' contains 12 entries: +ELF-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name +ELF-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND +ELF-GNU-NEXT: 1: 00000000 0 FILE LOCAL DEFAULT ABS trivial.ll +ELF-GNU-NEXT: 2: 00000000 13 OBJECT LOCAL DEFAULT 5 .L.str +ELF-GNU-NEXT: 3: 00000000 0 SECTION LOCAL DEFAULT 1 .text +ELF-GNU-NEXT: 4: 00000000 0 SECTION LOCAL DEFAULT 3 .data +ELF-GNU-NEXT: 5: 00000000 0 SECTION LOCAL DEFAULT 4 .bss +ELF-GNU-NEXT: 6: 00000000 0 SECTION LOCAL DEFAULT 5 .rodata.str1.1 +ELF-GNU-NEXT: 7: 00000000 0 SECTION LOCAL DEFAULT 6 .note.GNU-stack +ELF-GNU-NEXT: 8: 00000000 42 FUNC GLOBAL DEFAULT 1 main +ELF-GNU-NEXT: 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND SomeOtherFunction +ELF-GNU-NEXT: 10: 00000000 0 NOTYPE GLOBAL DEFAULT UND _GLOBAL_OFFSET_TABLE_ +ELF-GNU-NEXT: 11: 00000000 0 NOTYPE GLOBAL DEFAULT UND puts Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -814,6 +814,16 @@ bool IsDynamic) const { std::string SymbolName = maybeDemangle(unwrapOrError(Symbol->getName(StrTable))); + + if (SymbolName.size() == 0 && Symbol->getType() == ELF::STT_SECTION) { + unsigned SectionIndex; + StringRef SectionName; + auto Syms = unwrapOrError(ObjF->getELFFile()->symbols(DotSymtabSec)); + getSectionNameIndex(Symbol, Syms.begin(), SectionName, SectionIndex); + if (SectionName.size()) + return SectionName; + } + if (!IsDynamic) return SymbolName;