diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-06-22 13:43:38 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-06-22 13:43:38 +0000 |
commit | ff8b539f7ba4736a0635ad68e30c2f7422ddae0f (patch) | |
tree | cc63ec69c73cec427295817c0dca4312ac020e1b /llvm/tools/llvm-readobj/ELFDumper.cpp | |
parent | 1536c196426789a032e2456a1ffaefd262dbd4ab (diff) | |
download | bcm5719-llvm-ff8b539f7ba4736a0635ad68e30c2f7422ddae0f.tar.gz bcm5719-llvm-ff8b539f7ba4736a0635ad68e30c2f7422ddae0f.zip |
[llvm-readobj] - Teach llvm-readobj to print dependencies of SHT_GNU_verdef and refactor dumping method.
This patch changes single method of llvm-readobj.
It teaches SHT_GNU_verdef dumper to print version dependencies,
also it removes few fields from output that can be dumped with other keys
and slightly refactors code.
Testcase was also modified to match the changes.
Change is required for testcases of upcoming lld patches.
Differential revision: http://reviews.llvm.org/D21552
llvm-svn: 273417
Diffstat (limited to 'llvm/tools/llvm-readobj/ELFDumper.cpp')
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 1f45b7986a6..84e368e7aa3 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -530,21 +530,19 @@ static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper, const ELFO *Obj, const typename ELFO::Elf_Shdr *Sec, ScopedPrinter &W) { - DictScope SD(W, "Version definition"); + typedef typename ELFO::Elf_Verdef VerDef; + typedef typename ELFO::Elf_Verdaux VerdAux; + + DictScope SD(W, "SHT_GNU_verdef"); if (!Sec) return; - StringRef Name = unwrapOrError(Obj->getSectionName(Sec)); - W.printNumber("Section Name", Name, Sec->sh_name); - W.printHex("Address", Sec->sh_addr); - W.printHex("Offset", Sec->sh_offset); - W.printNumber("Link", Sec->sh_link); - unsigned verdef_entries = 0; // The number of entries in the section SHT_GNU_verdef // is determined by DT_VERDEFNUM tag. + unsigned VerDefsNum = 0; for (const typename ELFO::Elf_Dyn &Dyn : Dumper->dynamic_table()) { if (Dyn.d_tag == DT_VERDEFNUM) - verdef_entries = Dyn.d_un.d_val; + VerDefsNum = Dyn.d_un.d_val; } const uint8_t *SecStartAddress = (const uint8_t *)Obj->base() + Sec->sh_offset; @@ -553,22 +551,32 @@ static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper, const typename ELFO::Elf_Shdr *StrTab = unwrapOrError(Obj->getSection(Sec->sh_link)); - ListScope Entries(W, "Entries"); - for (unsigned i = 0; i < verdef_entries; ++i) { - if (P + sizeof(typename ELFO::Elf_Verdef) > SecEndAddress) + while (VerDefsNum--) { + if (P + sizeof(VerDef) > SecEndAddress) report_fatal_error("invalid offset in the section"); - auto *VD = reinterpret_cast<const typename ELFO::Elf_Verdef *>(P); - DictScope Entry(W, "Entry"); - W.printHex("Offset", (uintptr_t)P - (uintptr_t)SecStartAddress); - W.printNumber("Rev", VD->vd_version); - // FIXME: print something more readable. - W.printNumber("Flags", VD->vd_flags); + + auto *VD = reinterpret_cast<const VerDef *>(P); + DictScope Def(W, "Definition"); + W.printNumber("Version", VD->vd_version); + W.printEnum("Flags", VD->vd_flags, makeArrayRef(SymVersionFlags)); W.printNumber("Index", VD->vd_ndx); - W.printNumber("Cnt", VD->vd_cnt); W.printNumber("Hash", VD->vd_hash); W.printString("Name", StringRef((const char *)(Obj->base() + StrTab->sh_offset + VD->getAux()->vda_name))); + if (!VD->vd_cnt) + report_fatal_error("at least one definition string must exist"); + if (VD->vd_cnt > 2) + report_fatal_error("more than one predecessor is not expected"); + + if (VD->vd_cnt == 2) { + const uint8_t *PAux = P + VD->vd_aux + VD->getAux()->vda_next; + const VerdAux *Aux = reinterpret_cast<const VerdAux *>(PAux); + W.printString("Predecessor", + StringRef((const char *)(Obj->base() + StrTab->sh_offset + + Aux->vda_name))); + } + P += VD->vd_next; } } |