summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-10-10 19:14:30 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-10-10 19:14:30 +0000
commit0e3d04a1c6ea336c06ae4d1fa5cd58dfd96870bc (patch)
tree77a961c2c1fce4a9edeb9e8c0eaa0a613aef52b1 /lib/ExecutionEngine
parentde6c3080edac8c3c56a744d3886c9d2afb9b5dae (diff)
Return Expected from createRTDyldELFObject.
No functionality change, it just makes it easier to use Expected in Object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315348 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index bf527f5ca82..57289a125e1 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -133,14 +133,17 @@ public:
};
template <typename ELFT>
-static std::unique_ptr<DyldELFObject<ELFT>>
+static Expected<std::unique_ptr<DyldELFObject<ELFT>>>
createRTDyldELFObject(MemoryBufferRef Buffer, const ObjectFile &SourceObject,
- const LoadedELFObjectInfo &L, std::error_code &ec) {
+ const LoadedELFObjectInfo &L) {
typedef typename ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
typedef typename ELFDataTypeTypedefHelper<ELFT>::value_type addr_type;
+ std::error_code EC;
std::unique_ptr<DyldELFObject<ELFT>> Obj =
- llvm::make_unique<DyldELFObject<ELFT>>(Buffer, ec);
+ llvm::make_unique<DyldELFObject<ELFT>>(Buffer, EC);
+ if (EC)
+ return errorCodeToError(EC);
// Iterate over all sections in the object.
auto SI = SourceObject.section_begin();
@@ -171,27 +174,25 @@ createELFDebugObject(const ObjectFile &Obj, const LoadedELFObjectInfo &L) {
std::unique_ptr<MemoryBuffer> Buffer =
MemoryBuffer::getMemBufferCopy(Obj.getData(), Obj.getFileName());
- std::error_code ec;
-
- std::unique_ptr<ObjectFile> DebugObj;
+ Expected<std::unique_ptr<ObjectFile>> DebugObj(nullptr);
+ handleAllErrors(DebugObj.takeError());
if (Obj.getBytesInAddress() == 4 && Obj.isLittleEndian())
- DebugObj = createRTDyldELFObject<ELF32LE>(Buffer->getMemBufferRef(), Obj, L,
- ec);
+ DebugObj =
+ createRTDyldELFObject<ELF32LE>(Buffer->getMemBufferRef(), Obj, L);
else if (Obj.getBytesInAddress() == 4 && !Obj.isLittleEndian())
- DebugObj = createRTDyldELFObject<ELF32BE>(Buffer->getMemBufferRef(), Obj, L,
- ec);
+ DebugObj =
+ createRTDyldELFObject<ELF32BE>(Buffer->getMemBufferRef(), Obj, L);
else if (Obj.getBytesInAddress() == 8 && !Obj.isLittleEndian())
- DebugObj = createRTDyldELFObject<ELF64BE>(Buffer->getMemBufferRef(), Obj, L,
- ec);
+ DebugObj =
+ createRTDyldELFObject<ELF64BE>(Buffer->getMemBufferRef(), Obj, L);
else if (Obj.getBytesInAddress() == 8 && Obj.isLittleEndian())
- DebugObj = createRTDyldELFObject<ELF64LE>(Buffer->getMemBufferRef(), Obj, L,
- ec);
+ DebugObj =
+ createRTDyldELFObject<ELF64LE>(Buffer->getMemBufferRef(), Obj, L);
else
llvm_unreachable("Unexpected ELF format");
- assert(!ec && "Could not construct copy ELF object file");
-
- return OwningBinary<ObjectFile>(std::move(DebugObj), std::move(Buffer));
+ handleAllErrors(DebugObj.takeError());
+ return OwningBinary<ObjectFile>(std::move(*DebugObj), std::move(Buffer));
}
OwningBinary<ObjectFile>