[llvm] r315473 - Convert an ErrorOr to Expected.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 11 09:56:33 PDT 2017
Author: rafael
Date: Wed Oct 11 09:56:33 2017
New Revision: 315473
URL: http://llvm.org/viewvc/llvm-project?rev=315473&view=rev
Log:
Convert an ErrorOr to Expected.
getRelocationAddend should never be called on non SHT_RELA sections,
but changing that requires changing RelocVisitor.h.
Modified:
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/include/llvm/Object/RelocVisitor.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/trunk/test/Object/invalid.test
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=315473&r1=315472&r2=315473&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Wed Oct 11 09:56:33 2017
@@ -61,7 +61,7 @@ protected:
virtual uint64_t getSectionFlags(DataRefImpl Sec) const = 0;
virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0;
- virtual ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
+ virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
public:
using elf_symbol_iterator_range = iterator_range<elf_symbol_iterator>;
@@ -167,7 +167,7 @@ public:
return cast<ELFObjectFileBase>(RelocationRef::getObject());
}
- ErrorOr<int64_t> getAddend() const {
+ Expected<int64_t> getAddend() const {
return getObject()->getRelocationAddend(getRawDataRefImpl());
}
};
@@ -359,7 +359,7 @@ public:
section_iterator section_begin() const override;
section_iterator section_end() const override;
- ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const override;
+ Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const override;
uint8_t getBytesInAddress() const override;
StringRef getFileFormatName() const override;
@@ -822,10 +822,10 @@ void ELFObjectFile<ELFT>::getRelocationT
}
template <class ELFT>
-ErrorOr<int64_t>
+Expected<int64_t>
ELFObjectFile<ELFT>::getRelocationAddend(DataRefImpl Rel) const {
if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
- return object_error::parse_failed;
+ return createError("Section is not SHT_RELA");
return (int64_t)getRela(Rel)->r_addend;
}
Modified: llvm/trunk/include/llvm/Object/RelocVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/RelocVisitor.h?rev=315473&r1=315472&r2=315473&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/RelocVisitor.h (original)
+++ llvm/trunk/include/llvm/Object/RelocVisitor.h Wed Oct 11 09:56:33 2017
@@ -115,9 +115,10 @@ private:
}
int64_t getELFAddend(RelocationRef R) {
- ErrorOr<int64_t> AddendOrErr = ELFRelocationRef(R).getAddend();
- if (std::error_code EC = AddendOrErr.getError())
- report_fatal_error(EC.message());
+ Expected<int64_t> AddendOrErr = ELFRelocationRef(R).getAddend();
+ handleAllErrors(AddendOrErr.takeError(), [](const ErrorInfoBase &EI) {
+ report_fatal_error(EI.message());
+ });
return *AddendOrErr;
}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=315473&r1=315472&r2=315473&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Wed Oct 11 09:56:33 2017
@@ -611,7 +611,7 @@ Error RuntimeDyldELF::findOPDEntrySectio
if (auto AddendOrErr = i->getAddend())
Addend = *AddendOrErr;
else
- return errorCodeToError(AddendOrErr.getError());
+ return AddendOrErr.takeError();
++i;
if (i == e)
@@ -1079,8 +1079,11 @@ RuntimeDyldELF::processRelocationRef(
ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) {
const auto &Obj = cast<ELFObjectFileBase>(O);
uint64_t RelType = RelI->getType();
- ErrorOr<int64_t> AddendOrErr = ELFRelocationRef(*RelI).getAddend();
- int64_t Addend = AddendOrErr ? *AddendOrErr : 0;
+ int64_t Addend = 0;
+ if (Expected<int64_t> AddendOrErr = ELFRelocationRef(*RelI).getAddend())
+ Addend = *AddendOrErr;
+ else
+ consumeError(AddendOrErr.takeError());
elf_symbol_iterator Symbol = RelI->getSymbol();
// Obtain the symbol name which is referenced in the relocation
Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=315473&r1=315472&r2=315473&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Wed Oct 11 09:56:33 2017
@@ -1,9 +1,11 @@
-RUN: not llvm-dwarfdump %p/Inputs/invalid-bad-rel-type.elf 2>&1 | FileCheck %s
RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-type.elf 2>&1 | FileCheck %s
RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 | FileCheck %s
RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-zero-size.elf 2>&1 | FileCheck %s
CHECK: Invalid data was encountered while parsing the file
+RUN: not llvm-dwarfdump %p/Inputs/invalid-bad-rel-type.elf 2>&1 | FileCheck --check-prefix=RELA %s
+RELA: Section is not SHT_RELA
+
RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-non-null.elf 2>&1 | FileCheck --check-prefix=NON-NULL %s
NON-NULL: Invalid data was encountered while parsing the file
More information about the llvm-commits
mailing list