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

@@ -115,12 +115,10 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
// Maximum required total memory to allocate all common symbols
uint64_t CommonSize = 0;
error_code err;
// Parse symbols
DEBUG(dbgs() << "Parse symbols:\n");
for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols();
i != e; i.increment(err)) {
Check(err);
for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols(); i != e;
++i) {
object::SymbolRef::Type SymType;
StringRef Name;
Check(i->getType(SymType));
@@ -173,18 +171,16 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
// Parse and process relocations
DEBUG(dbgs() << "Parse relocations:\n");
for (section_iterator si = obj->begin_sections(),
se = obj->end_sections(); si != se; si.increment(err)) {
Check(err);
for (section_iterator si = obj->begin_sections(), se = obj->end_sections();
si != se; ++si) {
bool isFirstRelocation = true;
unsigned SectionID = 0;
StubMap Stubs;
section_iterator RelocatedSection = si->getRelocatedSection();
for (relocation_iterator i = si->begin_relocations(),
e = si->end_relocations(); i != e; i.increment(err)) {
Check(err);
e = si->end_relocations();
i != e; ++i) {
// If it's the first relocation in this section, find its SectionID
if (isFirstRelocation) {
SectionID =
@@ -251,21 +247,21 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
unsigned StubBufSize = 0,
StubSize = getMaxStubSize();
error_code err;
const ObjectFile *ObjFile = Obj.getObjectFile();
// FIXME: this is an inefficient way to handle this. We should computed the
// necessary section allocation size in loadObject by walking all the sections
// once.
if (StubSize > 0) {
for (section_iterator SI = ObjFile->begin_sections(),
SE = ObjFile->end_sections();
SI != SE; SI.increment(err), Check(err)) {
SE = ObjFile->end_sections();
SI != SE; ++SI) {
section_iterator RelSecI = SI->getRelocatedSection();
if (!(RelSecI == Section))
continue;
for (relocation_iterator I = SI->begin_relocations(),
E = SI->end_relocations(); I != E; I.increment(err), Check(err)) {
E = SI->end_relocations();
I != E; ++I) {
StubBufSize += StubSize;
}
}

View File

@@ -621,10 +621,8 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj,
RelocationValueRef &Rel) {
// Get the ELF symbol value (st_value) to compare with Relocation offset in
// .opd entries
error_code err;
for (section_iterator si = Obj.begin_sections(),
se = Obj.end_sections(); si != se; si.increment(err)) {
for (section_iterator si = Obj.begin_sections(), se = Obj.end_sections();
si != se; ++si) {
section_iterator RelSecI = si->getRelocatedSection();
if (RelSecI == Obj.end_sections())
continue;
@@ -636,14 +634,12 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj,
for (relocation_iterator i = si->begin_relocations(),
e = si->end_relocations(); i != e;) {
check(err);
// The R_PPC64_ADDR64 relocation indicates the first field
// of a .opd entry
uint64_t TypeFunc;
check(i->getType(TypeFunc));
if (TypeFunc != ELF::R_PPC64_ADDR64) {
i.increment(err);
++i;
continue;
}
@@ -653,10 +649,9 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj,
int64_t Addend;
check(getELFRelocationAddend(*i, Addend));
i = i.increment(err);
++i;
if (i == e)
break;
check(err);
// Just check if following relocation is a R_PPC64_TOC
uint64_t TypeTOC;