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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238899 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-06-03 05:14:22 +00:00
parent 8c7a0fd91a
commit 201a551929
19 changed files with 108 additions and 187 deletions

View File

@ -916,11 +916,8 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolName(Elf_Sym_Iter Sym) const {
template <class ELFT>
ErrorOr<StringRef> ELFFile<ELFT>::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)

View File

@ -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)

View File

@ -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 {

View File

@ -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)

View File

@ -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:]

View File

@ -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:]

View File

@ -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: }

View File

@ -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

View File

@ -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: }

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -327,10 +327,20 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
}
const Elf_Sym *symb =
EF.template getEntry<Elf_Sym>(sec->sh_link, symbol_index);
ErrorOr<StringRef> 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<StringRef> SecName = EF.getSectionName(SymSec);
if (std::error_code EC = SecName.getError())
return EC;
Target = *SecName;
} else {
ErrorOr<StringRef> 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<ELFT> *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<ELFT> *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<ELFT> *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<ELFT> *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;

View File

@ -705,26 +705,30 @@ void ELFDumper<ELFT>::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<const Elf_Shdr *, const Elf_Sym *> 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<StringRef> 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";
}
}