diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-02-28 08:15:59 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-02-28 08:15:59 +0000 |
commit | 7b4fce12b35bf89db45cbc13329146c58d156b53 (patch) | |
tree | 894bdced088b3827582a520d8cba6340852ebc24 /llvm/tools/llvm-readobj | |
parent | 6c57395fb438881018e0897f09f2137dc8dbd111 (diff) | |
download | bcm5719-llvm-7b4fce12b35bf89db45cbc13329146c58d156b53.tar.gz bcm5719-llvm-7b4fce12b35bf89db45cbc13329146c58d156b53.zip |
[llvm-readobj] - Fix the invalid dumping of the dynamic sections without terminating DT_NULL entry.
This is https://bugs.llvm.org/show_bug.cgi?id=40861,
Previously llvm-readobj would print the DT_NULL sometimes
for the dynamic section that has no terminator entry.
The logic of printDynamicTable was a bit overcomplicated.
I rewrote it slightly to fix the issue and commented.
Differential revision: https://reviews.llvm.org/D58716
llvm-svn: 355073
Diffstat (limited to 'llvm/tools/llvm-readobj')
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 3597acfe061..410ab3f87ca 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1914,35 +1914,29 @@ template <> void ELFDumper<ELF32LE>::printUnwindInfo() { template<class ELFT> void ELFDumper<ELFT>::printDynamicTable() { - auto I = dynamic_table().begin(); - auto E = dynamic_table().end(); - - if (I == E) - return; - - --E; - while (I != E && E->getTag() == ELF::DT_NULL) - --E; - if (E->getTag() != ELF::DT_NULL) - ++E; - ++E; + // A valid .dynamic section contains an array of entries terminated with + // a DT_NULL entry. However, sometimes the section content may continue + // past the DT_NULL entry, so to dump the section correctly, we first find + // the end of the entries by iterating over them. + size_t Size = 0; + Elf_Dyn_Range DynTableEntries = dynamic_table(); + for (; Size < DynTableEntries.size();) + if (DynTableEntries[Size++].getTag() == DT_NULL) + break; - ptrdiff_t Total = std::distance(I, E); - if (Total == 0) + if (!Size) return; raw_ostream &OS = W.getOStream(); - W.startLine() << "DynamicSection [ (" << Total << " entries)\n"; + W.startLine() << "DynamicSection [ (" << Size << " entries)\n"; bool Is64 = ELFT::Is64Bits; - W.startLine() << " Tag" << (Is64 ? " " : " ") << "Type" << " " << "Name/Value\n"; - while (I != E) { - const Elf_Dyn &Entry = *I; + for (size_t I = 0; I < Size; ++I) { + const Elf_Dyn &Entry = DynTableEntries[I]; uintX_t Tag = Entry.getTag(); - ++I; W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, opts::Output != opts::GNU) << " " << format("%-21s", getTypeString(ObjF->getELFFile()->getHeader()->e_machine, Tag)); printValue(Tag, Entry.getVal()); |