diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-24 21:32:21 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-24 21:32:21 +0000 |
commit | 584fe2db6ad04974b569da2d90860cc2b75c025b (patch) | |
tree | db2c62aeccda78b0669885a72340980b44065b53 /include | |
parent | 0078935812a53b12d257b94343ea20e78e6c9130 (diff) | |
download | llvm-584fe2db6ad04974b569da2d90860cc2b75c025b.tar.gz llvm-584fe2db6ad04974b569da2d90860cc2b75c025b.tar.bz2 llvm-584fe2db6ad04974b569da2d90860cc2b75c025b.tar.xz |
Make ObjectFile ownership of the MemoryBuffer optional.
This allows llvm-ar to mmap the input files only once.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200040 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Object/Binary.h | 3 | ||||
-rw-r--r-- | include/llvm/Object/COFF.h | 2 | ||||
-rw-r--r-- | include/llvm/Object/ELFObjectFile.h | 7 | ||||
-rw-r--r-- | include/llvm/Object/MachO.h | 2 | ||||
-rw-r--r-- | include/llvm/Object/ObjectFile.h | 13 |
5 files changed, 16 insertions, 11 deletions
diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index 7742f83cd0..420cc9bba8 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -31,11 +31,12 @@ private: Binary(const Binary &other) LLVM_DELETED_FUNCTION; unsigned int TypeID; + bool BufferOwned; protected: MemoryBuffer *Data; - Binary(unsigned int Type, MemoryBuffer *Source); + Binary(unsigned int Type, MemoryBuffer *Source, bool BufferOwned = true); enum { ID_Archive, diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 1514f279b4..38ea814ed1 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -320,7 +320,7 @@ protected: StringRef &Result) const; public: - COFFObjectFile(MemoryBuffer *Object, error_code &ec); + COFFObjectFile(MemoryBuffer *Object, error_code &EC, bool BufferOwned = true); virtual symbol_iterator begin_symbols() const; virtual symbol_iterator end_symbols() const; virtual symbol_iterator begin_dynamic_symbols() const; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index a536594ee2..17d2ec7b2f 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -165,7 +165,7 @@ protected: bool isDyldELFObject; public: - ELFObjectFile(MemoryBuffer *Object, error_code &ec); + ELFObjectFile(MemoryBuffer *Object, error_code &EC, bool BufferOwned = true); const Elf_Sym *getSymbol(DataRefImpl Symb) const; @@ -813,11 +813,12 @@ ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const { } template <class ELFT> -ELFObjectFile<ELFT>::ELFObjectFile(MemoryBuffer *Object, error_code &ec) +ELFObjectFile<ELFT>::ELFObjectFile(MemoryBuffer *Object, error_code &ec, + bool BufferOwned) : ObjectFile(getELFType(static_cast<endianness>(ELFT::TargetEndianness) == support::little, ELFT::Is64Bits), - Object), + Object, BufferOwned), EF(Object, ec) {} template <class ELFT> diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 100613ac8c..98c36b07bd 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -57,7 +57,7 @@ public: }; MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits, - error_code &ec); + error_code &EC, bool BufferOwned = true); virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const; virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const; diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 77833cbf94..806de34e76 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -270,7 +270,7 @@ class ObjectFile : public Binary { ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION; protected: - ObjectFile(unsigned int Type, MemoryBuffer *source); + ObjectFile(unsigned int Type, MemoryBuffer *Source, bool BufferOwned = true); const uint8_t *base() const { return reinterpret_cast<const uint8_t *>(Data->getBufferStart()); @@ -379,7 +379,7 @@ public: /// @brief Create ObjectFile from path. static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath); static ErrorOr<ObjectFile *> - createObjectFile(MemoryBuffer *Object, + createObjectFile(MemoryBuffer *Object, bool BufferOwned = true, sys::fs::file_magic Type = sys::fs::file_magic::unknown); static inline bool classof(const Binary *v) { @@ -387,9 +387,12 @@ public: } public: - static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object); - static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object); - static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object); + static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object, + bool BufferOwned = true); + static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object, + bool BufferOwned = true); + static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object, + bool BufferOwned = true); }; // Inline function definitions. |