summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-10-21 11:06:38 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-10-21 11:06:38 +0000
commit2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23 (patch)
treef9862a0f5568ba2e6e46f55e85ba2b720c50853e /llvm/tools/llvm-objdump
parentbac5f6bd21de81a9041a94c12b49eb108dbc77c4 (diff)
downloadbcm5719-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/llvm-objdump')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp23
1 files changed, 19 insertions, 4 deletions
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) {
OpenPOWER on IntegriCloud