From 044eb2f6afba375a914ac9d8024f8f5142bb912e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:10:56 +0000 Subject: Vendor import of llvm trunk r321017: https://llvm.org/svn/llvm-project/llvm/trunk@321017 --- lib/Object/COFFObjectFile.cpp | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'lib/Object/COFFObjectFile.cpp') diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 0a2053477caf1..b544fa5c14702 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -52,16 +52,6 @@ static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size) { return true; } -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 object_error::unexpected_eof; - } - return std::error_code(); -} - // Sets Obj unless any bytes in [addr, addr + size) fall outsize of m. // Returns unexpected_eof if error. template @@ -69,7 +59,7 @@ 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 = checkOffset(M, Addr, Size)) + if (std::error_code EC = Binary::checkOffset(M, Addr, Size)) return EC; Obj = reinterpret_cast(Addr); return std::error_code(); @@ -383,7 +373,8 @@ getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) { // relocations. begin++; } - if (checkOffset(M, uintptr_t(begin), sizeof(coff_relocation) * NumRelocs)) + if (Binary::checkOffset(M, uintptr_t(begin), + sizeof(coff_relocation) * NumRelocs)) return nullptr; return begin; } @@ -904,7 +895,7 @@ StringRef COFFObjectFile::getFileFormatName() const { } } -unsigned COFFObjectFile::getArch() const { +Triple::ArchType COFFObjectFile::getArch() const { switch (getMachine()) { case COFF::IMAGE_FILE_MACHINE_I386: return Triple::x86; @@ -1599,12 +1590,12 @@ std::error_code ImportedSymbolRef::getOrdinal(uint16_t &Result) const { return std::error_code(); } -ErrorOr> +Expected> ObjectFile::createCOFFObjectFile(MemoryBufferRef Object) { std::error_code EC; std::unique_ptr Ret(new COFFObjectFile(Object, EC)); if (EC) - return EC; + return errorCodeToError(EC); return std::move(Ret); } @@ -1642,11 +1633,12 @@ std::error_code BaseRelocRef::getRVA(uint32_t &Result) const { return std::error_code(); } -#define RETURN_IF_ERROR(X) \ - if (auto EC = errorToErrorCode(X)) \ - return EC; +#define RETURN_IF_ERROR(E) \ + if (E) \ + return E; -ErrorOr> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) { +Expected> +ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) { BinaryStreamReader Reader = BinaryStreamReader(BBS); Reader.setOffset(Offset); uint16_t Length; @@ -1656,12 +1648,12 @@ ErrorOr> ResourceSectionRef::getDirStringAtOffset(uint32_t Offse return RawDirString; } -ErrorOr> +Expected> ResourceSectionRef::getEntryNameString(const coff_resource_dir_entry &Entry) { return getDirStringAtOffset(Entry.Identifier.getNameOffset()); } -ErrorOr +Expected ResourceSectionRef::getTableAtOffset(uint32_t Offset) { const coff_resource_dir_table *Table = nullptr; @@ -1672,11 +1664,11 @@ ResourceSectionRef::getTableAtOffset(uint32_t Offset) { return *Table; } -ErrorOr +Expected ResourceSectionRef::getEntrySubDir(const coff_resource_dir_entry &Entry) { return getTableAtOffset(Entry.Offset.value()); } -ErrorOr ResourceSectionRef::getBaseTable() { +Expected ResourceSectionRef::getBaseTable() { return getTableAtOffset(0); } -- cgit v1.2.3