Simplify the handling of iterators in ObjectFile.

None of the object file formats reported error on iterator increment. In
retrospect, that is not too surprising: no object format stores symbols or
sections in a linked list or other structure that requires chasing pointers.
As a consequence, all error checking can be done on begin() and end().

This reduces the text segment of bin/llvm-readobj in my machine from 521233 to
518526 bytes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200442 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-01-30 02:49:50 +00:00
parent 6bf3966f7f
commit efdbec8b0a
25 changed files with 147 additions and 365 deletions

View File

@ -55,8 +55,7 @@ public:
protected:
ELFFile<ELFT> EF;
error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
LLVM_OVERRIDE;
void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
LLVM_OVERRIDE;
error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const
@ -78,8 +77,7 @@ protected:
error_code getLibraryPath(DataRefImpl Data, StringRef &Res) const
LLVM_OVERRIDE;
error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
LLVM_OVERRIDE;
void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
LLVM_OVERRIDE;
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
@ -102,8 +100,7 @@ protected:
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
section_iterator getRelocatedSection(DataRefImpl Sec) const LLVM_OVERRIDE;
error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
LLVM_OVERRIDE;
void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
LLVM_OVERRIDE;
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
@ -222,10 +219,8 @@ typedef ELFObjectFile<ELFType<support::big, 2, false> > ELF32BEObjectFile;
typedef ELFObjectFile<ELFType<support::big, 2, true> > ELF64BEObjectFile;
template <class ELFT>
error_code ELFObjectFile<ELFT>::getSymbolNext(DataRefImpl Symb,
SymbolRef &Result) const {
Result = SymbolRef(toDRI(++toELFSymIter(Symb)), this);
return object_error::success;
void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Symb) const {
Symb = toDRI(++toELFSymIter(Symb));
}
template <class ELFT>
@ -439,10 +434,8 @@ error_code ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb,
}
template <class ELFT>
error_code ELFObjectFile<ELFT>::getSectionNext(DataRefImpl Sec,
SectionRef &Result) const {
Result = SectionRef(toDRI(++toELFShdrIter(Sec)), this);
return object_error::success;
void ELFObjectFile<ELFT>::moveSectionNext(DataRefImpl &Sec) const {
Sec = toDRI(++toELFShdrIter(Sec));
}
template <class ELFT>
@ -594,11 +587,8 @@ ELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const {
// Relocations
template <class ELFT>
error_code ELFObjectFile<ELFT>::getRelocationNext(DataRefImpl Rel,
RelocationRef &Result) const {
void ELFObjectFile<ELFT>::moveRelocationNext(DataRefImpl &Rel) const {
++Rel.d.b;
Result = RelocationRef(Rel, this);
return object_error::success;
}
template <class ELFT>