[llvm] 38f3ba5 - Revert "Migrate Binary::checkOffset from error_code to Error, NFC"
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 14:01:04 PDT 2020
Author: Nico Weber
Date: 2020-06-05T17:00:20-04:00
New Revision: 38f3ba591e3a64fa5bbe684b3171c7bda6c5b527
URL: https://github.com/llvm/llvm-project/commit/38f3ba591e3a64fa5bbe684b3171c7bda6c5b527
DIFF: https://github.com/llvm/llvm-project/commit/38f3ba591e3a64fa5bbe684b3171c7bda6c5b527.diff
LOG: Revert "Migrate Binary::checkOffset from error_code to Error, NFC"
This reverts commit 74bd98829d82312676a60c5c2d142e20691b2f13.
Breaks LLVM::section-headers.test everywhere, see e.g.
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/29940/steps/test-check-all/logs/FAIL%3A%20LLVM%3A%3Asection-headers.test
Added:
Modified:
llvm/include/llvm/Object/Binary.h
llvm/include/llvm/Object/ELFObjectFile.h
llvm/lib/Object/COFFObjectFile.cpp
llvm/lib/Object/XCOFFObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/Binary.h b/llvm/include/llvm/Object/Binary.h
index e95516f30a40..aa5e718f5e9b 100644
--- a/llvm/include/llvm/Object/Binary.h
+++ b/llvm/include/llvm/Object/Binary.h
@@ -160,14 +160,14 @@ class Binary {
return Triple::UnknownObjectFormat;
}
- static Error checkOffset(MemoryBufferRef M, uintptr_t Addr,
- const uint64_t Size) {
+ static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
+ const uint64_t Size) {
if (Addr + Size < Addr || Addr + Size < Size ||
Addr + Size > uintptr_t(M.getBufferEnd()) ||
Addr < uintptr_t(M.getBufferStart())) {
- return errorCodeToError(object_error::unexpected_eof);
+ return object_error::unexpected_eof;
}
- return Error::success();
+ return std::error_code();
}
};
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 62ecd8b5a7e5..d7fdc5294a0a 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -744,10 +744,10 @@ ELFObjectFile<ELFT>::getSectionContents(DataRefImpl Sec) const {
const Elf_Shdr *EShdr = getSection(Sec);
if (EShdr->sh_type == ELF::SHT_NOBITS)
return makeArrayRef((const uint8_t *)base(), 0);
- if (Error E =
+ if (std::error_code EC =
checkOffset(getMemoryBufferRef(),
(uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
- return std::move(E);
+ return errorCodeToError(EC);
return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset,
EShdr->sh_size);
}
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index 3d129592738c..78bcfb177ee5 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 (Error E = Binary::checkOffset(M, Addr, Size))
- return errorToErrorCode(std::move(E));
+ if (std::error_code EC = Binary::checkOffset(M, Addr, Size))
+ return EC;
Obj = reinterpret_cast<const T *>(Addr);
return std::error_code();
}
@@ -374,11 +374,9 @@ getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
// relocations.
begin++;
}
- if (auto E = Binary::checkOffset(M, uintptr_t(begin),
- sizeof(coff_relocation) * NumRelocs)) {
- consumeError(std::move(E));
+ if (Binary::checkOffset(M, uintptr_t(begin),
+ sizeof(coff_relocation) * NumRelocs))
return nullptr;
- }
return begin;
}
@@ -557,8 +555,8 @@ std::error_code COFFObjectFile::initImportTablePtr() {
uintptr_t IntPtr = 0;
if (std::error_code EC = getRvaPtr(ImportTableRva, IntPtr))
return EC;
- if (Error E = checkOffset(Data, IntPtr, DataEntry->Size))
- return errorToErrorCode(std::move(E));
+ if (std::error_code EC = checkOffset(Data, IntPtr, DataEntry->Size))
+ return EC;
ImportDirectory = reinterpret_cast<
const coff_import_directory_table_entry *>(IntPtr);
return std::error_code();
@@ -1095,8 +1093,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 (Error E = checkOffset(Data, ConStart, SectionSize))
- return E;
+ if (checkOffset(Data, ConStart, SectionSize))
+ return make_error<BinaryError>();
Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize);
return Error::success();
}
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index f75291d22eec..d41afc8bdc24 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -29,8 +29,8 @@ template <typename T>
static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr,
const uint64_t Size = sizeof(T)) {
uintptr_t Addr = uintptr_t(Ptr);
- if (Error E = Binary::checkOffset(M, Addr, Size))
- return std::move(E);
+ if (std::error_code EC = Binary::checkOffset(M, Addr, Size))
+ return errorCodeToError(EC);
return reinterpret_cast<const T *>(Addr);
}
More information about the llvm-commits
mailing list