diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-30 02:49:50 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-30 02:49:50 +0000 |
| commit | 5e812afaeb3db56db706e81e448db46c08298abd (patch) | |
| tree | 86d091fea3f71879287f607d9f616e410866099c /llvm/lib/MC | |
| parent | 980f2dc4fc9a27fa950f6f9c6baf554aa7cef351 (diff) | |
| download | bcm5719-llvm-5e812afaeb3db56db706e81e448db46c08298abd.tar.gz bcm5719-llvm-5e812afaeb3db56db706e81e448db46c08298abd.zip | |
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.
llvm-svn: 200442
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCObjectDisassembler.cpp | 24 | ||||
| -rw-r--r-- | llvm/lib/MC/MCObjectSymbolizer.cpp | 28 |
2 files changed, 12 insertions, 40 deletions
diff --git a/llvm/lib/MC/MCObjectDisassembler.cpp b/llvm/lib/MC/MCObjectDisassembler.cpp index 16a110f09bf..85de4111b7f 100644 --- a/llvm/lib/MC/MCObjectDisassembler.cpp +++ b/llvm/lib/MC/MCObjectDisassembler.cpp @@ -37,11 +37,8 @@ MCObjectDisassembler::MCObjectDisassembler(const ObjectFile &Obj, : Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {} uint64_t MCObjectDisassembler::getEntrypoint() { - error_code ec; for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) - break; + SI != SE; ++SI) { StringRef Name; SI->getName(Name); if (Name == "main" || Name == "_main") { @@ -90,13 +87,8 @@ MCModule *MCObjectDisassembler::buildModule(bool withCFG) { } void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) { - error_code ec; - for (section_iterator SI = Obj.begin_sections(), - SE = Obj.end_sections(); - SI != SE; - SI.increment(ec)) { - if (ec) break; - + for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections(); + SI != SE; ++SI) { bool isText; SI->isText(isText); bool isData; SI->isData(isData); if (!isData && !isText) @@ -184,11 +176,8 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) { AddressSetTy Splits; AddressSetTy Calls; - error_code ec; for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) - break; + SI != SE; ++SI) { SymbolRef::Type SymType; SI->getType(SymType); if (SymType == SymbolRef::ST_Function) { @@ -506,11 +495,8 @@ MCMachOObjectDisassembler::MCMachOObjectDisassembler( : MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF), VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) { - error_code ec; for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) - break; + SI != SE; ++SI) { StringRef Name; SI->getName(Name); // FIXME: We should use the S_ section type instead of the name. diff --git a/llvm/lib/MC/MCObjectSymbolizer.cpp b/llvm/lib/MC/MCObjectSymbolizer.cpp index cdf743e6bbb..3fb053dd789 100644 --- a/llvm/lib/MC/MCObjectSymbolizer.cpp +++ b/llvm/lib/MC/MCObjectSymbolizer.cpp @@ -52,10 +52,8 @@ MCMachObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo, : MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF), StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) { - error_code ec; for (section_iterator SI = MOOF->begin_sections(), SE = MOOF->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) break; + SI != SE; ++SI) { StringRef Name; SI->getName(Name); if (Name == "__stubs") { SectionRef StubsSec = *SI; @@ -91,10 +89,8 @@ StringRef MCMachObjectSymbolizer::findExternalFunctionAt(uint64_t Addr) { StringRef SymName; symbol_iterator SI = MOOF->begin_symbols(); - error_code ec; - for (uint32_t i = 0; i != SymtabIdx; ++i) { - SI.increment(ec); - } + for (uint32_t i = 0; i != SymtabIdx; ++i) + ++SI; SI->getName(SymName); assert(SI != MOOF->end_symbols() && "Stub wasn't found in the symbol table!"); assert(SymName.front() == '_' && "Mach-O symbol doesn't start with '_'!"); @@ -159,10 +155,8 @@ tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream, return false; uint64_t UValue = Value; // FIXME: map instead of looping each time? - error_code ec; for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) break; + SI != SE; ++SI) { uint64_t SymAddr; SI->getAddress(SymAddr); uint64_t SymSize; SI->getSize(SymSize); StringRef SymName; SI->getName(SymName); @@ -239,11 +233,8 @@ const RelocationRef *MCObjectSymbolizer::findRelocationAt(uint64_t Addr) { } void MCObjectSymbolizer::buildSectionList() { - error_code ec; for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) break; - + SI != SE; ++SI) { bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec); if (RequiredForExec == false) continue; @@ -263,11 +254,8 @@ void MCObjectSymbolizer::buildSectionList() { } void MCObjectSymbolizer::buildRelocationByAddrMap() { - error_code ec; for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) break; - + SI != SE; ++SI) { section_iterator RelSecI = SI->getRelocatedSection(); if (RelSecI == Obj->end_sections()) continue; @@ -279,9 +267,7 @@ void MCObjectSymbolizer::buildRelocationByAddrMap() { continue; for (relocation_iterator RI = SI->begin_relocations(), RE = SI->end_relocations(); - RI != RE; - RI.increment(ec)) { - if (ec) break; + RI != RE; ++RI) { // FIXME: libObject is inconsistent regarding error handling. The // overwhelming majority of methods always return object_error::success, // and assert for simple errors.. Here, ELFObjectFile::getRelocationOffset |

