diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-03 05:14:22 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-03 05:14:22 +0000 |
commit | 75d5b5495f1514e239c1b18254ddcf7a297e80ee (patch) | |
tree | 5298aa78b05bc21c610511543cf860a67d654b2a /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 37070a5a3aa3103ac8817ef7ff620d2c514e8548 (diff) | |
download | bcm5719-llvm-75d5b5495f1514e239c1b18254ddcf7a297e80ee.tar.gz bcm5719-llvm-75d5b5495f1514e239c1b18254ddcf7a297e80ee.zip |
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
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 75099314037..d03556c4615 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<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; |