summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/ObjectFile.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-06-23 21:53:12 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-06-23 21:53:12 +0000
commitc3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b (patch)
treeda0146a72b490ea2f0dfd25e6f1415e70b094058 /llvm/lib/Object/ObjectFile.cpp
parentd81c48392888bcc62ed8628ee3005a34d151ea96 (diff)
downloadbcm5719-llvm-c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b.tar.gz
bcm5719-llvm-c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b.zip
Make ObjectFile and BitcodeReader always own the MemoryBuffer.
This allows us to just use a std::unique_ptr to store the pointer to the buffer. The flip side is that they have to support releasing the buffer back to the caller. Overall this looks like a more efficient and less brittle api. llvm-svn: 211542
Diffstat (limited to 'llvm/lib/Object/ObjectFile.cpp')
-rw-r--r--llvm/lib/Object/ObjectFile.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp
index 7666ed53c37..738ea5fbb92 100644
--- a/llvm/lib/Object/ObjectFile.cpp
+++ b/llvm/lib/Object/ObjectFile.cpp
@@ -23,9 +23,8 @@ using namespace object;
void ObjectFile::anchor() { }
-ObjectFile::ObjectFile(unsigned int Type, MemoryBuffer *Source,
- bool BufferOwned)
- : SymbolicFile(Type, Source, BufferOwned) {}
+ObjectFile::ObjectFile(unsigned int Type, MemoryBuffer *Source)
+ : SymbolicFile(Type, Source) {}
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const {
@@ -47,7 +46,6 @@ section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
}
ErrorOr<ObjectFile *> ObjectFile::createObjectFile(MemoryBuffer *Object,
- bool BufferOwned,
sys::fs::file_magic Type) {
if (Type == sys::fs::file_magic::unknown)
Type = sys::fs::identify_magic(Object->getBuffer());
@@ -58,14 +56,12 @@ ErrorOr<ObjectFile *> ObjectFile::createObjectFile(MemoryBuffer *Object,
case sys::fs::file_magic::archive:
case sys::fs::file_magic::macho_universal_binary:
case sys::fs::file_magic::windows_resource:
- if (BufferOwned)
- delete Object;
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, BufferOwned);
+ return createELFObjectFile(Object);
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:
@@ -76,11 +72,11 @@ ErrorOr<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, BufferOwned);
+ return createMachOObjectFile(Object);
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, BufferOwned);
+ return createCOFFObjectFile(Object);
}
llvm_unreachable("Unexpected Object File Type");
}
OpenPOWER on IntegriCloud