Skip to content

Commit 38f3ba5

Browse files
committed
Revert "Migrate Binary::checkOffset from error_code to Error, NFC"
This reverts commit 74bd988. 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
1 parent ad4e7b9 commit 38f3ba5

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

llvm/include/llvm/Object/Binary.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ class Binary {
160160
return Triple::UnknownObjectFormat;
161161
}
162162

163-
static Error checkOffset(MemoryBufferRef M, uintptr_t Addr,
164-
const uint64_t Size) {
163+
static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
164+
const uint64_t Size) {
165165
if (Addr + Size < Addr || Addr + Size < Size ||
166166
Addr + Size > uintptr_t(M.getBufferEnd()) ||
167167
Addr < uintptr_t(M.getBufferStart())) {
168-
return errorCodeToError(object_error::unexpected_eof);
168+
return object_error::unexpected_eof;
169169
}
170-
return Error::success();
170+
return std::error_code();
171171
}
172172
};
173173

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,10 @@ ELFObjectFile<ELFT>::getSectionContents(DataRefImpl Sec) const {
744744
const Elf_Shdr *EShdr = getSection(Sec);
745745
if (EShdr->sh_type == ELF::SHT_NOBITS)
746746
return makeArrayRef((const uint8_t *)base(), 0);
747-
if (Error E =
747+
if (std::error_code EC =
748748
checkOffset(getMemoryBufferRef(),
749749
(uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
750-
return std::move(E);
750+
return errorCodeToError(EC);
751751
return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset,
752752
EShdr->sh_size);
753753
}

llvm/lib/Object/COFFObjectFile.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ static std::error_code getObject(const T *&Obj, MemoryBufferRef M,
5959
const void *Ptr,
6060
const uint64_t Size = sizeof(T)) {
6161
uintptr_t Addr = uintptr_t(Ptr);
62-
if (Error E = Binary::checkOffset(M, Addr, Size))
63-
return errorToErrorCode(std::move(E));
62+
if (std::error_code EC = Binary::checkOffset(M, Addr, Size))
63+
return EC;
6464
Obj = reinterpret_cast<const T *>(Addr);
6565
return std::error_code();
6666
}
@@ -374,11 +374,9 @@ getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
374374
// relocations.
375375
begin++;
376376
}
377-
if (auto E = Binary::checkOffset(M, uintptr_t(begin),
378-
sizeof(coff_relocation) * NumRelocs)) {
379-
consumeError(std::move(E));
377+
if (Binary::checkOffset(M, uintptr_t(begin),
378+
sizeof(coff_relocation) * NumRelocs))
380379
return nullptr;
381-
}
382380
return begin;
383381
}
384382

@@ -557,8 +555,8 @@ std::error_code COFFObjectFile::initImportTablePtr() {
557555
uintptr_t IntPtr = 0;
558556
if (std::error_code EC = getRvaPtr(ImportTableRva, IntPtr))
559557
return EC;
560-
if (Error E = checkOffset(Data, IntPtr, DataEntry->Size))
561-
return errorToErrorCode(std::move(E));
558+
if (std::error_code EC = checkOffset(Data, IntPtr, DataEntry->Size))
559+
return EC;
562560
ImportDirectory = reinterpret_cast<
563561
const coff_import_directory_table_entry *>(IntPtr);
564562
return std::error_code();
@@ -1095,8 +1093,8 @@ Error COFFObjectFile::getSectionContents(const coff_section *Sec,
10951093
// data, as there's nothing that says that is not allowed.
10961094
uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
10971095
uint32_t SectionSize = getSectionSize(Sec);
1098-
if (Error E = checkOffset(Data, ConStart, SectionSize))
1099-
return E;
1096+
if (checkOffset(Data, ConStart, SectionSize))
1097+
return make_error<BinaryError>();
11001098
Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize);
11011099
return Error::success();
11021100
}

llvm/lib/Object/XCOFFObjectFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ template <typename T>
2929
static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr,
3030
const uint64_t Size = sizeof(T)) {
3131
uintptr_t Addr = uintptr_t(Ptr);
32-
if (Error E = Binary::checkOffset(M, Addr, Size))
33-
return std::move(E);
32+
if (std::error_code EC = Binary::checkOffset(M, Addr, Size))
33+
return errorCodeToError(EC);
3434
return reinterpret_cast<const T *>(Addr);
3535
}
3636

0 commit comments

Comments
 (0)