diff options
| author | George Rimar <grimar@accesssoftek.com> | 2019-10-21 11:06:38 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2019-10-21 11:06:38 +0000 |
| commit | 2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23 (patch) | |
| tree | f9862a0f5568ba2e6e46f55e85ba2b720c50853e /llvm/tools | |
| parent | bac5f6bd21de81a9041a94c12b49eb108dbc77c4 (diff) | |
| download | bcm5719-llvm-2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23.tar.gz bcm5719-llvm-2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23.zip | |
[llvm/Object] - Make ELFObjectFile::getRelocatedSection return Expected<section_iterator>
It returns just a section_iterator currently and have a report_fatal_error call inside.
This change adds a way to return errors and handle them on caller sides.
The patch also changes/improves current users and adds test cases.
Differential revision: https://reviews.llvm.org/D69167
llvm-svn: 375408
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp | 6 | ||||
| -rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 23 | ||||
| -rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 12 |
3 files changed, 34 insertions, 7 deletions
diff --git a/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp b/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp index 83331265578..03e1bab9417 100644 --- a/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp +++ b/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp @@ -174,7 +174,11 @@ static void dumpCXXData(const ObjectFile *Obj) { SectionRelocMap.clear(); for (const SectionRef &Section : Obj->sections()) { - section_iterator Sec2 = Section.getRelocatedSection(); + Expected<section_iterator> ErrOrSec = Section.getRelocatedSection(); + if (!ErrOrSec) + error(ErrOrSec.takeError()); + + section_iterator Sec2 = *ErrOrSec; if (Sec2 != Obj->section_end()) SectionRelocMap[*Sec2].push_back(Section); } diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index c5381d53717..34a44b3b7fa 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -993,8 +993,17 @@ static size_t countSkippableZeroBytes(ArrayRef<uint8_t> Buf) { static std::map<SectionRef, std::vector<RelocationRef>> getRelocsMap(object::ObjectFile const &Obj) { std::map<SectionRef, std::vector<RelocationRef>> Ret; + uint64_t I = (uint64_t)-1; for (SectionRef Sec : Obj.sections()) { - section_iterator Relocated = Sec.getRelocatedSection(); + ++I; + Expected<section_iterator> RelocatedOrErr = Sec.getRelocatedSection(); + if (!RelocatedOrErr) + reportError(Obj.getFileName(), + "section (" + Twine(I) + + "): failed to get a relocated section: " + + toString(RelocatedOrErr.takeError())); + + section_iterator Relocated = *RelocatedOrErr; if (Relocated == Obj.section_end() || !checkSectionFilter(*Relocated).Keep) continue; std::vector<RelocationRef> &V = Ret[*Relocated]; @@ -1606,11 +1615,17 @@ void printRelocations(const ObjectFile *Obj) { // sections. Usually, there is an only one relocation section for // each relocated section. MapVector<SectionRef, std::vector<SectionRef>> SecToRelSec; - for (const SectionRef &Section : ToolSectionFilter(*Obj)) { + uint64_t Ndx; + for (const SectionRef &Section : ToolSectionFilter(*Obj, &Ndx)) { if (Section.relocation_begin() == Section.relocation_end()) continue; - const SectionRef TargetSec = *Section.getRelocatedSection(); - SecToRelSec[TargetSec].push_back(Section); + Expected<section_iterator> SecOrErr = Section.getRelocatedSection(); + if (!SecOrErr) + reportError(Obj->getFileName(), + "section (" + Twine(Ndx) + + "): unable to get a relocation target: " + + toString(SecOrErr.takeError())); + SecToRelSec[**SecOrErr].push_back(Section); } for (std::pair<SectionRef, std::vector<SectionRef>> &P : SecToRelSec) { diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 7e140933393..57144882c4b 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -4894,8 +4894,16 @@ void DumpStyle<ELFT>::printRelocatableStackSizes( if (SectionType != ELF::SHT_RELA && SectionType != ELF::SHT_REL) continue; - SectionRef Contents = *Sec.getRelocatedSection(); - const Elf_Shdr *ContentsSec = Obj->getSection(Contents.getRawDataRefImpl()); + Expected<section_iterator> RelSecOrErr = Sec.getRelocatedSection(); + if (!RelSecOrErr) + reportError(createStringError(object_error::parse_failed, + "%s: failed to get a relocated section: %s", + SectionName.data(), + toString(RelSecOrErr.takeError()).c_str()), + Obj->getFileName()); + + const Elf_Shdr *ContentsSec = + Obj->getSection((*RelSecOrErr)->getRawDataRefImpl()); Expected<StringRef> ContentsSectionNameOrErr = EF->getSectionName(ContentsSec); if (!ContentsSectionNameOrErr) { |

