summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-22 00:14:49 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-22 00:14:49 +0000
commit825fc31bd3a6e7604c4b69f28f32e90b5a882289 (patch)
tree2026366f101c87f4560963d62ecc0138540f31f9 /lib
parent6220c8f960fe287efcfc27f46ab6ad48e5b3c5d2 (diff)
downloadllvm-825fc31bd3a6e7604c4b69f28f32e90b5a882289.tar.gz
llvm-825fc31bd3a6e7604c4b69f28f32e90b5a882289.tar.bz2
llvm-825fc31bd3a6e7604c4b69f28f32e90b5a882289.tar.xz
Change createObjectFile to return an ErrorOr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/DebugInfo/DWARFUnit.cpp4
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h3
-rw-r--r--lib/Object/Object.cpp4
-rw-r--r--lib/Object/ObjectFile.cpp24
4 files changed, 17 insertions, 18 deletions
diff --git a/lib/DebugInfo/DWARFUnit.cpp b/lib/DebugInfo/DWARFUnit.cpp
index 5167eb947c..732fb82e73 100644
--- a/lib/DebugInfo/DWARFUnit.cpp
+++ b/lib/DebugInfo/DWARFUnit.cpp
@@ -263,12 +263,12 @@ bool DWARFUnit::parseDWO() {
sys::path::append(AbsolutePath, CompilationDir);
}
sys::path::append(AbsolutePath, DWOFileName);
- object::ObjectFile *DWOFile =
+ ErrorOr<object::ObjectFile *> DWOFile =
object::ObjectFile::createObjectFile(AbsolutePath);
if (!DWOFile)
return false;
// Reset DWOHolder.
- DWO.reset(new DWOHolder(DWOFile));
+ DWO.reset(new DWOHolder(DWOFile.get()));
DWARFUnit *DWOCU = DWO->getUnit();
// Verify that compile unit in .dwo file is valid.
if (DWOCU == 0 || DWOCU->getDWOId() != getDWOId()) {
diff --git a/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h b/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h
index 7666a869d6..2056f39b5a 100644
--- a/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h
+++ b/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h
@@ -44,7 +44,8 @@ public:
ObjectImageCommon(ObjectBuffer* Input)
: ObjectImage(Input) // saves Input as Buffer and takes ownership
{
- ObjFile = object::ObjectFile::createObjectFile(Buffer->getMemBuffer());
+ ObjFile =
+ object::ObjectFile::createObjectFile(Buffer->getMemBuffer()).get();
}
ObjectImageCommon(object::ObjectFile* Input)
: ObjectImage(NULL), ObjFile(Input) {}
diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp
index 1edc217178..e454d8eec7 100644
--- a/lib/Object/Object.cpp
+++ b/lib/Object/Object.cpp
@@ -59,7 +59,9 @@ wrap(const relocation_iterator *SI) {
// ObjectFile creation
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
- return wrap(ObjectFile::createObjectFile(unwrap(MemBuf)));
+ ErrorOr<ObjectFile*> ObjOrErr(ObjectFile::createObjectFile(unwrap(MemBuf)));
+ ObjectFile *Obj = ObjOrErr ? ObjOrErr.get() : 0;
+ return wrap(Obj);
}
void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile) {
diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp
index 2397f4b515..fd2b024687 100644
--- a/lib/Object/ObjectFile.cpp
+++ b/lib/Object/ObjectFile.cpp
@@ -37,26 +37,22 @@ section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
return section_iterator(SectionRef(Sec, this));
}
-ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
- if (Object->getBufferSize() < 64) {
- delete Object;
- return 0;
- }
-
+ErrorOr<ObjectFile *> ObjectFile::createObjectFile(MemoryBuffer *Object) {
+ OwningPtr<MemoryBuffer> ScopedObj(Object);
sys::fs::file_magic Type = sys::fs::identify_magic(Object->getBuffer());
+
switch (Type) {
case sys::fs::file_magic::unknown:
case sys::fs::file_magic::bitcode:
case sys::fs::file_magic::archive:
case sys::fs::file_magic::macho_universal_binary:
case sys::fs::file_magic::windows_resource:
- delete Object;
- return 0;
+ return object_error::invalid_file_type;
case sys::fs::file_magic::elf_relocatable:
case sys::fs::file_magic::elf_executable:
case sys::fs::file_magic::elf_shared_object:
case sys::fs::file_magic::elf_core:
- return createELFObjectFile(Object).get();
+ return createELFObjectFile(ScopedObj.take());
case sys::fs::file_magic::macho_object:
case sys::fs::file_magic::macho_executable:
case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
@@ -67,18 +63,18 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
case sys::fs::file_magic::macho_bundle:
case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
case sys::fs::file_magic::macho_dsym_companion:
- return createMachOObjectFile(Object).get();
+ return createMachOObjectFile(ScopedObj.take());
case sys::fs::file_magic::coff_object:
case sys::fs::file_magic::coff_import_library:
case sys::fs::file_magic::pecoff_executable:
- return createCOFFObjectFile(Object).get();
+ return createCOFFObjectFile(ScopedObj.take());
}
llvm_unreachable("Unexpected Object File Type");
}
-ObjectFile *ObjectFile::createObjectFile(StringRef ObjectPath) {
+ErrorOr<ObjectFile *> ObjectFile::createObjectFile(StringRef ObjectPath) {
OwningPtr<MemoryBuffer> File;
- if (MemoryBuffer::getFile(ObjectPath, File))
- return NULL;
+ if (error_code EC = MemoryBuffer::getFile(ObjectPath, File))
+ return EC;
return createObjectFile(File.take());
}