diff options
author | Reid Kleckner <rnk@google.com> | 2020-06-05 16:12:38 -0700 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2020-06-05 16:27:31 -0700 |
commit | e03a135be8cf912fbfeac11c28d0132b52f1fb07 (patch) | |
tree | 02c8542956d8de590defbafabb3db401f1bd892c /llvm/lib/Object/COFFObjectFile.cpp | |
parent | 1c44ace1e517f8c852fd2bd1d92c6443b525b2e2 (diff) | |
download | llvm-e03a135be8cf912fbfeac11c28d0132b52f1fb07.zip llvm-e03a135be8cf912fbfeac11c28d0132b52f1fb07.tar.gz llvm-e03a135be8cf912fbfeac11c28d0132b52f1fb07.tar.bz2 |
Re-land "Migrate Binary::checkOffset from error_code to Error, NFC"
This reverts commit 38f3ba591e3a64fa5bbe684b3171c7bda6c5b527.
Fix the XCOFF error handling. Unlike std::error_code, Error must be
consumed or handled.
Diffstat (limited to 'llvm/lib/Object/COFFObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index 78bcfb1..3d12959 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -59,8 +59,8 @@ static std::error_code getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr, const uint64_t Size = sizeof(T)) { uintptr_t Addr = uintptr_t(Ptr); - if (std::error_code EC = Binary::checkOffset(M, Addr, Size)) - return EC; + if (Error E = Binary::checkOffset(M, Addr, Size)) + return errorToErrorCode(std::move(E)); Obj = reinterpret_cast<const T *>(Addr); return std::error_code(); } @@ -374,9 +374,11 @@ getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) { // relocations. begin++; } - if (Binary::checkOffset(M, uintptr_t(begin), - sizeof(coff_relocation) * NumRelocs)) + if (auto E = Binary::checkOffset(M, uintptr_t(begin), + sizeof(coff_relocation) * NumRelocs)) { + consumeError(std::move(E)); return nullptr; + } return begin; } @@ -555,8 +557,8 @@ std::error_code COFFObjectFile::initImportTablePtr() { uintptr_t IntPtr = 0; if (std::error_code EC = getRvaPtr(ImportTableRva, IntPtr)) return EC; - if (std::error_code EC = checkOffset(Data, IntPtr, DataEntry->Size)) - return EC; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) + return errorToErrorCode(std::move(E)); ImportDirectory = reinterpret_cast< const coff_import_directory_table_entry *>(IntPtr); return std::error_code(); @@ -1093,8 +1095,8 @@ Error COFFObjectFile::getSectionContents(const coff_section *Sec, // data, as there's nothing that says that is not allowed. uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData; uint32_t SectionSize = getSectionSize(Sec); - if (checkOffset(Data, ConStart, SectionSize)) - return make_error<BinaryError>(); + if (Error E = checkOffset(Data, ConStart, SectionSize)) + return E; Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize); return Error::success(); } |