From 75d5b5495f1514e239c1b18254ddcf7a297e80ee Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 3 Jun 2015 05:14:22 +0000 Subject: [PATCH] Fix the interpretation of a 0 st_name. The ELF spec is very clear: ----------------------------------------------------------------------------- If the value is non-zero, it represents a string table index that gives the symbol name. Otherwise, the symbol table entry has no name. -------------------------------------------------------------------------- In particular, a st_name of 0 most certainly doesn't mean that the symbol has the same name as the section. llvm-svn: 238899 --- llvm/include/llvm/Object/ELF.h | 7 ++-- llvm/test/MC/ARM/arm-elf-symver.s | 6 ++-- llvm/test/MC/ELF/alias.s | 6 ++-- llvm/test/MC/ELF/comdat-dup-group-name.s | 5 --- llvm/test/MC/ELF/many-sections-2.s | 14 ++++---- llvm/test/MC/ELF/many-sections.s | 14 ++++---- llvm/test/MC/ELF/noexec.s | 14 ++++---- llvm/test/MC/ELF/relocation-386.s | 23 +------------ llvm/test/MC/ELF/relocation.s | 12 +------ llvm/test/MC/ELF/section-sym.s | 38 --------------------- llvm/test/MC/ELF/section-sym2.s | 10 ++---- llvm/test/MC/ELF/symver.s | 6 ++-- llvm/test/MC/ELF/undef.s | 8 ++--- llvm/test/MC/ELF/weakref.s | 6 ++-- llvm/test/Object/obj2yaml.test | 47 +++++++++----------------- llvm/test/Object/readobj-shared-object.test | 20 +++++------ llvm/test/tools/llvm-readobj/sections-ext.test | 2 +- llvm/tools/llvm-objdump/llvm-objdump.cpp | 35 +++++++++++++------ llvm/tools/llvm-readobj/ELFDumper.cpp | 22 +++++++----- 19 files changed, 108 insertions(+), 187 deletions(-) diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index 7403b4c..e87737d 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -916,11 +916,8 @@ ErrorOr ELFFile::getSymbolName(Elf_Sym_Iter Sym) const { template ErrorOr ELFFile::getSymbolName(const Elf_Shdr *Section, const Elf_Sym *Symb) const { - if (Symb->st_name == 0) { - const Elf_Shdr *ContainingSec = getSection(Symb); - if (ContainingSec) - return getSectionName(ContainingSec); - } + if (Symb->st_name == 0) + return StringRef(""); const Elf_Shdr *StrTab = getSection(Section->sh_link); if (Symb->st_name >= StrTab->sh_size) diff --git a/llvm/test/MC/ARM/arm-elf-symver.s b/llvm/test/MC/ARM/arm-elf-symver.s index b391970..691c604 100644 --- a/llvm/test/MC/ARM/arm-elf-symver.s +++ b/llvm/test/MC/ARM/arm-elf-symver.s @@ -78,7 +78,7 @@ global1: @ CHECK-NEXT: Section: .text @ CHECK-NEXT: } @ CHECK-NEXT: Symbol { -@ CHECK-NEXT: Name: .text (0) +@ CHECK-NEXT: Name: (0) @ CHECK-NEXT: Value: 0x0 @ CHECK-NEXT: Size: 0 @ CHECK-NEXT: Binding: Local (0x0) @@ -87,7 +87,7 @@ global1: @ CHECK-NEXT: Section: .text @ CHECK-NEXT: } @ CHECK-NEXT: Symbol { -@ CHECK-NEXT: Name: .data (0) +@ CHECK-NEXT: Name: (0) @ CHECK-NEXT: Value: 0x0 @ CHECK-NEXT: Size: 0 @ CHECK-NEXT: Binding: Local (0x0) @@ -96,7 +96,7 @@ global1: @ CHECK-NEXT: Section: .data @ CHECK-NEXT: } @ CHECK-NEXT: Symbol { -@ CHECK-NEXT: Name: .bss (0) +@ CHECK-NEXT: Name: (0) @ CHECK-NEXT: Value: 0x0 @ CHECK-NEXT: Size: 0 @ CHECK-NEXT: Binding: Local (0x0) diff --git a/llvm/test/MC/ELF/alias.s b/llvm/test/MC/ELF/alias.s index 92621bc..8bbeb36 100644 --- a/llvm/test/MC/ELF/alias.s +++ b/llvm/test/MC/ELF/alias.s @@ -107,15 +107,15 @@ leaq .Llocal1(%rip), %rdi // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .text (0) +// CHECK-NEXT: Name: (0) // CHECK-NOT: Symbol { // CHECK: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .data (0) +// CHECK-NEXT: Name: (0) // CHECK-NOT: Symbol { // CHECK: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .bss (0) +// CHECK-NEXT: Name: (0) // CHECK-NOT: Symbol { // CHECK: } // CHECK-NEXT: Symbol { diff --git a/llvm/test/MC/ELF/comdat-dup-group-name.s b/llvm/test/MC/ELF/comdat-dup-group-name.s index a2dc4cc..6644e2b 100644 --- a/llvm/test/MC/ELF/comdat-dup-group-name.s +++ b/llvm/test/MC/ELF/comdat-dup-group-name.s @@ -24,12 +24,7 @@ // CHECK-NOT: } // CHECK: Section: .group (0x7) -// CHECK: Name: .foo -// CHECK-NOT: } // CHECK: Section: .foo (0x6) - -// CHECK: Name: .foo -// CHECK-NOT: } // CHECK: Section: .foo (0x8) diff --git a/llvm/test/MC/ELF/many-sections-2.s b/llvm/test/MC/ELF/many-sections-2.s index b52c01a..5698fe6 100644 --- a/llvm/test/MC/ELF/many-sections-2.s +++ b/llvm/test/MC/ELF/many-sections-2.s @@ -32,13 +32,13 @@ // Test that this file has one section too many. -// SYMBOLS: Name: dm -// SYMBOLS-NEXT: Value: 0x0 -// SYMBOLS-NEXT: Size: 0 -// SYMBOLS-NEXT: Binding: Local (0x0) -// SYMBOLS-NEXT: Type: Section (0x3) -// SYMBOLS-NEXT: Other: 0 -// SYMBOLS-NEXT: Section: dm (0xFF00) +// SYMBOLS: Name: (0) +// SYMBOLS: Value: 0x0 +// SYMBOLS: Size: 0 +// SYMBOLS: Binding: Local (0x0) +// SYMBOLS: Type: Section (0x3) +// SYMBOLS: Other: 0 +// SYMBOLS: Section: dm (0xFF00) // SYMBOLS-NEXT: } // SYMBOLS-NEXT:] diff --git a/llvm/test/MC/ELF/many-sections.s b/llvm/test/MC/ELF/many-sections.s index dbba871..43463ba6 100644 --- a/llvm/test/MC/ELF/many-sections.s +++ b/llvm/test/MC/ELF/many-sections.s @@ -9,13 +9,13 @@ // Check the last referenced section. -// SYMBOLS: Name: zed -// SYMBOLS-NEXT: Value: 0x0 -// SYMBOLS-NEXT: Size: 0 -// SYMBOLS-NEXT: Binding: Local (0x0) -// SYMBOLS-NEXT: Type: Section (0x3) -// SYMBOLS-NEXT: Other: 0 -// SYMBOLS-NEXT: Section: zed (0xFEFF) +// SYMBOLS: Name: (0) +// SYMBOLS: Value: 0x0 +// SYMBOLS: Size: 0 +// SYMBOLS: Binding: Local (0x0) +// SYMBOLS: Type: Section (0x3) +// SYMBOLS: Other: 0 +// SYMBOLS: Section: zed (0xFEFF) // SYMBOLS-NEXT: } // SYMBOLS-NEXT:] diff --git a/llvm/test/MC/ELF/noexec.s b/llvm/test/MC/ELF/noexec.s index 3769427..d3d5cd4 100644 --- a/llvm/test/MC/ELF/noexec.s +++ b/llvm/test/MC/ELF/noexec.s @@ -16,11 +16,11 @@ // CHECK-NEXT: } // CHECK: Symbol { -// CHECK: Name: .note.GNU-stack (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .note.GNU-stack +// CHECK: Name: (0) +// CHECK: Value: 0x0 +// CHECK: Size: 0 +// CHECK: Binding: Local +// CHECK: Type: Section +// CHECK: Other: 0 +// CHECK: Section: .note.GNU-stack // CHECK-NEXT: } diff --git a/llvm/test/MC/ELF/relocation-386.s b/llvm/test/MC/ELF/relocation-386.s index 2af6add..6b7e02f 100644 --- a/llvm/test/MC/ELF/relocation-386.s +++ b/llvm/test/MC/ELF/relocation-386.s @@ -1,4 +1,4 @@ -// RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | llvm-readobj -r -t | FileCheck %s +// RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | llvm-readobj -r | FileCheck %s // Test that we produce the correct relocation types and that the relocations // correctly point to the section or the symbol. @@ -71,27 +71,6 @@ // CHECK-NEXT: } // CHECK-NEXT: ] -// Symbol 4 is zed -// CHECK: Symbol { -// CHECK: Name: zed -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: TLS -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: zedsec -// CHECK-NEXT: } -// Symbol 7 is section 4 -// CHECK: Symbol { -// CHECK: Name: .bss (0) -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .bss -// CHECK-NEXT: } - .text bar: leal .Lfoo@GOTOFF(%ebx), %eax diff --git a/llvm/test/MC/ELF/relocation.s b/llvm/test/MC/ELF/relocation.s index 2841612..7697eb0 100644 --- a/llvm/test/MC/ELF/relocation.s +++ b/llvm/test/MC/ELF/relocation.s @@ -1,4 +1,4 @@ -// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s -sr -t | FileCheck %s +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s -sr | FileCheck %s // Test that we produce the correct relocation. @@ -92,13 +92,3 @@ bar: // CHECK-NEXT: 0xDC R_X86_64_PLT32 foo 0x0 // CHECK-NEXT: ] // CHECK-NEXT: } - -// CHECK: Symbol { -// CHECK: Name: .text (0) -// CHECK-NEXT: Value: -// CHECK-NEXT: Size: -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: Section -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .text -// CHECK-NEXT: } diff --git a/llvm/test/MC/ELF/section-sym.s b/llvm/test/MC/ELF/section-sym.s index f012b2f..389ffd7 100644 --- a/llvm/test/MC/ELF/section-sym.s +++ b/llvm/test/MC/ELF/section-sym.s @@ -51,41 +51,3 @@ // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: ] - - -// The symbol 6 corresponds section 6 -// CHECK: Symbols [ - -// symbol 0 -// CHECK-NOT: Name -// CHECK: Name: - -// symbol 1 -// CHECK-NOT: Name -// CHECK: Name: f1 - -// symbol 2 -// CHECK-NOT: Name -// CHECK: Name: f2 - -// symbol 3 -// CHECK-NOT: Name -// CHECK: Name: .text - -// symbol 4 -// CHECK-NOT: Name -// CHECK: Name: .data - -// symbol 5 -// CHECK-NOT: Name -// CHECK: Name: .bss - -// symbol 6 -// CHECK-NOT: Name -// CHECK: Name: foo -// CHECK: Section: foo (0x6) - -// symbol 7 -// CHECK-NOT: Name -// CHECK: Name: foo -// CHECK: Section: foo (0x8) diff --git a/llvm/test/MC/ELF/section-sym2.s b/llvm/test/MC/ELF/section-sym2.s index f62e3f9..ca38632 100644 --- a/llvm/test/MC/ELF/section-sym2.s +++ b/llvm/test/MC/ELF/section-sym2.s @@ -19,10 +19,6 @@ mov .rodata, %rsi // There is only one .rodata symbol // CHECK:Symbols [ -// CHECK-NOT: Name: .rodata -// CHECK: Name: .rodata -// CHECK-NEXT: Value: 0x0 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local (0x0) -// CHECK-NEXT: Type: Section (0x3) -// CHECK-NOT: Name: .rodata +// CHECK: Type: Section (0x3) +// CHECK: Section: .rodata +// CHECK-NOT: Section: .rodata diff --git a/llvm/test/MC/ELF/symver.s b/llvm/test/MC/ELF/symver.s index 178c0ff..ece651e4 100644 --- a/llvm/test/MC/ELF/symver.s +++ b/llvm/test/MC/ELF/symver.s @@ -77,7 +77,7 @@ global1: // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .text +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -86,7 +86,7 @@ global1: // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .data +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -95,7 +95,7 @@ global1: // CHECK-NEXT: Section: .data // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .bss +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/llvm/test/MC/ELF/undef.s b/llvm/test/MC/ELF/undef.s index 245b563..dcb1660 100644 --- a/llvm/test/MC/ELF/undef.s +++ b/llvm/test/MC/ELF/undef.s @@ -42,7 +42,7 @@ test2_b = undef + 1 // CHECK-NEXT: Section: .rodata.str1.1 // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .text +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -51,7 +51,7 @@ test2_b = undef + 1 // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .data +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -60,7 +60,7 @@ test2_b = undef + 1 // CHECK-NEXT: Section: .data // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .bss +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -69,7 +69,7 @@ test2_b = undef + 1 // CHECK-NEXT: Section: .bss // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .rodata.str1.1 +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/llvm/test/MC/ELF/weakref.s b/llvm/test/MC/ELF/weakref.s index d263af3..76e420a 100644 --- a/llvm/test/MC/ELF/weakref.s +++ b/llvm/test/MC/ELF/weakref.s @@ -116,7 +116,7 @@ bar15: // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .text +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -125,7 +125,7 @@ bar15: // CHECK-NEXT: Section: .text // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .data +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -134,7 +134,7 @@ bar15: // CHECK-NEXT: Section: .data // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: .bss +// CHECK-NEXT: Name: (0) // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/llvm/test/Object/obj2yaml.test b/llvm/test/Object/obj2yaml.test index 2a3f7c8..08000f6 100644 --- a/llvm/test/Object/obj2yaml.test +++ b/llvm/test/Object/obj2yaml.test @@ -267,26 +267,19 @@ ELF-MIPSEL-NEXT: - Name: '$.str' ELF-MIPSEL-NEXT: Type: STT_OBJECT ELF-MIPSEL-NEXT: Section: .rodata.str1.1 ELF-MIPSEL-NEXT: Size: 0x000000000000000D -ELF-MIPSEL-NEXT: - Name: .text -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .text -ELF-MIPSEL-NEXT: - Name: .data -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .data -ELF-MIPSEL-NEXT: - Name: .bss -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .bss -ELF-MIPSEL-NEXT: - Name: .mdebug.abi32 -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .mdebug.abi32 -ELF-MIPSEL-NEXT: - Name: .rodata.str1.1 -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .rodata.str1.1 -ELF-MIPSEL-NEXT: - Name: .reginfo -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .reginfo -ELF-MIPSEL-NEXT: - Name: .MIPS.abiflags -ELF-MIPSEL-NEXT: Type: STT_SECTION +ELF-MIPSEL-NEXT: - Type: STT_SECTION ELF-MIPSEL-NEXT: Section: .MIPS.abiflags ELF-MIPSEL-NEXT: Global: ELF-MIPSEL-NEXT: - Name: main @@ -343,22 +336,17 @@ ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000004 ELF-MIPS64EL-NEXT: Content: '' ELF-MIPS64EL-NEXT: Symbols: ELF-MIPS64EL-NEXT: Local: -ELF-MIPS64EL-NEXT: - Name: .text -ELF-MIPS64EL-NEXT: Type: STT_SECTION +ELF-MIPS64EL-NEXT: - Type: STT_SECTION ELF-MIPS64EL-NEXT: Section: .text -ELF-MIPS64EL-NEXT: - Name: .data -ELF-MIPS64EL-NEXT: Type: STT_SECTION +ELF-MIPS64EL-NEXT: - Type: STT_SECTION ELF-MIPS64EL-NEXT: Section: .data -ELF-MIPS64EL-NEXT: - Name: .bss -ELF-MIPS64EL-NEXT: Type: STT_SECTION +ELF-MIPS64EL-NEXT: - Type: STT_SECTION ELF-MIPS64EL-NEXT: Section: .bss ELF-MIPS64EL-NEXT: - Name: bar ELF-MIPS64EL-NEXT: Section: .data -ELF-MIPS64EL-NEXT: - Name: .MIPS.options -ELF-MIPS64EL-NEXT: Type: STT_SECTION +ELF-MIPS64EL-NEXT: - Type: STT_SECTION ELF-MIPS64EL-NEXT: Section: .MIPS.options -ELF-MIPS64EL-NEXT: - Name: .pdr -ELF-MIPS64EL-NEXT: Type: STT_SECTION +ELF-MIPS64EL-NEXT: - Type: STT_SECTION ELF-MIPS64EL-NEXT: Section: .pdr ELF-MIPS64EL-NEXT: Global: ELF-MIPS64EL-NEXT: - Name: zed @@ -394,7 +382,7 @@ ELF-X86-64-NEXT: AddressAlign: 0x0000000000000008 ELF-X86-64-NEXT: Info: .text ELF-X86-64-NEXT: Relocations: ELF-X86-64-NEXT: - Offset: 0x000000000000000D -ELF-X86-64-NEXT: Symbol: .rodata.str1.1 +ELF-X86-64-NEXT: Symbol: '' ELF-X86-64-NEXT: Type: R_X86_64_32S ELF-X86-64-NEXT: - Offset: 0x0000000000000012 ELF-X86-64-NEXT: Symbol: puts @@ -408,14 +396,11 @@ ELF-X86-64-NEXT: Symbols: ELF-X86-64-NEXT: Local: ELF-X86-64-NEXT: - Name: trivial-object-test.s ELF-X86-64-NEXT: Type: STT_FILE -ELF-X86-64-NEXT: - Name: .text -ELF-X86-64-NEXT: Type: STT_SECTION +ELF-X86-64-NEXT: - Type: STT_SECTION ELF-X86-64-NEXT: Section: .text -ELF-X86-64-NEXT: - Name: .rodata.str1.1 -ELF-X86-64-NEXT: Type: STT_SECTION +ELF-X86-64-NEXT: - Type: STT_SECTION ELF-X86-64-NEXT: Section: .rodata.str1.1 -ELF-X86-64-NEXT: - Name: .note.GNU-stack -ELF-X86-64-NEXT: Type: STT_SECTION +ELF-X86-64-NEXT: - Type: STT_SECTION ELF-X86-64-NEXT: Section: .note.GNU-stack ELF-X86-64-NEXT: Global: ELF-X86-64-NEXT: - Name: main diff --git a/llvm/test/Object/readobj-shared-object.test b/llvm/test/Object/readobj-shared-object.test index 516d4c6..508caca 100644 --- a/llvm/test/Object/readobj-shared-object.test +++ b/llvm/test/Object/readobj-shared-object.test @@ -128,61 +128,61 @@ ELF: ] ELF: Symbols [ ELF: Symbol { -ELF: Name: .hash +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .hash ELF: } ELF: Symbol { -ELF: Name: .dynsym +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .dynsym ELF: } ELF: Symbol { -ELF: Name: .dynstr +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .dynstr ELF: } ELF: Symbol { -ELF: Name: .text +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .text ELF: } ELF: Symbol { -ELF: Name: .eh_frame +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .eh_frame ELF: } ELF: Symbol { -ELF: Name: .tdata +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .tdata ELF: } ELF: Symbol { -ELF: Name: .dynamic +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .dynamic ELF: } ELF: Symbol { -ELF: Name: .got.plt +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .got.plt ELF: } ELF: Symbol { -ELF: Name: .data +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .data ELF: } ELF: Symbol { -ELF: Name: .bss +ELF: Name: (0) ELF: Binding: Local ELF: Type: Section ELF: Section: .bss diff --git a/llvm/test/tools/llvm-readobj/sections-ext.test b/llvm/test/tools/llvm-readobj/sections-ext.test index 4024878..6b4a674 100644 --- a/llvm/test/tools/llvm-readobj/sections-ext.test +++ b/llvm/test/tools/llvm-readobj/sections-ext.test @@ -110,7 +110,7 @@ ELF-NEXT: Relocations [ ELF-NEXT: ] ELF-NEXT: Symbols [ ELF-NEXT: Symbol { -ELF-NEXT: Name: .text (0) +ELF-NEXT: Name: (0) ELF-NEXT: Value: 0x0 ELF-NEXT: Size: 0 ELF-NEXT: Binding: Local (0x0) diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 7509931..d03556c 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -327,10 +327,20 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, } const Elf_Sym *symb = EF.template getEntry(sec->sh_link, symbol_index); - ErrorOr SymName = - EF.getSymbolName(EF.getSection(sec->sh_link), symb); - if (!SymName) - return SymName.getError(); + StringRef Target; + const Elf_Shdr *SymSec = EF.getSection(symb); + if (symb->getType() == ELF::STT_SECTION) { + ErrorOr SecName = EF.getSectionName(SymSec); + if (std::error_code EC = SecName.getError()) + return EC; + Target = *SecName; + } else { + ErrorOr SymName = + EF.getSymbolName(EF.getSection(sec->sh_link), symb); + if (!SymName) + return SymName.getError(); + Target = *SymName; + } switch (EF.getHeader()->e_machine) { case ELF::EM_X86_64: switch (type) { @@ -339,7 +349,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, case ELF::R_X86_64_PC32: { std::string fmtbuf; raw_string_ostream fmt(fmtbuf); - fmt << *SymName << (addend < 0 ? "" : "+") << addend << "-P"; + fmt << Target << (addend < 0 ? "" : "+") << addend << "-P"; fmt.flush(); Result.append(fmtbuf.begin(), fmtbuf.end()); } break; @@ -350,7 +360,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, case ELF::R_X86_64_64: { std::string fmtbuf; raw_string_ostream fmt(fmtbuf); - fmt << *SymName << (addend < 0 ? "" : "+") << addend; + fmt << Target << (addend < 0 ? "" : "+") << addend; fmt.flush(); Result.append(fmtbuf.begin(), fmtbuf.end()); } break; @@ -361,7 +371,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, case ELF::EM_AARCH64: { std::string fmtbuf; raw_string_ostream fmt(fmtbuf); - fmt << *SymName; + fmt << Target; if (addend != 0) fmt << (addend < 0 ? "" : "+") << addend; fmt.flush(); @@ -372,7 +382,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, case ELF::EM_ARM: case ELF::EM_HEXAGON: case ELF::EM_MIPS: - res = *SymName; + res = Target; break; default: res = "Unknown"; @@ -1052,13 +1062,10 @@ void llvm::PrintSymbolTable(const ObjectFile *o) { return; } for (const SymbolRef &Symbol : o->symbols()) { - StringRef Name; uint64_t Address; SymbolRef::Type Type; uint32_t Flags = Symbol.getFlags(); section_iterator Section = o->section_end(); - if (error(Symbol.getName(Name))) - continue; if (error(Symbol.getAddress(Address))) continue; if (error(Symbol.getType(Type))) @@ -1066,6 +1073,12 @@ void llvm::PrintSymbolTable(const ObjectFile *o) { uint64_t Size = Symbol.getSize(); if (error(Symbol.getSection(Section))) continue; + StringRef Name; + if (Type == SymbolRef::ST_Debug && Section != o->section_end()) { + Section->getName(Name); + } else if (error(Symbol.getName(Name))) { + continue; + } bool Global = Flags & SymbolRef::SF_Global; bool Weak = Flags & SymbolRef::SF_Weak; diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 880143a..8963c5e 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -705,26 +705,30 @@ void ELFDumper::printRelocation(const Elf_Shdr *Sec, typename ELFO::Elf_Rela Rel) { SmallString<32> RelocName; Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); - StringRef SymbolName; + StringRef TargetName; std::pair Sym = Obj->getRelocationSymbol(Sec, &Rel); - if (Sym.first) - SymbolName = errorOrDefault(Obj->getSymbolName(Sym.first, Sym.second)); + if (Sym.second && Sym.second->getType() == ELF::STT_SECTION) { + const Elf_Shdr *Sec = Obj->getSection(Sym.second); + ErrorOr SecName = Obj->getSectionName(Sec); + if (SecName) + TargetName = SecName.get(); + } else if (Sym.first) { + TargetName = errorOrDefault(Obj->getSymbolName(Sym.first, Sym.second)); + } if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); W.printHex("Offset", Rel.r_offset); W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); - W.printNumber("Symbol", SymbolName.size() > 0 ? SymbolName : "-", + W.printNumber("Symbol", TargetName.size() > 0 ? TargetName : "-", Rel.getSymbol(Obj->isMips64EL())); W.printHex("Addend", Rel.r_addend); } else { raw_ostream& OS = W.startLine(); - OS << W.hex(Rel.r_offset) - << " " << RelocName - << " " << (SymbolName.size() > 0 ? SymbolName : "-") - << " " << W.hex(Rel.r_addend) - << "\n"; + OS << W.hex(Rel.r_offset) << " " << RelocName << " " + << (TargetName.size() > 0 ? TargetName : "-") << " " + << W.hex(Rel.r_addend) << "\n"; } } -- 2.7.4