Simplify now that we can iterate backwards. NFC.

llvm-svn: 242715
This commit is contained in:
Rafael Espindola 2015-07-20 21:45:56 +00:00
parent 71a71485f4
commit e3f7223778
2 changed files with 21 additions and 22 deletions

View File

@ -282,11 +282,9 @@ public:
}
const Elf_Dyn *dynamic_table_begin() const;
/// \param NULLEnd use one past the first DT_NULL entry as the end instead of
/// the section size.
const Elf_Dyn *dynamic_table_end(bool NULLEnd = false) const;
Elf_Dyn_Range dynamic_table(bool NULLEnd = false) const {
return make_range(dynamic_table_begin(), dynamic_table_end(NULLEnd));
const Elf_Dyn *dynamic_table_end() const;
Elf_Dyn_Range dynamic_table() const {
return make_range(dynamic_table_begin(), dynamic_table_end());
}
const Elf_Sym *dynamic_symbol_begin() const {
@ -818,24 +816,12 @@ ELFFile<ELFT>::dynamic_table_begin() const {
template <class ELFT>
const typename ELFFile<ELFT>::Elf_Dyn *
ELFFile<ELFT>::dynamic_table_end(bool NULLEnd) const {
ELFFile<ELFT>::dynamic_table_end() const {
uint64_t Size = DynamicRegion.Size;
if (Size % sizeof(Elf_Dyn))
report_fatal_error("Invalid dynamic table size");
const Elf_Dyn *Ret = dynamic_table_begin() + Size / sizeof(Elf_Dyn);
if (NULLEnd) {
const Elf_Dyn *Start = dynamic_table_begin();
while (Start != Ret && Start->getTag() != ELF::DT_NULL)
++Start;
// Include the DT_NULL.
if (Start != Ret)
++Start;
Ret = Start;
}
return Ret;
return dynamic_table_begin() + Size / sizeof(Elf_Dyn);
}
template <class ELFT>

View File

@ -1052,9 +1052,20 @@ template <> void ELFDumper<ELFType<support::little, false>>::printUnwindInfo() {
template<class ELFT>
void ELFDumper<ELFT>::printDynamicTable() {
auto DynTable = Obj->dynamic_table(true);
auto I = Obj->dynamic_table_begin();
auto E = Obj->dynamic_table_end();
ptrdiff_t Total = std::distance(DynTable.begin(), DynTable.end());
if (I == E)
return;
--E;
while (I != E && E->getTag() == ELF::DT_NULL)
--E;
if (E->getTag() != ELF::DT_NULL)
++E;
++E;
ptrdiff_t Total = std::distance(I, E);
if (Total == 0)
return;
@ -1066,7 +1077,9 @@ void ELFDumper<ELFT>::printDynamicTable() {
W.startLine()
<< " Tag" << (Is64 ? " " : " ") << "Type"
<< " " << "Name/Value\n";
for (const auto &Entry : DynTable) {
while (I != E) {
const typename ELFO::Elf_Dyn &Entry = *I;
++I;
W.startLine()
<< " "
<< format(Is64 ? "0x%016" PRIX64 : "0x%08" PRIX64, Entry.getTag())