summaryrefslogtreecommitdiff
path: root/tools/llvm-objdump
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-30 02:49:50 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-30 02:49:50 +0000
commitefdbec8b0a49fb67c3844be703548fdc6c1dded0 (patch)
tree040894fc0c18d09dfdfec8693a253bcf998cb8c5 /tools/llvm-objdump
parent6bf3966f7fd92217360877d1c04ea8ffe47c11cc (diff)
downloadllvm-efdbec8b0a49fb67c3844be703548fdc6c1dded0.tar.gz
llvm-efdbec8b0a49fb67c3844be703548fdc6c1dded0.tar.bz2
llvm-efdbec8b0a49fb67c3844be703548fdc6c1dded0.tar.xz
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
Diffstat (limited to 'tools/llvm-objdump')
-rw-r--r--tools/llvm-objdump/COFFDump.cpp23
-rw-r--r--tools/llvm-objdump/MachODump.cpp14
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp39
3 files changed, 21 insertions, 55 deletions
diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp
index 7b60a5d4dc..dd2db2b037 100644
--- a/tools/llvm-objdump/COFFDump.cpp
+++ b/tools/llvm-objdump/COFFDump.cpp
@@ -241,11 +241,7 @@ static void printImportTables(const COFFObjectFile *Obj) {
if (I == E)
return;
outs() << "The Import Tables:\n";
- error_code EC;
- for (; I != E; I = I.increment(EC)) {
- if (EC)
- return;
-
+ for (; I != E; I = ++I) {
const import_directory_table_entry *Dir;
StringRef Name;
if (I->getImportTableEntry(Dir)) return;
@@ -294,10 +290,7 @@ static void printExportTable(const COFFObjectFile *Obj) {
outs() << " DLL name: " << DllName << "\n";
outs() << " Ordinal base: " << OrdinalBase << "\n";
outs() << " Ordinal RVA Name\n";
- error_code EC;
- for (; I != E; I = I.increment(EC)) {
- if (EC)
- return;
+ for (; I != E; I = ++I) {
uint32_t Ordinal;
if (I->getOrdinal(Ordinal))
return;
@@ -327,12 +320,8 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
const coff_section *Pdata = 0;
- error_code EC;
- for (section_iterator SI = Obj->begin_sections(),
- SE = Obj->end_sections();
- SI != SE; SI.increment(EC)) {
- if (error(EC)) return;
-
+ for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
+ SI != SE; ++SI) {
StringRef Name;
if (error(SI->getName(Name))) continue;
@@ -342,10 +331,8 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
std::vector<RelocationRef> Rels;
for (relocation_iterator RI = SI->begin_relocations(),
RE = SI->end_relocations();
- RI != RE; RI.increment(EC)) {
- if (error(EC)) break;
+ RI != RE; ++RI)
Rels.push_back(*RI);
- }
// Sort relocations by address.
std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index 52c786f305..b8ce9c884a 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -154,13 +154,14 @@ getSectionsAndSymbols(const MachO::mach_header Header,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns,
uint64_t &BaseSegmentAddress) {
- error_code ec;
for (symbol_iterator SI = MachOObj->begin_symbols(),
- SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
+ SE = MachOObj->end_symbols();
+ SI != SE; ++SI)
Symbols.push_back(*SI);
for (section_iterator SI = MachOObj->begin_sections(),
- SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) {
+ SE = MachOObj->end_sections();
+ SI != SE; ++SI) {
SectionRef SR = *SI;
StringRef SectName;
SR.getName(SectName);
@@ -270,9 +271,8 @@ static void DisassembleInputMachO2(StringRef Filename,
else
BaseAddress = BaseSegmentAddress;
DiceTable Dices;
- error_code ec;
for (dice_iterator DI = MachOOF->begin_dices(), DE = MachOOF->end_dices();
- DI != DE; DI.increment(ec)){
+ DI != DE; ++DI) {
uint32_t Offset;
DI->getOffset(Offset);
Dices.push_back(std::make_pair(BaseAddress + Offset, *DI));
@@ -329,9 +329,9 @@ static void DisassembleInputMachO2(StringRef Filename,
// Parse relocations.
std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
- error_code ec;
for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
- RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) {
+ RE = Sections[SectIdx].end_relocations();
+ RI != RE; ++RI) {
uint64_t RelocOffset, SectionAddress;
RI->getOffset(RelocOffset);
Sections[SectIdx].getAddress(SectionAddress);
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 9a56bf9b4c..325e7006ed 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -387,18 +387,14 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
error_code EC;
std::map<SectionRef, SmallVector<SectionRef, 1> > SectionRelocMap;
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
- I != E; I.increment(EC)) {
- if (error(EC))
- break;
+ I != E; ++I) {
section_iterator Sec2 = I->getRelocatedSection();
if (Sec2 != Obj->end_sections())
SectionRelocMap[*Sec2].push_back(*I);
}
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
- I != E; I.increment(EC)) {
- if (error(EC))
- break;
+ I != E; ++I) {
bool Text;
if (error(I->isText(Text)))
break;
@@ -412,7 +408,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
// Make a list of all the symbols in this section.
std::vector<std::pair<uint64_t, StringRef> > Symbols;
for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
- SI != SE; SI.increment(EC)) {
+ SI != SE; ++SI) {
bool contains;
if (!error(I->containsSymbol(*SI, contains)) && contains) {
uint64_t Address;
@@ -441,11 +437,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
RelocSec != E; ++RelocSec) {
for (relocation_iterator RI = RelocSec->begin_relocations(),
RE = RelocSec->end_relocations();
- RI != RE; RI.increment(EC)) {
- if (error(EC))
- break;
+ RI != RE; ++RI)
Rels.push_back(*RI);
- }
}
}
@@ -559,11 +552,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
}
static void PrintRelocations(const ObjectFile *o) {
- error_code EC;
for (section_iterator si = o->begin_sections(), se = o->end_sections();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
if (si->begin_relocations() == si->end_relocations())
continue;
StringRef secname;
@@ -571,10 +561,7 @@ static void PrintRelocations(const ObjectFile *o) {
outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
for (relocation_iterator ri = si->begin_relocations(),
re = si->end_relocations();
- ri != re; ri.increment(EC)) {
- if (error(EC))
- return;
-
+ ri != re; ++ri) {
bool hidden;
uint64_t address;
SmallString<32> relocname;
@@ -593,12 +580,9 @@ static void PrintRelocations(const ObjectFile *o) {
static void PrintSectionHeaders(const ObjectFile *o) {
outs() << "Sections:\n"
"Idx Name Size Address Type\n";
- error_code EC;
unsigned i = 0;
for (section_iterator si = o->begin_sections(), se = o->end_sections();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
StringRef Name;
if (error(si->getName(Name)))
return;
@@ -621,9 +605,7 @@ static void PrintSectionHeaders(const ObjectFile *o) {
static void PrintSectionContents(const ObjectFile *o) {
error_code EC;
for (section_iterator si = o->begin_sections(), se = o->end_sections();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
StringRef Name;
StringRef Contents;
uint64_t BaseAddr;
@@ -714,11 +696,8 @@ static void PrintSymbolTable(const ObjectFile *o) {
if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o))
PrintCOFFSymbolTable(coff);
else {
- error_code EC;
for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
StringRef Name;
uint64_t Address;
SymbolRef::Type Type;