From: Rui Ueyama Date: Fri, 12 Dec 2014 10:27:33 +0000 (+0000) Subject: Make File always take the ownership of a MemoryBuffer. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=961f43fb70f65a2697f67c6857587608a888e6cb;p=platform%2Fupstream%2Fllvm.git Make File always take the ownership of a MemoryBuffer. The documentation of parseFile() said that "the resulting File object may take ownership of the MemoryBuffer." So, whether or not the ownership of a MemoryBuffer would be taken was not clear. A FileNode (a subclass of InputElement, which is being deprecated) keeps the ownership if a File doesn't take it. This patch makes File always take the ownership of a buffer. Buffers lifespan is not always the same as File instances. Files are able to deallocate buffers after parsing the contents. llvm-svn: 224113 --- diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h index 321956b..04e6c5c 100644 --- a/lld/include/lld/Core/File.h +++ b/lld/include/lld/Core/File.h @@ -19,6 +19,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/Support/ErrorHandling.h" #include +#include #include namespace lld { @@ -170,6 +171,15 @@ public: return _lastError.getValue(); } + // Usually each file owns a std::unique_ptr. + // However, there's one special case. If a file is an archive file, + // the archive file and its children all shares the same memory buffer. + // This method is used by the ArchiveFile to give its children + // co-ownership of the buffer. + void setSharedMemoryBuffer(std::shared_ptr mb) { + _sharedMemoryBuffer = mb; + } + protected: /// \brief only subclasses of File can be instantiated File(StringRef p, Kind kind) @@ -236,6 +246,7 @@ private: StringRef _path; Kind _kind; mutable uint64_t _ordinal; + std::shared_ptr _sharedMemoryBuffer; }; /// \brief A mutable File. diff --git a/lld/include/lld/Core/InputGraph.h b/lld/include/lld/Core/InputGraph.h index 3275b96..cf59693 100644 --- a/lld/include/lld/Core/InputGraph.h +++ b/lld/include/lld/Core/InputGraph.h @@ -214,12 +214,8 @@ public: bool getReplacements(InputGraph::InputElementVectorT &result) override; protected: - /// \brief Read the file into _buffer. - std::error_code getBuffer(StringRef filePath); - StringRef _path; // The path of the Input file InputGraph::FileVectorT _files; // A vector of lld File objects - std::unique_ptr _buffer; // Memory buffer to actual contents // The next file that would be processed by the resolver uint32_t _nextFileIndex; diff --git a/lld/include/lld/Driver/CoreInputGraph.h b/lld/include/lld/Driver/CoreInputGraph.h index abce9b9..a68b01a 100644 --- a/lld/include/lld/Driver/CoreInputGraph.h +++ b/lld/include/lld/Driver/CoreInputGraph.h @@ -44,8 +44,7 @@ public: if (std::error_code ec = mb.getError()) return ec; - _buffer = std::move(mb.get()); - return ctx.registry().parseFile(_buffer, _files); + return ctx.registry().parseFile(std::move(mb.get()), _files); } /// \brief Return the file that has to be processed by the resolver diff --git a/lld/include/lld/Driver/DarwinInputGraph.h b/lld/include/lld/Driver/DarwinInputGraph.h index 8c57ec5..b2b8cab 100644 --- a/lld/include/lld/Driver/DarwinInputGraph.h +++ b/lld/include/lld/Driver/DarwinInputGraph.h @@ -53,7 +53,7 @@ public: } private: - void narrowFatBuffer(StringRef filePath); + void narrowFatBuffer(std::unique_ptr &mb, StringRef filePath); MachOLinkingContext &_context; std::unique_ptr _archiveFile; diff --git a/lld/include/lld/ReaderWriter/Reader.h b/lld/include/lld/ReaderWriter/Reader.h index 35c0ebd..ab43a06 100644 --- a/lld/include/lld/ReaderWriter/Reader.h +++ b/lld/include/lld/ReaderWriter/Reader.h @@ -53,10 +53,9 @@ public: /// \brief Parse a supplied buffer (already filled with the contents of a /// file) and create a File object. - /// - /// The resulting File object may take ownership of the MemoryBuffer. + /// The resulting File object takes ownership of the MemoryBuffer. virtual std::error_code - parseFile(std::unique_ptr &mb, const class Registry &, + parseFile(std::unique_ptr mb, const class Registry &, std::vector> &result) const = 0; }; @@ -94,7 +93,7 @@ public: /// Walk the list of registered Readers and find one that can parse the /// supplied file and parse it. - std::error_code parseFile(std::unique_ptr &mb, + std::error_code parseFile(std::unique_ptr mb, std::vector> &result) const; /// Walk the list of registered kind tables to convert a Reference Kind diff --git a/lld/lib/Core/InputGraph.cpp b/lld/lib/Core/InputGraph.cpp index cde4127..8a6a646 100644 --- a/lld/lib/Core/InputGraph.cpp +++ b/lld/lib/Core/InputGraph.cpp @@ -94,17 +94,6 @@ void InputGraph::skipGroup() { _nextElementIndex++; } -/// \brief Read the file into _buffer. -std::error_code FileNode::getBuffer(StringRef filePath) { - // Create a memory buffer - ErrorOr> mb = - MemoryBuffer::getFileOrSTDIN(filePath); - if (std::error_code ec = mb.getError()) - return ec; - _buffer = std::move(mb.get()); - return std::error_code(); -} - bool FileNode::getReplacements(InputGraph::InputElementVectorT &result) { if (_files.size() < 2) return false; diff --git a/lld/lib/Driver/DarwinInputGraph.cpp b/lld/lib/Driver/DarwinInputGraph.cpp index 5bfa295..5cfef12 100644 --- a/lld/lib/Driver/DarwinInputGraph.cpp +++ b/lld/lib/Driver/DarwinInputGraph.cpp @@ -24,18 +24,20 @@ std::error_code MachOFileNode::parse(const LinkingContext &ctx, ErrorOr filePath = getPath(ctx); if (std::error_code ec = filePath.getError()) return ec; - - if (std::error_code ec = getBuffer(*filePath)) + ErrorOr> mbOrErr = + MemoryBuffer::getFileOrSTDIN(*filePath); + if (std::error_code ec = mbOrErr.getError()) return ec; + std::unique_ptr mb = std::move(mbOrErr.get()); _context.addInputFileDependency(*filePath); if (ctx.logInputFiles()) diagnostics << *filePath << "\n"; - narrowFatBuffer(*filePath); + narrowFatBuffer(mb, *filePath); std::vector> parsedFiles; - if (std::error_code ec = ctx.registry().parseFile(_buffer, parsedFiles)) + if (std::error_code ec = ctx.registry().parseFile(std::move(mb), parsedFiles)) return ec; for (std::unique_ptr &pf : parsedFiles) { // If file is a dylib, inform LinkingContext about it. @@ -61,19 +63,20 @@ std::error_code MachOFileNode::parse(const LinkingContext &ctx, /// If buffer contains a fat file, find required arch in fat buffer and /// switch buffer to point to just that required slice. -void MachOFileNode::narrowFatBuffer(StringRef filePath) { +void MachOFileNode::narrowFatBuffer(std::unique_ptr &mb, + StringRef filePath) { // Check if buffer is a "fat" file that contains needed arch. uint32_t offset; uint32_t size; - if (!_context.sliceFromFatFile(*_buffer, offset, size)) { + if (!_context.sliceFromFatFile(*mb, offset, size)) { return; } // Create new buffer containing just the needed slice. auto subuf = MemoryBuffer::getFileSlice(filePath, size, offset); if (subuf.getError()) return; - // The assignment to _buffer will release previous buffer. - _buffer = std::move(subuf.get()); + // The assignment to mb will release previous buffer. + mb = std::move(subuf.get()); } diff --git a/lld/lib/Driver/GnuLdInputGraph.cpp b/lld/lib/Driver/GnuLdInputGraph.cpp index f1a0922..0475521 100644 --- a/lld/lib/Driver/GnuLdInputGraph.cpp +++ b/lld/lib/Driver/GnuLdInputGraph.cpp @@ -20,14 +20,17 @@ std::error_code ELFFileNode::parse(const LinkingContext &ctx, ErrorOr filePath = getPath(ctx); if (std::error_code ec = filePath.getError()) return ec; - if (std::error_code ec = getBuffer(*filePath)) + ErrorOr> mb = + MemoryBuffer::getFileOrSTDIN(*filePath); + if (std::error_code ec = mb.getError()) return ec; if (ctx.logInputFiles()) diagnostics << *filePath << "\n"; if (_attributes._isWholeArchive) { std::vector> parsedFiles; - if (std::error_code ec = ctx.registry().parseFile(_buffer, parsedFiles)) + if (std::error_code ec = ctx.registry().parseFile( + std::move(mb.get()), parsedFiles)) return ec; assert(parsedFiles.size() == 1); std::unique_ptr f(parsedFiles[0].release()); @@ -42,7 +45,7 @@ std::error_code ELFFileNode::parse(const LinkingContext &ctx, _files.push_back(std::move(f)); return std::error_code(); } - return ctx.registry().parseFile(_buffer, _files); + return ctx.registry().parseFile(std::move(mb.get()), _files); } /// \brief Parse the GnuLD Script @@ -51,13 +54,15 @@ std::error_code GNULdScript::parse(const LinkingContext &ctx, ErrorOr filePath = getPath(ctx); if (std::error_code ec = filePath.getError()) return ec; - if (std::error_code ec = getBuffer(*filePath)) + ErrorOr> mb = + MemoryBuffer::getFileOrSTDIN(*filePath); + if (std::error_code ec = mb.getError()) return ec; if (ctx.logInputFiles()) diagnostics << *filePath << "\n"; - _lexer.reset(new script::Lexer(std::move(_buffer))); + _lexer.reset(new script::Lexer(std::move(mb.get()))); _parser.reset(new script::Parser(*_lexer.get())); _linkerScript = _parser->parse(); diff --git a/lld/lib/Driver/WinLinkInputGraph.cpp b/lld/lib/Driver/WinLinkInputGraph.cpp index 8696c8f..e5a2733 100644 --- a/lld/lib/Driver/WinLinkInputGraph.cpp +++ b/lld/lib/Driver/WinLinkInputGraph.cpp @@ -27,7 +27,9 @@ std::error_code PECOFFFileNode::parse(const LinkingContext &ctx, return ec; } - if (std::error_code ec = getBuffer(*filePath)) { + ErrorOr> mb = + MemoryBuffer::getFileOrSTDIN(*filePath); + if (std::error_code ec = mb.getError()) { diagnostics << "Cannot open file: " << *filePath << "\n"; return ec; } @@ -35,7 +37,7 @@ std::error_code PECOFFFileNode::parse(const LinkingContext &ctx, if (ctx.logInputFiles()) diagnostics << *filePath << "\n"; - return ctx.registry().parseFile(_buffer, _files); + return ctx.registry().parseFile(std::move(mb.get()), _files); } ErrorOr PECOFFFileNode::getNextFile() { diff --git a/lld/lib/Passes/RoundTripNativePass.cpp b/lld/lib/Passes/RoundTripNativePass.cpp index 96f3cf5..b828fde 100644 --- a/lld/lib/Passes/RoundTripNativePass.cpp +++ b/lld/lib/Passes/RoundTripNativePass.cpp @@ -40,7 +40,8 @@ void RoundTripNativePass::perform(std::unique_ptr &mergedFile) { if (!mb) return; - std::error_code ec = _context.registry().parseFile(mb.get(), _nativeFile); + std::error_code ec = _context.registry().parseFile( + std::move(mb.get()), _nativeFile); if (ec) { // Note: we need a way for Passes to report errors. llvm_unreachable("native reader not registered or read error"); diff --git a/lld/lib/Passes/RoundTripYAMLPass.cpp b/lld/lib/Passes/RoundTripYAMLPass.cpp index 7aab824..8dd9299 100644 --- a/lld/lib/Passes/RoundTripYAMLPass.cpp +++ b/lld/lib/Passes/RoundTripYAMLPass.cpp @@ -40,7 +40,8 @@ void RoundTripYAMLPass::perform(std::unique_ptr &mergedFile) { if (!mb) return; - std::error_code ec = _context.registry().parseFile(mb.get(), _yamlFile); + std::error_code ec = _context.registry().parseFile( + std::move(mb.get()), _yamlFile); if (ec) { // Note: we need a way for Passes to report errors. llvm_unreachable("yaml reader not registered or read error"); diff --git a/lld/lib/ReaderWriter/ELF/ELFReader.h b/lld/lib/ReaderWriter/ELF/ELFReader.h index 1b1dea1..881cd40 100644 --- a/lld/lib/ReaderWriter/ELF/ELFReader.h +++ b/lld/lib/ReaderWriter/ELF/ELFReader.h @@ -33,7 +33,7 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const class Registry &, + parseFile(std::unique_ptr mb, const class Registry &, std::vector> &result) const override { std::size_t maxAlignment = 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); @@ -72,7 +72,7 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const class Registry &, + parseFile(std::unique_ptr mb, const class Registry &, std::vector> &result) const override { std::size_t maxAlignment = 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFReader.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFReader.h index 7ccc812..aeb424d 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFReader.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFReader.h @@ -49,12 +49,12 @@ public: _flagMerger(flagMerger) {} std::error_code - parseFile(std::unique_ptr &mb, const Registry ®istry, + parseFile(std::unique_ptr mb, const Registry ®istry, std::vector> &result) const override { auto &hdr = *elfHeader(*mb); if (std::error_code ec = _flagMerger.merge(hdr.getFileClass(), hdr.e_flags)) return ec; - return BaseReaderType::parseFile(mb, registry, result); + return BaseReaderType::parseFile(std::move(mb), registry, result); } private: @@ -72,12 +72,12 @@ public: _flagMerger(flagMerger) {} std::error_code - parseFile(std::unique_ptr &mb, const Registry ®istry, + parseFile(std::unique_ptr mb, const Registry ®istry, std::vector> &result) const override { auto &hdr = *elfHeader(*mb); if (std::error_code ec = _flagMerger.merge(hdr.getFileClass(), hdr.e_flags)) return ec; - return BaseReaderType::parseFile(mb, registry, result); + return BaseReaderType::parseFile(std::move(mb), registry, result); } private: diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index 20a9a1c0..ffb2d66 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -33,10 +33,10 @@ namespace { /// \brief The FileArchive class represents an Archive Library file class FileArchive : public lld::ArchiveLibraryFile { public: - FileArchive(std::unique_ptr &mb, const Registry ®, + FileArchive(std::unique_ptr mb, const Registry ®, StringRef path, bool logLoading) - : ArchiveLibraryFile(path), _mb(mb), _registry(reg), - _logLoading(logLoading) {} + : ArchiveLibraryFile(path), _mb(std::shared_ptr(mb.release())), + _registry(reg), _logLoading(logLoading) {} std::error_code doParse() override { // Make Archive object which will be owned by FileArchive object. @@ -153,17 +153,13 @@ private: mb.getBuffer(), memberPath, false)); std::vector> files; - _registry.parseFile(memberMB, files); + _registry.parseFile(std::move(memberMB), files); assert(files.size() == 1); result = std::move(files[0]); - // Note: The object file parsers use getBufferIdentifier() from memberMB - // for the file path. And MemoryBuffer makes its own copy of the path. - // That means when if memberMB is destroyed, the lld:File objects will - // have a dangling reference for their path. To fix that, all the - // MemoryBuffers for the archive members are owned by _memberBuffers. - _memberBuffers.push_back(std::move(memberMB)); - + // The memory buffer is co-owned by the archive file and the children, + // so that the bufffer is deallocated when all the members are destructed. + result->setSharedMemoryBuffer(_mb); return std::error_code(); } @@ -214,7 +210,7 @@ private: typedef std::unordered_map MemberMap; typedef std::set InstantiatedSet; - std::unique_ptr &_mb; + std::shared_ptr _mb; const Registry &_registry; std::unique_ptr _archive; mutable MemberMap _symbolMemberMap; @@ -238,10 +234,11 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const Registry ®, + parseFile(std::unique_ptr mb, const Registry ®, std::vector> &result) const override { + StringRef path = mb->getBufferIdentifier(); std::unique_ptr file( - new FileArchive(mb, reg, mb->getBufferIdentifier(), _logLoading)); + new FileArchive(std::move(mb), reg, path, _logLoading)); result.push_back(std::move(file)); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/MachO/File.h b/lld/lib/ReaderWriter/MachO/File.h index 8d9d451..fdb7d3b 100644 --- a/lld/lib/ReaderWriter/MachO/File.h +++ b/lld/lib/ReaderWriter/MachO/File.h @@ -24,8 +24,8 @@ using lld::mach_o::normalized::Section; class MachOFile : public SimpleFile { public: - MachOFile(MemoryBuffer *mb, MachOLinkingContext *ctx) - : SimpleFile(mb->getBufferIdentifier()), _mb(mb), _ctx(ctx) {} + MachOFile(std::unique_ptr mb, MachOLinkingContext *ctx) + : SimpleFile(mb->getBufferIdentifier()), _mb(std::move(mb)), _ctx(ctx) {} MachOFile(StringRef path) : SimpleFile(path) {} @@ -177,9 +177,7 @@ public: std::error_code doParse() override { // Convert binary file to normalized mach-o. - std::unique_ptrmb(_mb); - auto normFile = normalized::readBinary(mb, _ctx->arch()); - mb.release(); + auto normFile = normalized::readBinary(_mb, _ctx->arch()); if (std::error_code ec = normFile.getError()) return ec; // Convert normalized mach-o to atoms. @@ -206,16 +204,17 @@ private: std::vector> SectionToAtoms; typedef llvm::StringMap NameToAtom; - MemoryBuffer *_mb; - MachOLinkingContext *_ctx; - SectionToAtoms _sectionAtoms; - NameToAtom _undefAtoms; + std::unique_ptr _mb; + MachOLinkingContext *_ctx; + SectionToAtoms _sectionAtoms; + NameToAtom _undefAtoms; }; class MachODylibFile : public SharedLibraryFile { public: - MachODylibFile(MemoryBuffer *mb, MachOLinkingContext *ctx) - : SharedLibraryFile(mb->getBufferIdentifier()), _mb(mb), _ctx(ctx) {} + MachODylibFile(std::unique_ptr mb, MachOLinkingContext *ctx) + : SharedLibraryFile(mb->getBufferIdentifier()), + _mb(std::move(mb)), _ctx(ctx) {} MachODylibFile(StringRef path) : SharedLibraryFile(path) {} @@ -275,9 +274,7 @@ public: std::error_code doParse() override { // Convert binary file to normalized mach-o. - std::unique_ptrmb(_mb); - auto normFile = normalized::readBinary(mb, _ctx->arch()); - mb.release(); + auto normFile = normalized::readBinary(_mb, _ctx->arch()); if (std::error_code ec = normFile.getError()) return ec; // Convert normalized mach-o to atoms. @@ -328,7 +325,7 @@ private: bool weakDef; }; - MemoryBuffer *_mb; + std::unique_ptr _mb; MachOLinkingContext *_ctx; StringRef _installName; uint32_t _currentVersion; diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 0b3f76c..89c6213 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -520,9 +520,9 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const Registry ®istry, + parseFile(std::unique_ptr mb, const Registry ®istry, std::vector> &result) const override { - auto *file = new MachOFile(mb.get(), &_ctx); + auto *file = new MachOFile(std::move(mb), &_ctx); result.push_back(std::unique_ptr(file)); return std::error_code(); } @@ -547,9 +547,9 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const Registry ®istry, + parseFile(std::unique_ptr mb, const Registry ®istry, std::vector> &result) const override { - auto *file = new MachODylibFile(mb.get(), &_ctx); + auto *file = new MachODylibFile(std::move(mb), &_ctx); result.push_back(std::unique_ptr(file)); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index c29fc45..c6932e6 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -999,7 +999,7 @@ public: } virtual std::error_code - parseFile(std::unique_ptr &mb, const class Registry &, + parseFile(std::unique_ptr mb, const class Registry &, std::vector> &result) const override { auto *file = new lld::native::File(std::move(mb)); result.push_back(std::unique_ptr(file)); diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index 6a908a7..e6b0a74 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -1074,7 +1074,7 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const Registry &, + parseFile(std::unique_ptr mb, const Registry &, std::vector> &result) const override { // Parse the memory buffer as PECOFF file. auto *file = new FileCOFF(std::move(mb), _ctx); diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp index e511ef2..6c80a14 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp @@ -325,7 +325,7 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const class Registry &, + parseFile(std::unique_ptr mb, const class Registry &, std::vector > &result) const override { auto *file = new FileImportLibrary(std::move(mb), _machine); result.push_back(std::unique_ptr(file)); diff --git a/lld/lib/ReaderWriter/Reader.cpp b/lld/lib/ReaderWriter/Reader.cpp index a730d0d..8cbaae1 100644 --- a/lld/lib/ReaderWriter/Reader.cpp +++ b/lld/lib/ReaderWriter/Reader.cpp @@ -30,7 +30,7 @@ void Registry::add(std::unique_ptr handler) { } std::error_code -Registry::parseFile(std::unique_ptr &mb, +Registry::parseFile(std::unique_ptr mb, std::vector> &result) const { // Get file type. StringRef content(mb->getBufferStart(), mb->getBufferSize()); @@ -42,7 +42,7 @@ Registry::parseFile(std::unique_ptr &mb, for (const std::unique_ptr &reader : _readers) { if (!reader->canParse(fileType, extension, *mb)) continue; - if (std::error_code ec = reader->parseFile(mb, *this, result)) + if (std::error_code ec = reader->parseFile(std::move(mb), *this, result)) return ec; for (std::unique_ptr &file : result) if (std::error_code ec = file->parse()) diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 3b03cdc..646e58c 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -1325,14 +1325,12 @@ public: } std::error_code - parseFile(std::unique_ptr &mb, const class Registry &, + parseFile(std::unique_ptr mb, const class Registry &, std::vector> &result) const override { - // Note: we do not take ownership of the MemoryBuffer. That is - // because yaml may produce multiple File objects, so there is no - // *one* File to take ownership. Therefore, the yaml File objects - // produced must make copies of all strings that come from YAML I/O. - // Otherwise the strings will become invalid when this MemoryBuffer - // is deallocated. + // Note: we do not store the unique pointer to the MemoryBuffer, + // so the buffer will be deallocated at end of this function. + // That's OK since the YAML file contents are parsed and consumed + // in this function. // Create YAML Input Reader. YamlContext yamlContext;