diff options
Diffstat (limited to 'lld/lib/ReaderWriter/FileArchive.cpp')
| -rw-r--r-- | lld/lib/ReaderWriter/FileArchive.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index a76399e57d0..20a9a1c0b88 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -33,12 +33,22 @@ namespace { /// \brief The FileArchive class represents an Archive Library file class FileArchive : public lld::ArchiveLibraryFile { public: - FileArchive(const Registry ®istry, Archive *archive, StringRef path, - bool isWholeArchive, bool logLoading) - : ArchiveLibraryFile(path), _registry(registry), - _archive(std::move(archive)), _isWholeArchive(isWholeArchive), + FileArchive(std::unique_ptr<MemoryBuffer> &mb, const Registry ®, + StringRef path, bool logLoading) + : ArchiveLibraryFile(path), _mb(mb), _registry(reg), _logLoading(logLoading) {} + std::error_code doParse() override { + // Make Archive object which will be owned by FileArchive object. + std::error_code ec; + _archive.reset(new Archive(_mb->getMemBufferRef(), ec)); + if (ec) + return ec; + if ((ec = buildTableOfContents())) + return ec; + return std::error_code(); + } + virtual ~FileArchive() {} /// \brief Check if any member of the archive contains an Atom with the @@ -204,6 +214,7 @@ private: typedef std::unordered_map<StringRef, Archive::child_iterator> MemberMap; typedef std::set<const char *> InstantiatedSet; + std::unique_ptr<MemoryBuffer> &_mb; const Registry &_registry; std::unique_ptr<Archive> _archive; mutable MemberMap _symbolMemberMap; @@ -229,20 +240,8 @@ public: std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®, std::vector<std::unique_ptr<File>> &result) const override { - MemoryBuffer &buff = *mb; - // Make Archive object which will be owned by FileArchive object. - std::error_code ec; - Archive *archive = new Archive(mb->getMemBufferRef(), ec); - if (ec) - return ec; - StringRef path = buff.getBufferIdentifier(); - // Construct FileArchive object. std::unique_ptr<FileArchive> file( - new FileArchive(reg, archive, path, false, _logLoading)); - ec = file->buildTableOfContents(); - if (ec) - return ec; - + new FileArchive(mb, reg, mb->getBufferIdentifier(), _logLoading)); result.push_back(std::move(file)); return std::error_code(); } |

