diff options
| author | Simon Atanasyan <simon@atanasyan.com> | 2015-04-08 09:19:45 +0000 |
|---|---|---|
| committer | Simon Atanasyan <simon@atanasyan.com> | 2015-04-08 09:19:45 +0000 |
| commit | 8e951ce3923320de7accd5c7c4d85d9c7ff18a3e (patch) | |
| tree | 01606182a5e33b56253716031b3ee0873e20dbfd | |
| parent | 34ec863b1cefcf15b1ad864f025202cbecbc0960 (diff) | |
| download | bcm5719-llvm-8e951ce3923320de7accd5c7c4d85d9c7ff18a3e.tar.gz bcm5719-llvm-8e951ce3923320de7accd5c7c4d85d9c7ff18a3e.zip | |
[ELF] Do not save a reference to GOTFile instance in xxxWriter classes
It's a follow-up to r234347. We do not need to keep a reference to
`GOTFile` instance in a xxxWriter class after ownership is transferred
to the caller of the `createImplicitFiles` method.
llvm-svn: 234396
5 files changed, 25 insertions, 31 deletions
diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h index b5e745de7e5..cb97d342077 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h @@ -32,22 +32,21 @@ private: GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {} llvm::BumpPtrAllocator _alloc; }; - - std::unique_ptr<GOTFile> _gotFile; }; template <class ELFT> AArch64DynamicLibraryWriter<ELFT>::AArch64DynamicLibraryWriter( AArch64LinkingContext &ctx, TargetLayout<ELFT> &layout) - : DynamicLibraryWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : DynamicLibraryWriter<ELFT>(ctx, layout) {} template <class ELFT> void AArch64DynamicLibraryWriter<ELFT>::createImplicitFiles( std::vector<std::unique_ptr<File>> &result) { DynamicLibraryWriter<ELFT>::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile)); - _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile)); - result.push_back(std::move(_gotFile)); + auto gotFile = llvm::make_unique<GOTFile>(this->_ctx); + gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile)); + gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile)); + result.push_back(std::move(gotFile)); } } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h index 4ad85656d02..1ef3aa85599 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h @@ -31,23 +31,22 @@ private: GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {} llvm::BumpPtrAllocator _alloc; }; - - std::unique_ptr<GOTFile> _gotFile; }; template <class ELFT> AArch64ExecutableWriter<ELFT>::AArch64ExecutableWriter( AArch64LinkingContext &ctx, TargetLayout<ELFT> &layout) - : ExecutableWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : ExecutableWriter<ELFT>(ctx, layout) {} template <class ELFT> void AArch64ExecutableWriter<ELFT>::createImplicitFiles( std::vector<std::unique_ptr<File>> &result) { ExecutableWriter<ELFT>::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile)); + auto gotFile = llvm::make_unique<GOTFile>(this->_ctx); + gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile)); if (this->_ctx.isDynamic()) - _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile)); - result.push_back(std::move(_gotFile)); + gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile)); + result.push_back(std::move(gotFile)); } } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h index 4f6642d398c..09f0eaf7bc7 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h @@ -30,22 +30,21 @@ private: GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {} llvm::BumpPtrAllocator _alloc; }; - - std::unique_ptr<GOTFile> _gotFile; }; template <class ELFT> X86DynamicLibraryWriter<ELFT>::X86DynamicLibraryWriter( X86LinkingContext &ctx, TargetLayout<ELFT> &layout) - : DynamicLibraryWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : DynamicLibraryWriter<ELFT>(ctx, layout) {} template <class ELFT> void X86DynamicLibraryWriter<ELFT>::createImplicitFiles( std::vector<std::unique_ptr<File>> &result) { DynamicLibraryWriter<ELFT>::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile)); - _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile)); - result.push_back(std::move(_gotFile)); + auto gotFile = llvm::make_unique<GOTFile>(this->_ctx); + gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile)); + gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile)); + result.push_back(std::move(gotFile)); } } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h index ba18396bde2..b67b7f04d2c 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h @@ -32,20 +32,19 @@ private: GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {} llvm::BumpPtrAllocator _alloc; }; - - std::unique_ptr<GOTFile> _gotFile; }; X86_64DynamicLibraryWriter::X86_64DynamicLibraryWriter( X86_64LinkingContext &ctx, X86_64TargetLayout &layout) - : DynamicLibraryWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : DynamicLibraryWriter(ctx, layout) {} void X86_64DynamicLibraryWriter::createImplicitFiles( std::vector<std::unique_ptr<File>> &result) { DynamicLibraryWriter::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile)); - _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile)); - result.push_back(std::move(_gotFile)); + auto gotFile = llvm::make_unique<GOTFile>(this->_ctx); + gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile)); + gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile)); + result.push_back(std::move(gotFile)); } } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h index 6f398595a52..79fdee54ed5 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h @@ -19,18 +19,18 @@ namespace elf { class X86_64ExecutableWriter : public ExecutableWriter<X86_64ELFType> { public: X86_64ExecutableWriter(X86_64LinkingContext &ctx, X86_64TargetLayout &layout) - : ExecutableWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : ExecutableWriter(ctx, layout) {} protected: // Add any runtime files and their atoms to the output void createImplicitFiles(std::vector<std::unique_ptr<File>> &result) override { ExecutableWriter::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) - GlobalOffsetTableAtom(*_gotFile)); + auto gotFile = llvm::make_unique<GOTFile>(this->_ctx); + gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile)); if (this->_ctx.isDynamic()) - _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile)); - result.push_back(std::move(_gotFile)); + gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile)); + result.push_back(std::move(gotFile)); } private: @@ -39,8 +39,6 @@ private: GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {} llvm::BumpPtrAllocator _alloc; }; - - std::unique_ptr<GOTFile> _gotFile; }; } // namespace elf |

