From 8e951ce3923320de7accd5c7c4d85d9c7ff18a3e Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 8 Apr 2015 09:19:45 +0000 Subject: [PATCH] [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 --- .../ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h | 11 +++++------ lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h | 11 +++++------ lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h | 11 +++++------ lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h | 11 +++++------ lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h | 12 +++++------- 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 b5e745d..cb97d34 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; }; template AArch64DynamicLibraryWriter::AArch64DynamicLibraryWriter( AArch64LinkingContext &ctx, TargetLayout &layout) - : DynamicLibraryWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : DynamicLibraryWriter(ctx, layout) {} template void AArch64DynamicLibraryWriter::createImplicitFiles( std::vector> &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(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 4ad8565..1ef3aa8 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; }; template AArch64ExecutableWriter::AArch64ExecutableWriter( AArch64LinkingContext &ctx, TargetLayout &layout) - : ExecutableWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : ExecutableWriter(ctx, layout) {} template void AArch64ExecutableWriter::createImplicitFiles( std::vector> &result) { ExecutableWriter::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile)); + auto gotFile = llvm::make_unique(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 4f6642d..09f0eaf 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; }; template X86DynamicLibraryWriter::X86DynamicLibraryWriter( X86LinkingContext &ctx, TargetLayout &layout) - : DynamicLibraryWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {} + : DynamicLibraryWriter(ctx, layout) {} template void X86DynamicLibraryWriter::createImplicitFiles( std::vector> &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(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 ba18396..b67b7f0 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; }; 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> &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(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 6f39859..79fdee5 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 { 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> &result) override { ExecutableWriter::createImplicitFiles(result); - _gotFile->addAtom(*new (_gotFile->_alloc) - GlobalOffsetTableAtom(*_gotFile)); + auto gotFile = llvm::make_unique(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; }; } // namespace elf -- 2.7.4