diff options
author | Simon Atanasyan <simon@atanasyan.com> | 2014-06-10 05:59:15 +0000 |
---|---|---|
committer | Simon Atanasyan <simon@atanasyan.com> | 2014-06-10 05:59:15 +0000 |
commit | efcef81061a1733bf8f033838306d9aa2c4b571e (patch) | |
tree | 6a96bd78cc5dfae0bdaa6424a5707aad388805c4 /tools/llvm-readobj | |
parent | 6e02efd1300d22257e457b84a065c73f53b21982 (diff) | |
download | llvm-efcef81061a1733bf8f033838306d9aa2c4b571e.tar.gz llvm-efcef81061a1733bf8f033838306d9aa2c4b571e.tar.bz2 llvm-efcef81061a1733bf8f033838306d9aa2c4b571e.tar.xz |
[llvm-readobj][ELF] Factor out the code retrieve ELF symbol information
(section name, section index, full name) into the separate functions.
No functional changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r-- | tools/llvm-readobj/ELFDumper.cpp | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index c07487a2f5..0a69915ac8 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -111,6 +111,53 @@ error_code createELFDumper(const object::ObjectFile *Obj, StreamWriter &Writer, } // namespace llvm +template <typename ELFO> +static std::string getFullSymbolName(const ELFO &Obj, + typename ELFO::Elf_Sym_Iter Symbol) { + StringRef SymbolName = errorOrDefault(Obj.getSymbolName(Symbol)); + if (!Symbol.isDynamic()) + return SymbolName; + + std::string FullSymbolName(SymbolName); + + bool IsDefault; + ErrorOr<StringRef> Version = + Obj.getSymbolVersion(nullptr, &*Symbol, IsDefault); + if (Version) { + FullSymbolName += (IsDefault ? "@@" : "@"); + FullSymbolName += *Version; + } else + error(Version.getError()); + return FullSymbolName; +} + +template <typename ELFO> +static void +getSectionNameIndex(const ELFO &Obj, typename ELFO::Elf_Sym_Iter Symbol, + StringRef &SectionName, unsigned &SectionIndex) { + SectionIndex = Symbol->st_shndx; + if (SectionIndex == SHN_UNDEF) { + SectionName = "Undefined"; + } else if (SectionIndex >= SHN_LOPROC && SectionIndex <= SHN_HIPROC) { + SectionName = "Processor Specific"; + } else if (SectionIndex >= SHN_LOOS && SectionIndex <= SHN_HIOS) { + SectionName = "Operating System Specific"; + } else if (SectionIndex > SHN_HIOS && SectionIndex < SHN_ABS) { + SectionName = "Reserved"; + } else if (SectionIndex == SHN_ABS) { + SectionName = "Absolute"; + } else if (SectionIndex == SHN_COMMON) { + SectionName = "Common"; + } else { + if (SectionIndex == SHN_XINDEX) + SectionIndex = Obj.getSymbolTableIndex(&*Symbol); + assert(SectionIndex != SHN_XINDEX && + "getSymbolTableIndex should handle this"); + const typename ELFO::Elf_Shdr *Sec = Obj.getSection(SectionIndex); + SectionName = errorOrDefault(Obj.getSectionName(Sec)); + } +} + static const EnumEntry<unsigned> ElfClass[] = { { "None", ELF::ELFCLASSNONE }, { "32-bit", ELF::ELFCLASS32 }, @@ -651,42 +698,10 @@ void ELFDumper<ELFT>::printDynamicSymbols() { template <class ELFT> void ELFDumper<ELFT>::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) { - StringRef SymbolName = errorOrDefault(Obj->getSymbolName(Symbol)); - - unsigned SectionIndex = Symbol->st_shndx; + unsigned SectionIndex = 0; StringRef SectionName; - if (SectionIndex == SHN_UNDEF) { - SectionName = "Undefined"; - } else if (SectionIndex >= SHN_LOPROC && SectionIndex <= SHN_HIPROC) { - SectionName = "Processor Specific"; - } else if (SectionIndex >= SHN_LOOS && SectionIndex <= SHN_HIOS) { - SectionName = "Operating System Specific"; - } else if (SectionIndex > SHN_HIOS && SectionIndex < SHN_ABS) { - SectionName = "Reserved"; - } else if (SectionIndex == SHN_ABS) { - SectionName = "Absolute"; - } else if (SectionIndex == SHN_COMMON) { - SectionName = "Common"; - } else { - if (SectionIndex == SHN_XINDEX) - SectionIndex = Obj->getSymbolTableIndex(&*Symbol); - assert(SectionIndex != SHN_XINDEX && - "getSymbolTableIndex should handle this"); - const Elf_Shdr *Sec = Obj->getSection(SectionIndex); - SectionName = errorOrDefault(Obj->getSectionName(Sec)); - } - - std::string FullSymbolName(SymbolName); - if (Symbol.isDynamic()) { - bool IsDefault; - ErrorOr<StringRef> Version = Obj->getSymbolVersion(nullptr, &*Symbol, - IsDefault); - if (Version) { - FullSymbolName += (IsDefault ? "@@" : "@"); - FullSymbolName += *Version; - } else - error(Version.getError()); - } + getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex); + std::string FullSymbolName = getFullSymbolName(*Obj, Symbol); DictScope D(W, "Symbol"); W.printNumber("Name", FullSymbolName, Symbol->st_name); |