aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-24 21:32:21 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-24 21:32:21 +0000
commitafcc3df7f4db85832b13a6f4d58e24ac9e7ccc43 (patch)
treee608147b8d62c19296d96c7e00de10c220811fe4 /llvm/lib/Object/MachOObjectFile.cpp
parent1b392619907d1b5bed4d8533ea8c0cf7e19c5b48 (diff)
downloadllvm-afcc3df7f4db85832b13a6f4d58e24ac9e7ccc43.zip
llvm-afcc3df7f4db85832b13a6f4d58e24ac9e7ccc43.tar.gz
llvm-afcc3df7f4db85832b13a6f4d58e24ac9e7ccc43.tar.bz2
Make ObjectFile ownership of the MemoryBuffer optional.
This allows llvm-ar to mmap the input files only once. llvm-svn: 200040
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index a930117..2409314 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -419,10 +419,10 @@ static uint32_t getSectionFlags(const MachOObjectFile *O,
return Sect.flags;
}
-MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
- bool IsLittleEndian, bool Is64bits,
- error_code &ec)
- : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object),
+MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian,
+ bool Is64bits, error_code &EC,
+ bool BufferOwned)
+ : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object, BufferOwned),
SymtabLoadCmd(NULL), DysymtabLoadCmd(NULL), DataInCodeLoadCmd(NULL) {
uint32_t LoadCommandCount = this->getHeader().ncmds;
MachO::LoadCommandType SegmentLoadType = is64Bit() ?
@@ -1582,18 +1582,19 @@ void MachOObjectFile::ReadULEB128s(uint64_t Index,
}
}
-ErrorOr<ObjectFile *> ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
+ErrorOr<ObjectFile *> ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer,
+ bool BufferOwned) {
StringRef Magic = Buffer->getBuffer().slice(0, 4);
error_code EC;
OwningPtr<MachOObjectFile> Ret;
if (Magic == "\xFE\xED\xFA\xCE")
- Ret.reset(new MachOObjectFile(Buffer, false, false, EC));
+ Ret.reset(new MachOObjectFile(Buffer, false, false, EC, BufferOwned));
else if (Magic == "\xCE\xFA\xED\xFE")
- Ret.reset(new MachOObjectFile(Buffer, true, false, EC));
+ Ret.reset(new MachOObjectFile(Buffer, true, false, EC, BufferOwned));
else if (Magic == "\xFE\xED\xFA\xCF")
- Ret.reset(new MachOObjectFile(Buffer, false, true, EC));
+ Ret.reset(new MachOObjectFile(Buffer, false, true, EC, BufferOwned));
else if (Magic == "\xCF\xFA\xED\xFE")
- Ret.reset(new MachOObjectFile(Buffer, true, true, EC));
+ Ret.reset(new MachOObjectFile(Buffer, true, true, EC, BufferOwned));
else {
delete Buffer;
return object_error::parse_failed;