diff options
author | Alexey Samsonov <samsonov@google.com> | 2014-03-13 13:52:54 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2014-03-13 13:52:54 +0000 |
commit | 063eb3fa2de0b1ba93b253a57e57a5a4358a33a2 (patch) | |
tree | 1a2f1bb8fd84e6948feecf9e907c0cebfd3e6935 /llvm/lib/MC | |
parent | cbc68521b3fbb0a6d8ca3e2cc6bff2772145ba32 (diff) | |
download | bcm5719-llvm-063eb3fa2de0b1ba93b253a57e57a5a4358a33a2.tar.gz bcm5719-llvm-063eb3fa2de0b1ba93b253a57e57a5a4358a33a2.zip |
[C++11] Introduce ObjectFile::sections().
Summary:
This adds ObjectFile::section_iterator_range, that allows to write
range-based for-loops running over all sections of a given file.
Several files from lib/ are converted to the new interface. Similar fixes
should be applied to a variety of llvm-* tools.
Reviewers: rafael
Reviewed By: rafael
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D3069
llvm-svn: 203799
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/MCObjectDisassembler.cpp | 30 | ||||
-rw-r--r-- | llvm/lib/MC/MCObjectSymbolizer.cpp | 41 |
2 files changed, 38 insertions, 33 deletions
diff --git a/llvm/lib/MC/MCObjectDisassembler.cpp b/llvm/lib/MC/MCObjectDisassembler.cpp index 5851bdfdb71..2cd7031f82c 100644 --- a/llvm/lib/MC/MCObjectDisassembler.cpp +++ b/llvm/lib/MC/MCObjectDisassembler.cpp @@ -87,20 +87,24 @@ MCModule *MCObjectDisassembler::buildModule(bool withCFG) { } void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) { - for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end(); - SI != SE; ++SI) { - bool isText; SI->isText(isText); - bool isData; SI->isData(isData); + for (const SectionRef &Section : Obj.sections()) { + bool isText; + Section.isText(isText); + bool isData; + Section.isData(isData); if (!isData && !isText) continue; - uint64_t StartAddr; SI->getAddress(StartAddr); - uint64_t SecSize; SI->getSize(SecSize); + uint64_t StartAddr; + Section.getAddress(StartAddr); + uint64_t SecSize; + Section.getSize(SecSize); if (StartAddr == UnknownAddressOrSize || SecSize == UnknownAddressOrSize) continue; StartAddr = getEffectiveLoadAddr(StartAddr); - StringRef Contents; SI->getContents(Contents); + StringRef Contents; + Section.getContents(Contents); StringRefMemoryObject memoryObject(Contents, StartAddr); // We don't care about things like non-file-backed sections yet. @@ -108,7 +112,8 @@ void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) { continue; uint64_t EndAddr = StartAddr + SecSize - 1; - StringRef SecName; SI->getName(SecName); + StringRef SecName; + Section.getName(SecName); if (isText) { MCTextAtom *Text = 0; @@ -495,17 +500,16 @@ MCMachOObjectDisassembler::MCMachOObjectDisassembler( : MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF), VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) { - for (section_iterator SI = MOOF.section_begin(), SE = MOOF.section_end(); - SI != SE; ++SI) { + for (const SectionRef &Section : MOOF.sections()) { StringRef Name; - SI->getName(Name); + Section.getName(Name); // FIXME: We should use the S_ section type instead of the name. if (Name == "__mod_init_func") { DEBUG(dbgs() << "Found __mod_init_func section!\n"); - SI->getContents(ModInitContents); + Section.getContents(ModInitContents); } else if (Name == "__mod_exit_func") { DEBUG(dbgs() << "Found __mod_exit_func section!\n"); - SI->getContents(ModExitContents); + Section.getContents(ModExitContents); } } } diff --git a/llvm/lib/MC/MCObjectSymbolizer.cpp b/llvm/lib/MC/MCObjectSymbolizer.cpp index 8aafcf6ee7c..4548a7d4251 100644 --- a/llvm/lib/MC/MCObjectSymbolizer.cpp +++ b/llvm/lib/MC/MCObjectSymbolizer.cpp @@ -51,11 +51,11 @@ MCMachObjectSymbolizer::MCMachObjectSymbolizer( : MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF), StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) { - for (section_iterator SI = MOOF->section_begin(), SE = MOOF->section_end(); - SI != SE; ++SI) { - StringRef Name; SI->getName(Name); + for (const SectionRef &Section : MOOF->sections()) { + StringRef Name; + Section.getName(Name); if (Name == "__stubs") { - SectionRef StubsSec = *SI; + SectionRef StubsSec = Section; if (MOOF->is64Bit()) { MachO::section_64 S = MOOF->getSection64(StubsSec.getRawDataRefImpl()); StubsIndSymIndex = S.reserved1; @@ -230,40 +230,41 @@ const RelocationRef *MCObjectSymbolizer::findRelocationAt(uint64_t Addr) { } void MCObjectSymbolizer::buildSectionList() { - for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end(); - SI != SE; ++SI) { - bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec); + for (const SectionRef &Section : Obj->sections()) { + bool RequiredForExec; + Section.isRequiredForExecution(RequiredForExec); if (RequiredForExec == false) continue; - uint64_t SAddr; SI->getAddress(SAddr); - uint64_t SSize; SI->getSize(SSize); - SortedSectionList::iterator It = std::lower_bound(SortedSections.begin(), - SortedSections.end(), - SAddr, - SectionStartsBefore); + uint64_t SAddr; + Section.getAddress(SAddr); + uint64_t SSize; + Section.getSize(SSize); + SortedSectionList::iterator It = + std::lower_bound(SortedSections.begin(), SortedSections.end(), SAddr, + SectionStartsBefore); if (It != SortedSections.end()) { uint64_t FoundSAddr; It->getAddress(FoundSAddr); if (FoundSAddr < SAddr + SSize) llvm_unreachable("Inserting overlapping sections"); } - SortedSections.insert(It, *SI); + SortedSections.insert(It, Section); } } void MCObjectSymbolizer::buildRelocationByAddrMap() { - for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end(); - SI != SE; ++SI) { - section_iterator RelSecI = SI->getRelocatedSection(); + for (const SectionRef &Section : Obj->sections()) { + section_iterator RelSecI = Section.getRelocatedSection(); if (RelSecI == Obj->section_end()) continue; uint64_t StartAddr; RelSecI->getAddress(StartAddr); uint64_t Size; RelSecI->getSize(Size); - bool RequiredForExec; RelSecI->isRequiredForExecution(RequiredForExec); + bool RequiredForExec; + RelSecI->isRequiredForExecution(RequiredForExec); if (RequiredForExec == false || Size == 0) continue; - for (relocation_iterator RI = SI->relocation_begin(), - RE = SI->relocation_end(); + for (relocation_iterator RI = Section.relocation_begin(), + RE = Section.relocation_end(); RI != RE; ++RI) { // FIXME: libObject is inconsistent regarding error handling. The // overwhelming majority of methods always return object_error::success, |