From a076ec54bee20c423cf710ea2818d01df84e28b0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 16 May 2019 11:33:48 +0000 Subject: [Object] Change object::SectionRef::getContents() to return Expected Expected> may be better but use Expected for now. Follow-up of D61781. llvm-svn: 360876 --- llvm/lib/Object/ELFObjectFile.cpp | 11 ++++++----- llvm/lib/Object/IRObjectFile.cpp | 10 +++++----- llvm/lib/Object/Object.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'llvm/lib/Object') diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp index cc1eeefec26..c0ac7a357f8 100644 --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/lib/Object/ELFObjectFile.cpp @@ -377,12 +377,13 @@ ELFObjectFileBase::getPltAddresses() const { } if (!Plt || !RelaPlt || !GotPlt) return {}; - StringRef PltContents; - if (Plt->getContents(PltContents)) + Expected PltContents = Plt->getContents(); + if (!PltContents) { + consumeError(PltContents.takeError()); return {}; - ArrayRef PltBytes((const uint8_t *)PltContents.data(), - Plt->getSize()); - auto PltEntries = MIA->findPltEntries(Plt->getAddress(), PltBytes, + } + auto PltEntries = MIA->findPltEntries(Plt->getAddress(), + arrayRefFromStringRef(*PltContents), GotPlt->getAddress(), Triple); // Build a map from GOT entry virtual address to PLT entry virtual address. DenseMap GotToPlt; diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp index debe7899bfe..636f1521262 100644 --- a/llvm/lib/Object/IRObjectFile.cpp +++ b/llvm/lib/Object/IRObjectFile.cpp @@ -74,12 +74,12 @@ Expected IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) { for (const SectionRef &Sec : Obj.sections()) { if (Sec.isBitcode()) { - StringRef SecContents; - if (std::error_code EC = Sec.getContents(SecContents)) - return errorCodeToError(EC); - if (SecContents.size() <= 1) + Expected Contents = Sec.getContents(); + if (!Contents) + return Contents.takeError(); + if (Contents->size() <= 1) return errorCodeToError(object_error::bitcode_section_not_found); - return MemoryBufferRef(SecContents, Obj.getFileName()); + return MemoryBufferRef(*Contents, Obj.getFileName()); } } diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index 77e27ec3e8f..e2511b7aed0 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -247,10 +247,10 @@ uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) { } const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) { - StringRef ret; - if (std::error_code ec = (*unwrap(SI))->getContents(ret)) - report_fatal_error(ec.message()); - return ret.data(); + if (Expected E = (*unwrap(SI))->getContents()) + return E->data(); + else + report_fatal_error(E.takeError()); } uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) { -- cgit v1.2.3