summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Object/ObjectFile.h4
-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
-rw-r--r--tools/lli/lli.cpp6
-rw-r--r--tools/llvm-ar/llvm-ar.cpp6
-rw-r--r--tools/llvm-dwarfdump/llvm-dwarfdump.cpp7
8 files changed, 31 insertions, 27 deletions
diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h
index 5ffa4293fbb..4aa1e066763 100644
--- a/include/llvm/Object/ObjectFile.h
+++ b/include/llvm/Object/ObjectFile.h
@@ -376,8 +376,8 @@ public:
/// @param ObjectPath The path to the object file. ObjectPath.isObject must
/// return true.
/// @brief Create ObjectFile from path.
- static ObjectFile *createObjectFile(StringRef ObjectPath);
- static ObjectFile *createObjectFile(MemoryBuffer *Object);
+ static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
+ static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object);
static inline bool classof(const Binary *v) {
return v->isObject();
diff --git a/lib/DebugInfo/DWARFUnit.cpp b/lib/DebugInfo/DWARFUnit.cpp
index 5167eb947c4..732fb82e73e 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 7666a869d6a..2056f39b5ac 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 1edc2171787..e454d8eec79 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 2397f4b515d..fd2b024687c 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());
}
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 8e6669221bf..2ee79793012 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -527,13 +527,13 @@ int main(int argc, char **argv, char * const *envp) {
}
for (unsigned i = 0, e = ExtraObjects.size(); i != e; ++i) {
- object::ObjectFile *Obj = object::ObjectFile::createObjectFile(
- ExtraObjects[i]);
+ ErrorOr<object::ObjectFile *> Obj =
+ object::ObjectFile::createObjectFile(ExtraObjects[i]);
if (!Obj) {
Err.print(argv[0], errs());
return 1;
}
- EE->addObjectFile(Obj);
+ EE->addObjectFile(Obj.get());
}
for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) {
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index 18f87760205..d4fe7d789c8 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -670,7 +670,11 @@ static void writeSymbolTable(
object::ObjectFile *Obj;
if (I->isNewMember()) {
const char *Filename = I->getNew();
- Obj = object::ObjectFile::createObjectFile(Filename);
+ if (ErrorOr<object::ObjectFile *> ObjOrErr =
+ object::ObjectFile::createObjectFile(Filename))
+ Obj = ObjOrErr.get();
+ else
+ Obj = NULL;
} else {
object::Archive::child_iterator OldMember = I->getOld();
OwningPtr<object::Binary> Binary;
diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 7c6cc68fb9f..f827909dc31 100644
--- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -93,11 +93,12 @@ static void DumpInput(const StringRef &Filename) {
return;
}
- OwningPtr<ObjectFile> Obj(ObjectFile::createObjectFile(Buff.take()));
- if (!Obj) {
- errs() << Filename << ": Unknown object file format\n";
+ ErrorOr<ObjectFile*> ObjOrErr(ObjectFile::createObjectFile(Buff.take()));
+ if (error_code EC = ObjOrErr.getError()) {
+ errs() << Filename << ": " << EC.message() << '\n';
return;
}
+ OwningPtr<ObjectFile> Obj(ObjOrErr.get());
OwningPtr<DIContext> DICtx(DIContext::getDWARFContext(Obj.get()));